1 | /* GLib testing framework examples and tests |
2 | * Copyright (C) 2007 Imendio AB |
3 | * Authors: Tim Janik |
4 | * |
5 | * This work is provided "as is"; redistribution and modification |
6 | * in whole or in part, in any medium, physical or electronic is |
7 | * permitted without restriction. |
8 | * |
9 | * This work is distributed in the hope that it will be useful, |
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
12 | * |
13 | * In no event shall the authors or contributors be liable for any |
14 | * direct, indirect, incidental, special, exemplary, or consequential |
15 | * damages (including, but not limited to, procurement of substitute |
16 | * goods or services; loss of use, data, or profits; or business |
17 | * interruption) however caused and on any theory of liability, whether |
18 | * in contract, strict liability, or tort (including negligence or |
19 | * otherwise) arising in any way out of the use of this software, even |
20 | * if advised of the possibility of such damage. |
21 | */ |
22 | |
23 | #include "config.h" |
24 | |
25 | /* We want to distinguish between messages originating from libglib |
26 | * and messages originating from this program. |
27 | */ |
28 | #undef G_LOG_DOMAIN |
29 | #define G_LOG_DOMAIN "testing" |
30 | |
31 | #include <glib.h> |
32 | #include <locale.h> |
33 | #include <stdlib.h> |
34 | #include <string.h> |
35 | |
36 | /* test assertion variants */ |
37 | static void |
38 | test_assertions_bad_cmpvariant_types (void) |
39 | { |
40 | GVariant *v1, *v2; |
41 | |
42 | v1 = g_variant_new_boolean (TRUE); |
43 | v2 = g_variant_new_string (string: "hello" ); |
44 | |
45 | g_assert_cmpvariant (v1, v2); |
46 | |
47 | g_variant_unref (value: v2); |
48 | g_variant_unref (value: v1); |
49 | |
50 | exit (status: 0); |
51 | } |
52 | |
53 | static void |
54 | test_assertions_bad_cmpvariant_values (void) |
55 | { |
56 | GVariant *v1, *v2; |
57 | |
58 | v1 = g_variant_new_string (string: "goodbye" ); |
59 | v2 = g_variant_new_string (string: "hello" ); |
60 | |
61 | g_assert_cmpvariant (v1, v2); |
62 | |
63 | g_variant_unref (value: v2); |
64 | g_variant_unref (value: v1); |
65 | |
66 | exit (status: 0); |
67 | } |
68 | |
69 | static void |
70 | test_assertions_bad_cmpstrv_null1 (void) |
71 | { |
72 | const char *strv[] = { "one" , "two" , "three" , NULL }; |
73 | g_assert_cmpstrv (strv, NULL); |
74 | exit (status: 0); |
75 | } |
76 | |
77 | static void |
78 | test_assertions_bad_cmpstrv_null2 (void) |
79 | { |
80 | const char *strv[] = { "one" , "two" , "three" , NULL }; |
81 | g_assert_cmpstrv (NULL, strv); |
82 | exit (status: 0); |
83 | } |
84 | |
85 | static void |
86 | test_assertions_bad_cmpstrv_length (void) |
87 | { |
88 | const char *strv1[] = { "one" , "two" , "three" , NULL }; |
89 | const char *strv2[] = { "one" , "two" , NULL }; |
90 | g_assert_cmpstrv (strv1, strv2); |
91 | exit (status: 0); |
92 | } |
93 | |
94 | static void |
95 | test_assertions_bad_cmpstrv_values (void) |
96 | { |
97 | const char *strv1[] = { "one" , "two" , "three" , NULL }; |
98 | const char *strv2[] = { "one" , "too" , "three" , NULL }; |
99 | g_assert_cmpstrv (strv1, strv2); |
100 | exit (status: 0); |
101 | } |
102 | |
103 | static void |
104 | test_assertions_bad_cmpstr (void) |
105 | { |
106 | g_assert_cmpstr ("fzz" , !=, "fzz" ); |
107 | exit (status: 0); |
108 | } |
109 | |
110 | static void |
111 | test_assertions_bad_cmpint (void) |
112 | { |
113 | g_assert_cmpint (4, !=, 4); |
114 | exit (status: 0); |
115 | } |
116 | |
117 | static void |
118 | test_assertions_bad_cmpmem_len (void) |
119 | { |
120 | g_assert_cmpmem ("foo" , 3, "foot" , 4); |
121 | exit (status: 0); |
122 | } |
123 | |
124 | static void |
125 | test_assertions_bad_cmpmem_data (void) |
126 | { |
127 | g_assert_cmpmem ("foo" , 3, "fzz" , 3); |
128 | exit (status: 0); |
129 | } |
130 | |
131 | static void |
132 | test_assertions_bad_cmpmem_null (void) |
133 | { |
134 | g_assert_cmpmem (NULL, 3, NULL, 3); |
135 | exit (status: 0); |
136 | } |
137 | |
138 | static void |
139 | test_assertions_bad_cmpfloat_epsilon (void) |
140 | { |
141 | g_assert_cmpfloat_with_epsilon (3.14, 3.15, 0.001); |
142 | exit (status: 0); |
143 | } |
144 | |
145 | /* Emulates something like rmdir() failing. */ |
146 | static int |
147 | return_errno (void) |
148 | { |
149 | errno = ERANGE; /* arbitrary non-zero value */ |
150 | return -1; |
151 | } |
152 | |
153 | /* Emulates something like rmdir() succeeding. */ |
154 | static int |
155 | return_no_errno (void) |
156 | { |
157 | return 0; |
158 | } |
159 | |
160 | static void |
161 | test_assertions_bad_no_errno (void) |
162 | { |
163 | g_assert_no_errno (return_errno ()); |
164 | } |
165 | |
166 | static void |
167 | test_assertions (void) |
168 | { |
169 | const char *strv1[] = { "one" , "two" , "three" , NULL }; |
170 | const char *strv2[] = { "one" , "two" , "three" , NULL }; |
171 | GVariant *v1, *v2; |
172 | gchar *fuu; |
173 | |
174 | g_assert_cmpint (1, >, 0); |
175 | g_assert_cmphex (2, ==, 2); |
176 | g_assert_cmpfloat (3.3, !=, 7); |
177 | g_assert_cmpfloat (7, <=, 3 + 4); |
178 | g_assert_cmpfloat_with_epsilon (3.14, 3.15, 0.01); |
179 | g_assert_cmpfloat_with_epsilon (3.14159, 3.1416, 0.0001); |
180 | g_assert (TRUE); |
181 | g_assert_true (TRUE); |
182 | g_assert_cmpstr ("foo" , !=, "faa" ); |
183 | fuu = g_strdup_printf (format: "f%s" , "uu" ); |
184 | g_test_queue_free (gfree_pointer: fuu); |
185 | g_assert_cmpstr ("foo" , !=, fuu); |
186 | g_assert_cmpstr ("fuu" , ==, fuu); |
187 | g_assert_cmpstr (NULL, <, "" ); |
188 | g_assert_cmpstr (NULL, ==, NULL); |
189 | g_assert_cmpstr ("" , >, NULL); |
190 | g_assert_cmpstr ("foo" , <, "fzz" ); |
191 | g_assert_cmpstr ("fzz" , >, "faa" ); |
192 | g_assert_cmpstr ("fzz" , ==, "fzz" ); |
193 | g_assert_cmpmem ("foo" , 3, "foot" , 3); |
194 | g_assert_cmpmem (NULL, 0, NULL, 0); |
195 | g_assert_cmpmem (NULL, 0, "foot" , 0); |
196 | g_assert_cmpmem ("foo" , 0, NULL, 0); |
197 | g_assert_no_errno (return_no_errno ()); |
198 | |
199 | g_assert_cmpstrv (NULL, NULL); |
200 | g_assert_cmpstrv (strv1, strv2); |
201 | |
202 | v1 = g_variant_new_parsed (format: "['hello', 'there']" ); |
203 | v2 = g_variant_new_parsed (format: "['hello', 'there']" ); |
204 | |
205 | g_assert_cmpvariant (v1, v1); |
206 | g_assert_cmpvariant (v1, v2); |
207 | |
208 | g_variant_unref (value: v2); |
209 | g_variant_unref (value: v1); |
210 | |
211 | g_test_trap_subprocess (test_path: "/misc/assertions/subprocess/bad_cmpvariant_types" , usec_timeout: 0, test_flags: 0); |
212 | g_test_trap_assert_failed (); |
213 | g_test_trap_assert_stderr ("*assertion failed*" ); |
214 | |
215 | g_test_trap_subprocess (test_path: "/misc/assertions/subprocess/bad_cmpvariant_values" , usec_timeout: 0, test_flags: 0); |
216 | g_test_trap_assert_failed (); |
217 | g_test_trap_assert_stderr ("*assertion failed*" ); |
218 | |
219 | g_test_trap_subprocess (test_path: "/misc/assertions/subprocess/bad_cmpstr" , usec_timeout: 0, test_flags: 0); |
220 | g_test_trap_assert_failed (); |
221 | g_test_trap_assert_stderr ("*assertion failed*" ); |
222 | |
223 | g_test_trap_subprocess (test_path: "/misc/assertions/subprocess/bad_cmpstrv_null1" , usec_timeout: 0, test_flags: 0); |
224 | g_test_trap_assert_failed (); |
225 | g_test_trap_assert_stderr ("*assertion failed*" ); |
226 | |
227 | g_test_trap_subprocess (test_path: "/misc/assertions/subprocess/bad_cmpstrv_null2" , usec_timeout: 0, test_flags: 0); |
228 | g_test_trap_assert_failed (); |
229 | g_test_trap_assert_stderr ("*assertion failed*" ); |
230 | |
231 | g_test_trap_subprocess (test_path: "/misc/assertions/subprocess/bad_cmpstrv_length" , usec_timeout: 0, test_flags: 0); |
232 | g_test_trap_assert_failed (); |
233 | g_test_trap_assert_stderr ("*assertion failed*" ); |
234 | |
235 | g_test_trap_subprocess (test_path: "/misc/assertions/subprocess/bad_cmpstrv_values" , usec_timeout: 0, test_flags: 0); |
236 | g_test_trap_assert_failed (); |
237 | g_test_trap_assert_stderr ("*assertion failed*" ); |
238 | |
239 | g_test_trap_subprocess (test_path: "/misc/assertions/subprocess/bad_cmpint" , usec_timeout: 0, test_flags: 0); |
240 | g_test_trap_assert_failed (); |
241 | g_test_trap_assert_stderr ("*assertion failed*" ); |
242 | |
243 | g_test_trap_subprocess (test_path: "/misc/assertions/subprocess/bad_cmpmem_len" , usec_timeout: 0, test_flags: 0); |
244 | g_test_trap_assert_failed (); |
245 | g_test_trap_assert_stderr ("*assertion failed*len*" ); |
246 | |
247 | g_test_trap_subprocess (test_path: "/misc/assertions/subprocess/bad_cmpmem_data" , usec_timeout: 0, test_flags: 0); |
248 | g_test_trap_assert_failed (); |
249 | g_test_trap_assert_stderr ("*assertion failed*" ); |
250 | g_test_trap_assert_stderr_unmatched ("*assertion failed*len*" ); |
251 | |
252 | g_test_trap_subprocess (test_path: "/misc/assertions/subprocess/bad_cmpmem_null" , usec_timeout: 0, test_flags: 0); |
253 | g_test_trap_assert_failed (); |
254 | g_test_trap_assert_stderr ("*assertion failed*NULL*" ); |
255 | |
256 | g_test_trap_subprocess (test_path: "/misc/assertions/subprocess/bad_cmpfloat_epsilon" , usec_timeout: 0, test_flags: 0); |
257 | g_test_trap_assert_failed (); |
258 | g_test_trap_assert_stderr ("*assertion failed*" ); |
259 | |
260 | g_test_trap_subprocess (test_path: "/misc/assertions/subprocess/bad_no_errno" , usec_timeout: 0, test_flags: 0); |
261 | g_test_trap_assert_failed (); |
262 | g_test_trap_assert_stderr ("*assertion failed*" ); |
263 | } |
264 | |
265 | /* test g_test_timer* API */ |
266 | static void |
267 | test_timer (void) |
268 | { |
269 | double ttime; |
270 | g_test_timer_start(); |
271 | g_assert_cmpfloat (g_test_timer_last(), ==, 0); |
272 | g_usleep (microseconds: 25 * 1000); |
273 | ttime = g_test_timer_elapsed(); |
274 | g_assert_cmpfloat (ttime, >, 0); |
275 | g_assert_cmpfloat (g_test_timer_last(), ==, ttime); |
276 | g_test_minimized_result (minimized_quantity: ttime, format: "timer-test-time: %fsec" , ttime); |
277 | g_test_maximized_result (maximized_quantity: 5, format: "bogus-quantity: %ddummies" , 5); /* simple API test */ |
278 | } |
279 | |
280 | #ifdef G_OS_UNIX |
281 | G_GNUC_BEGIN_IGNORE_DEPRECATIONS |
282 | |
283 | /* fork out for a failing test */ |
284 | static void |
285 | test_fork_fail (void) |
286 | { |
287 | if (g_test_trap_fork (usec_timeout: 0, test_trap_flags: G_TEST_TRAP_SILENCE_STDERR)) |
288 | { |
289 | g_assert_not_reached(); |
290 | } |
291 | g_test_trap_assert_failed(); |
292 | g_test_trap_assert_stderr ("*ERROR*test_fork_fail*should not be reached*" ); |
293 | } |
294 | |
295 | /* fork out to assert stdout and stderr patterns */ |
296 | static void |
297 | test_fork_patterns (void) |
298 | { |
299 | if (g_test_trap_fork (usec_timeout: 0, test_trap_flags: G_TEST_TRAP_SILENCE_STDOUT | G_TEST_TRAP_SILENCE_STDERR)) |
300 | { |
301 | g_print (format: "some stdout text: somagic17\n" ); |
302 | g_printerr (format: "some stderr text: semagic43\n" ); |
303 | exit (status: 0); |
304 | } |
305 | g_test_trap_assert_passed(); |
306 | g_test_trap_assert_stdout ("*somagic17*" ); |
307 | g_test_trap_assert_stderr ("*semagic43*" ); |
308 | } |
309 | |
310 | /* fork out for a timeout test */ |
311 | static void |
312 | test_fork_timeout (void) |
313 | { |
314 | /* allow child to run for only a fraction of a second */ |
315 | if (g_test_trap_fork (usec_timeout: 0.11 * 1000000, test_trap_flags: 0)) |
316 | { |
317 | /* loop and sleep forever */ |
318 | while (TRUE) |
319 | g_usleep (microseconds: 1000 * 1000); |
320 | } |
321 | g_test_trap_assert_failed(); |
322 | g_assert_true (g_test_trap_reached_timeout()); |
323 | } |
324 | |
325 | G_GNUC_END_IGNORE_DEPRECATIONS |
326 | #endif /* G_OS_UNIX */ |
327 | |
328 | static void |
329 | test_subprocess_fail (void) |
330 | { |
331 | if (g_test_subprocess ()) |
332 | { |
333 | g_assert_not_reached (); |
334 | return; |
335 | } |
336 | |
337 | g_test_trap_subprocess (NULL, usec_timeout: 0, test_flags: 0); |
338 | g_test_trap_assert_failed (); |
339 | g_test_trap_assert_stderr ("*ERROR*test_subprocess_fail*should not be reached*" ); |
340 | } |
341 | |
342 | static void |
343 | test_subprocess_no_such_test (void) |
344 | { |
345 | if (g_test_subprocess ()) |
346 | { |
347 | g_test_trap_subprocess (test_path: "/trap_subprocess/this-test-does-not-exist" , usec_timeout: 0, test_flags: 0); |
348 | g_assert_not_reached (); |
349 | return; |
350 | } |
351 | g_test_trap_subprocess (NULL, usec_timeout: 0, test_flags: 0); |
352 | g_test_trap_assert_failed (); |
353 | g_test_trap_assert_stderr ("*test does not exist*" ); |
354 | g_test_trap_assert_stderr_unmatched ("*should not be reached*" ); |
355 | } |
356 | |
357 | static void |
358 | test_subprocess_patterns (void) |
359 | { |
360 | if (g_test_subprocess ()) |
361 | { |
362 | g_print (format: "some stdout text: somagic17\n" ); |
363 | g_printerr (format: "some stderr text: semagic43\n" ); |
364 | exit (status: 0); |
365 | } |
366 | g_test_trap_subprocess (NULL, usec_timeout: 0, test_flags: 0); |
367 | g_test_trap_assert_passed (); |
368 | g_test_trap_assert_stdout ("*somagic17*" ); |
369 | g_test_trap_assert_stderr ("*semagic43*" ); |
370 | } |
371 | |
372 | static void |
373 | test_subprocess_timeout (void) |
374 | { |
375 | if (g_test_subprocess ()) |
376 | { |
377 | /* loop and sleep forever */ |
378 | while (TRUE) |
379 | g_usleep (microseconds: 1000 * 1000); |
380 | return; |
381 | } |
382 | /* allow child to run for only a fraction of a second */ |
383 | g_test_trap_subprocess (NULL, usec_timeout: 0.11 * 1000000, test_flags: 0); |
384 | g_test_trap_assert_failed (); |
385 | g_assert_true (g_test_trap_reached_timeout ()); |
386 | } |
387 | |
388 | /* run a test with fixture setup and teardown */ |
389 | typedef struct { |
390 | guint seed; |
391 | guint prime; |
392 | gchar *msg; |
393 | } Fixturetest; |
394 | static void |
395 | fixturetest_setup (Fixturetest *fix, |
396 | gconstpointer test_data) |
397 | { |
398 | g_assert_true (test_data == (void*) 0xc0cac01a); |
399 | fix->seed = 18; |
400 | fix->prime = 19; |
401 | fix->msg = g_strdup_printf (format: "%d" , fix->prime); |
402 | } |
403 | static void |
404 | fixturetest_test (Fixturetest *fix, |
405 | gconstpointer test_data) |
406 | { |
407 | guint prime = g_spaced_primes_closest (num: fix->seed); |
408 | g_assert_cmpint (prime, ==, fix->prime); |
409 | prime = g_ascii_strtoull (nptr: fix->msg, NULL, base: 0); |
410 | g_assert_cmpint (prime, ==, fix->prime); |
411 | g_assert_true (test_data == (void*) 0xc0cac01a); |
412 | } |
413 | static void |
414 | fixturetest_teardown (Fixturetest *fix, |
415 | gconstpointer test_data) |
416 | { |
417 | g_assert_true (test_data == (void*) 0xc0cac01a); |
418 | g_free (mem: fix->msg); |
419 | } |
420 | |
421 | static struct { |
422 | int bit, vint1, vint2, irange; |
423 | long double vdouble, drange; |
424 | } shared_rand_state; |
425 | |
426 | static void |
427 | test_rand1 (void) |
428 | { |
429 | shared_rand_state.bit = g_test_rand_bit(); |
430 | shared_rand_state.vint1 = g_test_rand_int(); |
431 | shared_rand_state.vint2 = g_test_rand_int(); |
432 | g_assert_cmpint (shared_rand_state.vint1, !=, shared_rand_state.vint2); |
433 | shared_rand_state.irange = g_test_rand_int_range (begin: 17, end: 35); |
434 | g_assert_cmpint (shared_rand_state.irange, >=, 17); |
435 | g_assert_cmpint (shared_rand_state.irange, <=, 35); |
436 | shared_rand_state.vdouble = g_test_rand_double(); |
437 | shared_rand_state.drange = g_test_rand_double_range (range_start: -999, range_end: +17); |
438 | g_assert_cmpfloat (shared_rand_state.drange, >=, -999); |
439 | g_assert_cmpfloat (shared_rand_state.drange, <=, +17); |
440 | } |
441 | |
442 | static void |
443 | test_rand2 (void) |
444 | { |
445 | /* this test only works if run after test1. |
446 | * we do this to check that random number generators |
447 | * are reseeded upon fixture setup. |
448 | */ |
449 | g_assert_cmpint (shared_rand_state.bit, ==, g_test_rand_bit()); |
450 | g_assert_cmpint (shared_rand_state.vint1, ==, g_test_rand_int()); |
451 | g_assert_cmpint (shared_rand_state.vint2, ==, g_test_rand_int()); |
452 | g_assert_cmpint (shared_rand_state.irange, ==, g_test_rand_int_range (17, 35)); |
453 | g_assert_cmpfloat (shared_rand_state.vdouble, ==, g_test_rand_double()); |
454 | g_assert_cmpfloat (shared_rand_state.drange, ==, g_test_rand_double_range (-999, +17)); |
455 | } |
456 | |
457 | static void |
458 | test_data_test (gconstpointer test_data) |
459 | { |
460 | g_assert_true (test_data == (void*) 0xc0c0baba); |
461 | } |
462 | |
463 | static void |
464 | test_random_conversions (void) |
465 | { |
466 | /* very simple conversion test using random numbers */ |
467 | int vint = g_test_rand_int(); |
468 | char *err, *str = g_strdup_printf (format: "%d" , vint); |
469 | gint64 vint64 = g_ascii_strtoll (nptr: str, endptr: &err, base: 10); |
470 | g_assert_cmphex (vint, ==, vint64); |
471 | g_assert_true (!err || *err == 0); |
472 | g_free (mem: str); |
473 | } |
474 | |
475 | static gboolean |
476 | fatal_handler (const gchar *log_domain, |
477 | GLogLevelFlags log_level, |
478 | const gchar *message, |
479 | gpointer user_data) |
480 | { |
481 | return FALSE; |
482 | } |
483 | |
484 | static void |
485 | test_fatal_log_handler_critical_pass (void) |
486 | { |
487 | g_test_log_set_fatal_handler (log_func: fatal_handler, NULL); |
488 | g_str_has_prefix (NULL, prefix: "file://" ); |
489 | g_critical ("Test passing" ); |
490 | exit (status: 0); |
491 | } |
492 | |
493 | static void |
494 | test_fatal_log_handler_error_fail (void) |
495 | { |
496 | g_error ("Test failing" ); |
497 | exit (status: 0); |
498 | } |
499 | |
500 | static void |
501 | test_fatal_log_handler_critical_fail (void) |
502 | { |
503 | g_str_has_prefix (NULL, prefix: "file://" ); |
504 | g_critical ("Test passing" ); |
505 | exit (status: 0); |
506 | } |
507 | |
508 | static void |
509 | test_fatal_log_handler (void) |
510 | { |
511 | g_test_trap_subprocess (test_path: "/misc/fatal-log-handler/subprocess/critical-pass" , usec_timeout: 0, test_flags: 0); |
512 | g_test_trap_assert_passed (); |
513 | g_test_trap_assert_stderr ("*CRITICAL*g_str_has_prefix*" ); |
514 | g_test_trap_assert_stderr ("*CRITICAL*Test passing*" ); |
515 | |
516 | g_test_trap_subprocess (test_path: "/misc/fatal-log-handler/subprocess/error-fail" , usec_timeout: 0, test_flags: 0); |
517 | g_test_trap_assert_failed (); |
518 | g_test_trap_assert_stderr ("*ERROR*Test failing*" ); |
519 | |
520 | g_test_trap_subprocess (test_path: "/misc/fatal-log-handler/subprocess/critical-fail" , usec_timeout: 0, test_flags: 0); |
521 | g_test_trap_assert_failed (); |
522 | g_test_trap_assert_stderr ("*CRITICAL*g_str_has_prefix*" ); |
523 | g_test_trap_assert_stderr_unmatched ("*CRITICAL*Test passing*" ); |
524 | } |
525 | |
526 | static void |
527 | test_expected_messages_warning (void) |
528 | { |
529 | g_warning ("This is a %d warning" , g_random_int ()); |
530 | g_return_if_reached (); |
531 | } |
532 | |
533 | static void |
534 | test_expected_messages_expect_warning (void) |
535 | { |
536 | g_test_expect_message (G_LOG_DOMAIN, log_level: G_LOG_LEVEL_WARNING, |
537 | pattern: "This is a * warning" ); |
538 | test_expected_messages_warning (); |
539 | } |
540 | |
541 | static void |
542 | test_expected_messages_wrong_warning (void) |
543 | { |
544 | g_test_expect_message (G_LOG_DOMAIN, log_level: G_LOG_LEVEL_CRITICAL, |
545 | pattern: "*should not be *" ); |
546 | test_expected_messages_warning (); |
547 | } |
548 | |
549 | static void |
550 | test_expected_messages_expected (void) |
551 | { |
552 | g_test_expect_message (G_LOG_DOMAIN, log_level: G_LOG_LEVEL_WARNING, |
553 | pattern: "This is a * warning" ); |
554 | g_test_expect_message (G_LOG_DOMAIN, log_level: G_LOG_LEVEL_CRITICAL, |
555 | pattern: "*should not be reached" ); |
556 | |
557 | test_expected_messages_warning (); |
558 | |
559 | g_test_assert_expected_messages (); |
560 | exit (status: 0); |
561 | } |
562 | |
563 | static void |
564 | test_expected_messages_null_domain (void) |
565 | { |
566 | g_test_expect_message (NULL, log_level: G_LOG_LEVEL_WARNING, pattern: "no domain" ); |
567 | g_log (NULL, log_level: G_LOG_LEVEL_WARNING, format: "no domain" ); |
568 | g_test_assert_expected_messages (); |
569 | } |
570 | |
571 | static void |
572 | test_expected_messages_expect_error (void) |
573 | { |
574 | /* make sure we can't try to expect a g_error() */ |
575 | g_test_expect_message (log_domain: "GLib" , log_level: G_LOG_LEVEL_CRITICAL, pattern: "*G_LOG_LEVEL_ERROR*" ); |
576 | g_test_expect_message (G_LOG_DOMAIN, log_level: G_LOG_LEVEL_ERROR, pattern: "this won't work" ); |
577 | g_test_assert_expected_messages (); |
578 | } |
579 | |
580 | static void |
581 | (void) |
582 | { |
583 | g_test_expect_message (G_LOG_DOMAIN, log_level: G_LOG_LEVEL_WARNING, |
584 | pattern: "This is a * warning" ); |
585 | g_test_expect_message (G_LOG_DOMAIN, log_level: G_LOG_LEVEL_CRITICAL, |
586 | pattern: "*should not be reached" ); |
587 | g_test_expect_message (G_LOG_DOMAIN, log_level: G_LOG_LEVEL_CRITICAL, |
588 | pattern: "nope" ); |
589 | |
590 | test_expected_messages_warning (); |
591 | |
592 | /* If we don't assert, it won't notice the missing message */ |
593 | exit (status: 0); |
594 | } |
595 | |
596 | static void |
597 | (void) |
598 | { |
599 | g_test_expect_message (G_LOG_DOMAIN, log_level: G_LOG_LEVEL_WARNING, |
600 | pattern: "This is a * warning" ); |
601 | g_test_expect_message (G_LOG_DOMAIN, log_level: G_LOG_LEVEL_CRITICAL, |
602 | pattern: "*should not be reached" ); |
603 | g_test_expect_message (G_LOG_DOMAIN, log_level: G_LOG_LEVEL_CRITICAL, |
604 | pattern: "nope" ); |
605 | |
606 | test_expected_messages_warning (); |
607 | |
608 | g_test_assert_expected_messages (); |
609 | exit (status: 0); |
610 | } |
611 | |
612 | static void |
613 | test_expected_messages (void) |
614 | { |
615 | g_test_trap_subprocess (test_path: "/misc/expected-messages/subprocess/warning" , usec_timeout: 0, test_flags: 0); |
616 | g_test_trap_assert_failed (); |
617 | g_test_trap_assert_stderr ("*This is a * warning*" ); |
618 | g_test_trap_assert_stderr_unmatched ("*should not be reached*" ); |
619 | |
620 | g_test_trap_subprocess (test_path: "/misc/expected-messages/subprocess/expect-warning" , usec_timeout: 0, test_flags: 0); |
621 | g_test_trap_assert_failed (); |
622 | g_test_trap_assert_stderr_unmatched ("*This is a * warning*" ); |
623 | g_test_trap_assert_stderr ("*should not be reached*" ); |
624 | |
625 | g_test_trap_subprocess (test_path: "/misc/expected-messages/subprocess/wrong-warning" , usec_timeout: 0, test_flags: 0); |
626 | g_test_trap_assert_failed (); |
627 | g_test_trap_assert_stderr_unmatched ("*should not be reached*" ); |
628 | g_test_trap_assert_stderr ("*GLib-CRITICAL*Did not see expected message testing-CRITICAL*should not be *WARNING*This is a * warning*" ); |
629 | |
630 | g_test_trap_subprocess (test_path: "/misc/expected-messages/subprocess/expected" , usec_timeout: 0, test_flags: 0); |
631 | g_test_trap_assert_passed (); |
632 | g_test_trap_assert_stderr ("" ); |
633 | |
634 | g_test_trap_subprocess (test_path: "/misc/expected-messages/subprocess/null-domain" , usec_timeout: 0, test_flags: 0); |
635 | g_test_trap_assert_passed (); |
636 | g_test_trap_assert_stderr ("" ); |
637 | |
638 | g_test_trap_subprocess (test_path: "/misc/expected-messages/subprocess/extra-warning" , usec_timeout: 0, test_flags: 0); |
639 | g_test_trap_assert_passed (); |
640 | g_test_trap_assert_stderr ("" ); |
641 | |
642 | g_test_trap_subprocess (test_path: "/misc/expected-messages/subprocess/unexpected-extra-warning" , usec_timeout: 0, test_flags: 0); |
643 | g_test_trap_assert_failed (); |
644 | g_test_trap_assert_stderr ("*GLib:ERROR*Did not see expected message testing-CRITICAL*nope*" ); |
645 | } |
646 | |
647 | static void |
648 | test_expected_messages_debug (void) |
649 | { |
650 | g_test_expect_message (log_domain: "Test" , log_level: G_LOG_LEVEL_WARNING, pattern: "warning message" ); |
651 | g_log (log_domain: "Test" , log_level: G_LOG_LEVEL_DEBUG, format: "should be ignored" ); |
652 | g_log (log_domain: "Test" , log_level: G_LOG_LEVEL_WARNING, format: "warning message" ); |
653 | g_test_assert_expected_messages (); |
654 | |
655 | g_test_expect_message (log_domain: "Test" , log_level: G_LOG_LEVEL_DEBUG, pattern: "debug message" ); |
656 | g_log (log_domain: "Test" , log_level: G_LOG_LEVEL_DEBUG, format: "debug message" ); |
657 | g_test_assert_expected_messages (); |
658 | } |
659 | |
660 | static void |
661 | test_dash_p_hidden (void) |
662 | { |
663 | if (!g_test_subprocess ()) |
664 | g_assert_not_reached (); |
665 | |
666 | g_print (format: "Test /misc/dash-p/subprocess/hidden ran\n" ); |
667 | } |
668 | |
669 | static void |
670 | test_dash_p_hidden_sub (void) |
671 | { |
672 | if (!g_test_subprocess ()) |
673 | g_assert_not_reached (); |
674 | |
675 | g_print (format: "Test /misc/dash-p/subprocess/hidden/sub ran\n" ); |
676 | } |
677 | |
678 | /* The rest of the dash_p tests will get run by the toplevel test |
679 | * process, but they shouldn't do anything there. |
680 | */ |
681 | |
682 | static void |
683 | test_dash_p_child (void) |
684 | { |
685 | if (!g_test_subprocess ()) |
686 | return; |
687 | |
688 | g_print (format: "Test /misc/dash-p/child ran\n" ); |
689 | } |
690 | |
691 | static void |
692 | test_dash_p_child_sub (void) |
693 | { |
694 | if (!g_test_subprocess ()) |
695 | return; |
696 | |
697 | g_print (format: "Test /misc/dash-p/child/sub ran\n" ); |
698 | } |
699 | |
700 | static void |
701 | test_dash_p_child_sub2 (void) |
702 | { |
703 | if (!g_test_subprocess ()) |
704 | return; |
705 | |
706 | g_print (format: "Test /misc/dash-p/child/sub2 ran\n" ); |
707 | } |
708 | |
709 | static void |
710 | test_dash_p_child_sub_child (void) |
711 | { |
712 | if (!g_test_subprocess ()) |
713 | return; |
714 | |
715 | g_print (format: "Test /misc/dash-p/child/subprocess ran\n" ); |
716 | } |
717 | |
718 | static void |
719 | test_dash_p (void) |
720 | { |
721 | g_test_trap_subprocess (test_path: "/misc/dash-p/subprocess/hidden" , usec_timeout: 0, test_flags: 0); |
722 | g_test_trap_assert_passed (); |
723 | g_test_trap_assert_stdout ("*Test /misc/dash-p/subprocess/hidden ran*" ); |
724 | g_test_trap_assert_stdout_unmatched ("*Test /misc/dash-p/subprocess/hidden/sub ran*" ); |
725 | g_test_trap_assert_stdout_unmatched ("*Test /misc/dash-p/subprocess/hidden/sub2 ran*" ); |
726 | g_test_trap_assert_stdout_unmatched ("*Test /misc/dash-p/subprocess/hidden/sub/subprocess ran*" ); |
727 | g_test_trap_assert_stdout_unmatched ("*Test /misc/dash-p/child*" ); |
728 | |
729 | g_test_trap_subprocess (test_path: "/misc/dash-p/subprocess/hidden/sub" , usec_timeout: 0, test_flags: 0); |
730 | g_test_trap_assert_passed (); |
731 | g_test_trap_assert_stdout ("*Test /misc/dash-p/subprocess/hidden/sub ran*" ); |
732 | g_test_trap_assert_stdout_unmatched ("*Test /misc/dash-p/subprocess/hidden ran*" ); |
733 | g_test_trap_assert_stdout_unmatched ("*Test /misc/dash-p/subprocess/hidden/sub2 ran*" ); |
734 | g_test_trap_assert_stdout_unmatched ("*Test /misc/dash-p/subprocess/hidden/subprocess ran*" ); |
735 | g_test_trap_assert_stdout_unmatched ("*Test /misc/dash-p/child*" ); |
736 | |
737 | g_test_trap_subprocess (test_path: "/misc/dash-p/child" , usec_timeout: 0, test_flags: 0); |
738 | g_test_trap_assert_passed (); |
739 | g_test_trap_assert_stdout ("*Test /misc/dash-p/child ran*" ); |
740 | g_test_trap_assert_stdout ("*Test /misc/dash-p/child/sub ran*" ); |
741 | g_test_trap_assert_stdout ("*Test /misc/dash-p/child/sub2 ran*" ); |
742 | g_test_trap_assert_stdout_unmatched ("*Test /misc/dash-p/child/subprocess ran*" ); |
743 | g_test_trap_assert_stdout_unmatched ("*Test /misc/dash-p/subprocess/hidden*" ); |
744 | |
745 | g_test_trap_subprocess (test_path: "/misc/dash-p/child/sub" , usec_timeout: 0, test_flags: 0); |
746 | g_test_trap_assert_passed (); |
747 | g_test_trap_assert_stdout ("*Test /misc/dash-p/child/sub ran*" ); |
748 | g_test_trap_assert_stdout_unmatched ("*Test /misc/dash-p/child ran*" ); |
749 | g_test_trap_assert_stdout_unmatched ("*Test /misc/dash-p/child/sub2 ran*" ); |
750 | g_test_trap_assert_stdout_unmatched ("*Test /misc/dash-p/child/subprocess ran*" ); |
751 | g_test_trap_assert_stdout_unmatched ("*Test /misc/dash-p/subprocess/hidden*" ); |
752 | } |
753 | |
754 | static void |
755 | test_nonfatal (void) |
756 | { |
757 | if (g_test_subprocess ()) |
758 | { |
759 | g_test_set_nonfatal_assertions (); |
760 | g_assert_cmpint (4, ==, 5); |
761 | g_print (format: "The End\n" ); |
762 | return; |
763 | } |
764 | g_test_trap_subprocess (NULL, usec_timeout: 0, test_flags: 0); |
765 | g_test_trap_assert_failed (); |
766 | g_test_trap_assert_stderr ("*assertion failed*4 == 5*" ); |
767 | g_test_trap_assert_stdout ("*The End*" ); |
768 | } |
769 | |
770 | static void |
771 | test_skip (void) |
772 | { |
773 | g_test_skip (msg: "Skipped should count as passed, not failed" ); |
774 | /* This function really means "the test concluded with a non-successful |
775 | * status" rather than "the test failed": it is documented to return |
776 | * true for skipped and incomplete tests, not just for failures. */ |
777 | g_assert_true (g_test_failed ()); |
778 | } |
779 | |
780 | static void |
781 | test_pass (void) |
782 | { |
783 | } |
784 | |
785 | static void |
786 | subprocess_fail (void) |
787 | { |
788 | /* Exit 1 instead of raising SIGABRT so that we can make assertions about |
789 | * how this combines with skipped/incomplete tests */ |
790 | g_test_set_nonfatal_assertions (); |
791 | g_test_fail (); |
792 | g_assert_true (g_test_failed ()); |
793 | } |
794 | |
795 | static void |
796 | test_fail (void) |
797 | { |
798 | if (g_test_subprocess ()) |
799 | { |
800 | subprocess_fail (); |
801 | return; |
802 | } |
803 | g_test_trap_subprocess (NULL, usec_timeout: 0, test_flags: 0); |
804 | g_test_trap_assert_failed (); |
805 | } |
806 | |
807 | static void |
808 | subprocess_incomplete (void) |
809 | { |
810 | g_test_incomplete (msg: "not done" ); |
811 | /* This function really means "the test concluded with a non-successful |
812 | * status" rather than "the test failed": it is documented to return |
813 | * true for skipped and incomplete tests, not just for failures. */ |
814 | g_assert_true (g_test_failed ()); |
815 | } |
816 | |
817 | static void |
818 | test_incomplete (void) |
819 | { |
820 | if (g_test_subprocess ()) |
821 | { |
822 | subprocess_incomplete (); |
823 | return; |
824 | } |
825 | g_test_trap_subprocess (NULL, usec_timeout: 0, test_flags: 0); |
826 | /* An incomplete test represents functionality that is known not to be |
827 | * implemented yet (an expected failure), so it does not cause test |
828 | * failure; but it does count as the test having been skipped, which |
829 | * causes nonzero exit status 77, which is treated as failure by |
830 | * g_test_trap_subprocess(). */ |
831 | g_test_trap_assert_failed (); |
832 | } |
833 | |
834 | static void |
835 | test_subprocess_timed_out (void) |
836 | { |
837 | if (g_test_subprocess ()) |
838 | { |
839 | g_usleep (microseconds: 1000000); |
840 | return; |
841 | } |
842 | g_test_trap_subprocess (NULL, usec_timeout: 50000, test_flags: 0); |
843 | g_assert_true (g_test_trap_reached_timeout ()); |
844 | } |
845 | |
846 | static void |
847 | test_path_first (void) |
848 | { |
849 | g_assert_cmpstr (g_test_get_path (), ==, "/misc/path/first" ); |
850 | } |
851 | |
852 | static void |
853 | test_path_second (void) |
854 | { |
855 | g_assert_cmpstr (g_test_get_path (), ==, "/misc/path/second" ); |
856 | } |
857 | |
858 | static const char *argv0; |
859 | |
860 | static void |
861 | test_combining (void) |
862 | { |
863 | GPtrArray *argv; |
864 | GError *error = NULL; |
865 | int status; |
866 | |
867 | g_test_message (format: "single test case skipped -> overall status 77" ); |
868 | argv = g_ptr_array_new (); |
869 | g_ptr_array_add (array: argv, data: (char *) argv0); |
870 | g_ptr_array_add (array: argv, data: "--GTestSubprocess" ); |
871 | g_ptr_array_add (array: argv, data: "-p" ); |
872 | g_ptr_array_add (array: argv, data: "/misc/skip" ); |
873 | g_ptr_array_add (array: argv, NULL); |
874 | |
875 | g_spawn_sync (NULL, argv: (char **) argv->pdata, NULL, |
876 | flags: G_SPAWN_STDOUT_TO_DEV_NULL | G_SPAWN_STDERR_TO_DEV_NULL, |
877 | NULL, NULL, NULL, NULL, exit_status: &status, |
878 | error: &error); |
879 | g_assert_no_error (error); |
880 | |
881 | g_spawn_check_exit_status (exit_status: status, error: &error); |
882 | g_assert_error (error, G_SPAWN_EXIT_ERROR, 77); |
883 | g_clear_error (err: &error); |
884 | |
885 | g_test_message (format: "each test case skipped -> overall status 77" ); |
886 | g_ptr_array_set_size (array: argv, length: 0); |
887 | g_ptr_array_add (array: argv, data: (char *) argv0); |
888 | g_ptr_array_add (array: argv, data: "--GTestSubprocess" ); |
889 | g_ptr_array_add (array: argv, data: "-p" ); |
890 | g_ptr_array_add (array: argv, data: "/misc/skip" ); |
891 | g_ptr_array_add (array: argv, data: "-p" ); |
892 | g_ptr_array_add (array: argv, data: "/misc/combining/subprocess/skip1" ); |
893 | g_ptr_array_add (array: argv, data: "-p" ); |
894 | g_ptr_array_add (array: argv, data: "/misc/combining/subprocess/skip2" ); |
895 | g_ptr_array_add (array: argv, NULL); |
896 | |
897 | g_spawn_sync (NULL, argv: (char **) argv->pdata, NULL, |
898 | flags: G_SPAWN_STDOUT_TO_DEV_NULL | G_SPAWN_STDERR_TO_DEV_NULL, |
899 | NULL, NULL, NULL, NULL, exit_status: &status, |
900 | error: &error); |
901 | g_assert_no_error (error); |
902 | |
903 | g_spawn_check_exit_status (exit_status: status, error: &error); |
904 | g_assert_error (error, G_SPAWN_EXIT_ERROR, 77); |
905 | g_clear_error (err: &error); |
906 | |
907 | g_test_message (format: "single test case incomplete -> overall status 77" ); |
908 | g_ptr_array_set_size (array: argv, length: 0); |
909 | g_ptr_array_add (array: argv, data: (char *) argv0); |
910 | g_ptr_array_add (array: argv, data: "--GTestSubprocess" ); |
911 | g_ptr_array_add (array: argv, data: "-p" ); |
912 | g_ptr_array_add (array: argv, data: "/misc/combining/subprocess/incomplete" ); |
913 | g_ptr_array_add (array: argv, NULL); |
914 | |
915 | g_spawn_sync (NULL, argv: (char **) argv->pdata, NULL, |
916 | flags: G_SPAWN_STDOUT_TO_DEV_NULL | G_SPAWN_STDERR_TO_DEV_NULL, |
917 | NULL, NULL, NULL, NULL, exit_status: &status, |
918 | error: &error); |
919 | g_assert_no_error (error); |
920 | |
921 | g_spawn_check_exit_status (exit_status: status, error: &error); |
922 | g_assert_error (error, G_SPAWN_EXIT_ERROR, 77); |
923 | g_clear_error (err: &error); |
924 | |
925 | g_test_message (format: "one pass and some skipped -> overall status 0" ); |
926 | g_ptr_array_set_size (array: argv, length: 0); |
927 | g_ptr_array_add (array: argv, data: (char *) argv0); |
928 | g_ptr_array_add (array: argv, data: "--GTestSubprocess" ); |
929 | g_ptr_array_add (array: argv, data: "-p" ); |
930 | g_ptr_array_add (array: argv, data: "/misc/skip" ); |
931 | g_ptr_array_add (array: argv, data: "-p" ); |
932 | g_ptr_array_add (array: argv, data: "/misc/combining/subprocess/pass" ); |
933 | g_ptr_array_add (array: argv, data: "-p" ); |
934 | g_ptr_array_add (array: argv, data: "/misc/combining/subprocess/skip1" ); |
935 | g_ptr_array_add (array: argv, NULL); |
936 | |
937 | g_spawn_sync (NULL, argv: (char **) argv->pdata, NULL, |
938 | flags: G_SPAWN_STDOUT_TO_DEV_NULL | G_SPAWN_STDERR_TO_DEV_NULL, |
939 | NULL, NULL, NULL, NULL, exit_status: &status, |
940 | error: &error); |
941 | g_assert_no_error (error); |
942 | |
943 | g_spawn_check_exit_status (exit_status: status, error: &error); |
944 | g_assert_no_error (error); |
945 | |
946 | g_test_message (format: "one pass and some incomplete -> overall status 0" ); |
947 | g_ptr_array_set_size (array: argv, length: 0); |
948 | g_ptr_array_add (array: argv, data: (char *) argv0); |
949 | g_ptr_array_add (array: argv, data: "--GTestSubprocess" ); |
950 | g_ptr_array_add (array: argv, data: "-p" ); |
951 | g_ptr_array_add (array: argv, data: "/misc/combining/subprocess/pass" ); |
952 | g_ptr_array_add (array: argv, data: "-p" ); |
953 | g_ptr_array_add (array: argv, data: "/misc/combining/subprocess/incomplete" ); |
954 | g_ptr_array_add (array: argv, NULL); |
955 | |
956 | g_spawn_sync (NULL, argv: (char **) argv->pdata, NULL, |
957 | flags: G_SPAWN_STDOUT_TO_DEV_NULL | G_SPAWN_STDERR_TO_DEV_NULL, |
958 | NULL, NULL, NULL, NULL, exit_status: &status, |
959 | error: &error); |
960 | g_assert_no_error (error); |
961 | |
962 | g_spawn_check_exit_status (exit_status: status, error: &error); |
963 | g_assert_no_error (error); |
964 | |
965 | g_test_message (format: "one pass and mix of skipped and incomplete -> overall status 0" ); |
966 | g_ptr_array_set_size (array: argv, length: 0); |
967 | g_ptr_array_add (array: argv, data: (char *) argv0); |
968 | g_ptr_array_add (array: argv, data: "--GTestSubprocess" ); |
969 | g_ptr_array_add (array: argv, data: "-p" ); |
970 | g_ptr_array_add (array: argv, data: "/misc/combining/subprocess/pass" ); |
971 | g_ptr_array_add (array: argv, data: "-p" ); |
972 | g_ptr_array_add (array: argv, data: "/misc/combining/subprocess/skip1" ); |
973 | g_ptr_array_add (array: argv, data: "-p" ); |
974 | g_ptr_array_add (array: argv, data: "/misc/combining/subprocess/incomplete" ); |
975 | g_ptr_array_add (array: argv, NULL); |
976 | |
977 | g_spawn_sync (NULL, argv: (char **) argv->pdata, NULL, |
978 | flags: G_SPAWN_STDOUT_TO_DEV_NULL | G_SPAWN_STDERR_TO_DEV_NULL, |
979 | NULL, NULL, NULL, NULL, exit_status: &status, |
980 | error: &error); |
981 | g_assert_no_error (error); |
982 | |
983 | g_spawn_check_exit_status (exit_status: status, error: &error); |
984 | g_assert_no_error (error); |
985 | |
986 | g_test_message (format: "one fail and some skipped -> overall status fail" ); |
987 | g_ptr_array_set_size (array: argv, length: 0); |
988 | g_ptr_array_add (array: argv, data: (char *) argv0); |
989 | g_ptr_array_add (array: argv, data: "--GTestSubprocess" ); |
990 | g_ptr_array_add (array: argv, data: "-p" ); |
991 | g_ptr_array_add (array: argv, data: "/misc/skip" ); |
992 | g_ptr_array_add (array: argv, data: "-p" ); |
993 | g_ptr_array_add (array: argv, data: "/misc/combining/subprocess/fail" ); |
994 | g_ptr_array_add (array: argv, data: "-p" ); |
995 | g_ptr_array_add (array: argv, data: "/misc/combining/subprocess/skip1" ); |
996 | g_ptr_array_add (array: argv, NULL); |
997 | |
998 | g_spawn_sync (NULL, argv: (char **) argv->pdata, NULL, |
999 | flags: G_SPAWN_STDOUT_TO_DEV_NULL | G_SPAWN_STDERR_TO_DEV_NULL, |
1000 | NULL, NULL, NULL, NULL, exit_status: &status, |
1001 | error: &error); |
1002 | g_assert_no_error (error); |
1003 | |
1004 | g_spawn_check_exit_status (exit_status: status, error: &error); |
1005 | g_assert_error (error, G_SPAWN_EXIT_ERROR, 1); |
1006 | g_clear_error (err: &error); |
1007 | |
1008 | g_test_message (format: "one fail and some incomplete -> overall status fail" ); |
1009 | g_ptr_array_set_size (array: argv, length: 0); |
1010 | g_ptr_array_add (array: argv, data: (char *) argv0); |
1011 | g_ptr_array_add (array: argv, data: "--GTestSubprocess" ); |
1012 | g_ptr_array_add (array: argv, data: "-p" ); |
1013 | g_ptr_array_add (array: argv, data: "/misc/combining/subprocess/fail" ); |
1014 | g_ptr_array_add (array: argv, data: "-p" ); |
1015 | g_ptr_array_add (array: argv, data: "/misc/combining/subprocess/incomplete" ); |
1016 | g_ptr_array_add (array: argv, NULL); |
1017 | |
1018 | g_spawn_sync (NULL, argv: (char **) argv->pdata, NULL, |
1019 | flags: G_SPAWN_STDOUT_TO_DEV_NULL | G_SPAWN_STDERR_TO_DEV_NULL, |
1020 | NULL, NULL, NULL, NULL, exit_status: &status, |
1021 | error: &error); |
1022 | g_assert_no_error (error); |
1023 | |
1024 | g_spawn_check_exit_status (exit_status: status, error: &error); |
1025 | g_assert_error (error, G_SPAWN_EXIT_ERROR, 1); |
1026 | g_clear_error (err: &error); |
1027 | |
1028 | g_test_message (format: "one fail and mix of skipped and incomplete -> overall status fail" ); |
1029 | g_ptr_array_set_size (array: argv, length: 0); |
1030 | g_ptr_array_add (array: argv, data: (char *) argv0); |
1031 | g_ptr_array_add (array: argv, data: "--GTestSubprocess" ); |
1032 | g_ptr_array_add (array: argv, data: "-p" ); |
1033 | g_ptr_array_add (array: argv, data: "/misc/combining/subprocess/fail" ); |
1034 | g_ptr_array_add (array: argv, data: "-p" ); |
1035 | g_ptr_array_add (array: argv, data: "/misc/combining/subprocess/skip1" ); |
1036 | g_ptr_array_add (array: argv, data: "-p" ); |
1037 | g_ptr_array_add (array: argv, data: "/misc/combining/subprocess/incomplete" ); |
1038 | g_ptr_array_add (array: argv, NULL); |
1039 | |
1040 | g_spawn_sync (NULL, argv: (char **) argv->pdata, NULL, |
1041 | flags: G_SPAWN_STDOUT_TO_DEV_NULL | G_SPAWN_STDERR_TO_DEV_NULL, |
1042 | NULL, NULL, NULL, NULL, exit_status: &status, |
1043 | error: &error); |
1044 | g_assert_no_error (error); |
1045 | |
1046 | g_spawn_check_exit_status (exit_status: status, error: &error); |
1047 | g_assert_error (error, G_SPAWN_EXIT_ERROR, 1); |
1048 | g_clear_error (err: &error); |
1049 | |
1050 | g_ptr_array_unref (array: argv); |
1051 | } |
1052 | |
1053 | /* Test the TAP output when a test suite is run with --tap. */ |
1054 | static void |
1055 | test_tap (void) |
1056 | { |
1057 | const char *testing_helper; |
1058 | GPtrArray *argv; |
1059 | GError *error = NULL; |
1060 | int status; |
1061 | gchar *output; |
1062 | |
1063 | testing_helper = g_test_get_filename (file_type: G_TEST_BUILT, first_path: "testing-helper" EXEEXT, NULL); |
1064 | |
1065 | g_test_message (format: "pass" ); |
1066 | argv = g_ptr_array_new (); |
1067 | g_ptr_array_add (array: argv, data: (char *) testing_helper); |
1068 | g_ptr_array_add (array: argv, data: "pass" ); |
1069 | g_ptr_array_add (array: argv, data: "--tap" ); |
1070 | g_ptr_array_add (array: argv, NULL); |
1071 | |
1072 | g_spawn_sync (NULL, argv: (char **) argv->pdata, NULL, |
1073 | flags: G_SPAWN_STDERR_TO_DEV_NULL, |
1074 | NULL, NULL, standard_output: &output, NULL, exit_status: &status, |
1075 | error: &error); |
1076 | g_assert_no_error (error); |
1077 | |
1078 | g_spawn_check_exit_status (exit_status: status, error: &error); |
1079 | g_assert_no_error (error); |
1080 | g_assert_nonnull (strstr (output, "\nok 1 /pass\n" )); |
1081 | g_free (mem: output); |
1082 | g_ptr_array_unref (array: argv); |
1083 | |
1084 | g_test_message (format: "skip" ); |
1085 | argv = g_ptr_array_new (); |
1086 | g_ptr_array_add (array: argv, data: (char *) testing_helper); |
1087 | g_ptr_array_add (array: argv, data: "skip" ); |
1088 | g_ptr_array_add (array: argv, data: "--tap" ); |
1089 | g_ptr_array_add (array: argv, NULL); |
1090 | |
1091 | g_spawn_sync (NULL, argv: (char **) argv->pdata, NULL, |
1092 | flags: G_SPAWN_STDERR_TO_DEV_NULL, |
1093 | NULL, NULL, standard_output: &output, NULL, exit_status: &status, |
1094 | error: &error); |
1095 | g_assert_no_error (error); |
1096 | |
1097 | g_spawn_check_exit_status (exit_status: status, error: &error); |
1098 | g_assert_no_error (error); |
1099 | g_assert_nonnull (strstr (output, "\nok 1 /skip # SKIP not enough tea\n" )); |
1100 | g_free (mem: output); |
1101 | g_ptr_array_unref (array: argv); |
1102 | |
1103 | g_test_message (format: "incomplete" ); |
1104 | argv = g_ptr_array_new (); |
1105 | g_ptr_array_add (array: argv, data: (char *) testing_helper); |
1106 | g_ptr_array_add (array: argv, data: "incomplete" ); |
1107 | g_ptr_array_add (array: argv, data: "--tap" ); |
1108 | g_ptr_array_add (array: argv, NULL); |
1109 | |
1110 | g_spawn_sync (NULL, argv: (char **) argv->pdata, NULL, |
1111 | flags: G_SPAWN_STDERR_TO_DEV_NULL, |
1112 | NULL, NULL, standard_output: &output, NULL, exit_status: &status, |
1113 | error: &error); |
1114 | g_assert_no_error (error); |
1115 | |
1116 | g_spawn_check_exit_status (exit_status: status, error: &error); |
1117 | g_assert_no_error (error); |
1118 | g_assert_nonnull (strstr (output, "\nnot ok 1 /incomplete # TODO mind reading not implemented yet\n" )); |
1119 | g_free (mem: output); |
1120 | g_ptr_array_unref (array: argv); |
1121 | |
1122 | g_test_message (format: "fail" ); |
1123 | argv = g_ptr_array_new (); |
1124 | g_ptr_array_add (array: argv, data: (char *) testing_helper); |
1125 | g_ptr_array_add (array: argv, data: "fail" ); |
1126 | g_ptr_array_add (array: argv, data: "--tap" ); |
1127 | g_ptr_array_add (array: argv, NULL); |
1128 | |
1129 | g_spawn_sync (NULL, argv: (char **) argv->pdata, NULL, |
1130 | flags: G_SPAWN_STDERR_TO_DEV_NULL, |
1131 | NULL, NULL, standard_output: &output, NULL, exit_status: &status, |
1132 | error: &error); |
1133 | g_assert_no_error (error); |
1134 | |
1135 | g_spawn_check_exit_status (exit_status: status, error: &error); |
1136 | g_assert_error (error, G_SPAWN_EXIT_ERROR, 1); |
1137 | g_assert_nonnull (strstr (output, "\nnot ok 1 /fail\n" )); |
1138 | g_free (mem: output); |
1139 | g_ptr_array_unref (array: argv); |
1140 | |
1141 | g_test_message (format: "all" ); |
1142 | argv = g_ptr_array_new (); |
1143 | g_ptr_array_add (array: argv, data: (char *) testing_helper); |
1144 | g_ptr_array_add (array: argv, data: "all" ); |
1145 | g_ptr_array_add (array: argv, data: "--tap" ); |
1146 | g_ptr_array_add (array: argv, NULL); |
1147 | |
1148 | g_spawn_sync (NULL, argv: (char **) argv->pdata, NULL, |
1149 | flags: G_SPAWN_STDOUT_TO_DEV_NULL | G_SPAWN_STDERR_TO_DEV_NULL, |
1150 | NULL, NULL, NULL, NULL, exit_status: &status, |
1151 | error: &error); |
1152 | g_assert_error (error, G_SPAWN_EXIT_ERROR, 1); |
1153 | g_clear_error (err: &error); |
1154 | g_ptr_array_unref (array: argv); |
1155 | |
1156 | g_test_message (format: "all-non-failures" ); |
1157 | argv = g_ptr_array_new (); |
1158 | g_ptr_array_add (array: argv, data: (char *) testing_helper); |
1159 | g_ptr_array_add (array: argv, data: "all-non-failures" ); |
1160 | g_ptr_array_add (array: argv, data: "--tap" ); |
1161 | g_ptr_array_add (array: argv, NULL); |
1162 | |
1163 | g_spawn_sync (NULL, argv: (char **) argv->pdata, NULL, |
1164 | flags: G_SPAWN_STDOUT_TO_DEV_NULL | G_SPAWN_STDERR_TO_DEV_NULL, |
1165 | NULL, NULL, NULL, NULL, exit_status: &status, |
1166 | error: &error); |
1167 | g_assert_no_error (error); |
1168 | |
1169 | g_spawn_check_exit_status (exit_status: status, error: &error); |
1170 | g_assert_no_error (error); |
1171 | |
1172 | g_ptr_array_unref (array: argv); |
1173 | |
1174 | g_test_message (format: "--GTestSkipCount" ); |
1175 | argv = g_ptr_array_new (); |
1176 | g_ptr_array_add (array: argv, data: (char *) testing_helper); |
1177 | g_ptr_array_add (array: argv, data: "skip-options" ); |
1178 | g_ptr_array_add (array: argv, data: "--tap" ); |
1179 | g_ptr_array_add (array: argv, data: "--GTestSkipCount" ); |
1180 | g_ptr_array_add (array: argv, data: "2" ); |
1181 | g_ptr_array_add (array: argv, NULL); |
1182 | |
1183 | g_spawn_sync (NULL, argv: (char **) argv->pdata, NULL, |
1184 | flags: G_SPAWN_STDERR_TO_DEV_NULL, |
1185 | NULL, NULL, standard_output: &output, NULL, exit_status: &status, |
1186 | error: &error); |
1187 | g_assert_no_error (error); |
1188 | g_assert_nonnull (strstr (output, "1..10\n" )); |
1189 | g_assert_nonnull (strstr (output, "\nok 1 /a # SKIP\n" )); |
1190 | g_assert_nonnull (strstr (output, "\nok 2 /b # SKIP\n" )); |
1191 | g_assert_nonnull (strstr (output, "\nok 3 /b/a\n" )); |
1192 | g_assert_nonnull (strstr (output, "\nok 4 /b/b\n" )); |
1193 | g_assert_nonnull (strstr (output, "\nok 5 /b/b/a\n" )); |
1194 | g_assert_nonnull (strstr (output, "\nok 6 /prefix/a\n" )); |
1195 | g_assert_nonnull (strstr (output, "\nok 7 /prefix/b/b\n" )); |
1196 | g_assert_nonnull (strstr (output, "\nok 8 /prefix-long/a\n" )); |
1197 | g_assert_nonnull (strstr (output, "\nok 9 /c/a\n" )); |
1198 | g_assert_nonnull (strstr (output, "\nok 10 /d/a\n" )); |
1199 | |
1200 | g_spawn_check_exit_status (exit_status: status, error: &error); |
1201 | g_assert_no_error (error); |
1202 | |
1203 | g_free (mem: output); |
1204 | g_ptr_array_unref (array: argv); |
1205 | |
1206 | g_test_message (format: "--GTestSkipCount=0 is the same as omitting it" ); |
1207 | argv = g_ptr_array_new (); |
1208 | g_ptr_array_add (array: argv, data: (char *) testing_helper); |
1209 | g_ptr_array_add (array: argv, data: "skip-options" ); |
1210 | g_ptr_array_add (array: argv, data: "--tap" ); |
1211 | g_ptr_array_add (array: argv, data: "--GTestSkipCount" ); |
1212 | g_ptr_array_add (array: argv, data: "0" ); |
1213 | g_ptr_array_add (array: argv, NULL); |
1214 | |
1215 | g_spawn_sync (NULL, argv: (char **) argv->pdata, NULL, |
1216 | flags: G_SPAWN_STDERR_TO_DEV_NULL, |
1217 | NULL, NULL, standard_output: &output, NULL, exit_status: &status, |
1218 | error: &error); |
1219 | g_assert_no_error (error); |
1220 | g_assert_nonnull (strstr (output, "1..10\n" )); |
1221 | g_assert_nonnull (strstr (output, "\nok 1 /a\n" )); |
1222 | g_assert_nonnull (strstr (output, "\nok 2 /b\n" )); |
1223 | g_assert_nonnull (strstr (output, "\nok 3 /b/a\n" )); |
1224 | g_assert_nonnull (strstr (output, "\nok 4 /b/b\n" )); |
1225 | g_assert_nonnull (strstr (output, "\nok 5 /b/b/a\n" )); |
1226 | g_assert_nonnull (strstr (output, "\nok 6 /prefix/a\n" )); |
1227 | g_assert_nonnull (strstr (output, "\nok 7 /prefix/b/b\n" )); |
1228 | g_assert_nonnull (strstr (output, "\nok 8 /prefix-long/a\n" )); |
1229 | g_assert_nonnull (strstr (output, "\nok 9 /c/a\n" )); |
1230 | g_assert_nonnull (strstr (output, "\nok 10 /d/a\n" )); |
1231 | |
1232 | g_spawn_check_exit_status (exit_status: status, error: &error); |
1233 | g_assert_no_error (error); |
1234 | |
1235 | g_free (mem: output); |
1236 | g_ptr_array_unref (array: argv); |
1237 | |
1238 | g_test_message (format: "--GTestSkipCount > number of tests skips all" ); |
1239 | argv = g_ptr_array_new (); |
1240 | g_ptr_array_add (array: argv, data: (char *) testing_helper); |
1241 | g_ptr_array_add (array: argv, data: "skip-options" ); |
1242 | g_ptr_array_add (array: argv, data: "--tap" ); |
1243 | g_ptr_array_add (array: argv, data: "--GTestSkipCount" ); |
1244 | g_ptr_array_add (array: argv, data: "11" ); |
1245 | g_ptr_array_add (array: argv, NULL); |
1246 | |
1247 | g_spawn_sync (NULL, argv: (char **) argv->pdata, NULL, |
1248 | flags: G_SPAWN_STDERR_TO_DEV_NULL, |
1249 | NULL, NULL, standard_output: &output, NULL, exit_status: &status, |
1250 | error: &error); |
1251 | g_assert_no_error (error); |
1252 | g_assert_nonnull (strstr (output, "1..10\n" )); |
1253 | g_assert_nonnull (strstr (output, "\nok 1 /a # SKIP\n" )); |
1254 | g_assert_nonnull (strstr (output, "\nok 2 /b # SKIP\n" )); |
1255 | g_assert_nonnull (strstr (output, "\nok 3 /b/a # SKIP\n" )); |
1256 | g_assert_nonnull (strstr (output, "\nok 4 /b/b # SKIP\n" )); |
1257 | g_assert_nonnull (strstr (output, "\nok 5 /b/b/a # SKIP\n" )); |
1258 | g_assert_nonnull (strstr (output, "\nok 6 /prefix/a # SKIP\n" )); |
1259 | g_assert_nonnull (strstr (output, "\nok 7 /prefix/b/b # SKIP\n" )); |
1260 | g_assert_nonnull (strstr (output, "\nok 8 /prefix-long/a # SKIP\n" )); |
1261 | g_assert_nonnull (strstr (output, "\nok 9 /c/a # SKIP\n" )); |
1262 | g_assert_nonnull (strstr (output, "\nok 10 /d/a # SKIP\n" )); |
1263 | |
1264 | g_spawn_check_exit_status (exit_status: status, error: &error); |
1265 | g_assert_no_error (error); |
1266 | |
1267 | g_free (mem: output); |
1268 | g_ptr_array_unref (array: argv); |
1269 | |
1270 | g_test_message (format: "-p" ); |
1271 | argv = g_ptr_array_new (); |
1272 | g_ptr_array_add (array: argv, data: (char *) testing_helper); |
1273 | g_ptr_array_add (array: argv, data: "skip-options" ); |
1274 | g_ptr_array_add (array: argv, data: "--tap" ); |
1275 | g_ptr_array_add (array: argv, data: "-p" ); |
1276 | g_ptr_array_add (array: argv, data: "/c/a" ); |
1277 | g_ptr_array_add (array: argv, data: "-p" ); |
1278 | g_ptr_array_add (array: argv, data: "/c/a" ); |
1279 | g_ptr_array_add (array: argv, data: "-p" ); |
1280 | g_ptr_array_add (array: argv, data: "/b" ); |
1281 | g_ptr_array_add (array: argv, NULL); |
1282 | |
1283 | g_spawn_sync (NULL, argv: (char **) argv->pdata, NULL, |
1284 | flags: G_SPAWN_STDERR_TO_DEV_NULL, |
1285 | NULL, NULL, standard_output: &output, NULL, exit_status: &status, |
1286 | error: &error); |
1287 | g_assert_no_error (error); |
1288 | g_assert_nonnull (strstr (output, "\nok 1 /c/a\n" )); |
1289 | g_assert_nonnull (strstr (output, "\nok 2 /c/a\n" )); |
1290 | g_assert_nonnull (strstr (output, "\nok 3 /b\n" )); |
1291 | g_assert_nonnull (strstr (output, "\nok 4 /b/a\n" )); |
1292 | g_assert_nonnull (strstr (output, "\nok 5 /b/b\n" )); |
1293 | g_assert_nonnull (strstr (output, "\n1..5\n" )); |
1294 | |
1295 | g_spawn_check_exit_status (exit_status: status, error: &error); |
1296 | g_assert_no_error (error); |
1297 | |
1298 | g_free (mem: output); |
1299 | g_ptr_array_unref (array: argv); |
1300 | |
1301 | g_test_message (format: "--run-prefix" ); |
1302 | argv = g_ptr_array_new (); |
1303 | g_ptr_array_add (array: argv, data: (char *) testing_helper); |
1304 | g_ptr_array_add (array: argv, data: "skip-options" ); |
1305 | g_ptr_array_add (array: argv, data: "--tap" ); |
1306 | g_ptr_array_add (array: argv, data: "-r" ); |
1307 | g_ptr_array_add (array: argv, data: "/c/a" ); |
1308 | g_ptr_array_add (array: argv, data: "-r" ); |
1309 | g_ptr_array_add (array: argv, data: "/c/a" ); |
1310 | g_ptr_array_add (array: argv, data: "--run-prefix" ); |
1311 | g_ptr_array_add (array: argv, data: "/b" ); |
1312 | g_ptr_array_add (array: argv, NULL); |
1313 | |
1314 | g_spawn_sync (NULL, argv: (char **) argv->pdata, NULL, |
1315 | flags: G_SPAWN_STDERR_TO_DEV_NULL, |
1316 | NULL, NULL, standard_output: &output, NULL, exit_status: &status, |
1317 | error: &error); |
1318 | g_assert_no_error (error); |
1319 | g_assert_nonnull (strstr (output, "\nok 1 /c/a\n" )); |
1320 | g_assert_nonnull (strstr (output, "\nok 2 /c/a\n" )); |
1321 | g_assert_nonnull (strstr (output, "\nok 3 /b\n" )); |
1322 | g_assert_nonnull (strstr (output, "\nok 4 /b/a\n" )); |
1323 | g_assert_nonnull (strstr (output, "\nok 5 /b/b\n" )); |
1324 | g_assert_nonnull (strstr (output, "\nok 6 /b/b/a\n" )); |
1325 | g_assert_nonnull (strstr (output, "\n1..6\n" )); |
1326 | |
1327 | g_spawn_check_exit_status (exit_status: status, error: &error); |
1328 | g_assert_no_error (error); |
1329 | |
1330 | g_free (mem: output); |
1331 | g_ptr_array_unref (array: argv); |
1332 | |
1333 | g_test_message (format: "--run-prefix 2" ); |
1334 | argv = g_ptr_array_new (); |
1335 | g_ptr_array_add (array: argv, data: (char *) testing_helper); |
1336 | g_ptr_array_add (array: argv, data: "skip-options" ); |
1337 | g_ptr_array_add (array: argv, data: "--tap" ); |
1338 | g_ptr_array_add (array: argv, data: "-r" ); |
1339 | g_ptr_array_add (array: argv, data: "/pre" ); |
1340 | g_ptr_array_add (array: argv, data: "--run-prefix" ); |
1341 | g_ptr_array_add (array: argv, data: "/b/b" ); |
1342 | g_ptr_array_add (array: argv, NULL); |
1343 | |
1344 | g_spawn_sync (NULL, argv: (char **) argv->pdata, NULL, |
1345 | flags: G_SPAWN_STDERR_TO_DEV_NULL, |
1346 | NULL, NULL, standard_output: &output, NULL, exit_status: &status, |
1347 | error: &error); |
1348 | g_assert_no_error (error); |
1349 | g_assert_nonnull (strstr (output, "\nok 1 /b/b\n" )); |
1350 | g_assert_nonnull (strstr (output, "\nok 2 /b/b/a\n" )); |
1351 | g_assert_nonnull (strstr (output, "\n1..2\n" )); |
1352 | |
1353 | g_spawn_check_exit_status (exit_status: status, error: &error); |
1354 | g_assert_no_error (error); |
1355 | |
1356 | g_free (mem: output); |
1357 | g_ptr_array_unref (array: argv); |
1358 | |
1359 | g_test_message (format: "--run-prefix conflict" ); |
1360 | argv = g_ptr_array_new (); |
1361 | g_ptr_array_add (array: argv, data: (char *) testing_helper); |
1362 | g_ptr_array_add (array: argv, data: "skip-options" ); |
1363 | g_ptr_array_add (array: argv, data: "--tap" ); |
1364 | g_ptr_array_add (array: argv, data: "-r" ); |
1365 | g_ptr_array_add (array: argv, data: "/c/a" ); |
1366 | g_ptr_array_add (array: argv, data: "-p" ); |
1367 | g_ptr_array_add (array: argv, data: "/c/a" ); |
1368 | g_ptr_array_add (array: argv, data: "--run-prefix" ); |
1369 | g_ptr_array_add (array: argv, data: "/b" ); |
1370 | g_ptr_array_add (array: argv, NULL); |
1371 | |
1372 | g_spawn_sync (NULL, argv: (char **) argv->pdata, NULL, |
1373 | flags: G_SPAWN_STDERR_TO_DEV_NULL, |
1374 | NULL, NULL, standard_output: &output, NULL, exit_status: &status, |
1375 | error: &error); |
1376 | g_assert_no_error (error); |
1377 | g_spawn_check_exit_status (exit_status: status, error: &error); |
1378 | g_assert_nonnull (error); |
1379 | g_assert_nonnull (strstr (output, "do not mix [-r | --run-prefix] with '-p'\n" )); |
1380 | g_clear_error (err: &error); |
1381 | |
1382 | g_free (mem: output); |
1383 | g_ptr_array_unref (array: argv); |
1384 | |
1385 | g_test_message (format: "-s" ); |
1386 | argv = g_ptr_array_new (); |
1387 | g_ptr_array_add (array: argv, data: (char *) testing_helper); |
1388 | g_ptr_array_add (array: argv, data: "skip-options" ); |
1389 | g_ptr_array_add (array: argv, data: "--tap" ); |
1390 | g_ptr_array_add (array: argv, data: "-s" ); |
1391 | g_ptr_array_add (array: argv, data: "/a" ); |
1392 | g_ptr_array_add (array: argv, data: "-s" ); |
1393 | g_ptr_array_add (array: argv, data: "/b" ); |
1394 | g_ptr_array_add (array: argv, data: "-s" ); |
1395 | g_ptr_array_add (array: argv, data: "/pre" ); |
1396 | g_ptr_array_add (array: argv, data: "-s" ); |
1397 | g_ptr_array_add (array: argv, data: "/c/a" ); |
1398 | g_ptr_array_add (array: argv, NULL); |
1399 | |
1400 | g_spawn_sync (NULL, argv: (char **) argv->pdata, NULL, |
1401 | flags: G_SPAWN_STDERR_TO_DEV_NULL, |
1402 | NULL, NULL, standard_output: &output, NULL, exit_status: &status, |
1403 | error: &error); |
1404 | g_assert_no_error (error); |
1405 | g_assert_nonnull (strstr (output, "1..10\n" )); |
1406 | g_assert_nonnull (strstr (output, "\nok 1 /a # SKIP by request" )); |
1407 | g_assert_nonnull (strstr (output, "\nok 2 /b # SKIP by request" )); |
1408 | /* "-s /b" would skip a test named exactly /b, but not a test named |
1409 | * /b/anything */ |
1410 | g_assert_nonnull (strstr (output, "\nok 3 /b/a\n" )); |
1411 | g_assert_nonnull (strstr (output, "\nok 4 /b/b\n" )); |
1412 | g_assert_nonnull (strstr (output, "\nok 5 /b/b/a\n" )); |
1413 | g_assert_nonnull (strstr (output, "\nok 6 /prefix/a\n" )); |
1414 | g_assert_nonnull (strstr (output, "\nok 7 /prefix/b/b\n" )); |
1415 | g_assert_nonnull (strstr (output, "\nok 8 /prefix-long/a\n" )); |
1416 | g_assert_nonnull (strstr (output, "\nok 9 /c/a # SKIP by request" )); |
1417 | g_assert_nonnull (strstr (output, "\nok 10 /d/a\n" )); |
1418 | |
1419 | g_spawn_check_exit_status (exit_status: status, error: &error); |
1420 | g_assert_no_error (error); |
1421 | |
1422 | g_free (mem: output); |
1423 | g_ptr_array_unref (array: argv); |
1424 | |
1425 | g_test_message (format: "--skip-prefix" ); |
1426 | argv = g_ptr_array_new (); |
1427 | g_ptr_array_add (array: argv, data: (char *) testing_helper); |
1428 | g_ptr_array_add (array: argv, data: "skip-options" ); |
1429 | g_ptr_array_add (array: argv, data: "--tap" ); |
1430 | g_ptr_array_add (array: argv, data: "-x" ); |
1431 | g_ptr_array_add (array: argv, data: "/a" ); |
1432 | g_ptr_array_add (array: argv, data: "--skip-prefix" ); |
1433 | g_ptr_array_add (array: argv, data: "/pre" ); |
1434 | g_ptr_array_add (array: argv, data: "-x" ); |
1435 | g_ptr_array_add (array: argv, data: "/c/a" ); |
1436 | g_ptr_array_add (array: argv, NULL); |
1437 | |
1438 | g_spawn_sync (NULL, argv: (char **) argv->pdata, NULL, |
1439 | flags: G_SPAWN_STDERR_TO_DEV_NULL, |
1440 | NULL, NULL, standard_output: &output, NULL, exit_status: &status, |
1441 | error: &error); |
1442 | g_assert_no_error (error); |
1443 | g_assert_nonnull (strstr (output, "1..10\n" )); |
1444 | g_assert_nonnull (strstr (output, "\nok 1 /a # SKIP by request" )); |
1445 | g_assert_nonnull (strstr (output, "\nok 2 /b\n" )); |
1446 | g_assert_nonnull (strstr (output, "\nok 3 /b/a\n" )); |
1447 | g_assert_nonnull (strstr (output, "\nok 4 /b/b\n" )); |
1448 | g_assert_nonnull (strstr (output, "\nok 5 /b/b/a\n" )); |
1449 | /* "--skip-prefix /pre" will skip all test path which begins with /pre */ |
1450 | g_assert_nonnull (strstr (output, "\nok 6 /prefix/a # SKIP by request" )); |
1451 | g_assert_nonnull (strstr (output, "\nok 7 /prefix/b/b # SKIP by request" )); |
1452 | g_assert_nonnull (strstr (output, "\nok 8 /prefix-long/a # SKIP by request" )); |
1453 | g_assert_nonnull (strstr (output, "\nok 9 /c/a # SKIP by request" )); |
1454 | g_assert_nonnull (strstr (output, "\nok 10 /d/a\n" )); |
1455 | |
1456 | g_spawn_check_exit_status (exit_status: status, error: &error); |
1457 | g_assert_no_error (error); |
1458 | |
1459 | g_free (mem: output); |
1460 | g_ptr_array_unref (array: argv); |
1461 | |
1462 | g_test_message (format: "--skip-prefix conflict" ); |
1463 | argv = g_ptr_array_new (); |
1464 | g_ptr_array_add (array: argv, data: (char *) testing_helper); |
1465 | g_ptr_array_add (array: argv, data: "skip-options" ); |
1466 | g_ptr_array_add (array: argv, data: "--tap" ); |
1467 | g_ptr_array_add (array: argv, data: "-s" ); |
1468 | g_ptr_array_add (array: argv, data: "/a" ); |
1469 | g_ptr_array_add (array: argv, data: "--skip-prefix" ); |
1470 | g_ptr_array_add (array: argv, data: "/pre" ); |
1471 | g_ptr_array_add (array: argv, data: "-x" ); |
1472 | g_ptr_array_add (array: argv, data: "/c/a" ); |
1473 | g_ptr_array_add (array: argv, NULL); |
1474 | |
1475 | g_spawn_sync (NULL, argv: (char **) argv->pdata, NULL, |
1476 | flags: G_SPAWN_STDERR_TO_DEV_NULL, |
1477 | NULL, NULL, standard_output: &output, NULL, exit_status: &status, |
1478 | error: &error); |
1479 | g_assert_no_error (error); |
1480 | g_spawn_check_exit_status (exit_status: status, error: &error); |
1481 | g_assert_nonnull (error); |
1482 | g_assert_nonnull (strstr (output, "do not mix [-x | --skip-prefix] with '-s'\n" )); |
1483 | g_clear_error (err: &error); |
1484 | |
1485 | g_free (mem: output); |
1486 | g_ptr_array_unref (array: argv); |
1487 | } |
1488 | |
1489 | static void |
1490 | test_tap_summary (void) |
1491 | { |
1492 | const char *testing_helper; |
1493 | GPtrArray *argv; |
1494 | GError *error = NULL; |
1495 | int status; |
1496 | gchar *output; |
1497 | |
1498 | g_test_summary (summary: "Test the output of g_test_summary() from the TAP output of a test." ); |
1499 | |
1500 | testing_helper = g_test_get_filename (file_type: G_TEST_BUILT, first_path: "testing-helper" EXEEXT, NULL); |
1501 | |
1502 | argv = g_ptr_array_new (); |
1503 | g_ptr_array_add (array: argv, data: (char *) testing_helper); |
1504 | g_ptr_array_add (array: argv, data: "summary" ); |
1505 | g_ptr_array_add (array: argv, data: "--tap" ); |
1506 | g_ptr_array_add (array: argv, NULL); |
1507 | |
1508 | g_spawn_sync (NULL, argv: (char **) argv->pdata, NULL, |
1509 | flags: G_SPAWN_STDERR_TO_DEV_NULL, |
1510 | NULL, NULL, standard_output: &output, NULL, exit_status: &status, |
1511 | error: &error); |
1512 | g_assert_no_error (error); |
1513 | |
1514 | g_spawn_check_exit_status (exit_status: status, error: &error); |
1515 | g_assert_no_error (error); |
1516 | /* Note: The test path in the output is not `/tap/summary` because it’s the |
1517 | * test path from testing-helper, not from this function. */ |
1518 | g_assert_nonnull (strstr (output, "\n# /summary summary: Tests that g_test_summary() " |
1519 | "works with TAP, by outputting a known " |
1520 | "summary message in testing-helper, and " |
1521 | "checking for it in the TAP output later.\n" )); |
1522 | g_free (mem: output); |
1523 | g_ptr_array_unref (array: argv); |
1524 | } |
1525 | |
1526 | int |
1527 | main (int argc, |
1528 | char *argv[]) |
1529 | { |
1530 | argv0 = argv[0]; |
1531 | |
1532 | setlocale (LC_ALL, locale: "" ); |
1533 | |
1534 | g_test_init (argc: &argc, argv: &argv, NULL); |
1535 | |
1536 | g_test_add_func (testpath: "/random-generator/rand-1" , test_func: test_rand1); |
1537 | g_test_add_func (testpath: "/random-generator/rand-2" , test_func: test_rand2); |
1538 | g_test_add_func (testpath: "/random-generator/random-conversions" , test_func: test_random_conversions); |
1539 | g_test_add_func (testpath: "/misc/assertions" , test_func: test_assertions); |
1540 | g_test_add_func (testpath: "/misc/assertions/subprocess/bad_cmpvariant_types" , test_func: test_assertions_bad_cmpvariant_types); |
1541 | g_test_add_func (testpath: "/misc/assertions/subprocess/bad_cmpvariant_values" , test_func: test_assertions_bad_cmpvariant_values); |
1542 | g_test_add_func (testpath: "/misc/assertions/subprocess/bad_cmpstr" , test_func: test_assertions_bad_cmpstr); |
1543 | g_test_add_func (testpath: "/misc/assertions/subprocess/bad_cmpstrv_null1" , test_func: test_assertions_bad_cmpstrv_null1); |
1544 | g_test_add_func (testpath: "/misc/assertions/subprocess/bad_cmpstrv_null2" , test_func: test_assertions_bad_cmpstrv_null2); |
1545 | g_test_add_func (testpath: "/misc/assertions/subprocess/bad_cmpstrv_length" , test_func: test_assertions_bad_cmpstrv_length); |
1546 | g_test_add_func (testpath: "/misc/assertions/subprocess/bad_cmpstrv_values" , test_func: test_assertions_bad_cmpstrv_values); |
1547 | g_test_add_func (testpath: "/misc/assertions/subprocess/bad_cmpint" , test_func: test_assertions_bad_cmpint); |
1548 | g_test_add_func (testpath: "/misc/assertions/subprocess/bad_cmpmem_len" , test_func: test_assertions_bad_cmpmem_len); |
1549 | g_test_add_func (testpath: "/misc/assertions/subprocess/bad_cmpmem_data" , test_func: test_assertions_bad_cmpmem_data); |
1550 | g_test_add_func (testpath: "/misc/assertions/subprocess/bad_cmpmem_null" , test_func: test_assertions_bad_cmpmem_null); |
1551 | g_test_add_func (testpath: "/misc/assertions/subprocess/bad_cmpfloat_epsilon" , test_func: test_assertions_bad_cmpfloat_epsilon); |
1552 | g_test_add_func (testpath: "/misc/assertions/subprocess/bad_no_errno" , test_func: test_assertions_bad_no_errno); |
1553 | g_test_add_data_func (testpath: "/misc/test-data" , test_data: (void*) 0xc0c0baba, test_func: test_data_test); |
1554 | g_test_add ("/misc/primetoul" , Fixturetest, (void*) 0xc0cac01a, fixturetest_setup, fixturetest_test, fixturetest_teardown); |
1555 | if (g_test_perf()) |
1556 | g_test_add_func (testpath: "/misc/timer" , test_func: test_timer); |
1557 | |
1558 | #ifdef G_OS_UNIX |
1559 | g_test_add_func (testpath: "/forking/fail assertion" , test_func: test_fork_fail); |
1560 | g_test_add_func (testpath: "/forking/patterns" , test_func: test_fork_patterns); |
1561 | if (g_test_slow()) |
1562 | g_test_add_func (testpath: "/forking/timeout" , test_func: test_fork_timeout); |
1563 | #endif |
1564 | |
1565 | g_test_add_func (testpath: "/trap_subprocess/fail" , test_func: test_subprocess_fail); |
1566 | g_test_add_func (testpath: "/trap_subprocess/no-such-test" , test_func: test_subprocess_no_such_test); |
1567 | if (g_test_slow ()) |
1568 | g_test_add_func (testpath: "/trap_subprocess/timeout" , test_func: test_subprocess_timeout); |
1569 | |
1570 | g_test_add_func (testpath: "/trap_subprocess/patterns" , test_func: test_subprocess_patterns); |
1571 | |
1572 | g_test_add_func (testpath: "/misc/fatal-log-handler" , test_func: test_fatal_log_handler); |
1573 | g_test_add_func (testpath: "/misc/fatal-log-handler/subprocess/critical-pass" , test_func: test_fatal_log_handler_critical_pass); |
1574 | g_test_add_func (testpath: "/misc/fatal-log-handler/subprocess/error-fail" , test_func: test_fatal_log_handler_error_fail); |
1575 | g_test_add_func (testpath: "/misc/fatal-log-handler/subprocess/critical-fail" , test_func: test_fatal_log_handler_critical_fail); |
1576 | |
1577 | g_test_add_func (testpath: "/misc/expected-messages" , test_func: test_expected_messages); |
1578 | g_test_add_func (testpath: "/misc/expected-messages/subprocess/warning" , test_func: test_expected_messages_warning); |
1579 | g_test_add_func (testpath: "/misc/expected-messages/subprocess/expect-warning" , test_func: test_expected_messages_expect_warning); |
1580 | g_test_add_func (testpath: "/misc/expected-messages/subprocess/wrong-warning" , test_func: test_expected_messages_wrong_warning); |
1581 | g_test_add_func (testpath: "/misc/expected-messages/subprocess/expected" , test_func: test_expected_messages_expected); |
1582 | g_test_add_func (testpath: "/misc/expected-messages/subprocess/null-domain" , test_func: test_expected_messages_null_domain); |
1583 | g_test_add_func (testpath: "/misc/expected-messages/subprocess/extra-warning" , test_func: test_expected_messages_extra_warning); |
1584 | g_test_add_func (testpath: "/misc/expected-messages/subprocess/unexpected-extra-warning" , test_func: test_expected_messages_unexpected_extra_warning); |
1585 | g_test_add_func (testpath: "/misc/expected-messages/expect-error" , test_func: test_expected_messages_expect_error); |
1586 | g_test_add_func (testpath: "/misc/expected-messages/skip-debug" , test_func: test_expected_messages_debug); |
1587 | |
1588 | g_test_add_func (testpath: "/misc/dash-p" , test_func: test_dash_p); |
1589 | g_test_add_func (testpath: "/misc/dash-p/child" , test_func: test_dash_p_child); |
1590 | g_test_add_func (testpath: "/misc/dash-p/child/sub" , test_func: test_dash_p_child_sub); |
1591 | g_test_add_func (testpath: "/misc/dash-p/child/sub/subprocess" , test_func: test_dash_p_child_sub_child); |
1592 | g_test_add_func (testpath: "/misc/dash-p/child/sub/subprocess/child" , test_func: test_dash_p_child_sub_child); |
1593 | g_test_add_func (testpath: "/misc/dash-p/child/sub2" , test_func: test_dash_p_child_sub2); |
1594 | g_test_add_func (testpath: "/misc/dash-p/subprocess/hidden" , test_func: test_dash_p_hidden); |
1595 | g_test_add_func (testpath: "/misc/dash-p/subprocess/hidden/sub" , test_func: test_dash_p_hidden_sub); |
1596 | |
1597 | g_test_add_func (testpath: "/misc/nonfatal" , test_func: test_nonfatal); |
1598 | |
1599 | g_test_add_func (testpath: "/misc/skip" , test_func: test_skip); |
1600 | g_test_add_func (testpath: "/misc/combining" , test_func: test_combining); |
1601 | g_test_add_func (testpath: "/misc/combining/subprocess/fail" , test_func: subprocess_fail); |
1602 | g_test_add_func (testpath: "/misc/combining/subprocess/skip1" , test_func: test_skip); |
1603 | g_test_add_func (testpath: "/misc/combining/subprocess/skip2" , test_func: test_skip); |
1604 | g_test_add_func (testpath: "/misc/combining/subprocess/incomplete" , test_func: subprocess_incomplete); |
1605 | g_test_add_func (testpath: "/misc/combining/subprocess/pass" , test_func: test_pass); |
1606 | g_test_add_func (testpath: "/misc/fail" , test_func: test_fail); |
1607 | g_test_add_func (testpath: "/misc/incomplete" , test_func: test_incomplete); |
1608 | g_test_add_func (testpath: "/misc/timeout" , test_func: test_subprocess_timed_out); |
1609 | |
1610 | g_test_add_func (testpath: "/misc/path/first" , test_func: test_path_first); |
1611 | g_test_add_func (testpath: "/misc/path/second" , test_func: test_path_second); |
1612 | |
1613 | g_test_add_func (testpath: "/tap" , test_func: test_tap); |
1614 | g_test_add_func (testpath: "/tap/summary" , test_func: test_tap_summary); |
1615 | |
1616 | return g_test_run(); |
1617 | } |
1618 | |