|
19 | 19 | #include "llvm/ADT/StringExtras.h"
|
20 | 20 | #include "llvm/ADT/StringRef.h"
|
21 | 21 | #include "llvm/Support/FileSystem.h"
|
| 22 | +#include "llvm/Support/Signals.h" |
22 | 23 | #include "llvm/Support/raw_ostream.h"
|
23 | 24 | #include "gtest/gtest.h"
|
24 | 25 | #include <random>
|
@@ -50,20 +51,23 @@ struct LocalizationTest : public ::testing::Test {
|
50 | 51 | std::string YAMLPath;
|
51 | 52 |
|
52 | 53 | 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")); |
59 | 55 | }
|
60 | 56 |
|
61 | 57 | void SetUp() override {
|
62 | 58 | bool failed = convertDefIntoYAML(YAMLPath);
|
63 | 59 | assert(!failed && "failed to generate a YAML file");
|
64 | 60 | }
|
65 | 61 |
|
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 | + } |
67 | 71 |
|
68 | 72 | /// Random number in [0,n)
|
69 | 73 | unsigned RandNumber(unsigned n) { return unsigned(rand()) % n; }
|
|
0 commit comments