Mercurial > irccd
comparison tests/test-jsapi-directory.c @ 1037:8f8ce47aba8a
make: switch to GNU make
author | David Demelier <markand@malikania.fr> |
---|---|
date | Tue, 27 Apr 2021 09:22:16 +0200 |
parents | 6da542806ed3 |
children | f06e9761cc90 |
comparison
equal
deleted
inserted
replaced
1036:bafb5943cd35 | 1037:8f8ce47aba8a |
---|---|
30 static void | 30 static void |
31 setup(void *udata) | 31 setup(void *udata) |
32 { | 32 { |
33 (void)udata; | 33 (void)udata; |
34 | 34 |
35 plugin = js_plugin_open("example", SOURCE "/data/example-plugin.js"); | 35 plugin = js_plugin_open("example", TOP "/tests/data/example-plugin.js"); |
36 ctx = js_plugin_get_context(plugin); | 36 ctx = js_plugin_get_context(plugin); |
37 | 37 |
38 duk_push_string(ctx, SOURCE); | 38 duk_push_string(ctx, TOP); |
39 duk_put_global_string(ctx, "SOURCE"); | 39 duk_put_global_string(ctx, "TOP"); |
40 | |
41 duk_push_string(ctx, BINARY); | |
42 duk_put_global_string(ctx, "BINARY"); | |
43 } | 40 } |
44 | 41 |
45 static void | 42 static void |
46 teardown(void *udata) | 43 teardown(void *udata) |
47 { | 44 { |
48 (void)udata; | 45 (void)udata; |
49 | 46 |
47 remove(TOP "/tests/1/2"); | |
48 remove(TOP "/tests/1"); | |
49 | |
50 irc_plugin_finish(plugin); | 50 irc_plugin_finish(plugin); |
51 | 51 |
52 plugin = NULL; | 52 plugin = NULL; |
53 ctx = NULL; | 53 ctx = NULL; |
54 } | 54 } |
55 | 55 |
56 GREATEST_TEST | 56 GREATEST_TEST |
57 object_constructor(void) | 57 object_constructor(void) |
58 { | 58 { |
59 const char *script = | 59 const char *script = |
60 "d = new Irccd.Directory(SOURCE + '/data/root');" | 60 "d = new Irccd.Directory(TOP + '/tests/data/root');" |
61 "p = d.path;" | 61 "p = d.path;" |
62 "l = d.entries.length;"; | 62 "l = d.entries.length;"; |
63 | 63 |
64 if (duk_peval_string(ctx, script) != 0) | 64 if (duk_peval_string(ctx, script) != 0) |
65 GREATEST_FAIL(); | 65 GREATEST_FAIL(); |
73 } | 73 } |
74 | 74 |
75 GREATEST_TEST | 75 GREATEST_TEST |
76 object_find(void) | 76 object_find(void) |
77 { | 77 { |
78 const char *script = "d = new Irccd.Directory(SOURCE + '/data/root');"; | 78 const char *script = "d = new Irccd.Directory(TOP + '/tests/data/root');"; |
79 | 79 |
80 if (duk_peval_string(ctx, script) != 0) | 80 if (duk_peval_string(ctx, script) != 0) |
81 GREATEST_FAIL(); | 81 GREATEST_FAIL(); |
82 | 82 |
83 /* Find "lines.txt" not recursively. */ | 83 /* Find "lines.txt" not recursively. */ |
84 if (duk_peval_string(ctx, "p = d.find('lines.txt');") != 0) | 84 if (duk_peval_string(ctx, "p = d.find('lines.txt');") != 0) |
85 GREATEST_FAIL(); | 85 GREATEST_FAIL(); |
86 | 86 |
87 duk_get_global_string(ctx, "p"); | 87 duk_get_global_string(ctx, "p"); |
88 GREATEST_ASSERT_STR_EQ(SOURCE "/data/root/lines.txt", duk_get_string(ctx, -1)); | 88 GREATEST_ASSERT_STR_EQ(TOP "/tests/data/root/lines.txt", duk_get_string(ctx, -1)); |
89 | 89 |
90 /* Find "unknown.txt" not recursively (not found). */ | 90 /* Find "unknown.txt" not recursively (not found). */ |
91 if (duk_peval_string(ctx, "p = d.find('unknown.txt');") != 0) | 91 if (duk_peval_string(ctx, "p = d.find('unknown.txt');") != 0) |
92 GREATEST_FAIL(); | 92 GREATEST_FAIL(); |
93 | 93 |
104 /* Find "file-2.txt" recursively. */ | 104 /* Find "file-2.txt" recursively. */ |
105 if (duk_peval_string(ctx, "p = d.find('file-2.txt', true);") != 0) | 105 if (duk_peval_string(ctx, "p = d.find('file-2.txt', true);") != 0) |
106 GREATEST_FAIL(); | 106 GREATEST_FAIL(); |
107 | 107 |
108 duk_get_global_string(ctx, "p"); | 108 duk_get_global_string(ctx, "p"); |
109 GREATEST_ASSERT_STR_EQ(SOURCE "/data/root/level-1/level-2/file-2.txt", duk_get_string(ctx, -1)); | 109 GREATEST_ASSERT_STR_EQ(TOP "/tests/data/root/level-1/level-2/file-2.txt", duk_get_string(ctx, -1)); |
110 | 110 |
111 GREATEST_PASS(); | 111 GREATEST_PASS(); |
112 } | 112 } |
113 | 113 |
114 GREATEST_TEST | 114 GREATEST_TEST |
115 object_remove(void) | 115 object_remove(void) |
116 { | 116 { |
117 struct stat st; | 117 struct stat st; |
118 | 118 |
119 /* First create an empty directory. */ | 119 /* First create an empty directory. */ |
120 mkdir(BINARY "/empty", 0700); | 120 mkdir(TOP "/tests/empty", 0700); |
121 | 121 |
122 if (duk_peval_string(ctx, "d = new Irccd.Directory(BINARY + '/empty')") != 0) | 122 if (duk_peval_string(ctx, "d = new Irccd.Directory(TOP + '/tests/empty')") != 0) |
123 GREATEST_FAIL(); | 123 GREATEST_FAIL(); |
124 | 124 |
125 /* Not recursive. */ | 125 /* Not recursive. */ |
126 if (duk_peval_string(ctx, "d.remove()") != 0) | 126 if (duk_peval_string(ctx, "d.remove()") != 0) |
127 GREATEST_FAIL(); | 127 GREATEST_FAIL(); |
128 | 128 |
129 GREATEST_ASSERT_EQ(-1, stat(BINARY "/empty", &st)); | 129 GREATEST_ASSERT_EQ(-1, stat(TOP "/tests/empty", &st)); |
130 | 130 |
131 mkdir(BINARY "/notempty", 0700); | 131 mkdir(TOP "/tests/notempty", 0700); |
132 mkdir(BINARY "/notempty/empty", 0700); | 132 mkdir(TOP "/tests/notempty/empty", 0700); |
133 | 133 |
134 if (duk_peval_string(ctx, "d = new Irccd.Directory(BINARY + '/notempty')") != 0) | 134 if (duk_peval_string(ctx, "d = new Irccd.Directory(TOP + '/tests/notempty')") != 0) |
135 GREATEST_FAIL(); | 135 GREATEST_FAIL(); |
136 | 136 |
137 /* Not recursive. */ | 137 /* Not recursive. */ |
138 if (duk_peval_string(ctx, "d.remove(true)") != 0) | 138 if (duk_peval_string(ctx, "d.remove(true)") != 0) |
139 GREATEST_FAIL(); | 139 GREATEST_FAIL(); |
140 | 140 |
141 GREATEST_ASSERT_EQ(-1, stat(BINARY "/notempty", &st)); | 141 GREATEST_ASSERT_EQ(-1, stat(TOP "/tests/notempty", &st)); |
142 | 142 |
143 GREATEST_PASS(); | 143 GREATEST_PASS(); |
144 } | 144 } |
145 | 145 |
146 GREATEST_SUITE(suite_object) | 146 GREATEST_SUITE(suite_object) |
154 | 154 |
155 GREATEST_TEST | 155 GREATEST_TEST |
156 free_find(void) | 156 free_find(void) |
157 { | 157 { |
158 /* Find "lines.txt" not recursively. */ | 158 /* Find "lines.txt" not recursively. */ |
159 if (duk_peval_string(ctx, "p = Irccd.Directory.find(SOURCE + '/data/root', 'lines.txt');") != 0) { | 159 if (duk_peval_string(ctx, "p = Irccd.Directory.find(TOP + '/tests/data/root', 'lines.txt');") != 0) { |
160 puts(duk_to_string(ctx, -1)); | 160 puts(duk_to_string(ctx, -1)); |
161 GREATEST_FAIL(); | 161 GREATEST_FAIL(); |
162 } | 162 } |
163 | 163 |
164 duk_get_global_string(ctx, "p"); | 164 duk_get_global_string(ctx, "p"); |
165 GREATEST_ASSERT_STR_EQ(SOURCE "/data/root/lines.txt", duk_get_string(ctx, -1)); | 165 GREATEST_ASSERT_STR_EQ(TOP "/tests/data/root/lines.txt", duk_get_string(ctx, -1)); |
166 | 166 |
167 /* Find "unknown.txt" not recursively (not found). */ | 167 /* Find "unknown.txt" not recursively (not found). */ |
168 if (duk_peval_string(ctx, "p = Irccd.Directory.find(SOURCE + '/data/root', 'unknown.txt');") != 0) | 168 if (duk_peval_string(ctx, "p = Irccd.Directory.find(TOP + '/tests/data/root', 'unknown.txt');") != 0) |
169 GREATEST_FAIL(); | 169 GREATEST_FAIL(); |
170 | 170 |
171 duk_get_global_string(ctx, "p"); | 171 duk_get_global_string(ctx, "p"); |
172 GREATEST_ASSERT(duk_is_null(ctx, -1)); | 172 GREATEST_ASSERT(duk_is_null(ctx, -1)); |
173 | 173 |
174 /* Find "file-2.txt" not recursively (exists but in sub directory). */ | 174 /* Find "file-2.txt" not recursively (exists but in sub directory). */ |
175 if (duk_peval_string(ctx, "p = Irccd.Directory.find(SOURCE + '/data/root', 'file-2.txt');") != 0) | 175 if (duk_peval_string(ctx, "p = Irccd.Directory.find(TOP + '/tests/data/root', 'file-2.txt');") != 0) |
176 GREATEST_FAIL(); | 176 GREATEST_FAIL(); |
177 | 177 |
178 duk_get_global_string(ctx, "p"); | 178 duk_get_global_string(ctx, "p"); |
179 GREATEST_ASSERT(duk_is_null(ctx, -1)); | 179 GREATEST_ASSERT(duk_is_null(ctx, -1)); |
180 | 180 |
181 /* Find "file-2.txt" recursively. */ | 181 /* Find "file-2.txt" recursively. */ |
182 if (duk_peval_string(ctx, "p = Irccd.Directory.find(SOURCE + '/data/root', 'file-2.txt', true);") != 0) | 182 if (duk_peval_string(ctx, "p = Irccd.Directory.find(TOP + '/tests/data/root', 'file-2.txt', true);") != 0) |
183 GREATEST_FAIL(); | 183 GREATEST_FAIL(); |
184 | 184 |
185 duk_get_global_string(ctx, "p"); | 185 duk_get_global_string(ctx, "p"); |
186 GREATEST_ASSERT_STR_EQ(SOURCE "/data/root/level-1/level-2/file-2.txt", duk_get_string(ctx, -1)); | 186 GREATEST_ASSERT_STR_EQ(TOP "/tests/data/root/level-1/level-2/file-2.txt", duk_get_string(ctx, -1)); |
187 | 187 |
188 GREATEST_PASS(); | 188 GREATEST_PASS(); |
189 } | 189 } |
190 | 190 |
191 GREATEST_TEST | 191 GREATEST_TEST |
192 free_remove(void) | 192 free_remove(void) |
193 { | 193 { |
194 struct stat st; | 194 struct stat st; |
195 | 195 |
196 /* First create an empty directory. */ | 196 /* First create an empty directory. */ |
197 mkdir(BINARY "/empty", 0700); | 197 mkdir(TOP "/tests/empty", 0700); |
198 | 198 |
199 /* Not recursive. */ | 199 /* Not recursive. */ |
200 if (duk_peval_string(ctx, "Irccd.Directory.remove(BINARY + '/empty')") != 0) { | 200 if (duk_peval_string(ctx, "Irccd.Directory.remove(TOP + '/tests/empty')") != 0) { |
201 puts(duk_to_string(ctx, -1)); | 201 puts(duk_to_string(ctx, -1)); |
202 GREATEST_FAIL(); | 202 GREATEST_FAIL(); |
203 } | 203 } |
204 | 204 |
205 GREATEST_ASSERT_EQ(-1, stat(BINARY "/empty", &st)); | 205 GREATEST_ASSERT_EQ(-1, stat(TOP "/tests/empty", &st)); |
206 | 206 |
207 mkdir(BINARY "/notempty", 0700); | 207 mkdir(TOP "/tests/notempty", 0700); |
208 mkdir(BINARY "/notempty/empty", 0700); | 208 mkdir(TOP "/tests/notempty/empty", 0700); |
209 | 209 |
210 /* Not recursive. */ | 210 /* Not recursive. */ |
211 if (duk_peval_string(ctx, "Irccd.Directory.remove(BINARY + '/notempty', true)") != 0) | 211 if (duk_peval_string(ctx, "Irccd.Directory.remove(TOP + '/tests/notempty', true)") != 0) |
212 GREATEST_FAIL(); | 212 GREATEST_FAIL(); |
213 | 213 |
214 GREATEST_ASSERT_EQ(-1, stat(BINARY "/notempty", &st)); | 214 GREATEST_ASSERT_EQ(-1, stat(TOP "/tests/notempty", &st)); |
215 | 215 |
216 GREATEST_PASS(); | 216 GREATEST_PASS(); |
217 } | 217 } |
218 | 218 |
219 GREATEST_TEST | 219 GREATEST_TEST |
220 free_mkdir(void) | 220 free_mkdir(void) |
221 { | 221 { |
222 struct stat st; | 222 struct stat st; |
223 | 223 |
224 remove(BINARY "/1/2"); | 224 remove(TOP "/tests/1/2"); |
225 remove(BINARY "/1"); | 225 remove(TOP "/tests/1"); |
226 | 226 |
227 if (duk_peval_string(ctx, "Irccd.Directory.mkdir(BINARY + '/1/2')") != 0) { | 227 if (duk_peval_string(ctx, "Irccd.Directory.mkdir(TOP + '/tests/1/2')") != 0) { |
228 puts(duk_to_string(ctx, -1)); | 228 puts(duk_to_string(ctx, -1)); |
229 GREATEST_FAIL(); | 229 GREATEST_FAIL(); |
230 } | 230 } |
231 | 231 |
232 GREATEST_ASSERT_EQ(0, stat(BINARY "/1/2", &st)); | 232 GREATEST_ASSERT_EQ(0, stat(TOP "/tests/1/2", &st)); |
233 | 233 |
234 GREATEST_PASS(); | 234 GREATEST_PASS(); |
235 } | 235 } |
236 | 236 |
237 GREATEST_SUITE(suite_free) | 237 GREATEST_SUITE(suite_free) |