1 #include <ccan/tal/path/path.h>
2 #include <ccan/tal/path/path.c>
3 #include <ccan/tap/tap.h>
7 char cwd[1024], *path, *ctx = tal_strdup(NULL, "ctx");
11 if (!getcwd(cwd, sizeof(cwd)))
14 unlink("run-rel-link");
16 if (mkdir("run-rel-foo", 0700) != 0)
18 if (symlink("run-rel-foo", "run-rel-link") != 0)
21 path = path_rel(ctx, ".", "run-rel-foo");
22 ok1(streq(path, "run-rel-foo"));
23 ok1(tal_parent(path) == ctx);
26 path = path_rel(ctx, "run-rel-foo", ".");
27 ok1(streq(path, ".."));
28 ok1(tal_parent(path) == ctx);
31 path = path_rel(ctx, ".", "run-rel-link");
32 /* This doesn't specify whether it preserves links. */
33 ok1(streq(path, "run-rel-link") || streq(path, "run-rel-foo"));
34 ok1(tal_parent(path) == ctx);
37 path = path_rel(ctx, "/", ".");
38 ok1(streq(path, cwd + 1));
39 ok1(tal_parent(path) == ctx);
42 path = path_rel(ctx, "run-rel-foo", "run-rel-foo");
43 ok1(streq(path, "."));
44 ok1(tal_parent(path) == ctx);
47 path = path_rel(ctx, take(tal_strdup(ctx, ".")), "run-rel-foo");
48 ok1(streq(path, "run-rel-foo"));
49 ok1(tal_parent(path) == ctx);
51 ok1(tal_first(ctx) == NULL);
53 path = path_rel(ctx, ".", take(tal_strdup(ctx, "run-rel-foo")));
54 ok1(streq(path, "run-rel-foo"));
55 ok1(tal_parent(path) == ctx);
57 ok1(tal_first(ctx) == NULL);
59 path = path_rel(ctx, take(tal_strdup(ctx, ".")),
60 take(tal_strdup(ctx, "run-rel-foo")));
61 ok1(streq(path, "run-rel-foo"));
62 ok1(tal_parent(path) == ctx);
64 ok1(tal_first(ctx) == NULL);