Skip to content

Commit 83a6331

Browse files
authored
Clean up temporary home directory to make tests more robust (#3146)
* Clean up temporary home directory to make tests more robust Signed-off-by: Addisu Z. Taddese <[email protected]> * Remove expectation that auto_default.log will exist This file only exists if the GUI has run. Since each test now starts with a clean ".gz" directory, this file will not exist when this test runs. Signed-off-by: Addisu Z. Taddese <[email protected]> --------- Signed-off-by: Addisu Z. Taddese <[email protected]>
1 parent b6f38d6 commit 83a6331

File tree

2 files changed

+4
-13
lines changed

2 files changed

+4
-13
lines changed

test/helpers/EnvTestFixture.hh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ class InternalFixture : public TestType
4848
// Documentation inherited
4949
protected: void TearDown() override
5050
{
51+
// Clean up fake home directory so that subsequent tests run on a clean slate.
52+
common::removeAll(this->kFakeHome);
5153
// Restore $HOME
5254
EXPECT_TRUE(common::setenv(GZ_HOMEDIR, this->realHome.c_str()));
5355
}

test/integration/log_system.cc

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -331,12 +331,6 @@ TEST_F(LogSystemTest, GZ_UTILS_TEST_DISABLED_ON_WIN32(LogDefaults))
331331
std::string(PROJECT_SOURCE_PATH), "test", "worlds",
332332
"log_record_dbl_pendulum.sdf");
333333

334-
// Change environment variable so that test files aren't written to $HOME
335-
std::string homeOrig;
336-
common::env(GZ_HOMEDIR, homeOrig);
337-
std::string homeFake = common::joinPaths(this->logsDir, "default");
338-
EXPECT_TRUE(common::setenv(GZ_HOMEDIR, homeFake.c_str()));
339-
340334
// Test case 1:
341335
// No path specified on command line. This does not go through
342336
// gz.cc, recording should take place in the `.gz` directory
@@ -359,10 +353,8 @@ TEST_F(LogSystemTest, GZ_UTILS_TEST_DISABLED_ON_WIN32(LogDefaults))
359353
recordServer.Run(true, 200, false);
360354
}
361355

362-
// We should expect to see "auto_default.log" and "state.tlog"
356+
// We should expect to see "state.tlog"
363357
EXPECT_FALSE(gzLogDirectory().empty());
364-
EXPECT_TRUE(common::exists(
365-
common::joinPaths(gzLogDirectory(), "auto_default.log")));
366358
EXPECT_TRUE(common::exists(
367359
common::joinPaths(gzLogDirectory(), "state.tlog")));
368360

@@ -380,7 +372,7 @@ TEST_F(LogSystemTest, GZ_UTILS_TEST_DISABLED_ON_WIN32(LogDefaults))
380372
// should be recorded here.
381373

382374
// Store number of files before running
383-
auto logPath = common::joinPaths(homeFake.c_str(), ".gz", "sim",
375+
auto logPath = common::joinPaths(this->kFakeHome, ".gz", "sim",
384376
"log");
385377
int nEntries = entryCount(logPath);
386378
std::vector<std::string> entriesBefore;
@@ -420,9 +412,6 @@ TEST_F(LogSystemTest, GZ_UTILS_TEST_DISABLED_ON_WIN32(LogDefaults))
420412
// Remove artifacts. Recreate new directory
421413
this->RemoveLogsDir();
422414
#endif
423-
424-
// Revert environment variable after test is done
425-
EXPECT_TRUE(common::setenv(GZ_HOMEDIR, homeOrig.c_str()));
426415
}
427416

428417
/////////////////////////////////////////////////

0 commit comments

Comments
 (0)