X-Git-Url: https://git.ozlabs.org/?a=blobdiff_plain;f=ccan%2Ftal%2Fpath%2Ftest%2Frun-rel.c;fp=ccan%2Ftal%2Fpath%2Ftest%2Frun-rel.c;h=7083c4bd1174ef7cc8092f8545f5ca2f2b08f330;hb=892f59bdc1830443f87ad3aaeddaab2eeefb5937;hp=0000000000000000000000000000000000000000;hpb=1322fd3377cc817720f7552a80d56dba447bcfea;p=ccan diff --git a/ccan/tal/path/test/run-rel.c b/ccan/tal/path/test/run-rel.c new file mode 100644 index 00000000..7083c4bd --- /dev/null +++ b/ccan/tal/path/test/run-rel.c @@ -0,0 +1,69 @@ +#include +#include +#include + +int main(void) +{ + char cwd[1024], *path, *ctx = tal_strdup(NULL, "ctx"); + + plan_tests(19); + + if (!getcwd(cwd, sizeof(cwd))) + abort(); + + unlink("run-rel-link"); + rmdir("run-rel-foo"); + if (mkdir("run-rel-foo", 0700) != 0) + abort(); + if (symlink("run-rel-foo", "run-rel-link") != 0) + abort(); + + path = path_rel(ctx, ".", "run-rel-foo"); + ok1(streq(path, "run-rel-foo")); + ok1(tal_parent(path) == ctx); + tal_free(path); + + path = path_rel(ctx, "run-rel-foo", "."); + ok1(streq(path, "..")); + ok1(tal_parent(path) == ctx); + tal_free(path); + + path = path_rel(ctx, ".", "run-rel-link"); + /* This doesn't specify whether it preserves links. */ + ok1(streq(path, "run-rel-link") || streq(path, "run-rel-foo")); + ok1(tal_parent(path) == ctx); + tal_free(path); + + path = path_rel(ctx, "/", "."); + ok1(streq(path, cwd + 1)); + ok1(tal_parent(path) == ctx); + tal_free(path); + + path = path_rel(ctx, "run-rel-foo", "run-rel-foo"); + ok1(streq(path, ".")); + ok1(tal_parent(path) == ctx); + tal_free(path); + + path = path_rel(ctx, take(tal_strdup(ctx, ".")), "run-rel-foo"); + ok1(streq(path, "run-rel-foo")); + ok1(tal_parent(path) == ctx); + tal_free(path); + ok1(tal_first(ctx) == NULL); + + path = path_rel(ctx, ".", take(tal_strdup(ctx, "run-rel-foo"))); + ok1(streq(path, "run-rel-foo")); + ok1(tal_parent(path) == ctx); + tal_free(path); + ok1(tal_first(ctx) == NULL); + + path = path_rel(ctx, take(tal_strdup(ctx, ".")), + take(tal_strdup(ctx, "run-rel-foo"))); + ok1(streq(path, "run-rel-foo")); + ok1(tal_parent(path) == ctx); + tal_free(path); + ok1(tal_first(ctx) == NULL); + + tal_free(ctx); + + return exit_status(); +}