1010//
1111// ===----------------------------------------------------------------------===//
1212
13+ #include " LocalizationTest.h"
1314#include " swift/Localization/LocalizationFormat.h"
1415#include " llvm/ADT/ArrayRef.h"
1516#include " llvm/ADT/SmallString.h"
1920#include " llvm/Support/Path.h"
2021#include " llvm/Support/Signals.h"
2122#include " llvm/Support/ToolOutputFile.h"
22- #include " llvm/Support/YAMLParser.h"
23- #include " llvm/Support/YAMLTraits.h"
2423#include " llvm/Support/raw_ostream.h"
2524#include " gtest/gtest.h"
2625#include < cstdlib>
3029
3130using namespace swift ;
3231using 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;
4933
5034static std::string getMainExecutablePath () {
5135 llvm::StringRef libPath = llvm::sys::path::parent_path (SWIFTLIB_DIR);
@@ -62,50 +46,7 @@ static std::string getDefaultLocalizationPath() {
6246 return std::string (DefaultDiagnosticMessagesDir);
6347}
6448
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) {
10950 ASSERT_TRUE (llvm::sys::fs::exists (getDefaultLocalizationPath ()));
11051 llvm::SmallString<128 > EnglishLocalization (getDefaultLocalizationPath ());
11152 llvm::sys::path::append (EnglishLocalization, " en" );
@@ -115,15 +56,15 @@ TEST_F(DefToYAMLConverterTest, MissingLocalizationFiles) {
11556 ASSERT_TRUE (llvm::sys::fs::exists (EnglishLocalization));
11657}
11758
118- TEST_F (DefToYAMLConverterTest, MatchDiagnosticMessagesSequentially ) {
59+ TEST_F (LocalizationTest, ConverterTestMatchDiagnosticMessagesSequentially ) {
11960 YAMLLocalizationProducer yaml (YAMLPath);
12061 yaml.forEachAvailable ([](swift::DiagID id, llvm::StringRef translation) {
12162 llvm::StringRef msg = diagnosticMessages[static_cast <uint32_t >(id)];
12263 ASSERT_EQ (msg, translation);
12364 });
12465}
12566
126- TEST_F (DefToYAMLConverterTest, MatchDiagnosticMessagesRandomly ) {
67+ TEST_F (LocalizationTest, ConverterTestMatchDiagnosticMessagesRandomly ) {
12768 YAMLLocalizationProducer yaml (YAMLPath);
12869
12970 std::random_device rd;
0 commit comments