Skip to content

Commit ad54f07

Browse files
tylerzhao7684zibaiwan
authored andcommitted
Workaround to clean up tmp directories
1 parent f982f7b commit ad54f07

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

lib/pkg_editor/test/pkg_editor_test.cpp

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ using random_bytes_engine =
5353
unsigned int>;
5454
namespace fs = std::experimental::filesystem::v1;
5555

56+
int tmpCount = 0;
57+
5658
static void l_remove_file(const char *filename) {
5759
#ifdef _WIN32
5860
_unlink(filename);
@@ -469,8 +471,9 @@ static bool is_same_tmpdir(const std::vector<fs::path> &files,
469471

470472
TEST(package, unpack) {
471473
int result;
472-
fs::path tmpdir = "tmp";
473-
std::string tmpdir_string = tmpdir.string();
474+
std::string tmpdir_string = "tmp" + std::to_string(tmpCount);
475+
tmpCount++;
476+
fs::path tmpdir = tmpdir_string;
474477
const char *tmpdir_c_str = tmpdir_string.c_str();
475478
std::vector<fs::path> files = generate_tmp_folder(tmpdir);
476479

@@ -485,12 +488,14 @@ TEST(package, unpack) {
485488

486489
// Compare some files to be sure that they are the same.
487490
CHECK(is_same_tmpdir(files, PACK_UNPACK_DIR));
491+
system(("rm -rf " + tmpdir_string).c_str());
488492
}
489493

490494
TEST(package, unpack_buffer) {
491495
int result;
492-
fs::path tmpdir = "tmp";
493-
std::string tmpdir_string = tmpdir.string();
496+
std::string tmpdir_string = "tmp" + std::to_string(tmpCount);
497+
tmpCount++;
498+
fs::path tmpdir = tmpdir_string;
494499
const char *tmpdir_c_str = tmpdir_string.c_str();
495500
std::vector<fs::path> files = generate_tmp_folder(tmpdir);
496501
// Create a known good input.
@@ -521,12 +526,14 @@ TEST(package, unpack_buffer) {
521526
CHECK_EQUAL(true, files_same("test/pkg_editor_test.cpp",
522527
PACK_UNPACK_DIR "/test/pkg_editor_test.cpp"));
523528
CHECK(is_same_tmpdir(files, PACK_UNPACK_DIR));
529+
system(("rm -rf " + tmpdir_string).c_str());
524530
}
525531

526532
TEST(package, unpack_buffer_stdin) {
527533
int result;
528-
fs::path tmpdir = "tmp";
529-
std::string tmpdir_string = tmpdir.string();
534+
std::string tmpdir_string = "tmp" + std::to_string(tmpCount);
535+
tmpCount++;
536+
fs::path tmpdir = tmpdir_string;
530537
const char *tmpdir_c_str = tmpdir_string.c_str();
531538
std::vector<fs::path> files = generate_tmp_folder(tmpdir);
532539

@@ -579,5 +586,6 @@ TEST(package, unpack_buffer_stdin) {
579586
CHECK_EQUAL(true, files_same("test/pkg_editor_test.cpp",
580587
PACK_UNPACK_DIR "/test/pkg_editor_test.cpp"));
581588
CHECK(is_same_tmpdir(files, PACK_UNPACK_DIR));
589+
system(("rm -rf " + tmpdir_string).c_str());
582590
}
583591
#endif

0 commit comments

Comments
 (0)