Skip to content

Commit 0baf844

Browse files
committed
[Localization] Expose a way to create temporary files through LocalizationTest
1 parent 4f464ff commit 0baf844

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

unittests/Localization/DefToYAMLConverterTests.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
#include "llvm/ADT/StringRef.h"
1919
#include "llvm/Support/FileSystem.h"
2020
#include "llvm/Support/Path.h"
21-
#include "llvm/Support/Signals.h"
2221
#include "llvm/Support/ToolOutputFile.h"
2322
#include "llvm/Support/raw_ostream.h"
2423
#include "gtest/gtest.h"

unittests/Localization/LocalizationTest.h

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "llvm/ADT/StringExtras.h"
2020
#include "llvm/ADT/StringRef.h"
2121
#include "llvm/Support/FileSystem.h"
22+
#include "llvm/Support/Signals.h"
2223
#include "llvm/Support/raw_ostream.h"
2324
#include "gtest/gtest.h"
2425
#include <random>
@@ -50,20 +51,23 @@ struct LocalizationTest : public ::testing::Test {
5051
std::string YAMLPath;
5152

5253
LocalizationTest() {
53-
llvm::SmallString<128> tempFilename;
54-
std::error_code error =
55-
llvm::sys::fs::createTemporaryFile("en", "yaml", tempFilename);
56-
assert(!error);
57-
58-
YAMLPath = std::string(tempFilename);
54+
YAMLPath = std::string(createTemporaryFile("en", "yaml"));
5955
}
6056

6157
void SetUp() override {
6258
bool failed = convertDefIntoYAML(YAMLPath);
6359
assert(!failed && "failed to generate a YAML file");
6460
}
6561

66-
void TearDown() override { llvm::sys::fs::remove(YAMLPath); }
62+
static std::string createTemporaryFile(std::string prefix,
63+
std::string suffix) {
64+
llvm::SmallString<128> tempFile;
65+
std::error_code error =
66+
llvm::sys::fs::createTemporaryFile(prefix, suffix, tempFile);
67+
assert(!error);
68+
llvm::sys::RemoveFileOnSignal(tempFile);
69+
return std::string(tempFile);
70+
}
6771

6872
/// Random number in [0,n)
6973
unsigned RandNumber(unsigned n) { return unsigned(rand()) % n; }

0 commit comments

Comments
 (0)