10
10
//
11
11
// ===----------------------------------------------------------------------===//
12
12
13
+ #include " LocalizationTest.h"
13
14
#include " swift/Localization/LocalizationFormat.h"
14
15
#include " llvm/ADT/ArrayRef.h"
15
16
#include " llvm/ADT/SmallString.h"
19
20
#include " llvm/Support/Path.h"
20
21
#include " llvm/Support/Signals.h"
21
22
#include " llvm/Support/ToolOutputFile.h"
22
- #include " llvm/Support/YAMLParser.h"
23
- #include " llvm/Support/YAMLTraits.h"
24
23
#include " llvm/Support/raw_ostream.h"
25
24
#include " gtest/gtest.h"
26
25
#include < cstdlib>
30
29
31
30
using namespace swift ;
32
31
using namespace swift ::diag;
33
-
34
- enum LocalDiagID : uint32_t {
35
- #define DIAG (KIND, ID, Options, Text, Signature ) ID,
36
- #include " swift/AST/DiagnosticsAll.def"
37
- NumDiags
38
- };
39
-
40
- static constexpr const char *const diagnosticID[] = {
41
- #define DIAG (KIND, ID, Options, Text, Signature ) #ID,
42
- #include " swift/AST/DiagnosticsAll.def"
43
- };
44
-
45
- static constexpr const char *const diagnosticMessages[] = {
46
- #define DIAG (KIND, ID, Options, Text, Signature ) Text,
47
- #include " swift/AST/DiagnosticsAll.def"
48
- };
32
+ using namespace swift ::unittests;
49
33
50
34
static std::string getMainExecutablePath () {
51
35
llvm::StringRef libPath = llvm::sys::path::parent_path (SWIFTLIB_DIR);
@@ -62,50 +46,7 @@ static std::string getDefaultLocalizationPath() {
62
46
return std::string (DefaultDiagnosticMessagesDir);
63
47
}
64
48
65
- struct DefToYAMLConverterTest : public ::testing::Test {
66
- std::string YAMLPath;
67
-
68
- public:
69
- DefToYAMLConverterTest () {
70
- llvm::SmallString<128 > tempFilename;
71
- std::error_code error =
72
- llvm::sys::fs::createTemporaryFile (" en" , " yaml" , tempFilename);
73
- assert (!error);
74
-
75
- YAMLPath = std::string (tempFilename);
76
- }
77
-
78
- void SetUp () override {
79
- bool failed = convertDefIntoYAML (YAMLPath);
80
- assert (!failed && " failed to generate a YAML file" );
81
- }
82
-
83
- void TearDown () override { llvm::sys::fs::remove (YAMLPath); }
84
-
85
- // / Random number in [0,n)
86
- unsigned RandNumber (unsigned n) { return unsigned (rand ()) % n; }
87
-
88
- protected:
89
- static bool convertDefIntoYAML (std::string outputPath) {
90
- std::error_code error;
91
- llvm::raw_fd_ostream OS (outputPath, error, llvm::sys::fs::F_None);
92
- if (OS.has_error () || error)
93
- return true ;
94
-
95
- llvm::ArrayRef<const char *> ids (diagnosticID, LocalDiagID::NumDiags);
96
- llvm::ArrayRef<const char *> messages (diagnosticMessages,
97
- LocalDiagID::NumDiags);
98
-
99
- DefToYAMLConverter converter (ids, messages);
100
- converter.convert (OS);
101
-
102
- OS.flush ();
103
-
104
- return OS.has_error ();
105
- }
106
- };
107
-
108
- TEST_F (DefToYAMLConverterTest, MissingLocalizationFiles) {
49
+ TEST_F (LocalizationTest, MissingLocalizationFiles) {
109
50
ASSERT_TRUE (llvm::sys::fs::exists (getDefaultLocalizationPath ()));
110
51
llvm::SmallString<128 > EnglishLocalization (getDefaultLocalizationPath ());
111
52
llvm::sys::path::append (EnglishLocalization, " en" );
@@ -115,15 +56,15 @@ TEST_F(DefToYAMLConverterTest, MissingLocalizationFiles) {
115
56
ASSERT_TRUE (llvm::sys::fs::exists (EnglishLocalization));
116
57
}
117
58
118
- TEST_F (DefToYAMLConverterTest, MatchDiagnosticMessagesSequentially ) {
59
+ TEST_F (LocalizationTest, ConverterTestMatchDiagnosticMessagesSequentially ) {
119
60
YAMLLocalizationProducer yaml (YAMLPath);
120
61
yaml.forEachAvailable ([](swift::DiagID id, llvm::StringRef translation) {
121
62
llvm::StringRef msg = diagnosticMessages[static_cast <uint32_t >(id)];
122
63
ASSERT_EQ (msg, translation);
123
64
});
124
65
}
125
66
126
- TEST_F (DefToYAMLConverterTest, MatchDiagnosticMessagesRandomly ) {
67
+ TEST_F (LocalizationTest, ConverterTestMatchDiagnosticMessagesRandomly ) {
127
68
YAMLLocalizationProducer yaml (YAMLPath);
128
69
129
70
std::random_device rd;
0 commit comments