Skip to content

Commit 86d3ae4

Browse files
mergify[bot]azeeyarjo129
authored
Clean up temporary home directory to make tests more robust (backport #3146) (#3150)
* 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]> (cherry picked from commit 83a6331) # Conflicts: # test/integration/log_system.cc * Resolve merege conflict Signed-off-by: Arjo Chakravarty <[email protected]> --------- Signed-off-by: Arjo Chakravarty <[email protected]> Co-authored-by: Addisu Z. Taddese <[email protected]> Co-authored-by: Arjo Chakravarty <[email protected]>
1 parent 2fdd8ba commit 86d3ae4

File tree

2 files changed

+3
-13
lines changed

2 files changed

+3
-13
lines changed

test/helpers/EnvTestFixture.hh

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

test/integration/log_system.cc

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -326,12 +326,6 @@ TEST_F(LogSystemTest, IGN_UTILS_TEST_DISABLED_ON_WIN32(LogDefaults))
326326
std::string(PROJECT_SOURCE_PATH), "test", "worlds",
327327
"log_record_dbl_pendulum.sdf");
328328

329-
// Change environment variable so that test files aren't written to $HOME
330-
std::string homeOrig;
331-
common::env(IGN_HOMEDIR, homeOrig);
332-
std::string homeFake = common::joinPaths(this->logsDir, "default");
333-
EXPECT_TRUE(common::setenv(IGN_HOMEDIR, homeFake.c_str()));
334-
335329
// Test case 1:
336330
// No path specified on command line. This does not go through
337331
// gz.cc, recording should take place in the `.ignition` directory
@@ -353,11 +347,8 @@ TEST_F(LogSystemTest, IGN_UTILS_TEST_DISABLED_ON_WIN32(LogDefaults))
353347
Server recordServer(recordServerConfig);
354348
recordServer.Run(true, 200, false);
355349
}
356-
357350
// We should expect to see "auto_default.log" and "state.tlog"
358351
EXPECT_FALSE(ignLogDirectory().empty());
359-
EXPECT_TRUE(common::exists(
360-
common::joinPaths(ignLogDirectory(), "auto_default.log")));
361352
EXPECT_TRUE(common::exists(
362353
common::joinPaths(ignLogDirectory(), "state.tlog")));
363354

@@ -375,7 +366,7 @@ TEST_F(LogSystemTest, IGN_UTILS_TEST_DISABLED_ON_WIN32(LogDefaults))
375366
// should be recorded here.
376367

377368
// Store number of files before running
378-
auto logPath = common::joinPaths(homeFake.c_str(), ".ignition", "gazebo",
369+
auto logPath = common::joinPaths(this->kFakeHome, ".ignition", "gazebo",
379370
"log");
380371
int nEntries = entryCount(logPath);
381372
std::vector<std::string> entriesBefore;
@@ -415,9 +406,6 @@ TEST_F(LogSystemTest, IGN_UTILS_TEST_DISABLED_ON_WIN32(LogDefaults))
415406
// Remove artifacts. Recreate new directory
416407
this->RemoveLogsDir();
417408
#endif
418-
419-
// Revert environment variable after test is done
420-
EXPECT_TRUE(common::setenv(IGN_HOMEDIR, homeOrig.c_str()));
421409
}
422410

423411
/////////////////////////////////////////////////

0 commit comments

Comments
 (0)