diff options
author | Joel Rosdahl <joel@rosdahl.net> | 2012-07-28 17:17:25 +0200 |
---|---|---|
committer | Joel Rosdahl <joel@rosdahl.net> | 2012-07-28 17:17:25 +0200 |
commit | 6595cf871eafaec254d1c8a61d5b926d2a822a50 (patch) | |
tree | e5c8a1f90cbe4115b4506a923568fa0e60dbe751 /test | |
parent | 752b2ffed0b2892d4fce25a9f1fb5511862d2e94 (diff) | |
parent | a5f8e78c61867fe64881323018bbeca83a43f6a1 (diff) | |
download | ccache-6595cf871eafaec254d1c8a61d5b926d2a822a50.tar.gz |
Merge branch 'maint'
* maint:
Improve get_relative_path and add unit tests
Canonicalize paths when computing path relative to base directory
Conflicts:
test/test_util.c
util.c
Diffstat (limited to 'test')
-rw-r--r-- | test/test_util.c | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/test/test_util.c b/test/test_util.c index 7a9fbcdb..0ad51d2e 100644 --- a/test/test_util.c +++ b/test/test_util.c @@ -41,6 +41,34 @@ TEST(dirname) CHECK_STR_EQ_FREE2("dir1/dir2", dirname("dir1/dir2/")); } +TEST(common_dir_prefix_length) +{ + CHECK_INT_EQ(0, common_dir_prefix_length("", "")); + CHECK_INT_EQ(0, common_dir_prefix_length("/", "/")); + CHECK_INT_EQ(0, common_dir_prefix_length("/", "/b")); + CHECK_INT_EQ(0, common_dir_prefix_length("/a", "/b")); + CHECK_INT_EQ(2, common_dir_prefix_length("/a", "/a")); + CHECK_INT_EQ(2, common_dir_prefix_length("/a", "/a/b")); + CHECK_INT_EQ(2, common_dir_prefix_length("/a/b", "/a/c")); + CHECK_INT_EQ(4, common_dir_prefix_length("/a/b", "/a/b")); +} + +TEST(get_relative_path) +{ + CHECK_STR_EQ_FREE2("a", get_relative_path("/doesn't matter", "a")); + CHECK_STR_EQ_FREE2("a/b", get_relative_path("/doesn't matter", "a/b")); + CHECK_STR_EQ_FREE2(".", get_relative_path("/a", "/a")); + CHECK_STR_EQ_FREE2("..", get_relative_path("/a/b", "/a")); + CHECK_STR_EQ_FREE2("b", get_relative_path("/a", "/a/b")); + CHECK_STR_EQ_FREE2("b/c", get_relative_path("/a", "/a/b/c")); + CHECK_STR_EQ_FREE2("../c", get_relative_path("/a/b", "/a/c")); + CHECK_STR_EQ_FREE2("../c/d", get_relative_path("/a/b", "/a/c/d")); + CHECK_STR_EQ_FREE2("../../c/d", get_relative_path("/a/b/c", "/a/c/d")); + CHECK_STR_EQ_FREE2("../..", get_relative_path("/a/b", "/")); + CHECK_STR_EQ_FREE2("../../c", get_relative_path("/a/b", "/c")); + CHECK_STR_EQ_FREE2("a/b", get_relative_path("/", "/a/b")); +} + TEST(format_hash_as_string) { unsigned char hash[16] = { |