1 #include <ccan/tal/path/path.h>
2 #include <ccan/tal/path/path.c>
3 #include <ccan/tap/tap.h>
8 char path1[1024], path2[1024], *ctx = tal_strdup(NULL, "ctx");
10 /* This is how many tests you plan to run */
14 if (!getcwd(path1, sizeof(path1)))
17 pd = path_pushd(NULL, "non-existent-dir");
22 pd = path_pushd(ctx, take(tal_strdup(ctx, "non-existent-dir")));
28 pd = path_pushd(ctx, take(NULL));
33 pd = path_pushd(ctx, "/tmp");
35 ok1(tal_parent(pd) == ctx);
37 if (!getcwd(path2, sizeof(path2)))
40 ok1(streq(path2, "/tmp"));
43 if (!getcwd(path2, sizeof(path2)))
45 ok1(streq(path2, path1));
47 pd = path_pushd(ctx, take(tal_strdup(ctx, "/tmp")));
49 ok1(tal_parent(pd) == ctx);
51 if (!getcwd(path2, sizeof(path2)))
53 ok1(streq(path2, path1));
56 /* Without fchdir, we can't push a path which no longer exists. */
57 if (mkdir("run-pushd-dir", 0700) != 0)
59 if (chdir("run-pushd-dir") != 0)
61 if (rmdir("../run-pushd-dir") != 0)
64 pd = path_pushd(ctx, path1);