Make g_test_run() return 77 if all tests are skipped
[platform/upstream/glib.git] / glib / tests / testing.c
1 /* GLib testing framework examples and tests
2  * Copyright (C) 2007 Imendio AB
3  * Authors: Tim Janik
4  *
5  * This work is provided "as is"; redistribution and modification
6  * in whole or in part, in any medium, physical or electronic is
7  * permitted without restriction.
8  *
9  * This work is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12  *
13  * In no event shall the authors or contributors be liable for any
14  * direct, indirect, incidental, special, exemplary, or consequential
15  * damages (including, but not limited to, procurement of substitute
16  * goods or services; loss of use, data, or profits; or business
17  * interruption) however caused and on any theory of liability, whether
18  * in contract, strict liability, or tort (including negligence or
19  * otherwise) arising in any way out of the use of this software, even
20  * if advised of the possibility of such damage.
21  */
22
23 #include <glib.h>
24
25 #include <stdlib.h>
26 #include <string.h>
27
28 /* test assertion variants */
29 static void
30 test_assertions_bad_cmpstr (void)
31 {
32   g_assert_cmpstr ("fzz", !=, "fzz");
33   exit (0);
34 }
35
36 static void
37 test_assertions_bad_cmpint (void)
38 {
39   g_assert_cmpint (4, !=, 4);
40   exit (0);
41 }
42
43 static void
44 test_assertions (void)
45 {
46   gchar *fuu;
47   g_assert_cmpint (1, >, 0);
48   g_assert_cmphex (2, ==, 2);
49   g_assert_cmpfloat (3.3, !=, 7);
50   g_assert_cmpfloat (7, <=, 3 + 4);
51   g_assert (TRUE);
52   g_assert_cmpstr ("foo", !=, "faa");
53   fuu = g_strdup_printf ("f%s", "uu");
54   g_test_queue_free (fuu);
55   g_assert_cmpstr ("foo", !=, fuu);
56   g_assert_cmpstr ("fuu", ==, fuu);
57   g_assert_cmpstr (NULL, <, "");
58   g_assert_cmpstr (NULL, ==, NULL);
59   g_assert_cmpstr ("", >, NULL);
60   g_assert_cmpstr ("foo", <, "fzz");
61   g_assert_cmpstr ("fzz", >, "faa");
62   g_assert_cmpstr ("fzz", ==, "fzz");
63
64   g_test_trap_subprocess ("/misc/assertions/subprocess/bad_cmpstr", 0, 0);
65   g_test_trap_assert_failed ();
66   g_test_trap_assert_stderr ("*assertion failed*");
67
68   g_test_trap_subprocess ("/misc/assertions/subprocess/bad_cmpint", 0, 0);
69   g_test_trap_assert_failed ();
70   g_test_trap_assert_stderr ("*assertion failed*");
71 }
72
73 /* test g_test_timer* API */
74 static void
75 test_timer (void)
76 {
77   double ttime;
78   g_test_timer_start();
79   g_assert_cmpfloat (g_test_timer_last(), ==, 0);
80   g_usleep (25 * 1000);
81   ttime = g_test_timer_elapsed();
82   g_assert_cmpfloat (ttime, >, 0);
83   g_assert_cmpfloat (g_test_timer_last(), ==, ttime);
84   g_test_minimized_result (ttime, "timer-test-time: %fsec", ttime);
85   g_test_maximized_result (5, "bogus-quantity: %ddummies", 5); /* simple API test */
86 }
87
88 #ifdef G_OS_UNIX
89 G_GNUC_BEGIN_IGNORE_DEPRECATIONS
90
91 /* fork out for a failing test */
92 static void
93 test_fork_fail (void)
94 {
95   if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR))
96     {
97       g_assert_not_reached();
98     }
99   g_test_trap_assert_failed();
100   g_test_trap_assert_stderr ("*ERROR*test_fork_fail*should not be reached*");
101 }
102
103 /* fork out to assert stdout and stderr patterns */
104 static void
105 test_fork_patterns (void)
106 {
107   if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDOUT | G_TEST_TRAP_SILENCE_STDERR))
108     {
109       g_print ("some stdout text: somagic17\n");
110       g_printerr ("some stderr text: semagic43\n");
111       exit (0);
112     }
113   g_test_trap_assert_passed();
114   g_test_trap_assert_stdout ("*somagic17*");
115   g_test_trap_assert_stderr ("*semagic43*");
116 }
117
118 /* fork out for a timeout test */
119 static void
120 test_fork_timeout (void)
121 {
122   /* allow child to run for only a fraction of a second */
123   if (g_test_trap_fork (0.11 * 1000000, 0))
124     {
125       /* loop and sleep forever */
126       while (TRUE)
127         g_usleep (1000 * 1000);
128     }
129   g_test_trap_assert_failed();
130   g_assert (g_test_trap_reached_timeout());
131 }
132
133 G_GNUC_END_IGNORE_DEPRECATIONS
134 #endif /* G_OS_UNIX */
135
136 static void
137 test_subprocess_fail (void)
138 {
139   if (g_test_subprocess ())
140     {
141       g_assert_not_reached ();
142       return;
143     }
144
145   g_test_trap_subprocess (NULL, 0, 0);
146   g_test_trap_assert_failed ();
147   g_test_trap_assert_stderr ("*ERROR*test_subprocess_fail*should not be reached*");
148 }
149
150 static void
151 test_subprocess_no_such_test (void)
152 {
153   if (g_test_subprocess ())
154     {
155       g_test_trap_subprocess ("/trap_subprocess/this-test-does-not-exist", 0, 0);
156       g_assert_not_reached ();
157       return;
158     }
159   g_test_trap_subprocess (NULL, 0, 0);
160   g_test_trap_assert_failed ();
161   g_test_trap_assert_stderr ("*test does not exist*");
162   g_test_trap_assert_stderr_unmatched ("*should not be reached*");
163 }
164
165 static void
166 test_subprocess_patterns (void)
167 {
168   if (g_test_subprocess ())
169     {
170       g_print ("some stdout text: somagic17\n");
171       g_printerr ("some stderr text: semagic43\n");
172       exit (0);
173     }
174   g_test_trap_subprocess (NULL, 0,  0);
175   g_test_trap_assert_passed ();
176   g_test_trap_assert_stdout ("*somagic17*");
177   g_test_trap_assert_stderr ("*semagic43*");
178 }
179
180 static void
181 test_subprocess_timeout (void)
182 {
183   if (g_test_subprocess ())
184     {
185       /* loop and sleep forever */
186       while (TRUE)
187         g_usleep (1000 * 1000);
188       return;
189     }
190   /* allow child to run for only a fraction of a second */
191   g_test_trap_subprocess (NULL, 0.11 * 1000000, 0);
192   g_test_trap_assert_failed ();
193   g_assert (g_test_trap_reached_timeout ());
194 }
195
196 /* run a test with fixture setup and teardown */
197 typedef struct {
198   guint  seed;
199   guint  prime;
200   gchar *msg;
201 } Fixturetest;
202 static void
203 fixturetest_setup (Fixturetest  *fix,
204                    gconstpointer test_data)
205 {
206   g_assert (test_data == (void*) 0xc0cac01a);
207   fix->seed = 18;
208   fix->prime = 19;
209   fix->msg = g_strdup_printf ("%d", fix->prime);
210 }
211 static void
212 fixturetest_test (Fixturetest  *fix,
213                   gconstpointer test_data)
214 {
215   guint prime = g_spaced_primes_closest (fix->seed);
216   g_assert_cmpint (prime, ==, fix->prime);
217   prime = g_ascii_strtoull (fix->msg, NULL, 0);
218   g_assert_cmpint (prime, ==, fix->prime);
219   g_assert (test_data == (void*) 0xc0cac01a);
220 }
221 static void
222 fixturetest_teardown (Fixturetest  *fix,
223                       gconstpointer test_data)
224 {
225   g_assert (test_data == (void*) 0xc0cac01a);
226   g_free (fix->msg);
227 }
228
229 static struct {
230   int bit, vint1, vint2, irange;
231   long double vdouble, drange;
232 } shared_rand_state;
233
234 static void
235 test_rand1 (void)
236 {
237   shared_rand_state.bit = g_test_rand_bit();
238   shared_rand_state.vint1 = g_test_rand_int();
239   shared_rand_state.vint2 = g_test_rand_int();
240   g_assert_cmpint (shared_rand_state.vint1, !=, shared_rand_state.vint2);
241   shared_rand_state.irange = g_test_rand_int_range (17, 35);
242   g_assert_cmpint (shared_rand_state.irange, >=, 17);
243   g_assert_cmpint (shared_rand_state.irange, <=, 35);
244   shared_rand_state.vdouble = g_test_rand_double();
245   shared_rand_state.drange = g_test_rand_double_range (-999, +17);
246   g_assert_cmpfloat (shared_rand_state.drange, >=, -999);
247   g_assert_cmpfloat (shared_rand_state.drange, <=, +17);
248 }
249
250 static void
251 test_rand2 (void)
252 {
253   /* this test only works if run after test1.
254    * we do this to check that random number generators
255    * are reseeded upon fixture setup.
256    */
257   g_assert_cmpint (shared_rand_state.bit, ==, g_test_rand_bit());
258   g_assert_cmpint (shared_rand_state.vint1, ==, g_test_rand_int());
259   g_assert_cmpint (shared_rand_state.vint2, ==, g_test_rand_int());
260   g_assert_cmpint (shared_rand_state.irange, ==, g_test_rand_int_range (17, 35));
261   g_assert_cmpfloat (shared_rand_state.vdouble, ==, g_test_rand_double());
262   g_assert_cmpfloat (shared_rand_state.drange, ==, g_test_rand_double_range (-999, +17));
263 }
264
265 static void
266 test_data_test (gconstpointer test_data)
267 {
268   g_assert (test_data == (void*) 0xc0c0baba);
269 }
270
271 static void
272 test_random_conversions (void)
273 {
274   /* very simple conversion test using random numbers */
275   int vint = g_test_rand_int();
276   char *err, *str = g_strdup_printf ("%d", vint);
277   gint64 vint64 = g_ascii_strtoll (str, &err, 10);
278   g_assert_cmphex (vint, ==, vint64);
279   g_assert (!err || *err == 0);
280   g_free (str);
281 }
282
283 static gboolean
284 fatal_handler (const gchar    *log_domain,
285                GLogLevelFlags  log_level,
286                const gchar    *message,
287                gpointer        user_data)
288 {
289   return FALSE;
290 }
291
292 static void
293 test_fatal_log_handler_critical_pass (void)
294 {
295   g_test_log_set_fatal_handler (fatal_handler, NULL);
296   g_str_has_prefix (NULL, "file://");
297   g_critical ("Test passing");
298   exit (0);
299 }
300
301 static void
302 test_fatal_log_handler_error_fail (void)
303 {
304   g_error ("Test failing");
305   exit (0);
306 }
307
308 static void
309 test_fatal_log_handler_critical_fail (void)
310 {
311   g_str_has_prefix (NULL, "file://");
312   g_critical ("Test passing");
313   exit (0);
314 }
315
316 static void
317 test_fatal_log_handler (void)
318 {
319   g_test_trap_subprocess ("/misc/fatal-log-handler/subprocess/critical-pass", 0, 0);
320   g_test_trap_assert_passed ();
321   g_test_trap_assert_stderr ("*CRITICAL*g_str_has_prefix*");
322   g_test_trap_assert_stderr ("*CRITICAL*Test passing*");
323
324   g_test_trap_subprocess ("/misc/fatal-log-handler/subprocess/error-fail", 0, 0);
325   g_test_trap_assert_failed ();
326   g_test_trap_assert_stderr ("*ERROR*Test failing*");
327
328   g_test_trap_subprocess ("/misc/fatal-log-handler/subprocess/critical-fail", 0, 0);
329   g_test_trap_assert_failed ();
330   g_test_trap_assert_stderr ("*CRITICAL*g_str_has_prefix*");
331   g_test_trap_assert_stderr_unmatched ("*CRITICAL*Test passing*");
332 }
333
334 static void
335 test_expected_messages_warning (void)
336 {
337   g_warning ("This is a %d warning", g_random_int ());
338   g_return_if_reached ();
339 }
340
341 static void
342 test_expected_messages_expect_warning (void)
343 {
344   g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_WARNING,
345                          "This is a * warning");
346   test_expected_messages_warning ();
347 }
348
349 static void
350 test_expected_messages_wrong_warning (void)
351 {
352   g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL,
353                          "*should not be *");
354   test_expected_messages_warning ();
355 }
356
357 static void
358 test_expected_messages_expected (void)
359 {
360   g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_WARNING,
361                          "This is a * warning");
362   g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL,
363                          "*should not be reached");
364
365   test_expected_messages_warning ();
366
367   g_test_assert_expected_messages ();
368   exit (0);
369 }
370
371 static void
372 test_expected_messages_null_domain (void)
373 {
374   g_test_expect_message (NULL, G_LOG_LEVEL_WARNING, "no domain");
375   g_log (NULL, G_LOG_LEVEL_WARNING, "no domain");
376   g_test_assert_expected_messages ();
377 }
378
379 static void
380 test_expected_messages_expect_error (void)
381 {
382   /* make sure we can't try to expect a g_error() */
383   g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL, "*G_LOG_LEVEL_ERROR*");
384   g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_ERROR, "this won't work");
385   g_test_assert_expected_messages ();
386 }
387
388 static void
389 test_expected_messages_extra_warning (void)
390 {
391   g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_WARNING,
392                          "This is a * warning");
393   g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL,
394                          "*should not be reached");
395   g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL,
396                          "nope");
397
398   test_expected_messages_warning ();
399
400   /* If we don't assert, it won't notice the missing message */
401   exit (0);
402 }
403
404 static void
405 test_expected_messages_unexpected_extra_warning (void)
406 {
407   g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_WARNING,
408                          "This is a * warning");
409   g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL,
410                          "*should not be reached");
411   g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL,
412                          "nope");
413
414   test_expected_messages_warning ();
415
416   g_test_assert_expected_messages ();
417   exit (0);
418 }
419
420 static void
421 test_expected_messages (void)
422 {
423   g_test_trap_subprocess ("/misc/expected-messages/subprocess/warning", 0, 0);
424   g_test_trap_assert_failed ();
425   g_test_trap_assert_stderr ("*This is a * warning*");
426   g_test_trap_assert_stderr_unmatched ("*should not be reached*");
427
428   g_test_trap_subprocess ("/misc/expected-messages/subprocess/expect-warning", 0, 0);
429   g_test_trap_assert_failed ();
430   g_test_trap_assert_stderr_unmatched ("*This is a * warning*");
431   g_test_trap_assert_stderr ("*should not be reached*");
432
433   g_test_trap_subprocess ("/misc/expected-messages/subprocess/wrong-warning", 0, 0);
434   g_test_trap_assert_failed ();
435   g_test_trap_assert_stderr_unmatched ("*should not be reached*");
436   g_test_trap_assert_stderr ("*Did not see expected message CRITICAL*should not be *WARNING*This is a * warning*");
437
438   g_test_trap_subprocess ("/misc/expected-messages/subprocess/expected", 0, 0);
439   g_test_trap_assert_passed ();
440   g_test_trap_assert_stderr ("");
441
442   g_test_trap_subprocess ("/misc/expected-messages/subprocess/null-domain", 0, 0);
443   g_test_trap_assert_passed ();
444   g_test_trap_assert_stderr ("");
445
446   g_test_trap_subprocess ("/misc/expected-messages/subprocess/extra-warning", 0, 0);
447   g_test_trap_assert_passed ();
448   g_test_trap_assert_stderr ("");
449
450   g_test_trap_subprocess ("/misc/expected-messages/subprocess/unexpected-extra-warning", 0, 0);
451   g_test_trap_assert_failed ();
452   g_test_trap_assert_stderr ("*Did not see expected message CRITICAL*nope*");
453 }
454
455 static void
456 test_expected_messages_debug (void)
457 {
458   g_test_expect_message ("Test", G_LOG_LEVEL_WARNING, "warning message");
459   g_log ("Test", G_LOG_LEVEL_DEBUG, "should be ignored");
460   g_log ("Test", G_LOG_LEVEL_WARNING, "warning message");
461   g_test_assert_expected_messages ();
462
463   g_test_expect_message ("Test", G_LOG_LEVEL_DEBUG, "debug message");
464   g_log ("Test", G_LOG_LEVEL_DEBUG, "debug message");
465   g_test_assert_expected_messages ();
466 }
467
468 static void
469 test_dash_p_hidden (void)
470 {
471   if (!g_test_subprocess ())
472     g_assert_not_reached ();
473
474   g_print ("Test /misc/dash-p/subprocess/hidden ran\n");
475 }
476
477 static void
478 test_dash_p_hidden_sub (void)
479 {
480   if (!g_test_subprocess ())
481     g_assert_not_reached ();
482
483   g_print ("Test /misc/dash-p/subprocess/hidden/sub ran\n");
484 }
485
486 /* The rest of the dash_p tests will get run by the toplevel test
487  * process, but they shouldn't do anything there.
488  */
489
490 static void
491 test_dash_p_child (void)
492 {
493   if (!g_test_subprocess ())
494     return;
495
496   g_print ("Test /misc/dash-p/child ran\n");
497 }
498
499 static void
500 test_dash_p_child_sub (void)
501 {
502   if (!g_test_subprocess ())
503     return;
504
505   g_print ("Test /misc/dash-p/child/sub ran\n");
506 }
507
508 static void
509 test_dash_p_child_sub2 (void)
510 {
511   if (!g_test_subprocess ())
512     return;
513
514   g_print ("Test /misc/dash-p/child/sub2 ran\n");
515 }
516
517 static void
518 test_dash_p_child_sub_child (void)
519 {
520   if (!g_test_subprocess ())
521     return;
522
523   g_print ("Test /misc/dash-p/child/subprocess ran\n");
524 }
525
526 static void
527 test_dash_p (void)
528 {
529   g_test_trap_subprocess ("/misc/dash-p/subprocess/hidden", 0, 0);
530   g_test_trap_assert_passed ();
531   g_test_trap_assert_stdout ("*Test /misc/dash-p/subprocess/hidden ran*");
532   g_test_trap_assert_stdout_unmatched ("*Test /misc/dash-p/subprocess/hidden/sub ran*");
533   g_test_trap_assert_stdout_unmatched ("*Test /misc/dash-p/subprocess/hidden/sub2 ran*");
534   g_test_trap_assert_stdout_unmatched ("*Test /misc/dash-p/subprocess/hidden/sub/subprocess ran*");
535   g_test_trap_assert_stdout_unmatched ("*Test /misc/dash-p/child*");
536
537   g_test_trap_subprocess ("/misc/dash-p/subprocess/hidden/sub", 0, 0);
538   g_test_trap_assert_passed ();
539   g_test_trap_assert_stdout ("*Test /misc/dash-p/subprocess/hidden/sub ran*");
540   g_test_trap_assert_stdout_unmatched ("*Test /misc/dash-p/subprocess/hidden ran*");
541   g_test_trap_assert_stdout_unmatched ("*Test /misc/dash-p/subprocess/hidden/sub2 ran*");
542   g_test_trap_assert_stdout_unmatched ("*Test /misc/dash-p/subprocess/hidden/subprocess ran*");
543   g_test_trap_assert_stdout_unmatched ("*Test /misc/dash-p/child*");
544
545   g_test_trap_subprocess ("/misc/dash-p/child", 0, 0);
546   g_test_trap_assert_passed ();
547   g_test_trap_assert_stdout ("*Test /misc/dash-p/child ran*");
548   g_test_trap_assert_stdout ("*Test /misc/dash-p/child/sub ran*");
549   g_test_trap_assert_stdout ("*Test /misc/dash-p/child/sub2 ran*");
550   g_test_trap_assert_stdout_unmatched ("*Test /misc/dash-p/child/subprocess ran*");
551   g_test_trap_assert_stdout_unmatched ("*Test /misc/dash-p/subprocess/hidden*");
552
553   g_test_trap_subprocess ("/misc/dash-p/child/sub", 0, 0);
554   g_test_trap_assert_passed ();
555   g_test_trap_assert_stdout ("*Test /misc/dash-p/child/sub ran*");
556   g_test_trap_assert_stdout_unmatched ("*Test /misc/dash-p/child ran*");
557   g_test_trap_assert_stdout_unmatched ("*Test /misc/dash-p/child/sub2 ran*");
558   g_test_trap_assert_stdout_unmatched ("*Test /misc/dash-p/child/subprocess ran*");
559   g_test_trap_assert_stdout_unmatched ("*Test /misc/dash-p/subprocess/hidden*");
560 }
561
562 static void
563 test_nonfatal (void)
564 {
565   if (g_test_subprocess ())
566     {
567       g_test_set_nonfatal_assertions ();
568       g_assert_cmpint (4, ==, 5);
569       g_print ("The End\n");
570       return;
571     }
572   g_test_trap_subprocess (NULL, 0, 0);
573   g_test_trap_assert_failed ();
574   g_test_trap_assert_stderr ("*assertion failed*4 == 5*");
575   g_test_trap_assert_stdout ("*The End*");
576 }
577
578 static void
579 test_skip (void)
580 {
581   g_test_skip ("Skipped should count as passed, not failed");
582 }
583
584 static void
585 test_pass (void)
586 {
587 }
588
589 static const char *argv0;
590
591 static void
592 test_skip_all (void)
593 {
594   GPtrArray *argv;
595   GError *error = NULL;
596   int status;
597
598   argv = g_ptr_array_new ();
599   g_ptr_array_add (argv, (char *) argv0);
600   g_ptr_array_add (argv, "--GTestSubprocess");
601   g_ptr_array_add (argv, "-p");
602   g_ptr_array_add (argv, "/misc/skip");
603   g_ptr_array_add (argv, NULL);
604
605   g_spawn_sync (NULL, (char **) argv->pdata, NULL,
606                 G_SPAWN_STDOUT_TO_DEV_NULL | G_SPAWN_STDERR_TO_DEV_NULL,
607                 NULL, NULL, NULL, NULL, &status,
608                 &error);
609   g_assert_no_error (error);
610
611   g_spawn_check_exit_status (status, &error);
612   g_assert_error (error, G_SPAWN_EXIT_ERROR, 77);
613   g_clear_error (&error);
614
615   g_ptr_array_set_size (argv, 0);
616   g_ptr_array_add (argv, (char *) argv0);
617   g_ptr_array_add (argv, "--GTestSubprocess");
618   g_ptr_array_add (argv, "-p");
619   g_ptr_array_add (argv, "/misc/skip");
620   g_ptr_array_add (argv, "-p");
621   g_ptr_array_add (argv, "/misc/skip-all/subprocess/skip1");
622   g_ptr_array_add (argv, "-p");
623   g_ptr_array_add (argv, "/misc/skip-all/subprocess/skip2");
624   g_ptr_array_add (argv, NULL);
625
626   g_spawn_sync (NULL, (char **) argv->pdata, NULL,
627                 G_SPAWN_STDOUT_TO_DEV_NULL | G_SPAWN_STDERR_TO_DEV_NULL,
628                 NULL, NULL, NULL, NULL, &status,
629                 &error);
630   g_assert_no_error (error);
631
632   g_spawn_check_exit_status (status, &error);
633   g_assert_error (error, G_SPAWN_EXIT_ERROR, 77);
634   g_clear_error (&error);
635
636   g_ptr_array_set_size (argv, 0);
637   g_ptr_array_add (argv, (char *) argv0);
638   g_ptr_array_add (argv, "--GTestSubprocess");
639   g_ptr_array_add (argv, "-p");
640   g_ptr_array_add (argv, "/misc/skip");
641   g_ptr_array_add (argv, "-p");
642   g_ptr_array_add (argv, "/misc/skip-all/subprocess/pass");
643   g_ptr_array_add (argv, "-p");
644   g_ptr_array_add (argv, "/misc/skip-all/subprocess/skip1");
645   g_ptr_array_add (argv, NULL);
646
647   g_spawn_sync (NULL, (char **) argv->pdata, NULL,
648                 G_SPAWN_STDOUT_TO_DEV_NULL | G_SPAWN_STDERR_TO_DEV_NULL,
649                 NULL, NULL, NULL, NULL, &status,
650                 &error);
651   g_assert_no_error (error);
652
653   g_spawn_check_exit_status (status, &error);
654   g_assert_no_error (error);
655
656   g_ptr_array_unref (argv);
657 }
658
659 int
660 main (int   argc,
661       char *argv[])
662 {
663   argv0 = argv[0];
664
665   g_test_init (&argc, &argv, NULL);
666
667   g_test_add_func ("/random-generator/rand-1", test_rand1);
668   g_test_add_func ("/random-generator/rand-2", test_rand2);
669   g_test_add_func ("/random-generator/random-conversions", test_random_conversions);
670   g_test_add_func ("/misc/assertions", test_assertions);
671   g_test_add_func ("/misc/assertions/subprocess/bad_cmpstr", test_assertions_bad_cmpstr);
672   g_test_add_func ("/misc/assertions/subprocess/bad_cmpint", test_assertions_bad_cmpint);
673   g_test_add_data_func ("/misc/test-data", (void*) 0xc0c0baba, test_data_test);
674   g_test_add ("/misc/primetoul", Fixturetest, (void*) 0xc0cac01a, fixturetest_setup, fixturetest_test, fixturetest_teardown);
675   if (g_test_perf())
676     g_test_add_func ("/misc/timer", test_timer);
677
678 #ifdef G_OS_UNIX
679   g_test_add_func ("/forking/fail assertion", test_fork_fail);
680   g_test_add_func ("/forking/patterns", test_fork_patterns);
681   if (g_test_slow())
682     g_test_add_func ("/forking/timeout", test_fork_timeout);
683 #endif
684
685   g_test_add_func ("/trap_subprocess/fail", test_subprocess_fail);
686   g_test_add_func ("/trap_subprocess/no-such-test", test_subprocess_no_such_test);
687   if (g_test_slow ())
688     g_test_add_func ("/trap_subprocess/timeout", test_subprocess_timeout);
689
690   g_test_add_func ("/trap_subprocess/patterns", test_subprocess_patterns);
691
692   g_test_add_func ("/misc/fatal-log-handler", test_fatal_log_handler);
693   g_test_add_func ("/misc/fatal-log-handler/subprocess/critical-pass", test_fatal_log_handler_critical_pass);
694   g_test_add_func ("/misc/fatal-log-handler/subprocess/error-fail", test_fatal_log_handler_error_fail);
695   g_test_add_func ("/misc/fatal-log-handler/subprocess/critical-fail", test_fatal_log_handler_critical_fail);
696
697   g_test_add_func ("/misc/expected-messages", test_expected_messages);
698   g_test_add_func ("/misc/expected-messages/subprocess/warning", test_expected_messages_warning);
699   g_test_add_func ("/misc/expected-messages/subprocess/expect-warning", test_expected_messages_expect_warning);
700   g_test_add_func ("/misc/expected-messages/subprocess/wrong-warning", test_expected_messages_wrong_warning);
701   g_test_add_func ("/misc/expected-messages/subprocess/expected", test_expected_messages_expected);
702   g_test_add_func ("/misc/expected-messages/subprocess/null-domain", test_expected_messages_null_domain);
703   g_test_add_func ("/misc/expected-messages/subprocess/extra-warning", test_expected_messages_extra_warning);
704   g_test_add_func ("/misc/expected-messages/subprocess/unexpected-extra-warning", test_expected_messages_unexpected_extra_warning);
705   g_test_add_func ("/misc/expected-messages/expect-error", test_expected_messages_expect_error);
706   g_test_add_func ("/misc/expected-messages/skip-debug", test_expected_messages_debug);
707
708   g_test_add_func ("/misc/dash-p", test_dash_p);
709   g_test_add_func ("/misc/dash-p/child", test_dash_p_child);
710   g_test_add_func ("/misc/dash-p/child/sub", test_dash_p_child_sub);
711   g_test_add_func ("/misc/dash-p/child/sub/subprocess", test_dash_p_child_sub_child);
712   g_test_add_func ("/misc/dash-p/child/sub/subprocess/child", test_dash_p_child_sub_child);
713   g_test_add_func ("/misc/dash-p/child/sub2", test_dash_p_child_sub2);
714   g_test_add_func ("/misc/dash-p/subprocess/hidden", test_dash_p_hidden);
715   g_test_add_func ("/misc/dash-p/subprocess/hidden/sub", test_dash_p_hidden_sub);
716
717   g_test_add_func ("/misc/nonfatal", test_nonfatal);
718
719   g_test_add_func ("/misc/skip", test_skip);
720   g_test_add_func ("/misc/skip-all", test_skip_all);
721   g_test_add_func ("/misc/skip-all/subprocess/skip1", test_skip);
722   g_test_add_func ("/misc/skip-all/subprocess/skip2", test_skip);
723   g_test_add_func ("/misc/skip-all/subprocess/pass", test_pass);
724
725   return g_test_run();
726 }