1 /* GLib testing framework examples and tests
2 * Copyright (C) 2007 Imendio AB
5 * SPDX-License-Identifier: LicenseRef-old-glib-tests
7 * This work is provided "as is"; redistribution and modification
8 * in whole or in part, in any medium, physical or electronic is
9 * permitted without restriction.
11 * This work is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15 * In no event shall the authors or contributors be liable for any
16 * direct, indirect, incidental, special, exemplary, or consequential
17 * damages (including, but not limited to, procurement of substitute
18 * goods or services; loss of use, data, or profits; or business
19 * interruption) however caused and on any theory of liability, whether
20 * in contract, strict liability, or tort (including negligence or
21 * otherwise) arising in any way out of the use of this software, even
22 * if advised of the possibility of such damage.
27 /* We want to distinguish between messages originating from libglib
28 * and messages originating from this program.
31 #define G_LOG_DOMAIN "testing"
38 #define TAP_VERSION G_STRINGIFY (13)
39 #define TAP_SUBTEST_PREFIX "# "
41 /* test assertion variants */
43 test_assertions_bad_cmpvariant_types (void)
47 v1 = g_variant_new_boolean (TRUE);
48 v2 = g_variant_new_string ("hello");
50 g_assert_cmpvariant (v1, v2);
59 test_assertions_bad_cmpvariant_values (void)
63 v1 = g_variant_new_string ("goodbye");
64 v2 = g_variant_new_string ("hello");
66 g_assert_cmpvariant (v1, v2);
75 test_assertions_bad_cmpstrv_null1 (void)
77 const char *strv[] = { "one", "two", "three", NULL };
78 g_assert_cmpstrv (strv, NULL);
83 test_assertions_bad_cmpstrv_null2 (void)
85 const char *strv[] = { "one", "two", "three", NULL };
86 g_assert_cmpstrv (NULL, strv);
91 test_assertions_bad_cmpstrv_length (void)
93 const char *strv1[] = { "one", "two", "three", NULL };
94 const char *strv2[] = { "one", "two", NULL };
95 g_assert_cmpstrv (strv1, strv2);
100 test_assertions_bad_cmpstrv_values (void)
102 const char *strv1[] = { "one", "two", "three", NULL };
103 const char *strv2[] = { "one", "too", "three", NULL };
104 g_assert_cmpstrv (strv1, strv2);
109 test_assertions_bad_cmpstr (void)
111 g_assert_cmpstr ("fzz", !=, "fzz");
116 test_assertions_bad_cmpint (void)
118 g_assert_cmpint (4, !=, 4);
123 test_assertions_bad_cmpmem_len (void)
125 g_assert_cmpmem ("foo", 3, "foot", 4);
130 test_assertions_bad_cmpmem_data (void)
132 g_assert_cmpmem ("foo", 3, "fzz", 3);
137 test_assertions_bad_cmpmem_null (void)
139 g_assert_cmpmem (NULL, 3, NULL, 3);
144 test_assertions_bad_cmpfloat_epsilon (void)
146 g_assert_cmpfloat_with_epsilon (3.14, 3.15, 0.001);
150 /* Emulates something like rmdir() failing. */
154 errno = ERANGE; /* arbitrary non-zero value */
158 /* Emulates something like rmdir() succeeding. */
160 return_no_errno (void)
166 test_assertions_bad_no_errno (void)
168 g_assert_no_errno (return_errno ());
172 test_assertions (void)
174 const char *strv1[] = { "one", "two", "three", NULL };
175 const char *strv2[] = { "one", "two", "three", NULL };
179 g_assert_cmpint (1, >, 0);
180 g_assert_cmphex (2, ==, 2);
181 g_assert_cmpfloat (3.3, !=, 7);
182 g_assert_cmpfloat (7, <=, 3 + 4);
183 g_assert_cmpfloat_with_epsilon (3.14, 3.15, 0.01);
184 g_assert_cmpfloat_with_epsilon (3.14159, 3.1416, 0.0001);
186 g_assert_true (TRUE);
187 g_assert_cmpstr ("foo", !=, "faa");
188 fuu = g_strdup_printf ("f%s", "uu");
189 g_test_queue_free (fuu);
190 g_assert_cmpstr ("foo", !=, fuu);
191 g_assert_cmpstr ("fuu", ==, fuu);
192 g_assert_cmpstr (NULL, <, "");
193 g_assert_cmpstr (NULL, ==, NULL);
194 g_assert_cmpstr ("", >, NULL);
195 g_assert_cmpstr ("foo", <, "fzz");
196 g_assert_cmpstr ("fzz", >, "faa");
197 g_assert_cmpstr ("fzz", ==, "fzz");
198 g_assert_cmpmem ("foo", 3, "foot", 3);
199 g_assert_cmpmem (NULL, 0, NULL, 0);
200 g_assert_cmpmem (NULL, 0, "foot", 0);
201 g_assert_cmpmem ("foo", 0, NULL, 0);
202 g_assert_no_errno (return_no_errno ());
204 g_assert_cmpstrv (NULL, NULL);
205 g_assert_cmpstrv (strv1, strv2);
207 v1 = g_variant_new_parsed ("['hello', 'there']");
208 v2 = g_variant_new_parsed ("['hello', 'there']");
210 g_assert_cmpvariant (v1, v1);
211 g_assert_cmpvariant (v1, v2);
213 g_variant_unref (v2);
214 g_variant_unref (v1);
216 g_test_trap_subprocess ("/misc/assertions/subprocess/bad_cmpvariant_types", 0,
217 G_TEST_SUBPROCESS_DEFAULT);
218 g_test_trap_assert_failed ();
219 g_test_trap_assert_stderr ("*assertion failed*");
221 g_test_trap_subprocess ("/misc/assertions/subprocess/bad_cmpvariant_values", 0,
222 G_TEST_SUBPROCESS_DEFAULT);
223 g_test_trap_assert_failed ();
224 g_test_trap_assert_stderr ("*assertion failed*");
226 g_test_trap_subprocess ("/misc/assertions/subprocess/bad_cmpstr", 0,
227 G_TEST_SUBPROCESS_DEFAULT);
228 g_test_trap_assert_failed ();
229 g_test_trap_assert_stderr ("*assertion failed*");
231 g_test_trap_subprocess ("/misc/assertions/subprocess/bad_cmpstrv_null1", 0,
232 G_TEST_SUBPROCESS_DEFAULT);
233 g_test_trap_assert_failed ();
234 g_test_trap_assert_stderr ("*assertion failed*");
236 g_test_trap_subprocess ("/misc/assertions/subprocess/bad_cmpstrv_null2", 0,
237 G_TEST_SUBPROCESS_DEFAULT);
238 g_test_trap_assert_failed ();
239 g_test_trap_assert_stderr ("*assertion failed*");
241 g_test_trap_subprocess ("/misc/assertions/subprocess/bad_cmpstrv_length", 0,
242 G_TEST_SUBPROCESS_DEFAULT);
243 g_test_trap_assert_failed ();
244 g_test_trap_assert_stderr ("*assertion failed*");
246 g_test_trap_subprocess ("/misc/assertions/subprocess/bad_cmpstrv_values", 0,
247 G_TEST_SUBPROCESS_DEFAULT);
248 g_test_trap_assert_failed ();
249 g_test_trap_assert_stderr ("*assertion failed*");
251 g_test_trap_subprocess ("/misc/assertions/subprocess/bad_cmpint", 0,
252 G_TEST_SUBPROCESS_DEFAULT);
253 g_test_trap_assert_failed ();
254 g_test_trap_assert_stderr ("*assertion failed*");
256 g_test_trap_subprocess ("/misc/assertions/subprocess/bad_cmpmem_len", 0,
257 G_TEST_SUBPROCESS_DEFAULT);
258 g_test_trap_assert_failed ();
259 g_test_trap_assert_stderr ("*assertion failed*len*");
261 g_test_trap_subprocess ("/misc/assertions/subprocess/bad_cmpmem_data", 0,
262 G_TEST_SUBPROCESS_DEFAULT);
263 g_test_trap_assert_failed ();
264 g_test_trap_assert_stderr ("*assertion failed*");
265 g_test_trap_assert_stderr_unmatched ("*assertion failed*len*");
267 g_test_trap_subprocess ("/misc/assertions/subprocess/bad_cmpmem_null", 0,
268 G_TEST_SUBPROCESS_DEFAULT);
269 g_test_trap_assert_failed ();
270 g_test_trap_assert_stderr ("*assertion failed*NULL*");
272 g_test_trap_subprocess ("/misc/assertions/subprocess/bad_cmpfloat_epsilon", 0,
273 G_TEST_SUBPROCESS_DEFAULT);
274 g_test_trap_assert_failed ();
275 g_test_trap_assert_stderr ("*assertion failed*");
277 g_test_trap_subprocess ("/misc/assertions/subprocess/bad_no_errno", 0,
278 G_TEST_SUBPROCESS_DEFAULT);
279 g_test_trap_assert_failed ();
280 g_test_trap_assert_stderr ("*assertion failed*");
283 /* test g_test_timer* API */
288 g_test_timer_start();
289 g_assert_cmpfloat (g_test_timer_last(), ==, 0);
290 g_usleep (25 * 1000);
291 ttime = g_test_timer_elapsed();
292 g_assert_cmpfloat (ttime, >, 0);
293 g_assert_cmpfloat (g_test_timer_last(), ==, ttime);
294 g_test_minimized_result (ttime, "timer-test-time: %fsec", ttime);
295 g_test_maximized_result (5, "bogus-quantity: %ddummies", 5); /* simple API test */
299 G_GNUC_BEGIN_IGNORE_DEPRECATIONS
301 /* fork out for a failing test */
303 test_fork_fail (void)
305 if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR))
307 g_assert_not_reached();
309 g_test_trap_assert_failed();
310 g_test_trap_assert_stderr ("*ERROR*test_fork_fail*should not be reached*");
313 /* fork out to assert stdout and stderr patterns */
315 test_fork_patterns (void)
317 if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDOUT | G_TEST_TRAP_SILENCE_STDERR))
319 g_print ("some stdout text: somagic17\n");
320 g_printerr ("some stderr text: semagic43\n");
323 g_test_trap_assert_passed();
324 g_test_trap_assert_stdout ("*somagic17*");
325 g_test_trap_assert_stderr ("*semagic43*");
328 /* fork out for a timeout test */
330 test_fork_timeout (void)
332 /* allow child to run for only a fraction of a second */
333 if (g_test_trap_fork (0.11 * 1000000, G_TEST_TRAP_DEFAULT))
335 /* loop and sleep forever */
337 g_usleep (1000 * 1000);
339 g_test_trap_assert_failed();
340 g_assert_true (g_test_trap_reached_timeout());
343 G_GNUC_END_IGNORE_DEPRECATIONS
344 #endif /* G_OS_UNIX */
347 test_subprocess_fail (void)
349 if (g_test_subprocess ())
351 g_assert_not_reached ();
355 g_test_trap_subprocess (NULL, 0, G_TEST_SUBPROCESS_DEFAULT);
356 g_test_trap_assert_failed ();
357 g_test_trap_assert_stderr ("*ERROR*test_subprocess_fail*should not be reached*");
361 test_subprocess_no_such_test (void)
363 if (g_test_subprocess ())
365 g_test_trap_subprocess ("/trap_subprocess/this-test-does-not-exist", 0,
366 G_TEST_SUBPROCESS_DEFAULT);
367 g_assert_not_reached ();
370 g_test_trap_subprocess (NULL, 0, G_TEST_SUBPROCESS_DEFAULT);
371 g_test_trap_assert_failed ();
372 g_test_trap_assert_stderr ("*test does not exist*");
373 g_test_trap_assert_stderr_unmatched ("*should not be reached*");
377 test_subprocess_patterns (void)
379 if (g_test_subprocess ())
381 g_print ("some stdout text: somagic17\n");
382 g_printerr ("some stderr text: semagic43\n");
385 g_test_trap_subprocess (NULL, 0, G_TEST_SUBPROCESS_DEFAULT);
386 g_test_trap_assert_passed ();
387 g_test_trap_assert_stdout ("*somagic17*");
388 g_test_trap_assert_stderr ("*semagic43*");
392 test_subprocess_timeout (void)
394 if (g_test_subprocess ())
396 /* loop and sleep forever */
398 g_usleep (1000 * 1000);
401 /* allow child to run for only a fraction of a second */
402 g_test_trap_subprocess (NULL, 0.11 * 1000000, G_TEST_SUBPROCESS_DEFAULT);
403 g_test_trap_assert_failed ();
404 g_assert_true (g_test_trap_reached_timeout ());
407 /* run a test with fixture setup and teardown */
414 fixturetest_setup (Fixturetest *fix,
415 gconstpointer test_data)
417 g_assert_true (test_data == (void*) 0xc0cac01a);
420 fix->msg = g_strdup_printf ("%d", fix->prime);
423 fixturetest_test (Fixturetest *fix,
424 gconstpointer test_data)
426 guint prime = g_spaced_primes_closest (fix->seed);
427 g_assert_cmpint (prime, ==, fix->prime);
428 prime = g_ascii_strtoull (fix->msg, NULL, 0);
429 g_assert_cmpint (prime, ==, fix->prime);
430 g_assert_true (test_data == (void*) 0xc0cac01a);
433 fixturetest_teardown (Fixturetest *fix,
434 gconstpointer test_data)
436 g_assert_true (test_data == (void*) 0xc0cac01a);
441 int bit, vint1, vint2, irange;
442 long double vdouble, drange;
448 shared_rand_state.bit = g_test_rand_bit();
449 shared_rand_state.vint1 = g_test_rand_int();
450 shared_rand_state.vint2 = g_test_rand_int();
451 g_assert_cmpint (shared_rand_state.vint1, !=, shared_rand_state.vint2);
452 shared_rand_state.irange = g_test_rand_int_range (17, 35);
453 g_assert_cmpint (shared_rand_state.irange, >=, 17);
454 g_assert_cmpint (shared_rand_state.irange, <=, 35);
455 shared_rand_state.vdouble = g_test_rand_double();
456 shared_rand_state.drange = g_test_rand_double_range (-999, +17);
457 g_assert_cmpfloat (shared_rand_state.drange, >=, -999);
458 g_assert_cmpfloat (shared_rand_state.drange, <=, +17);
464 /* this test only works if run after test1.
465 * we do this to check that random number generators
466 * are reseeded upon fixture setup.
468 g_assert_cmpint (shared_rand_state.bit, ==, g_test_rand_bit());
469 g_assert_cmpint (shared_rand_state.vint1, ==, g_test_rand_int());
470 g_assert_cmpint (shared_rand_state.vint2, ==, g_test_rand_int());
471 g_assert_cmpint (shared_rand_state.irange, ==, g_test_rand_int_range (17, 35));
472 g_assert_cmpfloat (shared_rand_state.vdouble, ==, g_test_rand_double());
473 g_assert_cmpfloat (shared_rand_state.drange, ==, g_test_rand_double_range (-999, +17));
477 test_data_test (gconstpointer test_data)
479 g_assert_true (test_data == (void*) 0xc0c0baba);
483 test_random_conversions (void)
485 /* very simple conversion test using random numbers */
486 int vint = g_test_rand_int();
487 char *err, *str = g_strdup_printf ("%d", vint);
488 gint64 vint64 = g_ascii_strtoll (str, &err, 10);
489 g_assert_cmpint (vint, ==, vint64);
490 g_assert_true (!err || *err == 0);
495 fatal_handler (const gchar *log_domain,
496 GLogLevelFlags log_level,
497 const gchar *message,
504 test_fatal_log_handler_critical_pass (void)
506 g_test_log_set_fatal_handler (fatal_handler, NULL);
507 g_str_has_prefix (NULL, "file://");
508 g_critical ("Test passing");
513 test_fatal_log_handler_error_fail (void)
515 g_error ("Test failing");
520 test_fatal_log_handler_critical_fail (void)
522 g_str_has_prefix (NULL, "file://");
523 g_critical ("Test passing");
528 test_fatal_log_handler (void)
530 g_test_trap_subprocess ("/misc/fatal-log-handler/subprocess/critical-pass", 0,
531 G_TEST_SUBPROCESS_DEFAULT);
532 g_test_trap_assert_passed ();
533 g_test_trap_assert_stderr ("*CRITICAL*g_str_has_prefix*");
534 g_test_trap_assert_stderr ("*CRITICAL*Test passing*");
536 g_test_trap_subprocess ("/misc/fatal-log-handler/subprocess/error-fail", 0,
537 G_TEST_SUBPROCESS_DEFAULT);
538 g_test_trap_assert_failed ();
539 g_test_trap_assert_stderr ("*ERROR*Test failing*");
541 g_test_trap_subprocess ("/misc/fatal-log-handler/subprocess/critical-fail", 0,
542 G_TEST_SUBPROCESS_DEFAULT);
543 g_test_trap_assert_failed ();
544 g_test_trap_assert_stderr ("*CRITICAL*g_str_has_prefix*");
545 g_test_trap_assert_stderr_unmatched ("*CRITICAL*Test passing*");
549 test_expected_messages_warning (void)
551 g_warning ("This is a %d warning", g_random_int ());
552 g_return_if_reached ();
556 test_expected_messages_expect_warning (void)
558 g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_WARNING,
559 "This is a * warning");
560 test_expected_messages_warning ();
564 test_expected_messages_wrong_warning (void)
566 g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL,
568 test_expected_messages_warning ();
572 test_expected_messages_expected (void)
574 g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_WARNING,
575 "This is a * warning");
576 g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL,
577 "*should not be reached");
579 test_expected_messages_warning ();
581 g_test_assert_expected_messages ();
586 test_expected_messages_null_domain (void)
588 g_test_expect_message (NULL, G_LOG_LEVEL_WARNING, "no domain");
589 g_log (NULL, G_LOG_LEVEL_WARNING, "no domain");
590 g_test_assert_expected_messages ();
594 test_expected_messages_expect_error (void)
596 /* make sure we can't try to expect a g_error() */
597 g_test_expect_message ("GLib", G_LOG_LEVEL_CRITICAL, "*G_LOG_LEVEL_ERROR*");
598 g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_ERROR, "this won't work");
599 g_test_assert_expected_messages ();
603 test_expected_messages_extra_warning (void)
605 g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_WARNING,
606 "This is a * warning");
607 g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL,
608 "*should not be reached");
609 g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL,
612 test_expected_messages_warning ();
614 /* If we don't assert, it won't notice the missing message */
619 test_expected_messages_unexpected_extra_warning (void)
621 g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_WARNING,
622 "This is a * warning");
623 g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL,
624 "*should not be reached");
625 g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL,
628 test_expected_messages_warning ();
630 g_test_assert_expected_messages ();
635 test_expected_messages (void)
637 g_test_trap_subprocess ("/misc/expected-messages/subprocess/warning", 0,
638 G_TEST_SUBPROCESS_DEFAULT);
639 g_test_trap_assert_failed ();
640 g_test_trap_assert_stderr ("*This is a * warning*");
641 g_test_trap_assert_stderr_unmatched ("*should not be reached*");
643 g_test_trap_subprocess ("/misc/expected-messages/subprocess/expect-warning", 0,
644 G_TEST_SUBPROCESS_DEFAULT);
645 g_test_trap_assert_failed ();
646 g_test_trap_assert_stderr_unmatched ("*This is a * warning*");
647 g_test_trap_assert_stderr ("*should not be reached*");
649 g_test_trap_subprocess ("/misc/expected-messages/subprocess/wrong-warning", 0,
650 G_TEST_SUBPROCESS_DEFAULT);
651 g_test_trap_assert_failed ();
652 g_test_trap_assert_stderr_unmatched ("*should not be reached*");
653 g_test_trap_assert_stderr ("*GLib-CRITICAL*Did not see expected message testing-CRITICAL*should not be *WARNING*This is a * warning*");
655 g_test_trap_subprocess ("/misc/expected-messages/subprocess/expected", 0,
656 G_TEST_SUBPROCESS_DEFAULT);
657 g_test_trap_assert_passed ();
658 g_test_trap_assert_stderr ("");
660 g_test_trap_subprocess ("/misc/expected-messages/subprocess/null-domain", 0,
661 G_TEST_SUBPROCESS_DEFAULT);
662 g_test_trap_assert_passed ();
663 g_test_trap_assert_stderr ("");
665 g_test_trap_subprocess ("/misc/expected-messages/subprocess/extra-warning", 0,
666 G_TEST_SUBPROCESS_DEFAULT);
667 g_test_trap_assert_passed ();
668 g_test_trap_assert_stderr ("");
670 g_test_trap_subprocess ("/misc/expected-messages/subprocess/unexpected-extra-warning", 0,
671 G_TEST_SUBPROCESS_DEFAULT);
672 g_test_trap_assert_failed ();
673 g_test_trap_assert_stderr ("*GLib:ERROR*Did not see expected message testing-CRITICAL*nope*");
679 g_test_trap_subprocess ("/misc/messages/subprocess/use-stderr", 0,
680 G_TEST_SUBPROCESS_DEFAULT);
681 g_test_trap_assert_stderr ("*message is in stderr*");
682 g_test_trap_assert_stderr ("*warning is in stderr*");
683 g_test_trap_has_passed ();
687 test_messages_use_stderr (void)
689 g_message ("message is in stderr");
690 g_warning ("warning is in stderr");
694 test_expected_messages_debug (void)
696 g_test_expect_message ("Test", G_LOG_LEVEL_WARNING, "warning message");
697 g_log ("Test", G_LOG_LEVEL_DEBUG, "should be ignored");
698 g_log ("Test", G_LOG_LEVEL_WARNING, "warning message");
699 g_test_assert_expected_messages ();
701 g_test_expect_message ("Test", G_LOG_LEVEL_DEBUG, "debug message");
702 g_log ("Test", G_LOG_LEVEL_DEBUG, "debug message");
703 g_test_assert_expected_messages ();
707 test_dash_p_hidden (void)
709 if (!g_test_subprocess ())
710 g_assert_not_reached ();
712 g_print ("Test /misc/dash-p/subprocess/hidden ran\n");
716 test_dash_p_hidden_sub (void)
718 if (!g_test_subprocess ())
719 g_assert_not_reached ();
721 g_print ("Test /misc/dash-p/subprocess/hidden/sub ran\n");
724 /* The rest of the dash_p tests will get run by the toplevel test
725 * process, but they shouldn't do anything there.
729 test_dash_p_child (void)
731 if (!g_test_subprocess ())
734 g_print ("Test /misc/dash-p/child ran\n");
738 test_dash_p_child_sub (void)
740 if (!g_test_subprocess ())
743 g_print ("Test /misc/dash-p/child/sub ran\n");
747 test_dash_p_child_sub2 (void)
749 if (!g_test_subprocess ())
752 g_print ("Test /misc/dash-p/child/sub2 ran\n");
756 test_dash_p_child_sub_child (void)
758 if (!g_test_subprocess ())
761 g_print ("Test /misc/dash-p/child/subprocess ran\n");
767 g_test_trap_subprocess ("/misc/dash-p/subprocess/hidden", 0,
768 G_TEST_SUBPROCESS_DEFAULT);
769 g_test_trap_assert_passed ();
770 g_test_trap_assert_stdout ("*Test /misc/dash-p/subprocess/hidden ran*");
771 g_test_trap_assert_stdout_unmatched ("*Test /misc/dash-p/subprocess/hidden/sub ran*");
772 g_test_trap_assert_stdout_unmatched ("*Test /misc/dash-p/subprocess/hidden/sub2 ran*");
773 g_test_trap_assert_stdout_unmatched ("*Test /misc/dash-p/subprocess/hidden/sub/subprocess ran*");
774 g_test_trap_assert_stdout_unmatched ("*Test /misc/dash-p/child*");
776 g_test_trap_subprocess ("/misc/dash-p/subprocess/hidden/sub", 0,
777 G_TEST_SUBPROCESS_DEFAULT);
778 g_test_trap_assert_passed ();
779 g_test_trap_assert_stdout ("*Test /misc/dash-p/subprocess/hidden/sub ran*");
780 g_test_trap_assert_stdout_unmatched ("*Test /misc/dash-p/subprocess/hidden ran*");
781 g_test_trap_assert_stdout_unmatched ("*Test /misc/dash-p/subprocess/hidden/sub2 ran*");
782 g_test_trap_assert_stdout_unmatched ("*Test /misc/dash-p/subprocess/hidden/subprocess ran*");
783 g_test_trap_assert_stdout_unmatched ("*Test /misc/dash-p/child*");
785 g_test_trap_subprocess ("/misc/dash-p/child", 0,
786 G_TEST_SUBPROCESS_DEFAULT);
787 g_test_trap_assert_passed ();
788 g_test_trap_assert_stdout ("*Test /misc/dash-p/child ran*");
789 g_test_trap_assert_stdout ("*Test /misc/dash-p/child/sub ran*");
790 g_test_trap_assert_stdout ("*Test /misc/dash-p/child/sub2 ran*");
791 g_test_trap_assert_stdout_unmatched ("*Test /misc/dash-p/child/subprocess ran*");
792 g_test_trap_assert_stdout_unmatched ("*Test /misc/dash-p/subprocess/hidden*");
794 g_test_trap_subprocess ("/misc/dash-p/child/sub", 0,
795 G_TEST_SUBPROCESS_DEFAULT);
796 g_test_trap_assert_passed ();
797 g_test_trap_assert_stdout ("*Test /misc/dash-p/child/sub ran*");
798 g_test_trap_assert_stdout_unmatched ("*Test /misc/dash-p/child ran*");
799 g_test_trap_assert_stdout_unmatched ("*Test /misc/dash-p/child/sub2 ran*");
800 g_test_trap_assert_stdout_unmatched ("*Test /misc/dash-p/child/subprocess ran*");
801 g_test_trap_assert_stdout_unmatched ("*Test /misc/dash-p/subprocess/hidden*");
807 if (g_test_subprocess ())
809 g_test_set_nonfatal_assertions ();
810 g_assert_cmpint (4, ==, 5);
811 g_print ("The End\n");
814 g_test_trap_subprocess (NULL, 0, G_TEST_SUBPROCESS_DEFAULT);
815 g_test_trap_assert_failed ();
816 g_test_trap_assert_stderr ("*assertion failed*4 == 5*");
817 g_test_trap_assert_stdout ("*The End*");
823 g_test_skip ("Skipped should count as passed, not failed");
824 /* This function really means "the test concluded with a non-successful
825 * status" rather than "the test failed": it is documented to return
826 * true for skipped and incomplete tests, not just for failures. */
827 g_assert_true (g_test_failed ());
836 subprocess_fail (void)
838 /* Exit 1 instead of raising SIGABRT so that we can make assertions about
839 * how this combines with skipped/incomplete tests */
840 g_test_set_nonfatal_assertions ();
842 g_assert_true (g_test_failed ());
848 if (g_test_subprocess ())
853 g_test_trap_subprocess (NULL, 0, G_TEST_SUBPROCESS_DEFAULT);
854 g_test_trap_assert_failed ();
858 subprocess_incomplete (void)
860 g_test_incomplete ("not done");
861 /* This function really means "the test concluded with a non-successful
862 * status" rather than "the test failed": it is documented to return
863 * true for skipped and incomplete tests, not just for failures. */
864 g_assert_true (g_test_failed ());
868 test_incomplete (void)
870 if (g_test_subprocess ())
872 subprocess_incomplete ();
875 g_test_trap_subprocess (NULL, 0, G_TEST_SUBPROCESS_DEFAULT);
876 /* An incomplete test represents functionality that is known not to be
877 * implemented yet (an expected failure), so it does not cause test
878 * failure; but it does count as the test having been skipped, which
879 * causes nonzero exit status 77, which is treated as failure by
880 * g_test_trap_subprocess(). */
881 g_test_trap_assert_failed ();
885 test_subprocess_timed_out (void)
887 if (g_test_subprocess ())
892 g_test_trap_subprocess (NULL, 50000, G_TEST_SUBPROCESS_DEFAULT);
893 g_assert_true (g_test_trap_reached_timeout ());
897 test_path_first (void)
899 g_assert_cmpstr (g_test_get_path (), ==, "/misc/path/first");
903 test_path_second (void)
905 g_assert_cmpstr (g_test_get_path (), ==, "/misc/path/second");
908 static const char *argv0;
911 test_combining (void)
914 GError *error = NULL;
917 g_test_message ("single test case skipped -> overall status 77");
918 argv = g_ptr_array_new ();
919 g_ptr_array_add (argv, (char *) argv0);
920 g_ptr_array_add (argv, "--GTestSubprocess");
921 g_ptr_array_add (argv, "-p");
922 g_ptr_array_add (argv, "/misc/skip");
923 g_ptr_array_add (argv, NULL);
925 g_spawn_sync (NULL, (char **) argv->pdata, NULL,
926 G_SPAWN_STDOUT_TO_DEV_NULL | G_SPAWN_STDERR_TO_DEV_NULL,
927 NULL, NULL, NULL, NULL, &status,
929 g_assert_no_error (error);
931 g_spawn_check_wait_status (status, &error);
932 g_assert_error (error, G_SPAWN_EXIT_ERROR, 77);
933 g_clear_error (&error);
935 g_test_message ("each test case skipped -> overall status 77");
936 g_ptr_array_set_size (argv, 0);
937 g_ptr_array_add (argv, (char *) argv0);
938 g_ptr_array_add (argv, "--GTestSubprocess");
939 g_ptr_array_add (argv, "-p");
940 g_ptr_array_add (argv, "/misc/skip");
941 g_ptr_array_add (argv, "-p");
942 g_ptr_array_add (argv, "/misc/combining/subprocess/skip1");
943 g_ptr_array_add (argv, "-p");
944 g_ptr_array_add (argv, "/misc/combining/subprocess/skip2");
945 g_ptr_array_add (argv, NULL);
947 g_spawn_sync (NULL, (char **) argv->pdata, NULL,
948 G_SPAWN_STDOUT_TO_DEV_NULL | G_SPAWN_STDERR_TO_DEV_NULL,
949 NULL, NULL, NULL, NULL, &status,
951 g_assert_no_error (error);
953 g_spawn_check_wait_status (status, &error);
954 g_assert_error (error, G_SPAWN_EXIT_ERROR, 77);
955 g_clear_error (&error);
957 g_test_message ("single test case incomplete -> overall status 77");
958 g_ptr_array_set_size (argv, 0);
959 g_ptr_array_add (argv, (char *) argv0);
960 g_ptr_array_add (argv, "--GTestSubprocess");
961 g_ptr_array_add (argv, "-p");
962 g_ptr_array_add (argv, "/misc/combining/subprocess/incomplete");
963 g_ptr_array_add (argv, NULL);
965 g_spawn_sync (NULL, (char **) argv->pdata, NULL,
966 G_SPAWN_STDOUT_TO_DEV_NULL | G_SPAWN_STDERR_TO_DEV_NULL,
967 NULL, NULL, NULL, NULL, &status,
969 g_assert_no_error (error);
971 g_spawn_check_wait_status (status, &error);
972 g_assert_error (error, G_SPAWN_EXIT_ERROR, 77);
973 g_clear_error (&error);
975 g_test_message ("one pass and some skipped -> overall status 0");
976 g_ptr_array_set_size (argv, 0);
977 g_ptr_array_add (argv, (char *) argv0);
978 g_ptr_array_add (argv, "--GTestSubprocess");
979 g_ptr_array_add (argv, "-p");
980 g_ptr_array_add (argv, "/misc/skip");
981 g_ptr_array_add (argv, "-p");
982 g_ptr_array_add (argv, "/misc/combining/subprocess/pass");
983 g_ptr_array_add (argv, "-p");
984 g_ptr_array_add (argv, "/misc/combining/subprocess/skip1");
985 g_ptr_array_add (argv, NULL);
987 g_spawn_sync (NULL, (char **) argv->pdata, NULL,
988 G_SPAWN_STDOUT_TO_DEV_NULL | G_SPAWN_STDERR_TO_DEV_NULL,
989 NULL, NULL, NULL, NULL, &status,
991 g_assert_no_error (error);
993 g_spawn_check_wait_status (status, &error);
994 g_assert_no_error (error);
996 g_test_message ("one pass and some incomplete -> overall status 0");
997 g_ptr_array_set_size (argv, 0);
998 g_ptr_array_add (argv, (char *) argv0);
999 g_ptr_array_add (argv, "--GTestSubprocess");
1000 g_ptr_array_add (argv, "-p");
1001 g_ptr_array_add (argv, "/misc/combining/subprocess/pass");
1002 g_ptr_array_add (argv, "-p");
1003 g_ptr_array_add (argv, "/misc/combining/subprocess/incomplete");
1004 g_ptr_array_add (argv, NULL);
1006 g_spawn_sync (NULL, (char **) argv->pdata, NULL,
1007 G_SPAWN_STDOUT_TO_DEV_NULL | G_SPAWN_STDERR_TO_DEV_NULL,
1008 NULL, NULL, NULL, NULL, &status,
1010 g_assert_no_error (error);
1012 g_spawn_check_wait_status (status, &error);
1013 g_assert_no_error (error);
1015 g_test_message ("one pass and mix of skipped and incomplete -> overall status 0");
1016 g_ptr_array_set_size (argv, 0);
1017 g_ptr_array_add (argv, (char *) argv0);
1018 g_ptr_array_add (argv, "--GTestSubprocess");
1019 g_ptr_array_add (argv, "-p");
1020 g_ptr_array_add (argv, "/misc/combining/subprocess/pass");
1021 g_ptr_array_add (argv, "-p");
1022 g_ptr_array_add (argv, "/misc/combining/subprocess/skip1");
1023 g_ptr_array_add (argv, "-p");
1024 g_ptr_array_add (argv, "/misc/combining/subprocess/incomplete");
1025 g_ptr_array_add (argv, NULL);
1027 g_spawn_sync (NULL, (char **) argv->pdata, NULL,
1028 G_SPAWN_STDOUT_TO_DEV_NULL | G_SPAWN_STDERR_TO_DEV_NULL,
1029 NULL, NULL, NULL, NULL, &status,
1031 g_assert_no_error (error);
1033 g_spawn_check_wait_status (status, &error);
1034 g_assert_no_error (error);
1036 g_test_message ("one fail and some skipped -> overall status fail");
1037 g_ptr_array_set_size (argv, 0);
1038 g_ptr_array_add (argv, (char *) argv0);
1039 g_ptr_array_add (argv, "--GTestSubprocess");
1040 g_ptr_array_add (argv, "-p");
1041 g_ptr_array_add (argv, "/misc/skip");
1042 g_ptr_array_add (argv, "-p");
1043 g_ptr_array_add (argv, "/misc/combining/subprocess/fail");
1044 g_ptr_array_add (argv, "-p");
1045 g_ptr_array_add (argv, "/misc/combining/subprocess/skip1");
1046 g_ptr_array_add (argv, NULL);
1048 g_spawn_sync (NULL, (char **) argv->pdata, NULL,
1049 G_SPAWN_STDOUT_TO_DEV_NULL | G_SPAWN_STDERR_TO_DEV_NULL,
1050 NULL, NULL, NULL, NULL, &status,
1052 g_assert_no_error (error);
1054 g_spawn_check_wait_status (status, &error);
1055 g_assert_error (error, G_SPAWN_EXIT_ERROR, 1);
1056 g_clear_error (&error);
1058 g_test_message ("one fail and some incomplete -> overall status fail");
1059 g_ptr_array_set_size (argv, 0);
1060 g_ptr_array_add (argv, (char *) argv0);
1061 g_ptr_array_add (argv, "--GTestSubprocess");
1062 g_ptr_array_add (argv, "-p");
1063 g_ptr_array_add (argv, "/misc/combining/subprocess/fail");
1064 g_ptr_array_add (argv, "-p");
1065 g_ptr_array_add (argv, "/misc/combining/subprocess/incomplete");
1066 g_ptr_array_add (argv, NULL);
1068 g_spawn_sync (NULL, (char **) argv->pdata, NULL,
1069 G_SPAWN_STDOUT_TO_DEV_NULL | G_SPAWN_STDERR_TO_DEV_NULL,
1070 NULL, NULL, NULL, NULL, &status,
1072 g_assert_no_error (error);
1074 g_spawn_check_wait_status (status, &error);
1075 g_assert_error (error, G_SPAWN_EXIT_ERROR, 1);
1076 g_clear_error (&error);
1078 g_test_message ("one fail and mix of skipped and incomplete -> overall status fail");
1079 g_ptr_array_set_size (argv, 0);
1080 g_ptr_array_add (argv, (char *) argv0);
1081 g_ptr_array_add (argv, "--GTestSubprocess");
1082 g_ptr_array_add (argv, "-p");
1083 g_ptr_array_add (argv, "/misc/combining/subprocess/fail");
1084 g_ptr_array_add (argv, "-p");
1085 g_ptr_array_add (argv, "/misc/combining/subprocess/skip1");
1086 g_ptr_array_add (argv, "-p");
1087 g_ptr_array_add (argv, "/misc/combining/subprocess/incomplete");
1088 g_ptr_array_add (argv, NULL);
1090 g_spawn_sync (NULL, (char **) argv->pdata, NULL,
1091 G_SPAWN_STDOUT_TO_DEV_NULL | G_SPAWN_STDERR_TO_DEV_NULL,
1092 NULL, NULL, NULL, NULL, &status,
1094 g_assert_no_error (error);
1096 g_spawn_check_wait_status (status, &error);
1097 g_assert_error (error, G_SPAWN_EXIT_ERROR, 1);
1098 g_clear_error (&error);
1100 g_ptr_array_unref (argv);
1103 /* Test the TAP output when a test suite is run with --tap. */
1107 const char *testing_helper;
1109 GError *error = NULL;
1114 testing_helper = g_test_get_filename (G_TEST_BUILT, "testing-helper" EXEEXT, NULL);
1116 g_test_message ("pass");
1117 argv = g_ptr_array_new ();
1118 g_ptr_array_add (argv, (char *) testing_helper);
1119 g_ptr_array_add (argv, "pass");
1120 g_ptr_array_add (argv, "--tap");
1121 g_ptr_array_add (argv, NULL);
1123 /* Remove the G_TEST_ROOT_PROCESS env so it will be considered a standalone test */
1124 envp = g_get_environ ();
1125 g_assert_nonnull (g_environ_getenv (envp, "G_TEST_ROOT_PROCESS"));
1126 envp = g_environ_unsetenv (g_steal_pointer (&envp), "G_TEST_ROOT_PROCESS");
1128 g_spawn_sync (NULL, (char **) argv->pdata, envp,
1129 G_SPAWN_STDERR_TO_DEV_NULL,
1130 NULL, NULL, &output, NULL, &status,
1132 g_assert_no_error (error);
1134 g_spawn_check_wait_status (status, &error);
1135 g_assert_no_error (error);
1136 g_assert_true (g_str_has_prefix (output, "TAP version " TAP_VERSION));
1137 g_assert_null (strstr (output, "# Subtest: "));
1138 g_assert_nonnull (strstr (output, "\nok 1 /pass\n"));
1140 g_ptr_array_unref (argv);
1142 g_test_message ("skip");
1143 argv = g_ptr_array_new ();
1144 g_ptr_array_add (argv, (char *) testing_helper);
1145 g_ptr_array_add (argv, "skip");
1146 g_ptr_array_add (argv, "--tap");
1147 g_ptr_array_add (argv, NULL);
1149 g_spawn_sync (NULL, (char **) argv->pdata, envp,
1150 G_SPAWN_STDERR_TO_DEV_NULL,
1151 NULL, NULL, &output, NULL, &status,
1153 g_assert_no_error (error);
1155 g_spawn_check_wait_status (status, &error);
1156 g_assert_no_error (error);
1157 g_assert_true (g_str_has_prefix (output, "TAP version " TAP_VERSION));
1158 g_assert_null (strstr (output, "# Subtest: "));
1159 g_assert_nonnull (strstr (output, "\nok 1 /skip # SKIP not enough tea\n"));
1161 g_ptr_array_unref (argv);
1163 g_test_message ("skip with printf format");
1164 argv = g_ptr_array_new ();
1165 g_ptr_array_add (argv, (char *) testing_helper);
1166 g_ptr_array_add (argv, "skip-printf");
1167 g_ptr_array_add (argv, "--tap");
1168 g_ptr_array_add (argv, NULL);
1170 g_spawn_sync (NULL, (char **) argv->pdata, envp,
1171 G_SPAWN_STDERR_TO_DEV_NULL,
1172 NULL, NULL, &output, NULL, &status,
1174 g_assert_no_error (error);
1176 g_spawn_check_wait_status (status, &error);
1177 g_assert_no_error (error);
1178 g_assert_true (g_str_has_prefix (output, "TAP version " TAP_VERSION));
1179 g_assert_null (strstr (output, "# Subtest: "));
1180 g_assert_nonnull (strstr (output, "\nok 1 /skip-printf # SKIP not enough coffee\n"));
1182 g_ptr_array_unref (argv);
1184 g_test_message ("incomplete");
1185 argv = g_ptr_array_new ();
1186 g_ptr_array_add (argv, (char *) testing_helper);
1187 g_ptr_array_add (argv, "incomplete");
1188 g_ptr_array_add (argv, "--tap");
1189 g_ptr_array_add (argv, NULL);
1191 g_spawn_sync (NULL, (char **) argv->pdata, envp,
1192 G_SPAWN_STDERR_TO_DEV_NULL,
1193 NULL, NULL, &output, NULL, &status,
1195 g_assert_no_error (error);
1197 g_spawn_check_wait_status (status, &error);
1198 g_assert_no_error (error);
1199 g_assert_true (g_str_has_prefix (output, "TAP version " TAP_VERSION));
1200 g_assert_null (strstr (output, "# Subtest: "));
1201 g_assert_nonnull (strstr (output, "\nnot ok 1 /incomplete # TODO mind reading not implemented yet\n"));
1203 g_ptr_array_unref (argv);
1205 g_test_message ("incomplete with printf format");
1206 argv = g_ptr_array_new ();
1207 g_ptr_array_add (argv, (char *) testing_helper);
1208 g_ptr_array_add (argv, "incomplete-printf");
1209 g_ptr_array_add (argv, "--tap");
1210 g_ptr_array_add (argv, NULL);
1212 g_spawn_sync (NULL, (char **) argv->pdata, envp,
1213 G_SPAWN_STDERR_TO_DEV_NULL,
1214 NULL, NULL, &output, NULL, &status,
1216 g_assert_no_error (error);
1218 g_spawn_check_wait_status (status, &error);
1219 g_assert_no_error (error);
1220 g_assert_true (g_str_has_prefix (output, "TAP version " TAP_VERSION));
1221 g_assert_null (strstr (output, "# Subtest: "));
1222 g_assert_nonnull (strstr (output, "\nnot ok 1 /incomplete-printf # TODO telekinesis not implemented yet\n"));
1224 g_ptr_array_unref (argv);
1226 g_test_message ("fail");
1227 argv = g_ptr_array_new ();
1228 g_ptr_array_add (argv, (char *) testing_helper);
1229 g_ptr_array_add (argv, "fail");
1230 g_ptr_array_add (argv, "--tap");
1231 g_ptr_array_add (argv, NULL);
1233 g_spawn_sync (NULL, (char **) argv->pdata, envp,
1234 G_SPAWN_STDERR_TO_DEV_NULL,
1235 NULL, NULL, &output, NULL, &status,
1237 g_assert_no_error (error);
1239 g_spawn_check_wait_status (status, &error);
1240 g_assert_error (error, G_SPAWN_EXIT_ERROR, 1);
1241 g_assert_true (g_str_has_prefix (output, "TAP version " TAP_VERSION));
1242 g_assert_null (strstr (output, "# Subtest: "));
1243 g_assert_nonnull (strstr (output, "\nnot ok 1 /fail\n"));
1245 g_clear_error (&error);
1246 g_ptr_array_unref (argv);
1248 g_test_message ("fail with message");
1249 argv = g_ptr_array_new ();
1250 g_ptr_array_add (argv, (char *) testing_helper);
1251 g_ptr_array_add (argv, "fail-printf");
1252 g_ptr_array_add (argv, "--tap");
1253 g_ptr_array_add (argv, NULL);
1255 g_spawn_sync (NULL, (char **) argv->pdata, envp,
1256 G_SPAWN_STDERR_TO_DEV_NULL,
1257 NULL, NULL, &output, NULL, &status,
1259 g_assert_no_error (error);
1261 g_spawn_check_wait_status (status, &error);
1262 g_assert_error (error, G_SPAWN_EXIT_ERROR, 1);
1263 g_assert_true (g_str_has_prefix (output, "TAP version " TAP_VERSION));
1264 g_assert_null (strstr (output, "# Subtest: "));
1265 g_assert_nonnull (strstr (output, "\nnot ok 1 /fail-printf - this test intentionally left failing\n"));
1267 g_clear_error (&error);
1268 g_ptr_array_unref (argv);
1270 g_test_message ("all");
1271 argv = g_ptr_array_new ();
1272 g_ptr_array_add (argv, (char *) testing_helper);
1273 g_ptr_array_add (argv, "all");
1274 g_ptr_array_add (argv, "--tap");
1275 g_ptr_array_add (argv, NULL);
1277 g_spawn_sync (NULL, (char **) argv->pdata, envp,
1278 G_SPAWN_STDOUT_TO_DEV_NULL | G_SPAWN_STDERR_TO_DEV_NULL,
1279 NULL, NULL, NULL, NULL, &status,
1281 g_assert_no_error (error);
1283 g_spawn_check_wait_status (status, &error);
1284 g_assert_error (error, G_SPAWN_EXIT_ERROR, 1);
1285 g_clear_error (&error);
1286 g_ptr_array_unref (argv);
1288 g_test_message ("all-non-failures");
1289 argv = g_ptr_array_new ();
1290 g_ptr_array_add (argv, (char *) testing_helper);
1291 g_ptr_array_add (argv, "all-non-failures");
1292 g_ptr_array_add (argv, "--tap");
1293 g_ptr_array_add (argv, NULL);
1295 g_spawn_sync (NULL, (char **) argv->pdata, envp,
1296 G_SPAWN_STDOUT_TO_DEV_NULL | G_SPAWN_STDERR_TO_DEV_NULL,
1297 NULL, NULL, NULL, NULL, &status,
1299 g_assert_no_error (error);
1301 g_spawn_check_wait_status (status, &error);
1302 g_assert_no_error (error);
1304 g_ptr_array_unref (argv);
1306 g_test_message ("--GTestSkipCount");
1307 argv = g_ptr_array_new ();
1308 g_ptr_array_add (argv, (char *) testing_helper);
1309 g_ptr_array_add (argv, "skip-options");
1310 g_ptr_array_add (argv, "--tap");
1311 g_ptr_array_add (argv, "--GTestSkipCount");
1312 g_ptr_array_add (argv, "2");
1313 g_ptr_array_add (argv, NULL);
1315 g_spawn_sync (NULL, (char **) argv->pdata, envp,
1316 G_SPAWN_STDERR_TO_DEV_NULL,
1317 NULL, NULL, &output, NULL, &status,
1319 g_assert_no_error (error);
1320 g_assert_true (g_str_has_prefix (output, "TAP version " TAP_VERSION));
1321 g_assert_null (strstr (output, "# Subtest: "));
1322 g_assert_nonnull (strstr (output, "1..10\n"));
1323 g_assert_nonnull (strstr (output, "\nok 1 /a # SKIP\n"));
1324 g_assert_nonnull (strstr (output, "\nok 2 /b # SKIP\n"));
1325 g_assert_nonnull (strstr (output, "\nok 3 /b/a\n"));
1326 g_assert_nonnull (strstr (output, "\nok 4 /b/b\n"));
1327 g_assert_nonnull (strstr (output, "\nok 5 /b/b/a\n"));
1328 g_assert_nonnull (strstr (output, "\nok 6 /prefix/a\n"));
1329 g_assert_nonnull (strstr (output, "\nok 7 /prefix/b/b\n"));
1330 g_assert_nonnull (strstr (output, "\nok 8 /prefix-long/a\n"));
1331 g_assert_nonnull (strstr (output, "\nok 9 /c/a\n"));
1332 g_assert_nonnull (strstr (output, "\nok 10 /d/a\n"));
1334 g_spawn_check_wait_status (status, &error);
1335 g_assert_no_error (error);
1338 g_ptr_array_unref (argv);
1340 g_test_message ("--GTestSkipCount=0 is the same as omitting it");
1341 argv = g_ptr_array_new ();
1342 g_ptr_array_add (argv, (char *) testing_helper);
1343 g_ptr_array_add (argv, "skip-options");
1344 g_ptr_array_add (argv, "--tap");
1345 g_ptr_array_add (argv, "--GTestSkipCount");
1346 g_ptr_array_add (argv, "0");
1347 g_ptr_array_add (argv, NULL);
1349 g_spawn_sync (NULL, (char **) argv->pdata, envp,
1350 G_SPAWN_STDERR_TO_DEV_NULL,
1351 NULL, NULL, &output, NULL, &status,
1353 g_assert_no_error (error);
1354 g_assert_true (g_str_has_prefix (output, "TAP version " TAP_VERSION));
1355 g_assert_null (strstr (output, "# Subtest: "));
1356 g_assert_nonnull (strstr (output, "1..10\n"));
1357 g_assert_nonnull (strstr (output, "\nok 1 /a\n"));
1358 g_assert_nonnull (strstr (output, "\nok 2 /b\n"));
1359 g_assert_nonnull (strstr (output, "\nok 3 /b/a\n"));
1360 g_assert_nonnull (strstr (output, "\nok 4 /b/b\n"));
1361 g_assert_nonnull (strstr (output, "\nok 5 /b/b/a\n"));
1362 g_assert_nonnull (strstr (output, "\nok 6 /prefix/a\n"));
1363 g_assert_nonnull (strstr (output, "\nok 7 /prefix/b/b\n"));
1364 g_assert_nonnull (strstr (output, "\nok 8 /prefix-long/a\n"));
1365 g_assert_nonnull (strstr (output, "\nok 9 /c/a\n"));
1366 g_assert_nonnull (strstr (output, "\nok 10 /d/a\n"));
1368 g_spawn_check_wait_status (status, &error);
1369 g_assert_no_error (error);
1372 g_ptr_array_unref (argv);
1374 g_test_message ("--GTestSkipCount > number of tests skips all");
1375 argv = g_ptr_array_new ();
1376 g_ptr_array_add (argv, (char *) testing_helper);
1377 g_ptr_array_add (argv, "skip-options");
1378 g_ptr_array_add (argv, "--tap");
1379 g_ptr_array_add (argv, "--GTestSkipCount");
1380 g_ptr_array_add (argv, "11");
1381 g_ptr_array_add (argv, NULL);
1383 g_spawn_sync (NULL, (char **) argv->pdata, envp,
1384 G_SPAWN_STDERR_TO_DEV_NULL,
1385 NULL, NULL, &output, NULL, &status,
1387 g_assert_no_error (error);
1388 g_assert_true (g_str_has_prefix (output, "TAP version " TAP_VERSION));
1389 g_assert_null (strstr (output, "# Subtest: "));
1390 g_assert_nonnull (strstr (output, "1..10\n"));
1391 g_assert_nonnull (strstr (output, "\nok 1 /a # SKIP\n"));
1392 g_assert_nonnull (strstr (output, "\nok 2 /b # SKIP\n"));
1393 g_assert_nonnull (strstr (output, "\nok 3 /b/a # SKIP\n"));
1394 g_assert_nonnull (strstr (output, "\nok 4 /b/b # SKIP\n"));
1395 g_assert_nonnull (strstr (output, "\nok 5 /b/b/a # SKIP\n"));
1396 g_assert_nonnull (strstr (output, "\nok 6 /prefix/a # SKIP\n"));
1397 g_assert_nonnull (strstr (output, "\nok 7 /prefix/b/b # SKIP\n"));
1398 g_assert_nonnull (strstr (output, "\nok 8 /prefix-long/a # SKIP\n"));
1399 g_assert_nonnull (strstr (output, "\nok 9 /c/a # SKIP\n"));
1400 g_assert_nonnull (strstr (output, "\nok 10 /d/a # SKIP\n"));
1402 g_spawn_check_wait_status (status, &error);
1403 g_assert_no_error (error);
1406 g_ptr_array_unref (argv);
1408 g_test_message ("-p");
1409 argv = g_ptr_array_new ();
1410 g_ptr_array_add (argv, (char *) testing_helper);
1411 g_ptr_array_add (argv, "skip-options");
1412 g_ptr_array_add (argv, "--tap");
1413 g_ptr_array_add (argv, "-p");
1414 g_ptr_array_add (argv, "/c/a");
1415 g_ptr_array_add (argv, "-p");
1416 g_ptr_array_add (argv, "/c/a");
1417 g_ptr_array_add (argv, "-p");
1418 g_ptr_array_add (argv, "/b");
1419 g_ptr_array_add (argv, NULL);
1421 g_spawn_sync (NULL, (char **) argv->pdata, envp,
1422 G_SPAWN_STDERR_TO_DEV_NULL,
1423 NULL, NULL, &output, NULL, &status,
1425 g_assert_no_error (error);
1426 g_assert_true (g_str_has_prefix (output, "TAP version " TAP_VERSION));
1427 g_assert_null (strstr (output, "# Subtest: "));
1428 g_assert_nonnull (strstr (output, "\nok 1 /c/a\n"));
1429 g_assert_nonnull (strstr (output, "\nok 2 /c/a\n"));
1430 g_assert_nonnull (strstr (output, "\nok 3 /b\n"));
1431 g_assert_nonnull (strstr (output, "\nok 4 /b/a\n"));
1432 g_assert_nonnull (strstr (output, "\nok 5 /b/b\n"));
1433 g_assert_nonnull (strstr (output, "\n1..5\n"));
1435 g_spawn_check_wait_status (status, &error);
1436 g_assert_no_error (error);
1439 g_ptr_array_unref (argv);
1441 g_test_message ("--run-prefix");
1442 argv = g_ptr_array_new ();
1443 g_ptr_array_add (argv, (char *) testing_helper);
1444 g_ptr_array_add (argv, "skip-options");
1445 g_ptr_array_add (argv, "--tap");
1446 g_ptr_array_add (argv, "-r");
1447 g_ptr_array_add (argv, "/c/a");
1448 g_ptr_array_add (argv, "-r");
1449 g_ptr_array_add (argv, "/c/a");
1450 g_ptr_array_add (argv, "--run-prefix");
1451 g_ptr_array_add (argv, "/b");
1452 g_ptr_array_add (argv, NULL);
1454 g_spawn_sync (NULL, (char **) argv->pdata, envp,
1455 G_SPAWN_STDERR_TO_DEV_NULL,
1456 NULL, NULL, &output, NULL, &status,
1458 g_assert_no_error (error);
1459 g_assert_true (g_str_has_prefix (output, "TAP version " TAP_VERSION));
1460 g_assert_null (strstr (output, "# Subtest: "));
1461 g_assert_nonnull (strstr (output, "\nok 1 /c/a\n"));
1462 g_assert_nonnull (strstr (output, "\nok 2 /c/a\n"));
1463 g_assert_nonnull (strstr (output, "\nok 3 /b\n"));
1464 g_assert_nonnull (strstr (output, "\nok 4 /b/a\n"));
1465 g_assert_nonnull (strstr (output, "\nok 5 /b/b\n"));
1466 g_assert_nonnull (strstr (output, "\nok 6 /b/b/a\n"));
1467 g_assert_nonnull (strstr (output, "\n1..6\n"));
1469 g_spawn_check_wait_status (status, &error);
1470 g_assert_no_error (error);
1473 g_ptr_array_unref (argv);
1475 g_test_message ("--run-prefix 2");
1476 argv = g_ptr_array_new ();
1477 g_ptr_array_add (argv, (char *) testing_helper);
1478 g_ptr_array_add (argv, "skip-options");
1479 g_ptr_array_add (argv, "--tap");
1480 g_ptr_array_add (argv, "-r");
1481 g_ptr_array_add (argv, "/pre");
1482 g_ptr_array_add (argv, "--run-prefix");
1483 g_ptr_array_add (argv, "/b/b");
1484 g_ptr_array_add (argv, NULL);
1486 g_spawn_sync (NULL, (char **) argv->pdata, envp,
1487 G_SPAWN_STDERR_TO_DEV_NULL,
1488 NULL, NULL, &output, NULL, &status,
1490 g_assert_no_error (error);
1491 g_assert_true (g_str_has_prefix (output, "TAP version " TAP_VERSION));
1492 g_assert_null (strstr (output, "# Subtest: "));
1493 g_assert_nonnull (strstr (output, "\nok 1 /b/b\n"));
1494 g_assert_nonnull (strstr (output, "\nok 2 /b/b/a\n"));
1495 g_assert_nonnull (strstr (output, "\n1..2\n"));
1497 g_spawn_check_wait_status (status, &error);
1498 g_assert_no_error (error);
1501 g_ptr_array_unref (argv);
1503 g_test_message ("--run-prefix conflict");
1504 argv = g_ptr_array_new ();
1505 g_ptr_array_add (argv, (char *) testing_helper);
1506 g_ptr_array_add (argv, "skip-options");
1507 g_ptr_array_add (argv, "--tap");
1508 g_ptr_array_add (argv, "-r");
1509 g_ptr_array_add (argv, "/c/a");
1510 g_ptr_array_add (argv, "-p");
1511 g_ptr_array_add (argv, "/c/a");
1512 g_ptr_array_add (argv, "--run-prefix");
1513 g_ptr_array_add (argv, "/b");
1514 g_ptr_array_add (argv, NULL);
1516 g_spawn_sync (NULL, (char **) argv->pdata, envp,
1517 G_SPAWN_STDERR_TO_DEV_NULL,
1518 NULL, NULL, &output, NULL, &status,
1520 g_assert_no_error (error);
1521 g_spawn_check_wait_status (status, &error);
1522 g_assert_nonnull (error);
1523 g_assert_false (g_str_has_prefix (output, "TAP version " TAP_VERSION));
1524 g_assert_nonnull (strstr (output, "do not mix [-r | --run-prefix] with '-p'\n"));
1525 g_clear_error (&error);
1528 g_ptr_array_unref (argv);
1530 g_test_message ("-s");
1531 argv = g_ptr_array_new ();
1532 g_ptr_array_add (argv, (char *) testing_helper);
1533 g_ptr_array_add (argv, "skip-options");
1534 g_ptr_array_add (argv, "--tap");
1535 g_ptr_array_add (argv, "-s");
1536 g_ptr_array_add (argv, "/a");
1537 g_ptr_array_add (argv, "-s");
1538 g_ptr_array_add (argv, "/b");
1539 g_ptr_array_add (argv, "-s");
1540 g_ptr_array_add (argv, "/pre");
1541 g_ptr_array_add (argv, "-s");
1542 g_ptr_array_add (argv, "/c/a");
1543 g_ptr_array_add (argv, NULL);
1545 g_spawn_sync (NULL, (char **) argv->pdata, envp,
1546 G_SPAWN_STDERR_TO_DEV_NULL,
1547 NULL, NULL, &output, NULL, &status,
1549 g_assert_no_error (error);
1550 g_assert_true (g_str_has_prefix (output, "TAP version " TAP_VERSION));
1551 g_assert_null (strstr (output, "# Subtest: "));
1552 g_assert_nonnull (strstr (output, "1..10\n"));
1553 g_assert_nonnull (strstr (output, "\nok 1 /a # SKIP by request"));
1554 g_assert_nonnull (strstr (output, "\nok 2 /b # SKIP by request"));
1555 /* "-s /b" would skip a test named exactly /b, but not a test named
1557 g_assert_nonnull (strstr (output, "\nok 3 /b/a\n"));
1558 g_assert_nonnull (strstr (output, "\nok 4 /b/b\n"));
1559 g_assert_nonnull (strstr (output, "\nok 5 /b/b/a\n"));
1560 g_assert_nonnull (strstr (output, "\nok 6 /prefix/a\n"));
1561 g_assert_nonnull (strstr (output, "\nok 7 /prefix/b/b\n"));
1562 g_assert_nonnull (strstr (output, "\nok 8 /prefix-long/a\n"));
1563 g_assert_nonnull (strstr (output, "\nok 9 /c/a # SKIP by request"));
1564 g_assert_nonnull (strstr (output, "\nok 10 /d/a\n"));
1566 g_spawn_check_wait_status (status, &error);
1567 g_assert_no_error (error);
1570 g_ptr_array_unref (argv);
1572 g_test_message ("--skip-prefix");
1573 argv = g_ptr_array_new ();
1574 g_ptr_array_add (argv, (char *) testing_helper);
1575 g_ptr_array_add (argv, "skip-options");
1576 g_ptr_array_add (argv, "--tap");
1577 g_ptr_array_add (argv, "-x");
1578 g_ptr_array_add (argv, "/a");
1579 g_ptr_array_add (argv, "--skip-prefix");
1580 g_ptr_array_add (argv, "/pre");
1581 g_ptr_array_add (argv, "-x");
1582 g_ptr_array_add (argv, "/c/a");
1583 g_ptr_array_add (argv, NULL);
1585 g_spawn_sync (NULL, (char **) argv->pdata, envp,
1586 G_SPAWN_STDERR_TO_DEV_NULL,
1587 NULL, NULL, &output, NULL, &status,
1589 g_assert_no_error (error);
1590 g_assert_true (g_str_has_prefix (output, "TAP version " TAP_VERSION));
1591 g_assert_null (strstr (output, "# Subtest: "));
1592 g_assert_nonnull (strstr (output, "1..10\n"));
1593 g_assert_nonnull (strstr (output, "\nok 1 /a # SKIP by request"));
1594 g_assert_nonnull (strstr (output, "\nok 2 /b\n"));
1595 g_assert_nonnull (strstr (output, "\nok 3 /b/a\n"));
1596 g_assert_nonnull (strstr (output, "\nok 4 /b/b\n"));
1597 g_assert_nonnull (strstr (output, "\nok 5 /b/b/a\n"));
1598 /* "--skip-prefix /pre" will skip all test path which begins with /pre */
1599 g_assert_nonnull (strstr (output, "\nok 6 /prefix/a # SKIP by request"));
1600 g_assert_nonnull (strstr (output, "\nok 7 /prefix/b/b # SKIP by request"));
1601 g_assert_nonnull (strstr (output, "\nok 8 /prefix-long/a # SKIP by request"));
1602 g_assert_nonnull (strstr (output, "\nok 9 /c/a # SKIP by request"));
1603 g_assert_nonnull (strstr (output, "\nok 10 /d/a\n"));
1605 g_spawn_check_wait_status (status, &error);
1606 g_assert_no_error (error);
1609 g_ptr_array_unref (argv);
1611 g_test_message ("--skip-prefix conflict");
1612 argv = g_ptr_array_new ();
1613 g_ptr_array_add (argv, (char *) testing_helper);
1614 g_ptr_array_add (argv, "skip-options");
1615 g_ptr_array_add (argv, "--tap");
1616 g_ptr_array_add (argv, "-s");
1617 g_ptr_array_add (argv, "/a");
1618 g_ptr_array_add (argv, "--skip-prefix");
1619 g_ptr_array_add (argv, "/pre");
1620 g_ptr_array_add (argv, "-x");
1621 g_ptr_array_add (argv, "/c/a");
1622 g_ptr_array_add (argv, NULL);
1624 g_spawn_sync (NULL, (char **) argv->pdata, envp,
1625 G_SPAWN_STDERR_TO_DEV_NULL,
1626 NULL, NULL, &output, NULL, &status,
1628 g_assert_no_error (error);
1629 g_spawn_check_wait_status (status, &error);
1630 g_assert_nonnull (error);
1631 g_assert_false (g_str_has_prefix (output, "TAP version " TAP_VERSION));
1632 g_assert_nonnull (strstr (output, "do not mix [-x | --skip-prefix] with '-s'\n"));
1633 g_clear_error (&error);
1636 g_ptr_array_unref (argv);
1640 /* Test the TAP output when a test suite is run with --tap. */
1642 test_tap_subtest (void)
1644 const char *testing_helper;
1646 GError *error = NULL;
1651 testing_helper = g_test_get_filename (G_TEST_BUILT, "testing-helper" EXEEXT, NULL);
1653 g_test_message ("pass");
1654 argv = g_ptr_array_new ();
1655 g_ptr_array_add (argv, (char *) testing_helper);
1656 g_ptr_array_add (argv, "pass");
1657 g_ptr_array_add (argv, "--tap");
1658 g_ptr_array_add (argv, NULL);
1660 envp = g_get_environ ();
1661 g_assert_nonnull (g_environ_getenv (envp, "G_TEST_ROOT_PROCESS"));
1662 g_clear_pointer (&envp, g_strfreev);
1664 g_spawn_sync (NULL, (char **) argv->pdata, envp,
1665 G_SPAWN_STDERR_TO_DEV_NULL,
1666 NULL, NULL, &output, NULL, &status,
1668 g_assert_no_error (error);
1670 g_spawn_check_wait_status (status, &error);
1671 g_assert_no_error (error);
1672 g_assert_null (strstr (output, "TAP version " TAP_VERSION));
1673 g_assert_true (g_str_has_prefix (output, "# Subtest: "));
1674 g_assert_nonnull (strstr (output,
1675 "\n" TAP_SUBTEST_PREFIX "ok 1 /pass\n"));
1677 g_ptr_array_unref (argv);
1679 g_test_message ("skip");
1680 argv = g_ptr_array_new ();
1681 g_ptr_array_add (argv, (char *) testing_helper);
1682 g_ptr_array_add (argv, "skip");
1683 g_ptr_array_add (argv, "--tap");
1684 g_ptr_array_add (argv, NULL);
1686 g_spawn_sync (NULL, (char **) argv->pdata, envp,
1687 G_SPAWN_STDERR_TO_DEV_NULL,
1688 NULL, NULL, &output, NULL, &status,
1690 g_assert_no_error (error);
1692 g_spawn_check_wait_status (status, &error);
1693 g_assert_no_error (error);
1694 g_assert_null (strstr (output, "TAP version " TAP_VERSION));
1695 g_assert_true (g_str_has_prefix (output, "# Subtest: "));
1696 g_assert_nonnull (strstr (output,
1697 "\n" TAP_SUBTEST_PREFIX "ok 1 /skip # SKIP not enough tea\n"));
1699 g_ptr_array_unref (argv);
1701 g_test_message ("skip with printf format");
1702 argv = g_ptr_array_new ();
1703 g_ptr_array_add (argv, (char *) testing_helper);
1704 g_ptr_array_add (argv, "skip-printf");
1705 g_ptr_array_add (argv, "--tap");
1706 g_ptr_array_add (argv, NULL);
1708 g_spawn_sync (NULL, (char **) argv->pdata, envp,
1709 G_SPAWN_STDERR_TO_DEV_NULL,
1710 NULL, NULL, &output, NULL, &status,
1712 g_assert_no_error (error);
1714 g_spawn_check_wait_status (status, &error);
1715 g_assert_no_error (error);
1716 g_assert_null (strstr (output, "TAP version " TAP_VERSION));
1717 g_assert_true (g_str_has_prefix (output, "# Subtest: "));
1718 g_assert_nonnull (strstr (output,
1719 "\n" TAP_SUBTEST_PREFIX "ok 1 /skip-printf # SKIP not enough coffee\n"));
1721 g_ptr_array_unref (argv);
1723 g_test_message ("incomplete");
1724 argv = g_ptr_array_new ();
1725 g_ptr_array_add (argv, (char *) testing_helper);
1726 g_ptr_array_add (argv, "incomplete");
1727 g_ptr_array_add (argv, "--tap");
1728 g_ptr_array_add (argv, NULL);
1730 g_spawn_sync (NULL, (char **) argv->pdata, envp,
1731 G_SPAWN_STDERR_TO_DEV_NULL,
1732 NULL, NULL, &output, NULL, &status,
1734 g_assert_no_error (error);
1736 g_spawn_check_wait_status (status, &error);
1737 g_assert_no_error (error);
1738 g_assert_null (strstr (output, "TAP version " TAP_VERSION));
1739 g_assert_null (strstr (output, "\n# Subtest: "));
1740 g_assert_nonnull (strstr (output,
1741 "\n" TAP_SUBTEST_PREFIX "not ok 1 /incomplete # TODO mind reading not implemented yet\n"));
1743 g_ptr_array_unref (argv);
1745 g_test_message ("incomplete with printf format");
1746 argv = g_ptr_array_new ();
1747 g_ptr_array_add (argv, (char *) testing_helper);
1748 g_ptr_array_add (argv, "incomplete-printf");
1749 g_ptr_array_add (argv, "--tap");
1750 g_ptr_array_add (argv, NULL);
1752 g_spawn_sync (NULL, (char **) argv->pdata, envp,
1753 G_SPAWN_STDERR_TO_DEV_NULL,
1754 NULL, NULL, &output, NULL, &status,
1756 g_assert_no_error (error);
1758 g_spawn_check_wait_status (status, &error);
1759 g_assert_no_error (error);
1760 g_assert_null (strstr (output, "TAP version " TAP_VERSION));
1761 g_assert_null( strstr (output, "\n# Subtest: "));
1762 g_assert_nonnull (strstr (output,
1763 "\n" TAP_SUBTEST_PREFIX "not ok 1 /incomplete-printf # TODO telekinesis not implemented yet\n"));
1765 g_ptr_array_unref (argv);
1767 g_test_message ("fail");
1768 argv = g_ptr_array_new ();
1769 g_ptr_array_add (argv, (char *) testing_helper);
1770 g_ptr_array_add (argv, "fail");
1771 g_ptr_array_add (argv, "--tap");
1772 g_ptr_array_add (argv, NULL);
1774 g_spawn_sync (NULL, (char **) argv->pdata, envp,
1775 G_SPAWN_STDERR_TO_DEV_NULL,
1776 NULL, NULL, &output, NULL, &status,
1778 g_assert_no_error (error);
1780 g_spawn_check_wait_status (status, &error);
1781 g_assert_error (error, G_SPAWN_EXIT_ERROR, 1);
1782 g_assert_null (strstr (output, "TAP version " TAP_VERSION));
1783 g_assert_null( strstr (output, "\n# Subtest: "));
1784 g_assert_nonnull (strstr (output,
1785 "\n" TAP_SUBTEST_PREFIX "not ok 1 /fail\n"));
1787 g_clear_error (&error);
1788 g_ptr_array_unref (argv);
1790 g_test_message ("fail with message");
1791 argv = g_ptr_array_new ();
1792 g_ptr_array_add (argv, (char *) testing_helper);
1793 g_ptr_array_add (argv, "fail-printf");
1794 g_ptr_array_add (argv, "--tap");
1795 g_ptr_array_add (argv, NULL);
1797 g_spawn_sync (NULL, (char **) argv->pdata, envp,
1798 G_SPAWN_STDERR_TO_DEV_NULL,
1799 NULL, NULL, &output, NULL, &status,
1801 g_assert_no_error (error);
1803 g_spawn_check_wait_status (status, &error);
1804 g_assert_error (error, G_SPAWN_EXIT_ERROR, 1);
1805 g_assert_null (strstr (output, "TAP version " TAP_VERSION));
1806 g_assert_null( strstr (output, "\n# Subtest: "));
1807 g_assert_nonnull (strstr (output,
1808 "\n" TAP_SUBTEST_PREFIX "not ok 1 /fail-printf - this test intentionally left failing\n"));
1810 g_clear_error (&error);
1811 g_ptr_array_unref (argv);
1813 g_test_message ("all");
1814 argv = g_ptr_array_new ();
1815 g_ptr_array_add (argv, (char *) testing_helper);
1816 g_ptr_array_add (argv, "all");
1817 g_ptr_array_add (argv, "--tap");
1818 g_ptr_array_add (argv, NULL);
1820 g_spawn_sync (NULL, (char **) argv->pdata, envp,
1821 G_SPAWN_STDOUT_TO_DEV_NULL | G_SPAWN_STDERR_TO_DEV_NULL,
1822 NULL, NULL, NULL, NULL, &status,
1824 g_assert_no_error (error);
1826 g_spawn_check_wait_status (status, &error);
1827 g_assert_error (error, G_SPAWN_EXIT_ERROR, 1);
1828 g_clear_error (&error);
1829 g_ptr_array_unref (argv);
1831 g_test_message ("all-non-failures");
1832 argv = g_ptr_array_new ();
1833 g_ptr_array_add (argv, (char *) testing_helper);
1834 g_ptr_array_add (argv, "all-non-failures");
1835 g_ptr_array_add (argv, "--tap");
1836 g_ptr_array_add (argv, NULL);
1838 g_spawn_sync (NULL, (char **) argv->pdata, envp,
1839 G_SPAWN_STDOUT_TO_DEV_NULL | G_SPAWN_STDERR_TO_DEV_NULL,
1840 NULL, NULL, NULL, NULL, &status,
1842 g_assert_no_error (error);
1844 g_spawn_check_wait_status (status, &error);
1845 g_assert_no_error (error);
1847 g_ptr_array_unref (argv);
1849 g_test_message ("--GTestSkipCount");
1850 argv = g_ptr_array_new ();
1851 g_ptr_array_add (argv, (char *) testing_helper);
1852 g_ptr_array_add (argv, "skip-options");
1853 g_ptr_array_add (argv, "--tap");
1854 g_ptr_array_add (argv, "--GTestSkipCount");
1855 g_ptr_array_add (argv, "2");
1856 g_ptr_array_add (argv, NULL);
1858 g_spawn_sync (NULL, (char **) argv->pdata, envp,
1859 G_SPAWN_STDERR_TO_DEV_NULL,
1860 NULL, NULL, &output, NULL, &status,
1862 g_assert_no_error (error);
1863 g_assert_null (strstr (output, "TAP version " TAP_VERSION));
1864 g_assert_null( strstr (output, "\n# Subtest: "));
1865 g_assert_nonnull (strstr (output, TAP_SUBTEST_PREFIX "1..10\n"));
1866 g_assert_nonnull (strstr (output,
1867 "\n" TAP_SUBTEST_PREFIX "ok 1 /a # SKIP\n"));
1868 g_assert_nonnull (strstr (output,
1869 "\n" TAP_SUBTEST_PREFIX "ok 2 /b # SKIP\n"));
1870 g_assert_nonnull (strstr (output,
1871 "\n" TAP_SUBTEST_PREFIX "ok 3 /b/a\n"));
1872 g_assert_nonnull (strstr (output,
1873 "\n" TAP_SUBTEST_PREFIX "ok 4 /b/b\n"));
1874 g_assert_nonnull (strstr (output,
1875 "\n" TAP_SUBTEST_PREFIX "ok 5 /b/b/a\n"));
1876 g_assert_nonnull (strstr (output,
1877 "\n" TAP_SUBTEST_PREFIX "ok 6 /prefix/a\n"));
1878 g_assert_nonnull (strstr (output,
1879 "\n" TAP_SUBTEST_PREFIX "ok 7 /prefix/b/b\n"));
1880 g_assert_nonnull (strstr (output,
1881 "\n" TAP_SUBTEST_PREFIX "ok 8 /prefix-long/a\n"));
1882 g_assert_nonnull (strstr (output,
1883 "\n" TAP_SUBTEST_PREFIX "ok 9 /c/a\n"));
1884 g_assert_nonnull (strstr (output,
1885 "\n" TAP_SUBTEST_PREFIX "ok 10 /d/a\n"));
1887 g_spawn_check_wait_status (status, &error);
1888 g_assert_no_error (error);
1891 g_ptr_array_unref (argv);
1893 g_test_message ("--GTestSkipCount=0 is the same as omitting it");
1894 argv = g_ptr_array_new ();
1895 g_ptr_array_add (argv, (char *) testing_helper);
1896 g_ptr_array_add (argv, "skip-options");
1897 g_ptr_array_add (argv, "--tap");
1898 g_ptr_array_add (argv, "--GTestSkipCount");
1899 g_ptr_array_add (argv, "0");
1900 g_ptr_array_add (argv, NULL);
1902 g_spawn_sync (NULL, (char **) argv->pdata, envp,
1903 G_SPAWN_STDERR_TO_DEV_NULL,
1904 NULL, NULL, &output, NULL, &status,
1906 g_assert_no_error (error);
1907 g_assert_null (strstr (output, "TAP version " TAP_VERSION));
1908 g_assert_null( strstr (output, "\n# Subtest: "));
1909 g_assert_nonnull (strstr (output, TAP_SUBTEST_PREFIX "1..10\n"));
1910 g_assert_nonnull (strstr (output,
1911 "\n" TAP_SUBTEST_PREFIX "ok 1 /a\n"));
1912 g_assert_nonnull (strstr (output,
1913 "\n" TAP_SUBTEST_PREFIX "ok 2 /b\n"));
1914 g_assert_nonnull (strstr (output,
1915 "\n" TAP_SUBTEST_PREFIX "ok 3 /b/a\n"));
1916 g_assert_nonnull (strstr (output,
1917 "\n" TAP_SUBTEST_PREFIX "ok 4 /b/b\n"));
1918 g_assert_nonnull (strstr (output,
1919 "\n" TAP_SUBTEST_PREFIX "ok 5 /b/b/a\n"));
1920 g_assert_nonnull (strstr (output,
1921 "\n" TAP_SUBTEST_PREFIX "ok 6 /prefix/a\n"));
1922 g_assert_nonnull (strstr (output,
1923 "\n" TAP_SUBTEST_PREFIX "ok 7 /prefix/b/b\n"));
1924 g_assert_nonnull (strstr (output,
1925 "\n" TAP_SUBTEST_PREFIX "ok 8 /prefix-long/a\n"));
1926 g_assert_nonnull (strstr (output,
1927 "\n" TAP_SUBTEST_PREFIX "ok 9 /c/a\n"));
1928 g_assert_nonnull (strstr (output,
1929 "\n" TAP_SUBTEST_PREFIX "ok 10 /d/a\n"));
1931 g_spawn_check_wait_status (status, &error);
1932 g_assert_no_error (error);
1935 g_ptr_array_unref (argv);
1937 g_test_message ("--GTestSkipCount > number of tests skips all");
1938 argv = g_ptr_array_new ();
1939 g_ptr_array_add (argv, (char *) testing_helper);
1940 g_ptr_array_add (argv, "skip-options");
1941 g_ptr_array_add (argv, "--tap");
1942 g_ptr_array_add (argv, "--GTestSkipCount");
1943 g_ptr_array_add (argv, "11");
1944 g_ptr_array_add (argv, NULL);
1946 g_spawn_sync (NULL, (char **) argv->pdata, envp,
1947 G_SPAWN_STDERR_TO_DEV_NULL,
1948 NULL, NULL, &output, NULL, &status,
1950 g_assert_no_error (error);
1951 g_assert_null (strstr (output, "TAP version " TAP_VERSION));
1952 g_assert_null( strstr (output, "\n# Subtest: "));
1953 g_assert_nonnull (strstr (output, TAP_SUBTEST_PREFIX "1..10\n"));
1954 g_assert_nonnull (strstr (output,
1955 "\n" TAP_SUBTEST_PREFIX "ok 1 /a # SKIP\n"));
1956 g_assert_nonnull (strstr (output,
1957 "\n" TAP_SUBTEST_PREFIX "ok 2 /b # SKIP\n"));
1958 g_assert_nonnull (strstr (output,
1959 "\n" TAP_SUBTEST_PREFIX "ok 3 /b/a # SKIP\n"));
1960 g_assert_nonnull (strstr (output,
1961 "\n" TAP_SUBTEST_PREFIX "ok 4 /b/b # SKIP\n"));
1962 g_assert_nonnull (strstr (output,
1963 "\n" TAP_SUBTEST_PREFIX "ok 5 /b/b/a # SKIP\n"));
1964 g_assert_nonnull (strstr (output,
1965 "\n" TAP_SUBTEST_PREFIX "ok 6 /prefix/a # SKIP\n"));
1966 g_assert_nonnull (strstr (output,
1967 "\n" TAP_SUBTEST_PREFIX "ok 7 /prefix/b/b # SKIP\n"));
1968 g_assert_nonnull (strstr (output,
1969 "\n" TAP_SUBTEST_PREFIX "ok 8 /prefix-long/a # SKIP\n"));
1970 g_assert_nonnull (strstr (output,
1971 "\n" TAP_SUBTEST_PREFIX "ok 9 /c/a # SKIP\n"));
1972 g_assert_nonnull (strstr (output,
1973 "\n" TAP_SUBTEST_PREFIX "ok 10 /d/a # SKIP\n"));
1975 g_spawn_check_wait_status (status, &error);
1976 g_assert_no_error (error);
1979 g_ptr_array_unref (argv);
1981 g_test_message ("-p");
1982 argv = g_ptr_array_new ();
1983 g_ptr_array_add (argv, (char *) testing_helper);
1984 g_ptr_array_add (argv, "skip-options");
1985 g_ptr_array_add (argv, "--tap");
1986 g_ptr_array_add (argv, "-p");
1987 g_ptr_array_add (argv, "/c/a");
1988 g_ptr_array_add (argv, "-p");
1989 g_ptr_array_add (argv, "/c/a");
1990 g_ptr_array_add (argv, "-p");
1991 g_ptr_array_add (argv, "/b");
1992 g_ptr_array_add (argv, NULL);
1994 g_spawn_sync (NULL, (char **) argv->pdata, envp,
1995 G_SPAWN_STDERR_TO_DEV_NULL,
1996 NULL, NULL, &output, NULL, &status,
1998 g_assert_no_error (error);
1999 g_assert_null (strstr (output, "TAP version " TAP_VERSION));
2000 g_assert_null( strstr (output, "\n# Subtest: "));
2001 g_assert_nonnull (strstr (output,
2002 "\n" TAP_SUBTEST_PREFIX "ok 1 /c/a\n"));
2003 g_assert_nonnull (strstr (output,
2004 "\n" TAP_SUBTEST_PREFIX "ok 2 /c/a\n"));
2005 g_assert_nonnull (strstr (output,
2006 "\n" TAP_SUBTEST_PREFIX "ok 3 /b\n"));
2007 g_assert_nonnull (strstr (output,
2008 "\n" TAP_SUBTEST_PREFIX "ok 4 /b/a\n"));
2009 g_assert_nonnull (strstr (output,
2010 "\n" TAP_SUBTEST_PREFIX "ok 5 /b/b\n"));
2011 g_assert_nonnull (strstr (output,
2012 "\n" TAP_SUBTEST_PREFIX "1..5\n"));
2014 g_spawn_check_wait_status (status, &error);
2015 g_assert_no_error (error);
2018 g_ptr_array_unref (argv);
2020 g_test_message ("--run-prefix");
2021 argv = g_ptr_array_new ();
2022 g_ptr_array_add (argv, (char *) testing_helper);
2023 g_ptr_array_add (argv, "skip-options");
2024 g_ptr_array_add (argv, "--tap");
2025 g_ptr_array_add (argv, "-r");
2026 g_ptr_array_add (argv, "/c/a");
2027 g_ptr_array_add (argv, "-r");
2028 g_ptr_array_add (argv, "/c/a");
2029 g_ptr_array_add (argv, "--run-prefix");
2030 g_ptr_array_add (argv, "/b");
2031 g_ptr_array_add (argv, NULL);
2033 g_spawn_sync (NULL, (char **) argv->pdata, envp,
2034 G_SPAWN_STDERR_TO_DEV_NULL,
2035 NULL, NULL, &output, NULL, &status,
2037 g_assert_no_error (error);
2038 g_assert_null (strstr (output, "TAP version " TAP_VERSION));
2039 g_assert_null( strstr (output, "\n# Subtest: "));
2040 g_assert_nonnull (strstr (output,
2041 "\n" TAP_SUBTEST_PREFIX "ok 1 /c/a\n"));
2042 g_assert_nonnull (strstr (output,
2043 "\n" TAP_SUBTEST_PREFIX "ok 2 /c/a\n"));
2044 g_assert_nonnull (strstr (output,
2045 "\n" TAP_SUBTEST_PREFIX "ok 3 /b\n"));
2046 g_assert_nonnull (strstr (output,
2047 "\n" TAP_SUBTEST_PREFIX "ok 4 /b/a\n"));
2048 g_assert_nonnull (strstr (output,
2049 "\n" TAP_SUBTEST_PREFIX "ok 5 /b/b\n"));
2050 g_assert_nonnull (strstr (output,
2051 "\n" TAP_SUBTEST_PREFIX "ok 6 /b/b/a\n"));
2052 g_assert_nonnull (strstr (output,
2053 "\n" TAP_SUBTEST_PREFIX "1..6\n"));
2055 g_spawn_check_wait_status (status, &error);
2056 g_assert_no_error (error);
2059 g_ptr_array_unref (argv);
2061 g_test_message ("--run-prefix 2");
2062 argv = g_ptr_array_new ();
2063 g_ptr_array_add (argv, (char *) testing_helper);
2064 g_ptr_array_add (argv, "skip-options");
2065 g_ptr_array_add (argv, "--tap");
2066 g_ptr_array_add (argv, "-r");
2067 g_ptr_array_add (argv, "/pre");
2068 g_ptr_array_add (argv, "--run-prefix");
2069 g_ptr_array_add (argv, "/b/b");
2070 g_ptr_array_add (argv, NULL);
2072 g_spawn_sync (NULL, (char **) argv->pdata, envp,
2073 G_SPAWN_STDERR_TO_DEV_NULL,
2074 NULL, NULL, &output, NULL, &status,
2076 g_assert_no_error (error);
2077 g_assert_null (strstr (output, "TAP version " TAP_VERSION));
2078 g_assert_null( strstr (output, "\n# Subtest: "));
2079 g_assert_nonnull (strstr (output,
2080 "\n" TAP_SUBTEST_PREFIX "ok 1 /b/b\n"));
2081 g_assert_nonnull (strstr (output,
2082 "\n" TAP_SUBTEST_PREFIX "ok 2 /b/b/a\n"));
2083 g_assert_nonnull (strstr (output,
2084 "\n" TAP_SUBTEST_PREFIX "1..2\n"));
2086 g_spawn_check_wait_status (status, &error);
2087 g_assert_no_error (error);
2090 g_ptr_array_unref (argv);
2092 g_test_message ("--run-prefix conflict");
2093 argv = g_ptr_array_new ();
2094 g_ptr_array_add (argv, (char *) testing_helper);
2095 g_ptr_array_add (argv, "skip-options");
2096 g_ptr_array_add (argv, "--tap");
2097 g_ptr_array_add (argv, "-r");
2098 g_ptr_array_add (argv, "/c/a");
2099 g_ptr_array_add (argv, "-p");
2100 g_ptr_array_add (argv, "/c/a");
2101 g_ptr_array_add (argv, "--run-prefix");
2102 g_ptr_array_add (argv, "/b");
2103 g_ptr_array_add (argv, NULL);
2105 g_spawn_sync (NULL, (char **) argv->pdata, envp,
2106 G_SPAWN_STDERR_TO_DEV_NULL,
2107 NULL, NULL, &output, NULL, &status,
2109 g_assert_no_error (error);
2110 g_spawn_check_wait_status (status, &error);
2111 g_assert_nonnull (error);
2112 g_assert_null (strstr (output, "TAP version " TAP_VERSION));
2113 g_assert_null( strstr (output, "\n# Subtest: "));
2114 g_assert_nonnull (strstr (output, "do not mix [-r | --run-prefix] with '-p'\n"));
2115 g_clear_error (&error);
2118 g_ptr_array_unref (argv);
2120 g_test_message ("-s");
2121 argv = g_ptr_array_new ();
2122 g_ptr_array_add (argv, (char *) testing_helper);
2123 g_ptr_array_add (argv, "skip-options");
2124 g_ptr_array_add (argv, "--tap");
2125 g_ptr_array_add (argv, "-s");
2126 g_ptr_array_add (argv, "/a");
2127 g_ptr_array_add (argv, "-s");
2128 g_ptr_array_add (argv, "/b");
2129 g_ptr_array_add (argv, "-s");
2130 g_ptr_array_add (argv, "/pre");
2131 g_ptr_array_add (argv, "-s");
2132 g_ptr_array_add (argv, "/c/a");
2133 g_ptr_array_add (argv, NULL);
2135 g_spawn_sync (NULL, (char **) argv->pdata, envp,
2136 G_SPAWN_STDERR_TO_DEV_NULL,
2137 NULL, NULL, &output, NULL, &status,
2139 g_assert_no_error (error);
2140 g_assert_null (strstr (output, "TAP version " TAP_VERSION));
2141 g_assert_null( strstr (output, "\n# Subtest: "));
2142 g_assert_nonnull (strstr (output, TAP_SUBTEST_PREFIX "1..10\n"));
2143 g_assert_nonnull (strstr (output,
2144 "\n" TAP_SUBTEST_PREFIX "ok 1 /a # SKIP by request"));
2145 g_assert_nonnull (strstr (output,
2146 "\n" TAP_SUBTEST_PREFIX "ok 2 /b # SKIP by request"));
2147 /* "-s /b" would skip a test named exactly /b, but not a test named
2149 g_assert_nonnull (strstr (output,
2150 "\n" TAP_SUBTEST_PREFIX "ok 3 /b/a\n"));
2151 g_assert_nonnull (strstr (output,
2152 "\n" TAP_SUBTEST_PREFIX "ok 4 /b/b\n"));
2153 g_assert_nonnull (strstr (output,
2154 "\n" TAP_SUBTEST_PREFIX "ok 5 /b/b/a\n"));
2155 g_assert_nonnull (strstr (output,
2156 "\n" TAP_SUBTEST_PREFIX "ok 6 /prefix/a\n"));
2157 g_assert_nonnull (strstr (output,
2158 "\n" TAP_SUBTEST_PREFIX "ok 7 /prefix/b/b\n"));
2159 g_assert_nonnull (strstr (output,
2160 "\n" TAP_SUBTEST_PREFIX "ok 8 /prefix-long/a\n"));
2161 g_assert_nonnull (strstr (output,
2162 "\n" TAP_SUBTEST_PREFIX "ok 9 /c/a # SKIP by request"));
2163 g_assert_nonnull (strstr (output,
2164 "\n" TAP_SUBTEST_PREFIX "ok 10 /d/a\n"));
2166 g_spawn_check_wait_status (status, &error);
2167 g_assert_no_error (error);
2170 g_ptr_array_unref (argv);
2172 g_test_message ("--skip-prefix");
2173 argv = g_ptr_array_new ();
2174 g_ptr_array_add (argv, (char *) testing_helper);
2175 g_ptr_array_add (argv, "skip-options");
2176 g_ptr_array_add (argv, "--tap");
2177 g_ptr_array_add (argv, "-x");
2178 g_ptr_array_add (argv, "/a");
2179 g_ptr_array_add (argv, "--skip-prefix");
2180 g_ptr_array_add (argv, "/pre");
2181 g_ptr_array_add (argv, "-x");
2182 g_ptr_array_add (argv, "/c/a");
2183 g_ptr_array_add (argv, NULL);
2185 g_spawn_sync (NULL, (char **) argv->pdata, envp,
2186 G_SPAWN_STDERR_TO_DEV_NULL,
2187 NULL, NULL, &output, NULL, &status,
2189 g_assert_no_error (error);
2190 g_assert_null (strstr (output, "TAP version " TAP_VERSION));
2191 g_assert_true (g_str_has_prefix (output, "# Subtest: "));
2192 g_assert_nonnull (strstr (output, TAP_SUBTEST_PREFIX "1..10\n"));
2193 g_assert_nonnull (strstr (output,
2194 "\n" TAP_SUBTEST_PREFIX "ok 1 /a # SKIP by request"));
2195 g_assert_nonnull (strstr (output,
2196 "\n" TAP_SUBTEST_PREFIX "ok 2 /b\n"));
2197 g_assert_nonnull (strstr (output,
2198 "\n" TAP_SUBTEST_PREFIX "ok 3 /b/a\n"));
2199 g_assert_nonnull (strstr (output,
2200 "\n" TAP_SUBTEST_PREFIX "ok 4 /b/b\n"));
2201 g_assert_nonnull (strstr (output,
2202 "\n" TAP_SUBTEST_PREFIX "ok 5 /b/b/a\n"));
2203 /* "--skip-prefix /pre" will skip all test path which begins with /pre */
2204 g_assert_nonnull (strstr (output,
2205 "\n" TAP_SUBTEST_PREFIX "ok 6 /prefix/a # SKIP by request"));
2206 g_assert_nonnull (strstr (output,
2207 "\n" TAP_SUBTEST_PREFIX "ok 7 /prefix/b/b # SKIP by request"));
2208 g_assert_nonnull (strstr (output,
2209 "\n" TAP_SUBTEST_PREFIX "ok 8 /prefix-long/a # SKIP by request"));
2210 g_assert_nonnull (strstr (output,
2211 "\n" TAP_SUBTEST_PREFIX "ok 9 /c/a # SKIP by request"));
2212 g_assert_nonnull (strstr (output,
2213 "\n" TAP_SUBTEST_PREFIX "ok 10 /d/a\n"));
2215 g_spawn_check_wait_status (status, &error);
2216 g_assert_no_error (error);
2219 g_ptr_array_unref (argv);
2223 test_tap_summary (void)
2225 const char *testing_helper;
2227 GError *error = NULL;
2232 g_test_summary ("Test the output of g_test_summary() from the TAP output of a test.");
2234 testing_helper = g_test_get_filename (G_TEST_BUILT, "testing-helper" EXEEXT, NULL);
2236 argv = g_ptr_array_new ();
2237 g_ptr_array_add (argv, (char *) testing_helper);
2238 g_ptr_array_add (argv, "summary");
2239 g_ptr_array_add (argv, "--tap");
2240 g_ptr_array_add (argv, NULL);
2242 /* Remove the G_TEST_ROOT_PROCESS env so it will be considered a standalone test */
2243 envp = g_get_environ ();
2244 g_assert_nonnull (g_environ_getenv (envp, "G_TEST_ROOT_PROCESS"));
2245 envp = g_environ_unsetenv (g_steal_pointer (&envp), "G_TEST_ROOT_PROCESS");
2247 g_spawn_sync (NULL, (char **) argv->pdata, envp,
2248 G_SPAWN_STDERR_TO_DEV_NULL,
2249 NULL, NULL, &output, NULL, &status,
2251 g_assert_no_error (error);
2253 g_spawn_check_wait_status (status, &error);
2254 g_assert_no_error (error);
2255 g_assert_null (strstr (output, "# Subtest: "));
2257 /* Note: The test path in the output is not `/tap/summary` because it’s the
2258 * test path from testing-helper, not from this function. */g_assert_null (strstr (output, "# Subtest: "));
2259 g_assert_nonnull (strstr (output, "\n# /summary summary: Tests that g_test_summary() "
2260 "works with TAP, by outputting a known "
2261 "summary message in testing-helper, and "
2262 "checking for it in the TAP output later.\n"));
2264 g_ptr_array_unref (argv);
2269 test_tap_subtest_summary (void)
2271 const char *testing_helper;
2273 GError *error = NULL;
2277 g_test_summary ("Test the output of g_test_summary() from the TAP output of a test.");
2279 testing_helper = g_test_get_filename (G_TEST_BUILT, "testing-helper" EXEEXT, NULL);
2281 argv = g_ptr_array_new ();
2282 g_ptr_array_add (argv, (char *) testing_helper);
2283 g_ptr_array_add (argv, "summary");
2284 g_ptr_array_add (argv, "--tap");
2285 g_ptr_array_add (argv, NULL);
2287 g_spawn_sync (NULL, (char **) argv->pdata, NULL,
2288 G_SPAWN_STDERR_TO_DEV_NULL,
2289 NULL, NULL, &output, NULL, &status,
2291 g_assert_no_error (error);
2293 g_spawn_check_wait_status (status, &error);
2294 g_assert_no_error (error);
2295 /* Note: The test path in the output is not `/tap/summary` because it’s the
2296 * test path from testing-helper, not from this function. */
2297 g_assert_true (g_str_has_prefix (output, "# Subtest: "));
2298 g_assert_nonnull (strstr (output,
2299 "\n" TAP_SUBTEST_PREFIX
2300 "# /summary summary: Tests that g_test_summary() "
2301 "works with TAP, by outputting a known "
2302 "summary message in testing-helper, and "
2303 "checking for it in the TAP output later.\n"));
2305 g_ptr_array_unref (argv);
2309 test_tap_message (void)
2311 const char *testing_helper;
2313 GError *error = NULL;
2316 char **output_lines;
2319 g_test_summary ("Test the output of g_test_message() from the TAP output of a test.");
2321 testing_helper = g_test_get_filename (G_TEST_BUILT, "testing-helper" EXEEXT, NULL);
2323 argv = g_ptr_array_new ();
2324 g_ptr_array_add (argv, (char *) testing_helper);
2325 g_ptr_array_add (argv, "message");
2326 g_ptr_array_add (argv, "--tap");
2327 g_ptr_array_add (argv, NULL);
2329 /* Remove the G_TEST_ROOT_PROCESS env so it will be considered a standalone test */
2330 envp = g_get_environ ();
2331 g_assert_nonnull (g_environ_getenv (envp, "G_TEST_ROOT_PROCESS"));
2332 envp = g_environ_unsetenv (g_steal_pointer (&envp), "G_TEST_ROOT_PROCESS");
2334 g_spawn_sync (NULL, (char **) argv->pdata, envp,
2335 G_SPAWN_STDERR_TO_DEV_NULL,
2336 NULL, NULL, &output, NULL, &status,
2338 g_assert_no_error (error);
2340 g_spawn_check_wait_status (status, &error);
2341 g_assert_no_error (error);
2343 g_assert_null (strstr (output, "# Subtest: "));
2345 const char *expected_tap_header = "\n1..1\n";
2346 const char *interesting_lines = strstr (output, expected_tap_header);
2347 g_assert_nonnull (interesting_lines);
2348 interesting_lines += strlen (expected_tap_header);
2350 output_lines = g_strsplit (interesting_lines, "\n", -1);
2351 g_assert_cmpuint (g_strv_length (output_lines), >=, 12);
2354 g_assert_cmpstr (output_lines[i++], ==, "# Tests that single line message works");
2355 g_assert_cmpstr (output_lines[i++], ==, "# Tests that multi");
2356 g_assert_cmpstr (output_lines[i++], ==, "# ");
2357 g_assert_cmpstr (output_lines[i++], ==, "# line");
2358 g_assert_cmpstr (output_lines[i++], ==, "# message");
2359 g_assert_cmpstr (output_lines[i++], ==, "# works");
2360 g_assert_cmpstr (output_lines[i++], ==, "# ");
2361 g_assert_cmpstr (output_lines[i++], ==, "# Tests that multi");
2362 g_assert_cmpstr (output_lines[i++], ==, "# line");
2363 g_assert_cmpstr (output_lines[i++], ==, "# message");
2364 g_assert_cmpstr (output_lines[i++], ==, "# works with leading and trailing too");
2365 g_assert_cmpstr (output_lines[i++], ==, "# ");
2368 g_strfreev (output_lines);
2370 g_ptr_array_unref (argv);
2374 test_tap_subtest_message (void)
2376 const char *testing_helper;
2378 GError *error = NULL;
2381 char **output_lines;
2383 g_test_summary ("Test the output of g_test_message() from the TAP output of a sub-test.");
2385 testing_helper = g_test_get_filename (G_TEST_BUILT, "testing-helper" EXEEXT, NULL);
2387 argv = g_ptr_array_new ();
2388 g_ptr_array_add (argv, (char *) testing_helper);
2389 g_ptr_array_add (argv, "message");
2390 g_ptr_array_add (argv, "--tap");
2391 g_ptr_array_add (argv, NULL);
2393 g_spawn_sync (NULL, (char **) argv->pdata, NULL,
2394 G_SPAWN_STDERR_TO_DEV_NULL,
2395 NULL, NULL, &output, NULL, &status,
2397 g_assert_no_error (error);
2399 g_spawn_check_wait_status (status, &error);
2400 g_assert_no_error (error);
2402 g_assert_true (g_str_has_prefix (output, "# Subtest: "));
2404 const char *expected_tap_header = "\n" TAP_SUBTEST_PREFIX "1..1\n";
2405 const char *interesting_lines = strstr (output, expected_tap_header);
2406 g_assert_nonnull (interesting_lines);
2407 interesting_lines += strlen (expected_tap_header);
2409 output_lines = g_strsplit (interesting_lines, "\n", -1);
2410 g_assert_cmpuint (g_strv_length (output_lines), >=, 12);
2413 g_assert_cmpstr (output_lines[i++], ==, TAP_SUBTEST_PREFIX "# Tests that single line message works");
2414 g_assert_cmpstr (output_lines[i++], ==, TAP_SUBTEST_PREFIX "# Tests that multi");
2415 g_assert_cmpstr (output_lines[i++], ==, TAP_SUBTEST_PREFIX "# ");
2416 g_assert_cmpstr (output_lines[i++], ==, TAP_SUBTEST_PREFIX "# line");
2417 g_assert_cmpstr (output_lines[i++], ==, TAP_SUBTEST_PREFIX "# message");
2418 g_assert_cmpstr (output_lines[i++], ==, TAP_SUBTEST_PREFIX "# works");
2419 g_assert_cmpstr (output_lines[i++], ==, TAP_SUBTEST_PREFIX "# ");
2420 g_assert_cmpstr (output_lines[i++], ==, TAP_SUBTEST_PREFIX "# Tests that multi");
2421 g_assert_cmpstr (output_lines[i++], ==, TAP_SUBTEST_PREFIX "# line");
2422 g_assert_cmpstr (output_lines[i++], ==, TAP_SUBTEST_PREFIX "# message");
2423 g_assert_cmpstr (output_lines[i++], ==, TAP_SUBTEST_PREFIX "# works with leading and trailing too");
2424 g_assert_cmpstr (output_lines[i++], ==, TAP_SUBTEST_PREFIX "# ");
2427 g_strfreev (output_lines);
2428 g_ptr_array_unref (argv);
2432 test_tap_print (void)
2434 const char *testing_helper;
2436 GError *error = NULL;
2439 char **output_lines;
2442 g_test_summary ("Test the output of g_print() from the TAP output of a test.");
2444 testing_helper = g_test_get_filename (G_TEST_BUILT, "testing-helper" EXEEXT, NULL);
2446 argv = g_ptr_array_new ();
2447 g_ptr_array_add (argv, (char *) testing_helper);
2448 g_ptr_array_add (argv, "print");
2449 g_ptr_array_add (argv, "--tap");
2450 g_ptr_array_add (argv, NULL);
2452 /* Remove the G_TEST_ROOT_PROCESS env so it will be considered a standalone test */
2453 envp = g_get_environ ();
2454 g_assert_nonnull (g_environ_getenv (envp, "G_TEST_ROOT_PROCESS"));
2455 envp = g_environ_unsetenv (g_steal_pointer (&envp), "G_TEST_ROOT_PROCESS");
2457 g_spawn_sync (NULL, (char **) argv->pdata, envp,
2458 G_SPAWN_STDERR_TO_DEV_NULL,
2459 NULL, NULL, &output, NULL, &status,
2461 g_assert_no_error (error);
2463 g_spawn_check_wait_status (status, &error);
2464 g_assert_no_error (error);
2466 const char *expected_tap_header = "\n1..1\n";
2467 const char *interesting_lines = strstr (output, expected_tap_header);
2468 g_assert_nonnull (interesting_lines);
2469 interesting_lines += strlen (expected_tap_header);
2471 output_lines = g_strsplit (interesting_lines, "\n", -1);
2472 g_assert_cmpuint (g_strv_length (output_lines), >=, 3);
2475 g_assert_cmpstr (output_lines[i++], ==, "# Tests that single line message works");
2476 g_assert_cmpstr (output_lines[i++], ==, "# test that multiple");
2477 g_assert_cmpstr (output_lines[i++], ==, "# lines can be written separately");
2481 g_strfreev (output_lines);
2482 g_ptr_array_unref (argv);
2486 test_tap_subtest_print (void)
2488 const char *testing_helper;
2490 GError *error = NULL;
2493 char **output_lines;
2495 g_test_summary ("Test the output of g_test_print() from the TAP output of a sub-test.");
2497 testing_helper = g_test_get_filename (G_TEST_BUILT, "testing-helper" EXEEXT, NULL);
2499 argv = g_ptr_array_new ();
2500 g_ptr_array_add (argv, (char *) testing_helper);
2501 g_ptr_array_add (argv, "print");
2502 g_ptr_array_add (argv, "--tap");
2503 g_ptr_array_add (argv, NULL);
2505 g_spawn_sync (NULL, (char **) argv->pdata, NULL,
2506 G_SPAWN_STDERR_TO_DEV_NULL,
2507 NULL, NULL, &output, NULL, &status,
2509 g_assert_no_error (error);
2511 g_spawn_check_wait_status (status, &error);
2512 g_assert_no_error (error);
2514 const char *expected_tap_header = "\n" TAP_SUBTEST_PREFIX "1..1\n";
2515 const char *interesting_lines = strstr (output, expected_tap_header);
2516 g_assert_nonnull (interesting_lines);
2517 interesting_lines += strlen (expected_tap_header);
2519 output_lines = g_strsplit (interesting_lines, "\n", -1);
2520 g_assert_cmpuint (g_strv_length (output_lines), >=, 3);
2523 g_assert_cmpstr (output_lines[i++], ==, TAP_SUBTEST_PREFIX "# Tests that single line message works");
2524 g_assert_cmpstr (output_lines[i++], ==, TAP_SUBTEST_PREFIX "# test that multiple");
2525 g_assert_cmpstr (output_lines[i++], ==, TAP_SUBTEST_PREFIX "# lines can be written separately");
2528 g_strfreev (output_lines);
2529 g_ptr_array_unref (argv);
2533 test_tap_subtest_stdout (void)
2535 const char *testing_helper;
2537 GError *error = NULL;
2540 char **output_lines;
2542 g_test_summary ("Test the stdout from the TAP output of a sub-test.");
2544 testing_helper = g_test_get_filename (G_TEST_BUILT, "testing-helper" EXEEXT, NULL);
2546 argv = g_ptr_array_new ();
2547 g_ptr_array_add (argv, (char *) testing_helper);
2548 g_ptr_array_add (argv, "subprocess-stdout");
2549 g_ptr_array_add (argv, "--tap");
2550 g_ptr_array_add (argv, NULL);
2552 g_spawn_sync (NULL, (char **) argv->pdata, NULL,
2553 G_SPAWN_STDERR_TO_DEV_NULL,
2554 NULL, NULL, &output, NULL, &status,
2556 g_assert_no_error (error);
2558 g_spawn_check_wait_status (status, &error);
2559 g_assert_no_error (error);
2561 const char *expected_tap_header = "\n" TAP_SUBTEST_PREFIX "1..1\n";
2562 const char *interesting_lines = strstr (output, expected_tap_header);
2563 g_assert_nonnull (interesting_lines);
2565 interesting_lines = strstr (interesting_lines, TAP_SUBTEST_PREFIX "# /sub-stdout");
2566 g_assert_nonnull (interesting_lines);
2568 output_lines = g_strsplit (interesting_lines, "\n", -1);
2569 g_assert_cmpuint (g_strv_length (output_lines), >=, 5);
2572 g_assert_cmpstr (output_lines[i++], ==,
2573 TAP_SUBTEST_PREFIX "# /sub-stdout: Tests that single line message works");
2574 g_assert_cmpstr (output_lines[i++], ==,
2575 TAP_SUBTEST_PREFIX "# test that multiple");
2576 g_assert_cmpstr (output_lines[i++], ==,
2577 TAP_SUBTEST_PREFIX "# lines can be written separately");
2578 g_assert_cmpstr (output_lines[i++], ==,
2579 TAP_SUBTEST_PREFIX "# And another line has been put");
2580 g_assert_cmpstr (output_lines[i++], ==,
2581 TAP_SUBTEST_PREFIX "ok 1 /sub-stdout");
2584 g_strfreev (output_lines);
2585 g_ptr_array_unref (argv);
2589 test_tap_subtest_stdout_no_new_line (void)
2591 const char *testing_helper;
2593 GError *error = NULL;
2596 char **output_lines;
2598 g_test_summary ("Test the stdout from the TAP output of a sub-test.");
2600 testing_helper = g_test_get_filename (G_TEST_BUILT, "testing-helper" EXEEXT, NULL);
2602 argv = g_ptr_array_new ();
2603 g_ptr_array_add (argv, (char *) testing_helper);
2604 g_ptr_array_add (argv, "subprocess-stdout-no-nl");
2605 g_ptr_array_add (argv, "--tap");
2606 g_ptr_array_add (argv, NULL);
2608 g_spawn_sync (NULL, (char **) argv->pdata, NULL,
2609 G_SPAWN_STDERR_TO_DEV_NULL,
2610 NULL, NULL, &output, NULL, &status,
2612 g_assert_no_error (error);
2614 g_spawn_check_wait_status (status, &error);
2615 g_assert_no_error (error);
2617 const char *expected_tap_header = "\n" TAP_SUBTEST_PREFIX "1..1\n";
2618 const char *interesting_lines = strstr (output, expected_tap_header);
2619 g_assert_nonnull (interesting_lines);
2621 interesting_lines = strstr (interesting_lines, TAP_SUBTEST_PREFIX "# /sub-stdout-no-nl");
2622 g_assert_nonnull (interesting_lines);
2624 output_lines = g_strsplit (interesting_lines, "\n", -1);
2625 g_assert_cmpuint (g_strv_length (output_lines), >=, 2);
2628 g_assert_cmpstr (output_lines[i++], ==,
2629 TAP_SUBTEST_PREFIX "# /sub-stdout-no-nl: A message without trailing new line");
2630 g_assert_cmpstr (output_lines[i++], ==,
2631 TAP_SUBTEST_PREFIX "ok 1 /sub-stdout-no-nl");
2634 g_strfreev (output_lines);
2635 g_ptr_array_unref (argv);
2639 test_tap_error (void)
2641 const char *testing_helper;
2643 GError *error = NULL;
2648 g_test_summary ("Test that g_error() generates Bail out TAP output of a test.");
2650 testing_helper = g_test_get_filename (G_TEST_BUILT, "testing-helper" EXEEXT, NULL);
2652 argv = g_ptr_array_new ();
2653 g_ptr_array_add (argv, (char *) testing_helper);
2654 g_ptr_array_add (argv, "error");
2655 g_ptr_array_add (argv, "--tap");
2656 g_ptr_array_add (argv, NULL);
2658 /* Remove the G_TEST_ROOT_PROCESS env so it will be considered a standalone test */
2659 envp = g_get_environ ();
2660 g_assert_nonnull (g_environ_getenv (envp, "G_TEST_ROOT_PROCESS"));
2661 envp = g_environ_unsetenv (g_steal_pointer (&envp), "G_TEST_ROOT_PROCESS");
2663 g_spawn_sync (NULL, (char **) argv->pdata, envp,
2664 G_SPAWN_STDERR_TO_DEV_NULL,
2665 NULL, NULL, &output, NULL, &status,
2667 g_assert_no_error (error);
2669 g_spawn_check_wait_status (status, &error);
2670 g_assert_nonnull (error);
2672 g_assert_false (g_str_has_prefix (output, "# Subtest: "));
2674 const char *expected_tap_header = "\n1..1\n";
2675 const char *interesting_lines = strstr (output, expected_tap_header);
2676 g_assert_nonnull (interesting_lines);
2677 interesting_lines += strlen (expected_tap_header);
2679 g_assert_cmpstr (interesting_lines, ==, "not ok /error - GLib-FATAL-ERROR: This should error out "
2680 "Because it's just wrong!\n"
2685 g_ptr_array_unref (argv);
2686 g_clear_error (&error);
2690 test_tap_subtest_error (void)
2692 const char *testing_helper;
2694 GError *error = NULL;
2698 g_test_summary ("Test that g_error() generates Bail out TAP output of a test.");
2700 testing_helper = g_test_get_filename (G_TEST_BUILT, "testing-helper" EXEEXT, NULL);
2702 argv = g_ptr_array_new ();
2703 g_ptr_array_add (argv, (char *) testing_helper);
2704 g_ptr_array_add (argv, "error");
2705 g_ptr_array_add (argv, "--tap");
2706 g_ptr_array_add (argv, NULL);
2708 g_spawn_sync (NULL, (char **) argv->pdata, NULL,
2709 G_SPAWN_STDERR_TO_DEV_NULL,
2710 NULL, NULL, &output, NULL, &status,
2712 g_assert_no_error (error);
2714 g_spawn_check_wait_status (status, &error);
2715 g_assert_nonnull (error);
2717 g_assert_true (g_str_has_prefix (output, "# Subtest: "));
2719 const char *expected_tap_header = "\n" TAP_SUBTEST_PREFIX "1..1\n";
2720 const char *interesting_lines = strstr (output, expected_tap_header);
2721 g_assert_nonnull (interesting_lines);
2722 interesting_lines += strlen (expected_tap_header);
2724 g_assert_cmpstr (interesting_lines, ==,
2725 TAP_SUBTEST_PREFIX "not ok /error - GLib-FATAL-ERROR: This should error out "
2726 "Because it's just wrong!\n"
2727 TAP_SUBTEST_PREFIX "Bail out!\n");
2730 g_ptr_array_unref (argv);
2731 g_clear_error (&error);
2735 test_tap_error_and_pass (void)
2737 const char *testing_helper;
2739 GError *error = NULL;
2744 g_test_summary ("Test that g_error() generates Bail out TAP output of a test.");
2746 testing_helper = g_test_get_filename (G_TEST_BUILT, "testing-helper" EXEEXT, NULL);
2748 /* Remove the G_TEST_ROOT_PROCESS env so it will be considered a standalone test */
2749 envp = g_get_environ ();
2750 g_assert_nonnull (g_environ_getenv (envp, "G_TEST_ROOT_PROCESS"));
2751 envp = g_environ_unsetenv (g_steal_pointer (&envp), "G_TEST_ROOT_PROCESS");
2753 argv = g_ptr_array_new ();
2754 g_ptr_array_add (argv, (char *) testing_helper);
2755 g_ptr_array_add (argv, "error-and-pass");
2756 g_ptr_array_add (argv, "--tap");
2757 g_ptr_array_add (argv, NULL);
2759 g_spawn_sync (NULL, (char **) argv->pdata, envp,
2760 G_SPAWN_STDERR_TO_DEV_NULL,
2761 NULL, NULL, &output, NULL, &status,
2763 g_assert_no_error (error);
2765 g_spawn_check_wait_status (status, &error);
2766 g_assert_nonnull (error);
2768 const char *expected_tap_header = "\n1..2\n";
2769 const char *interesting_lines = strstr (output, expected_tap_header);
2770 g_assert_nonnull (interesting_lines);
2771 interesting_lines += strlen (expected_tap_header);
2773 g_assert_cmpstr (interesting_lines, ==, "not ok /error - GLib-FATAL-ERROR: This should error out "
2774 "Because it's just wrong!\n"
2779 g_ptr_array_unref (argv);
2780 g_clear_error (&error);
2784 test_tap_subtest_error_and_pass (void)
2786 const char *testing_helper;
2788 GError *error = NULL;
2792 g_test_summary ("Test that g_error() generates Bail out TAP output of a test.");
2794 testing_helper = g_test_get_filename (G_TEST_BUILT, "testing-helper" EXEEXT, NULL);
2796 argv = g_ptr_array_new ();
2797 g_ptr_array_add (argv, (char *) testing_helper);
2798 g_ptr_array_add (argv, "error-and-pass");
2799 g_ptr_array_add (argv, "--tap");
2800 g_ptr_array_add (argv, NULL);
2802 g_spawn_sync (NULL, (char **) argv->pdata, NULL,
2803 G_SPAWN_STDERR_TO_DEV_NULL,
2804 NULL, NULL, &output, NULL, &status,
2806 g_assert_no_error (error);
2808 g_spawn_check_wait_status (status, &error);
2809 g_assert_nonnull (error);
2811 g_assert_true (g_str_has_prefix (output, "# Subtest: "));
2813 const char *expected_tap_header = "\n" TAP_SUBTEST_PREFIX "1..2\n";
2814 const char *interesting_lines = strstr (output, expected_tap_header);
2815 g_assert_nonnull (interesting_lines);
2816 interesting_lines += strlen (expected_tap_header);
2818 g_assert_cmpstr (interesting_lines, ==,
2819 TAP_SUBTEST_PREFIX "not ok /error - GLib-FATAL-ERROR: This should error out "
2820 "Because it's just wrong!\n"
2821 TAP_SUBTEST_PREFIX "Bail out!\n");
2824 g_ptr_array_unref (argv);
2825 g_clear_error (&error);
2829 test_init_no_argv0 (void)
2831 const char *testing_helper;
2833 GError *error = NULL;
2837 g_test_summary ("Test that g_test_init() can be called safely with argc == 0.");
2839 testing_helper = g_test_get_filename (G_TEST_BUILT, "testing-helper" EXEEXT, NULL);
2841 argv = g_ptr_array_new ();
2842 g_ptr_array_add (argv, (char *) testing_helper);
2843 g_ptr_array_add (argv, "init-null-argv0");
2844 g_ptr_array_add (argv, NULL);
2846 /* This has to be spawned manually and can’t be run with g_test_subprocess()
2847 * because the test helper can’t be run after `g_test_init()` has been called
2848 * in the process. */
2849 g_spawn_sync (NULL, (char **) argv->pdata, NULL,
2850 G_SPAWN_STDERR_TO_DEV_NULL,
2851 NULL, NULL, &output, NULL, &status,
2853 g_assert_no_error (error);
2855 g_spawn_check_wait_status (status, &error);
2856 g_assert_no_error (error);
2857 g_assert_nonnull (strstr (output, "# random seed:"));
2859 g_ptr_array_unref (argv);
2867 char *filename, *filename2;
2871 setlocale (LC_ALL, "");
2873 g_test_init (&argc, &argv, NULL);
2875 /* Part of a test for
2876 * https://gitlab.gnome.org/GNOME/glib/-/issues/2563, see below */
2877 filename = g_test_build_filename (G_TEST_BUILT, "nonexistent", NULL);
2879 g_test_add_func ("/random-generator/rand-1", test_rand1);
2880 g_test_add_func ("/random-generator/rand-2", test_rand2);
2881 g_test_add_func ("/random-generator/random-conversions", test_random_conversions);
2882 g_test_add_func ("/misc/assertions", test_assertions);
2883 g_test_add_func ("/misc/assertions/subprocess/bad_cmpvariant_types", test_assertions_bad_cmpvariant_types);
2884 g_test_add_func ("/misc/assertions/subprocess/bad_cmpvariant_values", test_assertions_bad_cmpvariant_values);
2885 g_test_add_func ("/misc/assertions/subprocess/bad_cmpstr", test_assertions_bad_cmpstr);
2886 g_test_add_func ("/misc/assertions/subprocess/bad_cmpstrv_null1", test_assertions_bad_cmpstrv_null1);
2887 g_test_add_func ("/misc/assertions/subprocess/bad_cmpstrv_null2", test_assertions_bad_cmpstrv_null2);
2888 g_test_add_func ("/misc/assertions/subprocess/bad_cmpstrv_length", test_assertions_bad_cmpstrv_length);
2889 g_test_add_func ("/misc/assertions/subprocess/bad_cmpstrv_values", test_assertions_bad_cmpstrv_values);
2890 g_test_add_func ("/misc/assertions/subprocess/bad_cmpint", test_assertions_bad_cmpint);
2891 g_test_add_func ("/misc/assertions/subprocess/bad_cmpmem_len", test_assertions_bad_cmpmem_len);
2892 g_test_add_func ("/misc/assertions/subprocess/bad_cmpmem_data", test_assertions_bad_cmpmem_data);
2893 g_test_add_func ("/misc/assertions/subprocess/bad_cmpmem_null", test_assertions_bad_cmpmem_null);
2894 g_test_add_func ("/misc/assertions/subprocess/bad_cmpfloat_epsilon", test_assertions_bad_cmpfloat_epsilon);
2895 g_test_add_func ("/misc/assertions/subprocess/bad_no_errno", test_assertions_bad_no_errno);
2896 g_test_add_data_func ("/misc/test-data", (void*) 0xc0c0baba, test_data_test);
2897 g_test_add ("/misc/primetoul", Fixturetest, (void*) 0xc0cac01a, fixturetest_setup, fixturetest_test, fixturetest_teardown);
2899 g_test_add_func ("/misc/timer", test_timer);
2902 g_test_add_func ("/forking/fail assertion", test_fork_fail);
2903 g_test_add_func ("/forking/patterns", test_fork_patterns);
2905 g_test_add_func ("/forking/timeout", test_fork_timeout);
2908 g_test_add_func ("/trap_subprocess/fail", test_subprocess_fail);
2909 g_test_add_func ("/trap_subprocess/no-such-test", test_subprocess_no_such_test);
2911 g_test_add_func ("/trap_subprocess/timeout", test_subprocess_timeout);
2913 g_test_add_func ("/trap_subprocess/patterns", test_subprocess_patterns);
2915 g_test_add_func ("/misc/fatal-log-handler", test_fatal_log_handler);
2916 g_test_add_func ("/misc/fatal-log-handler/subprocess/critical-pass", test_fatal_log_handler_critical_pass);
2917 g_test_add_func ("/misc/fatal-log-handler/subprocess/error-fail", test_fatal_log_handler_error_fail);
2918 g_test_add_func ("/misc/fatal-log-handler/subprocess/critical-fail", test_fatal_log_handler_critical_fail);
2920 g_test_add_func ("/misc/expected-messages", test_expected_messages);
2921 g_test_add_func ("/misc/expected-messages/subprocess/warning", test_expected_messages_warning);
2922 g_test_add_func ("/misc/expected-messages/subprocess/expect-warning", test_expected_messages_expect_warning);
2923 g_test_add_func ("/misc/expected-messages/subprocess/wrong-warning", test_expected_messages_wrong_warning);
2924 g_test_add_func ("/misc/expected-messages/subprocess/expected", test_expected_messages_expected);
2925 g_test_add_func ("/misc/expected-messages/subprocess/null-domain", test_expected_messages_null_domain);
2926 g_test_add_func ("/misc/expected-messages/subprocess/extra-warning", test_expected_messages_extra_warning);
2927 g_test_add_func ("/misc/expected-messages/subprocess/unexpected-extra-warning", test_expected_messages_unexpected_extra_warning);
2928 g_test_add_func ("/misc/expected-messages/expect-error", test_expected_messages_expect_error);
2929 g_test_add_func ("/misc/expected-messages/skip-debug", test_expected_messages_debug);
2931 g_test_add_func ("/misc/messages", test_messages);
2932 g_test_add_func ("/misc/messages/subprocess/use-stderr", test_messages_use_stderr);
2934 g_test_add_func ("/misc/dash-p", test_dash_p);
2935 g_test_add_func ("/misc/dash-p/child", test_dash_p_child);
2936 g_test_add_func ("/misc/dash-p/child/sub", test_dash_p_child_sub);
2937 g_test_add_func ("/misc/dash-p/child/sub/subprocess", test_dash_p_child_sub_child);
2938 g_test_add_func ("/misc/dash-p/child/sub/subprocess/child", test_dash_p_child_sub_child);
2939 g_test_add_func ("/misc/dash-p/child/sub2", test_dash_p_child_sub2);
2940 g_test_add_func ("/misc/dash-p/subprocess/hidden", test_dash_p_hidden);
2941 g_test_add_func ("/misc/dash-p/subprocess/hidden/sub", test_dash_p_hidden_sub);
2943 g_test_add_func ("/misc/nonfatal", test_nonfatal);
2945 g_test_add_func ("/misc/skip", test_skip);
2946 g_test_add_func ("/misc/combining", test_combining);
2947 g_test_add_func ("/misc/combining/subprocess/fail", subprocess_fail);
2948 g_test_add_func ("/misc/combining/subprocess/skip1", test_skip);
2949 g_test_add_func ("/misc/combining/subprocess/skip2", test_skip);
2950 g_test_add_func ("/misc/combining/subprocess/incomplete", subprocess_incomplete);
2951 g_test_add_func ("/misc/combining/subprocess/pass", test_pass);
2952 g_test_add_func ("/misc/fail", test_fail);
2953 g_test_add_func ("/misc/incomplete", test_incomplete);
2954 g_test_add_func ("/misc/timeout", test_subprocess_timed_out);
2956 g_test_add_func ("/misc/path/first", test_path_first);
2957 g_test_add_func ("/misc/path/second", test_path_second);
2959 g_test_add_func ("/tap", test_tap);
2960 g_test_add_func ("/tap/subtest", test_tap_subtest);
2961 g_test_add_func ("/tap/summary", test_tap_summary);
2962 g_test_add_func ("/tap/subtest/summary", test_tap_subtest_summary);
2963 g_test_add_func ("/tap/message", test_tap_message);
2964 g_test_add_func ("/tap/subtest/message", test_tap_subtest_message);
2965 g_test_add_func ("/tap/print", test_tap_print);
2966 g_test_add_func ("/tap/subtest/print", test_tap_subtest_print);
2967 g_test_add_func ("/tap/subtest/stdout", test_tap_subtest_stdout);
2968 g_test_add_func ("/tap/subtest/stdout-no-new-line", test_tap_subtest_stdout_no_new_line);
2969 g_test_add_func ("/tap/error", test_tap_error);
2970 g_test_add_func ("/tap/subtest/error", test_tap_subtest_error);
2971 g_test_add_func ("/tap/error-and-pass", test_tap_error_and_pass);
2972 g_test_add_func ("/tap/subtest/error-and-pass", test_tap_subtest_error_and_pass);
2974 g_test_add_func ("/init/no_argv0", test_init_no_argv0);
2976 ret = g_test_run ();
2978 /* We can't test for https://gitlab.gnome.org/GNOME/glib/-/issues/2563
2979 * from a test-case, because the whole point of that issue is that it's
2980 * about whether certain patterns are valid after g_test_run() has
2981 * returned... so put an ad-hoc test here, and just crash if it fails. */
2982 filename2 = g_test_build_filename (G_TEST_BUILT, "nonexistent", NULL);
2983 g_assert_cmpstr (filename, ==, filename2);