-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.c
48 lines (42 loc) · 907 Bytes
/
test.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include <assert.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <string.h>
#include "path-join/path-join.h"
#include "rimraf.h"
static bool
exists(char *path) {
struct stat b;
return 0 == (stat(path, &b));
}
static void
test_setup() {
char *dirs[] = {
"./tmp",
"./tmp/foo",
"./tmp/foo/bar",
"./tmp/foo/bar/baz",
NULL
};
for (int i = 0; dirs[i]; i++) {
mkdir(dirs[i], 0777);
char *f = path_join(dirs[i], "hello");
FILE *fp = fopen(f, "w");
fwrite("hello", 1, 5, fp);
fclose(fp);
free(f);
}
}
int
main(void) {
test_setup();
assert(0 == rimraf("./tmp"));
assert(false == exists("./tmp/foo/bar/baz/hello"));
assert(false == exists("./tmp/foo/bar/hello"));
assert(false == exists("./tmp/foo/hello"));
assert(false == exists("./tmp/hello"));
assert(false == exists("./tmp"));
return 0;
}