# # patch "ChangeLog" # from [204f139360eb7a130c7c43d2c9823d079d16b885] # to [2e5f194edd0d5aec8ff764e7cf2f5f26f4551601] # # patch "file_io.hh" # from [eab3db8560596948de644e9b8d94108ac5db39e7] # to [8187a0cdf077dcc00e0929ed7e4c7b264acce4b4] # # patch "paths.cc" # from [9b7c66bbcc5a4da1ebcff29799abd5e7028a967c] # to [ff4f52bb2a5bb8242990526aa3f96a6d36c800c7] # ======================================================================== --- ChangeLog 204f139360eb7a130c7c43d2c9823d079d16b885 +++ ChangeLog 2e5f194edd0d5aec8ff764e7cf2f5f26f4551601 @@ -1,5 +1,10 @@ 2005-08-25 Nathaniel Smith + * paths.cc: Lots of compile fixes for unit tests. + Add a test for access_tracker. + +2005-08-25 Nathaniel Smith + * paths.cc: Many fixes. Now compiles. 2005-08-25 Nathaniel Smith ======================================================================== --- file_io.hh eab3db8560596948de644e9b8d94108ac5db39e7 +++ file_io.hh 8187a0cdf077dcc00e0929ed7e4c7b264acce4b4 @@ -69,7 +69,9 @@ // returns true if the string content is binary according to monotone euristic bool guess_binary(std::string const & s); +// app_state.cc assumes that this is implemented by boost::fs void mkdir_p(any_path const & path); + void make_dir_for(file_path const & p); void make_dir_for(bookkeeping_path const & p); ======================================================================== --- paths.cc 9b7c66bbcc5a4da1ebcff29799abd5e7028a967c +++ paths.cc ff4f52bb2a5bb8242990526aa3f96a6d36c800c7 @@ -40,6 +40,11 @@ I(initialized); return value; } + // for unit tests + void unset() + { + used = initialized = false; + } T value; bool initialized, used; access_tracker() : initialized(false), used(false) {}; @@ -443,10 +448,10 @@ "c:foo", "c:/foo", 0 }; - initial_rel_path = file_path(); + initial_rel_path.set(file_path(), true); for (char const ** c = baddies; *c; ++c) BOOST_CHECK_THROW(file_path_internal(*c), logic_error); - initial_rel_path = file_path_internal("blah/blah/blah"); + initial_rel_path.set(file_path_internal("blah/blah/blah"), true); for (char const ** c = baddies; *c; ++c) BOOST_CHECK_THROW(file_path_internal(*c), logic_error); @@ -480,7 +485,7 @@ } } - initial_rel_path = file_path(); + initial_rel_path.unset(); } static void check_fp_normalizes_to(char * before, char * after) @@ -502,7 +507,7 @@ static void test_file_path_external_no_prefix() { - intial_rel_path = file_path() + initial_rel_path.set(file_path(), true); char const * baddies[] = {"/foo", "../bar", @@ -536,12 +541,12 @@ check_fp_normalizes_to("./foo", "foo"); check_fp_normalizes_to("foo///.//", "foo"); - intial_rel_path = file_path() + initial_rel_path.unset(); } static void test_file_path_external_prefix_a_b() { - initial_rel_path = file_path_internal("a/b"); + initial_rel_path.set(file_path_internal("a/b"), true); char const * baddies[] = {"/foo", "../../../bar", @@ -578,7 +583,7 @@ check_fp_normalizes_to("../..", ""); check_fp_normalizes_to("MT/foo", "a/b/MT/foo"); - initial_rel_path = file_path(); + initial_rel_path.unset(); } static void test_split_join() @@ -667,8 +672,7 @@ static void test_system_path() { - system_path initial_abs_path_saved = initial_abs_path; - initial_abs_path = system_path("/a/b"); + initial_abs_path.set(system_path("/a/b"), true); BOOST_CHECK_THROW(system_path(""), informative_failure); @@ -702,8 +706,8 @@ // finally, make sure that the copy-from-any_path constructor works right // in particular, it should interpret the paths it gets as being relative to // the project root, not the initial path - working_root = system_path("/working/root"); - initial_rel_path = file_path_internal("rel/initial"); + working_root.set(system_path("/working/root"), true); + initial_rel_path.set(file_path_internal("rel/initial"), true); BOOST_CHECK(system_path(system_path("foo/bar")).as_internal() == "/a/b/foo/bar"); BOOST_CHECK(system_path(system_path("/foo/bar")).as_internal() == "/foo/bar"); @@ -714,11 +718,23 @@ BOOST_CHECK(system_path(bookkeeping_path("MT/foo/bar")).as_internal() == "/working/root/MT/foo/bar"); - initial_abs_path = initial_abs_path_saved; - working_root = initial_abs_path_saved; - initial_rel_path = file_path(); + initial_abs_path.unset(); + working_root.unset(); + initial_rel_path.unset(); } +static void test_access_tracker() +{ + access_tracker a; + BOOST_CHECK_THROW(a.get(), invariant_failure); + a.set(1, false); + BOOST_CHECK_THROW(a.set(2, false), invariant_failure); + a.set(2, true); + BOOST_CHECK_THROW(a.set(3, false), invariant_failure); + BOOST_CHECK(a.get() == 2); + BOOST_CHECK_THROW(a.set(3, true), invariant_failure); +} + void add_paths_tests(test_suite * suite) { I(suite); @@ -729,6 +745,7 @@ suite->add(BOOST_TEST_CASE(&test_split_join)); suite->add(BOOST_TEST_CASE(&test_bookkeeping_path)); suite->add(BOOST_TEST_CASE(&test_system_path)); + suite->add(BOOST_TEST_CASE(&test_access_tracker)); } #endif // BUILD_UNIT_TESTS