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, *path2, *ctx = tal_strdup(NULL, "ctx");
11 if (!getcwd(cwd, sizeof(cwd)))
14 unlink("run-canon-link");
15 rmdir("run-canon-foo");
16 if (mkdir("run-canon-foo", 0700) != 0)
18 if (symlink("run-canon-foo", "run-canon-link") != 0)
21 path = path_canon(ctx, "run-canon-foo");
22 ok1(tal_parent(path) == ctx);
23 ok1(strends(path, "run-canon-foo"));
24 ok1(strstarts(path, cwd));
25 ok1(path[strlen(cwd)] == PATH_SEP);
26 ok1(strlen(path) == strlen(cwd) + 1 + strlen("run-canon-foo"));
29 ok1(!path_canon(ctx, take(NULL)));
30 ok1(tal_first(ctx) == NULL);
32 /* Test take doesn't leak. */
33 ok1(tal_first(ctx) == NULL);
34 path = path_canon(ctx, take(tal_strdup(ctx, "run-canon-foo")));
35 ok1(strends(path, "run-canon-foo"));
36 ok1(strstarts(path, cwd));
37 ok1(path[strlen(cwd)] == PATH_SEP);
38 ok1(strlen(path) == strlen(cwd) + 1 + strlen("run-canon-foo"));
39 ok1(tal_first(ctx) == path && tal_next(path) == NULL);
40 path2 = path_canon(ctx, "run-canon-link");
41 ok1(streq(path2, path));
43 unlink("run-canon-link");
44 if (symlink(".", "run-canon-link") != 0)
47 path = path_canon(ctx, "run-canon-link");
48 ok1(streq(path, cwd));