]> git.ozlabs.org Git - ccan/blob - ccan/tal/path/test/run-rel.c
take, tal, tal/path, tal/str, tal/talloc: annotate APIs with TAKES.
[ccan] / ccan / tal / path / test / run-rel.c
1 #include <ccan/tal/path/path.h>
2 #include <ccan/tal/path/path.c>
3 #include <ccan/tap/tap.h>
4
5 int main(void)
6 {
7         char cwd[1024], *path, *ctx = tal_strdup(NULL, "ctx");
8
9         plan_tests(19);
10
11         if (!getcwd(cwd, sizeof(cwd)))
12                 abort();
13
14         unlink("run-rel-link");
15         rmdir("run-rel-foo");
16         if (mkdir("run-rel-foo", 0700) != 0)
17                 abort();
18         if (symlink("run-rel-foo", "run-rel-link") != 0)
19                 abort();
20
21         path = path_rel(ctx, ".", "run-rel-foo");
22         ok1(streq(path, "run-rel-foo"));
23         ok1(tal_parent(path) == ctx);
24         tal_free(path);
25
26         path = path_rel(ctx, "run-rel-foo", ".");
27         ok1(streq(path, ".."));
28         ok1(tal_parent(path) == ctx);
29         tal_free(path);
30
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);
35         tal_free(path);
36
37         path = path_rel(ctx, "/", ".");
38         ok1(streq(path, cwd + 1));
39         ok1(tal_parent(path) == ctx);
40         tal_free(path);
41
42         path = path_rel(ctx, "run-rel-foo", "run-rel-foo");
43         ok1(streq(path, "."));
44         ok1(tal_parent(path) == ctx);
45         tal_free(path);
46
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);
50         tal_free(path);
51         ok1(tal_first(ctx) == NULL);
52
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);
56         tal_free(path);
57         ok1(tal_first(ctx) == NULL);
58
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);
63         tal_free(path);
64         ok1(tal_first(ctx) == NULL);
65
66         tal_free(ctx);
67
68         return exit_status();
69 }