]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
test-path-util: add coverage for path edge cases
authorfavilances <favilances@proton.me>
Sat, 9 May 2026 18:52:04 +0000 (21:52 +0300)
committerLuca Boccassi <luca.boccassi@gmail.com>
Mon, 11 May 2026 09:23:37 +0000 (10:23 +0100)
Path utility helpers are used throughout systemd for validation, comparison and manipulation of filesystem paths. Add coverage for additional corner cases around absolute path detection, normalization and prefix matching so regressions in these common helpers are easier to catch.

Co-developed-by: OpenAI Codex <noreply@openai.com>
Signed-off-by: favilances <favilances@proton.me>
src/test/test-path-util.c

index ef4f29172d838b1868cea3fdc408bc1b37869c08..1dc260a46732e57fcf7444793827627b04a23ed2 100644 (file)
@@ -24,8 +24,12 @@ TEST(print_paths) {
 }
 
 TEST(path) {
+        assert_se(!path_is_absolute(NULL));
+        assert_se(!path_is_absolute(""));
         assert_se( path_is_absolute("/"));
+        assert_se( path_is_absolute("//"));
         assert_se(!path_is_absolute("./"));
+        assert_se(!path_is_absolute("foo/bar"));
 
         assert_se( PATH_IN_SET("/bin", "/", "/bin", "/foo"));
         assert_se( PATH_IN_SET("/bin", "/bin"));
@@ -42,6 +46,21 @@ TEST(path) {
         assert_se(!path_equal(NULL, "a"));
 }
 
+TEST(path_is_normalized) {
+        assert_se( path_is_normalized("/"));
+        assert_se( path_is_normalized("/usr/bin"));
+        assert_se( path_is_normalized("usr/bin"));
+
+        assert_se(!path_is_normalized(""));
+        assert_se(!path_is_normalized("."));
+        assert_se(!path_is_normalized("./usr/bin"));
+        assert_se(!path_is_normalized("/usr//bin"));
+        assert_se(!path_is_normalized("/usr/./bin"));
+        assert_se(!path_is_normalized("/usr/bin/."));
+        assert_se(!path_is_normalized("../usr/bin"));
+        assert_se(!path_is_normalized("/usr/../bin"));
+}
+
 TEST(is_path) {
         assert_se(!is_path("foo"));
         assert_se(!is_path("dos.ext"));
@@ -760,6 +779,9 @@ TEST(path_startswith) {
         test_path_startswith_one("/foo/bar/barfoo/", "/foo/bar/barfo", NULL, NULL);
         test_path_startswith_one("/foo/bar/barfoo/", "/foo/bar/bar", NULL, NULL);
         test_path_startswith_one("/foo/bar/barfoo/", "/fo", NULL, NULL);
+        test_path_startswith_one("/usr/binary", "/usr/bin", NULL, NULL);
+        test_path_startswith_one("/foo/barista", "/foo/bar", NULL, NULL);
+        test_path_startswith_one("foo/barista", "foo/bar", NULL, NULL);
 }
 
 static void test_path_startswith_return_leading_slash_one(const char *path, const char *prefix, const char *expected) {