diff options
author | Tim Mayberry <mojofunk@gmail.com> | 2015-02-12 14:05:10 +1000 |
---|---|---|
committer | Tim Mayberry <mojofunk@gmail.com> | 2015-02-12 20:06:47 +1000 |
commit | 0550ec31bcedfee8c84bec22c9cebe3e58adbed8 (patch) | |
tree | a35df203f59513a478444e7e9d9f818c7e484c58 /libs | |
parent | 9a7ae1ad9977a01a73ada81653cb7552514a6f8a (diff) |
Add local PwdReset class to reset pwd in event of test failure
This fixes subsequent tests that rely on pwd but not PBD::path_is_within
breakage caused by commit 2689848e
Diffstat (limited to 'libs')
-rw-r--r-- | libs/pbd/test/filesystem_test.cc | 35 |
1 files changed, 26 insertions, 9 deletions
diff --git a/libs/pbd/test/filesystem_test.cc b/libs/pbd/test/filesystem_test.cc index 2e3638ea71..53ad08196d 100644 --- a/libs/pbd/test/filesystem_test.cc +++ b/libs/pbd/test/filesystem_test.cc @@ -19,14 +19,36 @@ using namespace PBD; CPPUNIT_TEST_SUITE_REGISTRATION (FilesystemTest); +namespace { + +class PwdReset +{ +public: + + PwdReset(const string& new_pwd) + : m_old_pwd(Glib::get_current_dir()) { + CPPUNIT_ASSERT (g_chdir (new_pwd.c_str()) == 0); + } + + ~PwdReset() + { + CPPUNIT_ASSERT (g_chdir (m_old_pwd.c_str()) == 0); + } + +private: + + string m_old_pwd; + +}; + +} // anon + void FilesystemTest::testPathIsWithin () { #ifndef PLATFORM_WINDOWS string output_path = test_output_directory ("testPathIsWithin"); - string orig_path = Glib::get_current_dir (); - - CPPUNIT_ASSERT (g_chdir (output_path.c_str()) == 0); + PwdReset pwd_reset(output_path); CPPUNIT_ASSERT (g_mkdir_with_parents ("foo/bar/baz", 0755) == 0); @@ -48,7 +70,6 @@ FilesystemTest::testPathIsWithin () CPPUNIT_ASSERT (PBD::path_is_within ("foo/bar", "foo/bar")); CPPUNIT_ASSERT (PBD::path_is_within ("foo/jim/baz", "frobozz") == false); - CPPUNIT_ASSERT (g_chdir (orig_path.c_str()) == 0); #endif } @@ -219,9 +240,7 @@ FilesystemTest::testCanonicalPath () { #ifndef PLATFORM_WINDOWS string top_dir = test_output_directory ("testCanonicalPath"); - string orig_path = Glib::get_current_dir (); - - CPPUNIT_ASSERT (g_chdir (top_dir.c_str()) == 0); + PwdReset pwd_reset(top_dir); string pwd = Glib::get_current_dir (); @@ -239,7 +258,5 @@ FilesystemTest::testCanonicalPath () CPPUNIT_ASSERT (canonical_path == expected_path); CPPUNIT_ASSERT (expanded_path == expected_path); - - CPPUNIT_ASSERT (g_chdir (orig_path.c_str()) == 0); #endif } |