comparison tests/test-jsapi-file.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
31 static void 31 static void
32 setup(void *udata) 32 setup(void *udata)
33 { 33 {
34 (void)udata; 34 (void)udata;
35 35
36 plugin = js_plugin_open("example", SOURCE "/data/example-plugin.js"); 36 plugin = js_plugin_open("example", TOP "/tests/data/example-plugin.js");
37 ctx = js_plugin_get_context(plugin); 37 ctx = js_plugin_get_context(plugin);
38 38
39 duk_push_string(ctx, SOURCE); 39 duk_push_string(ctx, TOP);
40 duk_put_global_string(ctx, "SOURCE"); 40 duk_put_global_string(ctx, "TOP");
41
42 duk_push_string(ctx, BINARY);
43 duk_put_global_string(ctx, "BINARY");
44 } 41 }
45 42
46 static void 43 static void
47 teardown(void *udata) 44 teardown(void *udata)
48 { 45 {
72 if (duk_peval_string(ctx, "result = Irccd.File.dirname('/usr/local/etc/irccd.conf');")) 69 if (duk_peval_string(ctx, "result = Irccd.File.dirname('/usr/local/etc/irccd.conf');"))
73 GREATEST_FAIL(); 70 GREATEST_FAIL();
74 71
75 GREATEST_ASSERT(duk_get_global_string(ctx, "result")); 72 GREATEST_ASSERT(duk_get_global_string(ctx, "result"));
76 GREATEST_ASSERT_STR_EQ("/usr/local/etc", duk_get_string(ctx, -1)); 73 GREATEST_ASSERT_STR_EQ("/usr/local/etc", duk_get_string(ctx, -1));
77 74
78 GREATEST_PASS(); 75 GREATEST_PASS();
79 } 76 }
80 77
81 GREATEST_TEST 78 GREATEST_TEST
82 free_exists(void) 79 free_exists(void)
83 { 80 {
84 if (duk_peval_string(ctx, "result = Irccd.File.exists(SOURCE + '/data/root/file-1.txt')")) 81 if (duk_peval_string(ctx, "result = Irccd.File.exists(TOP + '/tests/data/root/file-1.txt')"))
85 GREATEST_FAIL(); 82 GREATEST_FAIL();
86 83
87 GREATEST_ASSERT(duk_get_global_string(ctx, "result")); 84 GREATEST_ASSERT(duk_get_global_string(ctx, "result"));
88 GREATEST_ASSERT(duk_get_boolean(ctx, -1)); 85 GREATEST_ASSERT(duk_get_boolean(ctx, -1));
89 86
106 free_remove(void) 103 free_remove(void)
107 { 104 {
108 FILE *fp; 105 FILE *fp;
109 struct stat st; 106 struct stat st;
110 107
111 if (!(fp = fopen(BINARY "/test.bin", "w"))) 108 if (!(fp = fopen(TOP "/tests/test.bin", "w")))
112 GREATEST_FAIL(); 109 GREATEST_FAIL();
113 110
114 fclose(fp); 111 fclose(fp);
115 112
116 if (duk_peval_string(ctx, "Irccd.File.remove(BINARY + '/test.bin')") != 0) 113 if (duk_peval_string(ctx, "Irccd.File.remove(TOP + '/tests/test.bin')") != 0)
117 GREATEST_FAIL(); 114 GREATEST_FAIL();
118 115
119 GREATEST_ASSERT(stat(BINARY "/test.bin", &st) < 0); 116 GREATEST_ASSERT(stat(TOP "/tests/test.bin", &st) < 0);
120 117
121 GREATEST_PASS(); 118 GREATEST_PASS();
122 } 119 }
123 120
124 GREATEST_SUITE(suite_free) 121 GREATEST_SUITE(suite_free)
134 131
135 GREATEST_TEST 132 GREATEST_TEST
136 object_basename(void) 133 object_basename(void)
137 { 134 {
138 const int ret = duk_peval_string(ctx, 135 const int ret = duk_peval_string(ctx,
139 "f = new Irccd.File(SOURCE + '/data/root/file-1.txt', 'r');" 136 "f = new Irccd.File(TOP + '/tests/data/root/file-1.txt', 'r');"
140 "result = f.basename();" 137 "result = f.basename();"
141 ); 138 );
142 139
143 if (ret != 0) 140 if (ret != 0)
144 GREATEST_FAIL(); 141 GREATEST_FAIL();
151 148
152 GREATEST_TEST 149 GREATEST_TEST
153 object_basename_closed(void) 150 object_basename_closed(void)
154 { 151 {
155 const int ret = duk_peval_string(ctx, 152 const int ret = duk_peval_string(ctx,
156 "f = new Irccd.File(SOURCE + '/data/root/file-1.txt', 'r');" 153 "f = new Irccd.File(TOP + '/tests/data/root/file-1.txt', 'r');"
157 "f.close();" 154 "f.close();"
158 "result = f.basename();" 155 "result = f.basename();"
159 ); 156 );
160 157
161 if (ret != 0) 158 if (ret != 0)
169 166
170 GREATEST_TEST 167 GREATEST_TEST
171 object_dirname(void) 168 object_dirname(void)
172 { 169 {
173 const int ret = duk_peval_string(ctx, 170 const int ret = duk_peval_string(ctx,
174 "f = new Irccd.File(SOURCE + '/data/root/file-1.txt', 'r');" 171 "f = new Irccd.File(TOP + '/tests/data/root/file-1.txt', 'r');"
175 "result = f.dirname();" 172 "result = f.dirname();"
176 ); 173 );
177 174
178 if (ret != 0) 175 if (ret != 0)
179 GREATEST_FAIL(); 176 GREATEST_FAIL();
180 177
181 GREATEST_ASSERT(duk_get_global_string(ctx, "result")); 178 GREATEST_ASSERT(duk_get_global_string(ctx, "result"));
182 GREATEST_ASSERT_STR_EQ(SOURCE "/data/root", duk_get_string(ctx, -1)); 179 GREATEST_ASSERT_STR_EQ(TOP "/tests/data/root", duk_get_string(ctx, -1));
183 180
184 GREATEST_PASS(); 181 GREATEST_PASS();
185 } 182 }
186 183
187 GREATEST_TEST 184 GREATEST_TEST
188 object_dirname_closed(void) 185 object_dirname_closed(void)
189 { 186 {
190 const int ret = duk_peval_string(ctx, 187 const int ret = duk_peval_string(ctx,
191 "f = new Irccd.File(SOURCE + '/data/root/file-1.txt', 'r');" 188 "f = new Irccd.File(TOP + '/tests/data/root/file-1.txt', 'r');"
192 "f.close();" 189 "f.close();"
193 "result = f.dirname();" 190 "result = f.dirname();"
194 ); 191 );
195 192
196 if (ret != 0) 193 if (ret != 0)
197 GREATEST_FAIL(); 194 GREATEST_FAIL();
198 195
199 GREATEST_ASSERT(duk_get_global_string(ctx, "result")); 196 GREATEST_ASSERT(duk_get_global_string(ctx, "result"));
200 GREATEST_ASSERT_STR_EQ(SOURCE "/data/root", duk_get_string(ctx, -1)); 197 GREATEST_ASSERT_STR_EQ(TOP "/tests/data/root", duk_get_string(ctx, -1));
201 198
202 GREATEST_PASS(); 199 GREATEST_PASS();
203 } 200 }
204 201
205 GREATEST_TEST 202 GREATEST_TEST
206 object_lines(void) 203 object_lines(void)
207 { 204 {
208 const int ret = duk_peval_string(ctx, 205 const int ret = duk_peval_string(ctx,
209 "result = new Irccd.File(SOURCE + '/data/root/lines.txt', 'r').lines();" 206 "result = new Irccd.File(TOP + '/tests/data/root/lines.txt', 'r').lines();"
210 ); 207 );
211 208
212 if (ret != 0) 209 if (ret != 0)
213 GREATEST_FAIL(); 210 GREATEST_FAIL();
214 211
227 GREATEST_TEST 224 GREATEST_TEST
228 object_lines_closed(void) 225 object_lines_closed(void)
229 { 226 {
230 const int ret = duk_peval_string(ctx, 227 const int ret = duk_peval_string(ctx,
231 "try {" 228 "try {"
232 " f = new Irccd.File(SOURCE + '/data/root/lines.txt', 'r');" 229 " f = new Irccd.File(TOP + '/tests/data/root/lines.txt', 'r');"
233 " f.close();" 230 " f.close();"
234 " f.lines();" 231 " f.lines();"
235 "} catch (e) {" 232 "} catch (e) {"
236 " name = e.name;" 233 " name = e.name;"
237 "}" 234 "}"
248 245
249 GREATEST_TEST 246 GREATEST_TEST
250 object_seek1(void) 247 object_seek1(void)
251 { 248 {
252 const int ret = duk_peval_string(ctx, 249 const int ret = duk_peval_string(ctx,
253 "f = new Irccd.File(SOURCE + '/data/root/file-1.txt', 'r');" 250 "f = new Irccd.File(TOP + '/tests/data/root/file-1.txt', 'r');"
254 "f.seek(Irccd.File.SeekSet, 6);" 251 "f.seek(Irccd.File.SeekSet, 6);"
255 "result = f.read(1);" 252 "result = f.read(1);"
256 ); 253 );
257 254
258 if (ret != 0) 255 if (ret != 0)
266 263
267 GREATEST_TEST 264 GREATEST_TEST
268 object_seek2(void) 265 object_seek2(void)
269 { 266 {
270 const int ret = duk_peval_string(ctx, 267 const int ret = duk_peval_string(ctx,
271 "f = new Irccd.File(SOURCE + '/data/root/file-1.txt', 'r');" 268 "f = new Irccd.File(TOP + '/tests/data/root/file-1.txt', 'r');"
272 "f.seek(Irccd.File.SeekSet, 2);" 269 "f.seek(Irccd.File.SeekSet, 2);"
273 "f.seek(Irccd.File.SeekCur, 4);" 270 "f.seek(Irccd.File.SeekCur, 4);"
274 "result = f.read(1);" 271 "result = f.read(1);"
275 ); 272 );
276 273
285 282
286 GREATEST_TEST 283 GREATEST_TEST
287 object_seek3(void) 284 object_seek3(void)
288 { 285 {
289 const int ret = duk_peval_string(ctx, 286 const int ret = duk_peval_string(ctx,
290 "f = new Irccd.File(SOURCE + '/data/root/file-1.txt', 'r');" 287 "f = new Irccd.File(TOP + '/tests/data/root/file-1.txt', 'r');"
291 "f.seek(Irccd.File.SeekEnd, -2);" 288 "f.seek(Irccd.File.SeekEnd, -2);"
292 "result = f.read(1);" 289 "result = f.read(1);"
293 ); 290 );
294 291
295 if (ret != 0) 292 if (ret != 0)
304 GREATEST_TEST 301 GREATEST_TEST
305 object_seek_closed(void) 302 object_seek_closed(void)
306 { 303 {
307 const int ret = duk_peval_string(ctx, 304 const int ret = duk_peval_string(ctx,
308 "try {" 305 "try {"
309 " f = new Irccd.File(SOURCE + '/data/root/file-1.txt', 'r');" 306 " f = new Irccd.File(TOP + '/tests/data/root/file-1.txt', 'r');"
310 " f.close();" 307 " f.close();"
311 " f.seek(Irccd.File.SeekEnd, -2);" 308 " f.seek(Irccd.File.SeekEnd, -2);"
312 "} catch (e) {" 309 "} catch (e) {"
313 " name = e.name" 310 " name = e.name"
314 "}" 311 "}"
325 322
326 GREATEST_TEST 323 GREATEST_TEST
327 object_read(void) 324 object_read(void)
328 { 325 {
329 const int ret = duk_peval_string(ctx, 326 const int ret = duk_peval_string(ctx,
330 "f = new Irccd.File(SOURCE + '/data/root/file-1.txt', 'r');" 327 "f = new Irccd.File(TOP + '/tests/data/root/file-1.txt', 'r');"
331 "result = f.read();" 328 "result = f.read();"
332 ); 329 );
333 330
334 if (ret != 0) 331 if (ret != 0)
335 GREATEST_FAIL(); 332 GREATEST_FAIL();
343 GREATEST_TEST 340 GREATEST_TEST
344 object_read_closed(void) 341 object_read_closed(void)
345 { 342 {
346 const int ret = duk_peval_string(ctx, 343 const int ret = duk_peval_string(ctx,
347 "try {" 344 "try {"
348 " f = new Irccd.File(SOURCE + '/data/root/file-1.txt', 'r');" 345 " f = new Irccd.File(TOP + '/tests/data/root/file-1.txt', 'r');"
349 " f.close();" 346 " f.close();"
350 " f.read();" 347 " f.read();"
351 "} catch (e) {" 348 "} catch (e) {"
352 " name = e.name;" 349 " name = e.name;"
353 "}" 350 "}"
365 GREATEST_TEST 362 GREATEST_TEST
366 object_readline(void) 363 object_readline(void)
367 { 364 {
368 const int ret = duk_peval_string(ctx, 365 const int ret = duk_peval_string(ctx,
369 "result = [];" 366 "result = [];"
370 "f = new Irccd.File(SOURCE + '/data/root/lines.txt', 'r');" 367 "f = new Irccd.File(TOP + '/tests/data/root/lines.txt', 'r');"
371 "for (var s; s = f.readline(); ) {" 368 "for (var s; s = f.readline(); ) {"
372 " result.push(s);" 369 " result.push(s);"
373 "}" 370 "}"
374 ); 371 );
375 372
394 object_readline_closed(void) 391 object_readline_closed(void)
395 { 392 {
396 const int ret = duk_peval_string(ctx, 393 const int ret = duk_peval_string(ctx,
397 "try {" 394 "try {"
398 " result = [];" 395 " result = [];"
399 " f = new Irccd.File(SOURCE + '/data/root/lines.txt', 'r');" 396 " f = new Irccd.File(TOP + '/tests/data/root/lines.txt', 'r');"
400 " f.close();" 397 " f.close();"
401 " for (var s; s = f.readline(); ) {" 398 " for (var s; s = f.readline(); ) {"
402 " result.push(s);" 399 " result.push(s);"
403 " }" 400 " }"
404 "} catch (e) {" 401 "} catch (e) {"