Ensure filefunc unit test works with all working dirs
authorChristian Herdtweck <christian.herdtweck@intra2net.com>
Wed, 25 Jan 2017 08:58:08 +0000 (09:58 +0100)
committerThomas Jarosch <thomas.jarosch@intra2net.com>
Wed, 22 Mar 2017 09:47:12 +0000 (10:47 +0100)
The __FILE__ macro contains an absolute path.

test/test_filefunc.cpp

index 1fb51f8..4d5f931 100644 (file)
@@ -98,7 +98,7 @@ BOOST_FIXTURE_TEST_SUITE(TestFileFunc, TestFileFuncFixture)
 
 BOOST_AUTO_TEST_CASE(StatTest1)
 {
-    I2n::Stat stat("Makefile");
+    I2n::Stat stat(__FILE__);
 
     BOOST_CHECK_EQUAL( true, (bool)stat );
     BOOST_CHECK_EQUAL( true, stat.is_regular_file() );
@@ -151,18 +151,20 @@ BOOST_AUTO_TEST_CASE(DirTest1)
     typedef std::vector< std::string > StringVector;
     StringVector names;
 
-    bool res= I2n::get_dir(".",names);
+    string test_dir = dirname(__FILE__);
+    bool res= I2n::get_dir(test_dir,names);
 
     BOOST_CHECK_EQUAL( true, res );
     BOOST_CHECK( ! names.empty() );
 
-    StringVector::iterator it = std::find( names.begin(), names.end(), "Makefile");
+    BOOST_MESSAGE("Looking for " << basename(__FILE__) << " in " << test_dir);
+    StringVector::iterator it = std::find( names.begin(), names.end(), basename(__FILE__));
     BOOST_CHECK( it != names.end() );
 
     it = std::find( names.begin(), names.end(), "." );
     BOOST_CHECK( it == names.end() );
 
-    names= get_dir(".",true);
+    names= get_dir(test_dir,true);
     BOOST_CHECK( ! names.empty() );
 
     for (it= names.begin(); it!=names.end(); ++it)