diff options
author | Peter Hutterer <peter.hutterer@who-t.net> | 2021-02-18 13:43:23 +1000 |
---|---|---|
committer | Peter Hutterer <peter.hutterer@who-t.net> | 2021-02-23 10:56:53 +1000 |
commit | 671eb8cbbb4dc5c88d38c935c176d61604154584 (patch) | |
tree | 5c5c00feea0c24c16ca73d1fbc83a340dc6a96fa /test | |
parent | fd9d165a7724dd518f4ad2a92187637130345389 (diff) | |
download | libinput-671eb8cbbb4dc5c88d38c935c176d61604154584.tar.gz |
utils: add a safe version of basename
So we don't need to worry about the libgen.h include game.
And we can switch trunkname over to that, making it a bit simpler.
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Diffstat (limited to 'test')
-rw-r--r-- | test/test-utils.c | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/test/test-utils.c b/test/test-utils.c index f31b2e07..dbd58031 100644 --- a/test/test-utils.c +++ b/test/test-utils.c @@ -1292,6 +1292,35 @@ START_TEST(strneq_test) } END_TEST +START_TEST(basename_test) +{ + struct test { + const char *path; + const char *expected; + } tests[] = { + { "a", "a" }, + { "foo.c", "foo.c" }, + { "foo", "foo" }, + { "/path/to/foo.h", "foo.h" }, + { "../bar.foo", "bar.foo" }, + { "./bar.foo.baz", "bar.foo.baz" }, + { "./", NULL }, + { "/", NULL }, + { "/bar/", NULL }, + { "/bar", "bar" }, + { "", NULL }, + }; + struct test *t; + + ARRAY_FOR_EACH(tests, t) { + const char *result = safe_basename(t->path); + if (t->expected == NULL) + ck_assert(result == NULL); + else + ck_assert_str_eq(result, t->expected); + } +} +END_TEST START_TEST(trunkname_test) { struct test { @@ -1300,6 +1329,7 @@ START_TEST(trunkname_test) } tests[] = { { "foo.c", "foo" }, { "/path/to/foo.h", "foo" }, + { "/path/to/foo", "foo" }, { "../bar.foo", "bar" }, { "./bar.foo.baz", "bar.foo" }, { "./", "" }, @@ -1362,6 +1392,7 @@ litest_utils_suite(void) tcase_add_test(tc, streq_test); tcase_add_test(tc, strneq_test); tcase_add_test(tc, trunkname_test); + tcase_add_test(tc, basename_test); suite_add_tcase(s, tc); |