LCOV - code coverage report
Current view: top level - glib/glib/tests - testing.c (source / functions) Hit Total Coverage
Test: unnamed Lines: 1703 1808 94.2 %
Date: 2024-04-16 05:15:53 Functions: 59 82 72.0 %
Branches: 27 50 54.0 %

           Branch data     Line data    Source code
       1                 :            : /* GLib testing framework examples and tests
       2                 :            :  * Copyright (C) 2007 Imendio AB
       3                 :            :  * Authors: Tim Janik
       4                 :            :  *
       5                 :            :  * SPDX-License-Identifier: LicenseRef-old-glib-tests
       6                 :            :  *
       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.
      10                 :            :  *
      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.
      14                 :            :  *
      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.
      23                 :            :  */
      24                 :            : 
      25                 :            : #include "config.h"
      26                 :            : 
      27                 :            : /* We want to distinguish between messages originating from libglib
      28                 :            :  * and messages originating from this program.
      29                 :            :  */
      30                 :            : #undef G_LOG_DOMAIN
      31                 :            : #define G_LOG_DOMAIN "testing"
      32                 :            : 
      33                 :            : #include <glib.h>
      34                 :            : #include <locale.h>
      35                 :            : #include <stdlib.h>
      36                 :            : #include <string.h>
      37                 :            : 
      38                 :            : #define TAP_VERSION G_STRINGIFY (13)
      39                 :            : #define TAP_SUBTEST_PREFIX "#    "
      40                 :            : 
      41                 :            : /* test assertion variants */
      42                 :            : static void
      43                 :          0 : test_assertions_bad_cmpvariant_types (void)
      44                 :            : {
      45                 :            :   GVariant *v1, *v2;
      46                 :            : 
      47                 :          0 :   v1 = g_variant_new_boolean (TRUE);
      48                 :          0 :   v2 = g_variant_new_string ("hello");
      49                 :            : 
      50                 :          0 :   g_assert_cmpvariant (v1, v2);
      51                 :            : 
      52                 :          0 :   g_variant_unref (v2);
      53                 :          0 :   g_variant_unref (v1);
      54                 :            : 
      55                 :          0 :   exit (0);
      56                 :            : }
      57                 :            : 
      58                 :            : static void
      59                 :          0 : test_assertions_bad_cmpvariant_values (void)
      60                 :            : {
      61                 :            :   GVariant *v1, *v2;
      62                 :            : 
      63                 :          0 :   v1 = g_variant_new_string ("goodbye");
      64                 :          0 :   v2 = g_variant_new_string ("hello");
      65                 :            : 
      66                 :          0 :   g_assert_cmpvariant (v1, v2);
      67                 :            : 
      68                 :          0 :   g_variant_unref (v2);
      69                 :          0 :   g_variant_unref (v1);
      70                 :            : 
      71                 :          0 :   exit (0);
      72                 :            : }
      73                 :            : 
      74                 :            : static void
      75                 :          0 : test_assertions_bad_cmpstrv_null1 (void)
      76                 :            : {
      77                 :          0 :   const char *strv[] = { "one", "two", "three", NULL };
      78                 :          0 :   g_assert_cmpstrv (strv, NULL);
      79                 :          0 :   exit (0);
      80                 :            : }
      81                 :            : 
      82                 :            : static void
      83                 :          0 : test_assertions_bad_cmpstrv_null2 (void)
      84                 :            : {
      85                 :          0 :   const char *strv[] = { "one", "two", "three", NULL };
      86                 :          0 :   g_assert_cmpstrv (NULL, strv);
      87                 :          0 :   exit (0);
      88                 :            : }
      89                 :            : 
      90                 :            : static void
      91                 :          0 : test_assertions_bad_cmpstrv_length (void)
      92                 :            : {
      93                 :          0 :   const char *strv1[] = { "one", "two", "three", NULL };
      94                 :          0 :   const char *strv2[] = { "one", "two", NULL };
      95                 :          0 :   g_assert_cmpstrv (strv1, strv2);
      96                 :          0 :   exit (0);
      97                 :            : }
      98                 :            : 
      99                 :            : static void
     100                 :          0 : test_assertions_bad_cmpstrv_values (void)
     101                 :            : {
     102                 :          0 :   const char *strv1[] = { "one", "two", "three", NULL };
     103                 :          0 :   const char *strv2[] = { "one", "too", "three", NULL };
     104                 :          0 :   g_assert_cmpstrv (strv1, strv2);
     105                 :          0 :   exit (0);
     106                 :            : }
     107                 :            : 
     108                 :            : static void
     109                 :          0 : test_assertions_bad_cmpstr (void)
     110                 :            : {
     111                 :          0 :   g_assert_cmpstr ("fzz", !=, "fzz");
     112                 :          0 :   exit (0);
     113                 :            : }
     114                 :            : 
     115                 :            : static void
     116                 :          0 : test_assertions_bad_cmpint (void)
     117                 :            : {
     118                 :          0 :   g_assert_cmpint (4, !=, 4);
     119                 :          0 :   exit (0);
     120                 :            : }
     121                 :            : 
     122                 :            : static void
     123                 :          0 : test_assertions_bad_cmpmem_len (void)
     124                 :            : {
     125                 :          0 :   g_assert_cmpmem ("foo", 3, "foot", 4);
     126                 :          0 :   exit (0);
     127                 :            : }
     128                 :            : 
     129                 :            : static void
     130                 :          0 : test_assertions_bad_cmpmem_data (void)
     131                 :            : {
     132                 :          0 :   g_assert_cmpmem ("foo", 3, "fzz", 3);
     133                 :          0 :   exit (0);
     134                 :            : }
     135                 :            : 
     136                 :            : static void
     137                 :          0 : test_assertions_bad_cmpmem_null (void)
     138                 :            : {
     139                 :          0 :   g_assert_cmpmem (NULL, 3, NULL, 3);
     140                 :          0 :   exit (0);
     141                 :            : }
     142                 :            : 
     143                 :            : static void
     144                 :          0 : test_assertions_bad_cmpfloat_epsilon (void)
     145                 :            : {
     146                 :          0 :   g_assert_cmpfloat_with_epsilon (3.14, 3.15, 0.001);
     147                 :          0 :   exit (0);
     148                 :            : }
     149                 :            : 
     150                 :            : /* Emulates something like rmdir() failing. */
     151                 :            : static int
     152                 :          0 : return_errno (void)
     153                 :            : {
     154                 :          0 :   errno = ERANGE;  /* arbitrary non-zero value */
     155                 :          0 :   return -1;
     156                 :            : }
     157                 :            : 
     158                 :            : /* Emulates something like rmdir() succeeding. */
     159                 :            : static int
     160                 :          1 : return_no_errno (void)
     161                 :            : {
     162                 :          1 :   return 0;
     163                 :            : }
     164                 :            : 
     165                 :            : static void
     166                 :          0 : test_assertions_bad_no_errno (void)
     167                 :            : {
     168                 :          0 :   g_assert_no_errno (return_errno ());
     169                 :          0 : }
     170                 :            : 
     171                 :            : static void
     172                 :          1 : test_assertions (void)
     173                 :            : {
     174                 :          1 :   const char *strv1[] = { "one", "two", "three", NULL };
     175                 :          1 :   const char *strv2[] = { "one", "two", "three", NULL };
     176                 :            :   GVariant *v1, *v2;
     177                 :            :   gchar *fuu;
     178                 :            : 
     179                 :          1 :   g_assert_cmpint (1, >, 0);
     180                 :          1 :   g_assert_cmphex (2, ==, 2);
     181                 :          1 :   g_assert_cmpfloat (3.3, !=, 7);
     182                 :          1 :   g_assert_cmpfloat (7, <=, 3 + 4);
     183                 :          1 :   g_assert_cmpfloat_with_epsilon (3.14, 3.15, 0.01);
     184                 :          1 :   g_assert_cmpfloat_with_epsilon (3.14159, 3.1416, 0.0001);
     185                 :            :   g_assert (TRUE);
     186                 :            :   g_assert_true (TRUE);
     187                 :          1 :   g_assert_cmpstr ("foo", !=, "faa");
     188                 :          1 :   fuu = g_strdup_printf ("f%s", "uu");
     189                 :          1 :   g_test_queue_free (fuu);
     190                 :          1 :   g_assert_cmpstr ("foo", !=, fuu);
     191                 :          1 :   g_assert_cmpstr ("fuu", ==, fuu);
     192                 :          1 :   g_assert_cmpstr (NULL, <, "");
     193                 :          1 :   g_assert_cmpstr (NULL, ==, NULL);
     194                 :          1 :   g_assert_cmpstr ("", >, NULL);
     195                 :          1 :   g_assert_cmpstr ("foo", <, "fzz");
     196                 :          1 :   g_assert_cmpstr ("fzz", >, "faa");
     197                 :          1 :   g_assert_cmpstr ("fzz", ==, "fzz");
     198                 :          1 :   g_assert_cmpmem ("foo", 3, "foot", 3);
     199                 :          1 :   g_assert_cmpmem (NULL, 0, NULL, 0);
     200                 :          1 :   g_assert_cmpmem (NULL, 0, "foot", 0);
     201                 :          1 :   g_assert_cmpmem ("foo", 0, NULL, 0);
     202                 :          1 :   g_assert_no_errno (return_no_errno ());
     203                 :            : 
     204                 :          1 :   g_assert_cmpstrv (NULL, NULL);
     205                 :          4 :   g_assert_cmpstrv (strv1, strv2);
     206                 :            : 
     207                 :          1 :   v1 = g_variant_new_parsed ("['hello', 'there']");
     208                 :          1 :   v2 = g_variant_new_parsed ("['hello', 'there']");
     209                 :            : 
     210                 :          1 :   g_assert_cmpvariant (v1, v1);
     211                 :          1 :   g_assert_cmpvariant (v1, v2);
     212                 :            : 
     213                 :          1 :   g_variant_unref (v2);
     214                 :          1 :   g_variant_unref (v1);
     215                 :            : 
     216                 :          1 :   g_test_trap_subprocess ("/misc/assertions/subprocess/bad_cmpvariant_types", 0,
     217                 :            :                           G_TEST_SUBPROCESS_DEFAULT);
     218                 :          1 :   g_test_trap_assert_failed ();
     219                 :          1 :   g_test_trap_assert_stderr ("*assertion failed*");
     220                 :            : 
     221                 :          1 :   g_test_trap_subprocess ("/misc/assertions/subprocess/bad_cmpvariant_values", 0,
     222                 :            :                           G_TEST_SUBPROCESS_DEFAULT);
     223                 :          1 :   g_test_trap_assert_failed ();
     224                 :          1 :   g_test_trap_assert_stderr ("*assertion failed*");
     225                 :            : 
     226                 :          1 :   g_test_trap_subprocess ("/misc/assertions/subprocess/bad_cmpstr", 0,
     227                 :            :                           G_TEST_SUBPROCESS_DEFAULT);
     228                 :          1 :   g_test_trap_assert_failed ();
     229                 :          1 :   g_test_trap_assert_stderr ("*assertion failed*");
     230                 :            : 
     231                 :          1 :   g_test_trap_subprocess ("/misc/assertions/subprocess/bad_cmpstrv_null1", 0,
     232                 :            :                           G_TEST_SUBPROCESS_DEFAULT);
     233                 :          1 :   g_test_trap_assert_failed ();
     234                 :          1 :   g_test_trap_assert_stderr ("*assertion failed*");
     235                 :            : 
     236                 :          1 :   g_test_trap_subprocess ("/misc/assertions/subprocess/bad_cmpstrv_null2", 0,
     237                 :            :                           G_TEST_SUBPROCESS_DEFAULT);
     238                 :          1 :   g_test_trap_assert_failed ();
     239                 :          1 :   g_test_trap_assert_stderr ("*assertion failed*");
     240                 :            : 
     241                 :          1 :   g_test_trap_subprocess ("/misc/assertions/subprocess/bad_cmpstrv_length", 0,
     242                 :            :                           G_TEST_SUBPROCESS_DEFAULT);
     243                 :          1 :   g_test_trap_assert_failed ();
     244                 :          1 :   g_test_trap_assert_stderr ("*assertion failed*");
     245                 :            : 
     246                 :          1 :   g_test_trap_subprocess ("/misc/assertions/subprocess/bad_cmpstrv_values", 0,
     247                 :            :                           G_TEST_SUBPROCESS_DEFAULT);
     248                 :          1 :   g_test_trap_assert_failed ();
     249                 :          1 :   g_test_trap_assert_stderr ("*assertion failed*");
     250                 :            : 
     251                 :          1 :   g_test_trap_subprocess ("/misc/assertions/subprocess/bad_cmpint", 0,
     252                 :            :                           G_TEST_SUBPROCESS_DEFAULT);
     253                 :          1 :   g_test_trap_assert_failed ();
     254                 :          1 :   g_test_trap_assert_stderr ("*assertion failed*");
     255                 :            : 
     256                 :          1 :   g_test_trap_subprocess ("/misc/assertions/subprocess/bad_cmpmem_len", 0,
     257                 :            :                           G_TEST_SUBPROCESS_DEFAULT);
     258                 :          1 :   g_test_trap_assert_failed ();
     259                 :          1 :   g_test_trap_assert_stderr ("*assertion failed*len*");
     260                 :            : 
     261                 :          1 :   g_test_trap_subprocess ("/misc/assertions/subprocess/bad_cmpmem_data", 0,
     262                 :            :                           G_TEST_SUBPROCESS_DEFAULT);
     263                 :          1 :   g_test_trap_assert_failed ();
     264                 :          1 :   g_test_trap_assert_stderr ("*assertion failed*");
     265                 :          1 :   g_test_trap_assert_stderr_unmatched ("*assertion failed*len*");
     266                 :            : 
     267                 :          1 :   g_test_trap_subprocess ("/misc/assertions/subprocess/bad_cmpmem_null", 0,
     268                 :            :                           G_TEST_SUBPROCESS_DEFAULT);
     269                 :          1 :   g_test_trap_assert_failed ();
     270                 :          1 :   g_test_trap_assert_stderr ("*assertion failed*NULL*");
     271                 :            : 
     272                 :          1 :   g_test_trap_subprocess ("/misc/assertions/subprocess/bad_cmpfloat_epsilon", 0,
     273                 :            :                           G_TEST_SUBPROCESS_DEFAULT);
     274                 :          1 :   g_test_trap_assert_failed ();
     275                 :          1 :   g_test_trap_assert_stderr ("*assertion failed*");
     276                 :            : 
     277                 :          1 :   g_test_trap_subprocess ("/misc/assertions/subprocess/bad_no_errno", 0,
     278                 :            :                           G_TEST_SUBPROCESS_DEFAULT);
     279                 :          1 :   g_test_trap_assert_failed ();
     280                 :          1 :   g_test_trap_assert_stderr ("*assertion failed*");
     281                 :          1 : }
     282                 :            : 
     283                 :            : /* test g_test_timer* API */
     284                 :            : static void
     285                 :          0 : test_timer (void)
     286                 :            : {
     287                 :            :   double ttime;
     288                 :          0 :   g_test_timer_start();
     289                 :          0 :   g_assert_cmpfloat (g_test_timer_last(), ==, 0);
     290                 :          0 :   g_usleep (25 * 1000);
     291                 :          0 :   ttime = g_test_timer_elapsed();
     292                 :          0 :   g_assert_cmpfloat (ttime, >, 0);
     293                 :          0 :   g_assert_cmpfloat (g_test_timer_last(), ==, ttime);
     294                 :          0 :   g_test_minimized_result (ttime, "timer-test-time: %fsec", ttime);
     295                 :          0 :   g_test_maximized_result (5, "bogus-quantity: %ddummies", 5); /* simple API test */
     296                 :          0 : }
     297                 :            : 
     298                 :            : #ifdef G_OS_UNIX
     299                 :            : G_GNUC_BEGIN_IGNORE_DEPRECATIONS
     300                 :            : 
     301                 :            : /* fork out for a failing test */
     302                 :            : static void
     303                 :          1 : test_fork_fail (void)
     304                 :            : {
     305         [ -  + ]:          1 :   if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR))
     306                 :            :     {
     307                 :            :       g_assert_not_reached();
     308                 :            :     }
     309                 :          1 :   g_test_trap_assert_failed();
     310                 :          1 :   g_test_trap_assert_stderr ("*ERROR*test_fork_fail*should not be reached*");
     311                 :          1 : }
     312                 :            : 
     313                 :            : /* fork out to assert stdout and stderr patterns */
     314                 :            : static void
     315                 :          1 : test_fork_patterns (void)
     316                 :            : {
     317         [ +  + ]:          1 :   if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDOUT | G_TEST_TRAP_SILENCE_STDERR))
     318                 :            :     {
     319                 :          1 :       g_print ("some stdout text: somagic17\n");
     320                 :          1 :       g_printerr ("some stderr text: semagic43\n");
     321                 :          1 :       exit (0);
     322                 :            :     }
     323                 :          1 :   g_test_trap_assert_passed();
     324                 :          1 :   g_test_trap_assert_stdout ("*somagic17*");
     325                 :          1 :   g_test_trap_assert_stderr ("*semagic43*");
     326                 :          1 : }
     327                 :            : 
     328                 :            : /* fork out for a timeout test */
     329                 :            : static void
     330                 :          0 : test_fork_timeout (void)
     331                 :            : {
     332                 :            :   /* allow child to run for only a fraction of a second */
     333         [ #  # ]:          0 :   if (g_test_trap_fork (0.11 * 1000000, G_TEST_TRAP_DEFAULT))
     334                 :            :     {
     335                 :            :       /* loop and sleep forever */
     336                 :            :       while (TRUE)
     337                 :          0 :         g_usleep (1000 * 1000);
     338                 :            :     }
     339                 :          0 :   g_test_trap_assert_failed();
     340                 :          0 :   g_assert_true (g_test_trap_reached_timeout());
     341                 :          0 : }
     342                 :            : 
     343                 :            : G_GNUC_END_IGNORE_DEPRECATIONS
     344                 :            : #endif /* G_OS_UNIX */
     345                 :            : 
     346                 :            : static void
     347                 :          1 : test_subprocess_fail (void)
     348                 :            : {
     349         [ -  + ]:          1 :   if (g_test_subprocess ())
     350                 :            :     {
     351                 :            :       g_assert_not_reached ();
     352                 :            :       return;
     353                 :            :     }
     354                 :            : 
     355                 :          1 :   g_test_trap_subprocess (NULL, 0, G_TEST_SUBPROCESS_DEFAULT);
     356                 :          1 :   g_test_trap_assert_failed ();
     357                 :          1 :   g_test_trap_assert_stderr ("*ERROR*test_subprocess_fail*should not be reached*");
     358                 :            : }
     359                 :            : 
     360                 :            : static void
     361                 :          1 : test_subprocess_no_such_test (void)
     362                 :            : {
     363         [ -  + ]:          1 :   if (g_test_subprocess ())
     364                 :            :     {
     365                 :          0 :       g_test_trap_subprocess ("/trap_subprocess/this-test-does-not-exist", 0,
     366                 :            :                               G_TEST_SUBPROCESS_DEFAULT);
     367                 :            :       g_assert_not_reached ();
     368                 :            :       return;
     369                 :            :     }
     370                 :          1 :   g_test_trap_subprocess (NULL, 0, G_TEST_SUBPROCESS_DEFAULT);
     371                 :          1 :   g_test_trap_assert_failed ();
     372                 :          1 :   g_test_trap_assert_stderr ("*test does not exist*");
     373                 :          1 :   g_test_trap_assert_stderr_unmatched ("*should not be reached*");
     374                 :            : }
     375                 :            : 
     376                 :            : static void
     377                 :          2 : test_subprocess_patterns (void)
     378                 :            : {
     379         [ +  + ]:          2 :   if (g_test_subprocess ())
     380                 :            :     {
     381                 :          1 :       g_print ("some stdout text: somagic17\n");
     382                 :          1 :       g_printerr ("some stderr text: semagic43\n");
     383                 :          1 :       exit (0);
     384                 :            :     }
     385                 :          1 :   g_test_trap_subprocess (NULL, 0, G_TEST_SUBPROCESS_DEFAULT);
     386                 :          1 :   g_test_trap_assert_passed ();
     387                 :          1 :   g_test_trap_assert_stdout ("*somagic17*");
     388                 :          1 :   g_test_trap_assert_stderr ("*semagic43*");
     389                 :          1 : }
     390                 :            : 
     391                 :            : static void
     392                 :          1 : test_subprocess_timeout (void)
     393                 :            : {
     394         [ -  + ]:          1 :   if (g_test_subprocess ())
     395                 :            :     {
     396                 :            :       /* loop and sleep forever */
     397                 :            :       while (TRUE)
     398                 :          0 :         g_usleep (G_USEC_PER_SEC);
     399                 :            :       return;
     400                 :            :     }
     401                 :            :   /* allow child to run for only a fraction of a second */
     402                 :          1 :   g_test_trap_subprocess (NULL, 0.05 * G_USEC_PER_SEC, G_TEST_SUBPROCESS_DEFAULT);
     403                 :          1 :   g_test_trap_assert_failed ();
     404                 :          1 :   g_assert_true (g_test_trap_reached_timeout ());
     405                 :            : }
     406                 :            : 
     407                 :            : static void
     408                 :          2 : test_subprocess_envp (void)
     409                 :            : {
     410                 :          2 :   char **envp = NULL;
     411                 :            : 
     412         [ +  + ]:          2 :   if (g_test_subprocess ())
     413                 :            :     {
     414                 :          1 :       g_assert_cmpstr (g_getenv ("TEST_SUBPROCESS_VARIABLE"), ==, "definitely set");
     415                 :          1 :       return;
     416                 :            :     }
     417                 :            : 
     418                 :          1 :   envp = g_get_environ ();
     419                 :          1 :   envp = g_environ_setenv (g_steal_pointer (&envp), "TEST_SUBPROCESS_VARIABLE", "definitely set", TRUE);
     420                 :          1 :   g_test_trap_subprocess_with_envp (NULL, (const gchar * const *) envp,
     421                 :            :                                     0, G_TEST_SUBPROCESS_DEFAULT);
     422                 :          1 :   g_test_trap_assert_passed ();
     423                 :          1 :   g_strfreev (envp);
     424                 :            : }
     425                 :            : 
     426                 :            : /* run a test with fixture setup and teardown */
     427                 :            : typedef struct {
     428                 :            :   guint  seed;
     429                 :            :   guint  prime;
     430                 :            :   gchar *msg;
     431                 :            : } Fixturetest;
     432                 :            : static void
     433                 :          1 : fixturetest_setup (Fixturetest  *fix,
     434                 :            :                    gconstpointer test_data)
     435                 :            : {
     436                 :          1 :   g_assert_true (test_data == (void*) 0xc0cac01a);
     437                 :          1 :   fix->seed = 18;
     438                 :          1 :   fix->prime = 19;
     439                 :          1 :   fix->msg = g_strdup_printf ("%d", fix->prime);
     440                 :          1 : }
     441                 :            : static void
     442                 :          1 : fixturetest_test (Fixturetest  *fix,
     443                 :            :                   gconstpointer test_data)
     444                 :            : {
     445                 :          1 :   guint prime = g_spaced_primes_closest (fix->seed);
     446                 :          1 :   g_assert_cmpint (prime, ==, fix->prime);
     447                 :          1 :   prime = g_ascii_strtoull (fix->msg, NULL, 0);
     448                 :          1 :   g_assert_cmpint (prime, ==, fix->prime);
     449                 :          1 :   g_assert_true (test_data == (void*) 0xc0cac01a);
     450                 :          1 : }
     451                 :            : static void
     452                 :          1 : fixturetest_teardown (Fixturetest  *fix,
     453                 :            :                       gconstpointer test_data)
     454                 :            : {
     455                 :          1 :   g_assert_true (test_data == (void*) 0xc0cac01a);
     456                 :          1 :   g_free (fix->msg);
     457                 :          1 : }
     458                 :            : 
     459                 :            : static struct {
     460                 :            :   int bit, vint1, vint2, irange;
     461                 :            :   long double vdouble, drange;
     462                 :            : } shared_rand_state;
     463                 :            : 
     464                 :            : static void
     465                 :          1 : test_rand1 (void)
     466                 :            : {
     467                 :          1 :   shared_rand_state.bit = g_test_rand_bit();
     468                 :          1 :   shared_rand_state.vint1 = g_test_rand_int();
     469                 :          1 :   shared_rand_state.vint2 = g_test_rand_int();
     470                 :          1 :   g_assert_cmpint (shared_rand_state.vint1, !=, shared_rand_state.vint2);
     471                 :          1 :   shared_rand_state.irange = g_test_rand_int_range (17, 35);
     472                 :          1 :   g_assert_cmpint (shared_rand_state.irange, >=, 17);
     473                 :          1 :   g_assert_cmpint (shared_rand_state.irange, <=, 35);
     474                 :          1 :   shared_rand_state.vdouble = g_test_rand_double();
     475                 :          1 :   shared_rand_state.drange = g_test_rand_double_range (-999, +17);
     476                 :          1 :   g_assert_cmpfloat (shared_rand_state.drange, >=, -999);
     477                 :          1 :   g_assert_cmpfloat (shared_rand_state.drange, <=, +17);
     478                 :          1 : }
     479                 :            : 
     480                 :            : static void
     481                 :          1 : test_rand2 (void)
     482                 :            : {
     483                 :            :   /* this test only works if run after test1.
     484                 :            :    * we do this to check that random number generators
     485                 :            :    * are reseeded upon fixture setup.
     486                 :            :    */
     487                 :          1 :   g_assert_cmpint (shared_rand_state.bit, ==, g_test_rand_bit());
     488                 :          1 :   g_assert_cmpint (shared_rand_state.vint1, ==, g_test_rand_int());
     489                 :          1 :   g_assert_cmpint (shared_rand_state.vint2, ==, g_test_rand_int());
     490                 :          1 :   g_assert_cmpint (shared_rand_state.irange, ==, g_test_rand_int_range (17, 35));
     491                 :          1 :   g_assert_cmpfloat (shared_rand_state.vdouble, ==, g_test_rand_double());
     492                 :          1 :   g_assert_cmpfloat (shared_rand_state.drange, ==, g_test_rand_double_range (-999, +17));
     493                 :          1 : }
     494                 :            : 
     495                 :            : static void
     496                 :          1 : test_data_test (gconstpointer test_data)
     497                 :            : {
     498                 :          1 :   g_assert_true (test_data == (void*) 0xc0c0baba);
     499                 :          1 : }
     500                 :            : 
     501                 :            : static void
     502                 :          1 : test_random_conversions (void)
     503                 :            : {
     504                 :            :   /* very simple conversion test using random numbers */
     505                 :          1 :   int vint = g_test_rand_int();
     506                 :          1 :   char *err, *str = g_strdup_printf ("%d", vint);
     507                 :          1 :   gint64 vint64 = g_ascii_strtoll (str, &err, 10);
     508                 :          1 :   g_assert_cmpint (vint, ==, vint64);
     509                 :          1 :   g_assert_true (!err || *err == 0);
     510                 :          1 :   g_free (str);
     511                 :          1 : }
     512                 :            : 
     513                 :            : static gboolean
     514                 :          2 : fatal_handler (const gchar    *log_domain,
     515                 :            :                GLogLevelFlags  log_level,
     516                 :            :                const gchar    *message,
     517                 :            :                gpointer        user_data)
     518                 :            : {
     519                 :          2 :   return FALSE;
     520                 :            : }
     521                 :            : 
     522                 :            : static void
     523                 :          1 : test_fatal_log_handler_critical_pass (void)
     524                 :            : {
     525                 :          1 :   g_test_log_set_fatal_handler (fatal_handler, NULL);
     526   [ -  +  -  -  :          1 :   g_str_has_prefix (NULL, "file://");
                   -  - ]
     527                 :          1 :   g_critical ("Test passing");
     528                 :          1 :   exit (0);
     529                 :            : }
     530                 :            : 
     531                 :            : static void
     532                 :          0 : test_fatal_log_handler_error_fail (void)
     533                 :            : {
     534                 :          0 :   g_error ("Test failing");
     535                 :            :   exit (0);
     536                 :            : }
     537                 :            : 
     538                 :            : static void
     539                 :          0 : test_fatal_log_handler_critical_fail (void)
     540                 :            : {
     541   [ #  #  #  #  :          0 :   g_str_has_prefix (NULL, "file://");
                   #  # ]
     542                 :          0 :   g_critical ("Test passing");
     543                 :          0 :   exit (0);
     544                 :            : }
     545                 :            : 
     546                 :            : static void
     547                 :          1 : test_fatal_log_handler (void)
     548                 :            : {
     549                 :          1 :   g_test_trap_subprocess ("/misc/fatal-log-handler/subprocess/critical-pass", 0,
     550                 :            :                           G_TEST_SUBPROCESS_DEFAULT);
     551                 :          1 :   g_test_trap_assert_passed ();
     552                 :          1 :   g_test_trap_assert_stderr ("*CRITICAL*g_str_has_prefix*");
     553                 :          1 :   g_test_trap_assert_stderr ("*CRITICAL*Test passing*");
     554                 :            : 
     555                 :          1 :   g_test_trap_subprocess ("/misc/fatal-log-handler/subprocess/error-fail", 0,
     556                 :            :                           G_TEST_SUBPROCESS_DEFAULT);
     557                 :          1 :   g_test_trap_assert_failed ();
     558                 :          1 :   g_test_trap_assert_stderr ("*ERROR*Test failing*");
     559                 :            : 
     560                 :          1 :   g_test_trap_subprocess ("/misc/fatal-log-handler/subprocess/critical-fail", 0,
     561                 :            :                           G_TEST_SUBPROCESS_DEFAULT);
     562                 :          1 :   g_test_trap_assert_failed ();
     563                 :          1 :   g_test_trap_assert_stderr ("*CRITICAL*g_str_has_prefix*");
     564                 :          1 :   g_test_trap_assert_stderr_unmatched ("*CRITICAL*Test passing*");
     565                 :          1 : }
     566                 :            : 
     567                 :            : static void
     568                 :          2 : test_expected_messages_warning (void)
     569                 :            : {
     570                 :          2 :   g_warning ("This is a %d warning", g_random_int ());
     571                 :            :   g_return_if_reached ();
     572                 :            : }
     573                 :            : 
     574                 :            : static void
     575                 :          0 : test_expected_messages_expect_warning (void)
     576                 :            : {
     577                 :          0 :   g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_WARNING,
     578                 :            :                          "This is a * warning");
     579                 :          0 :   test_expected_messages_warning ();
     580                 :          0 : }
     581                 :            : 
     582                 :            : static void
     583                 :          0 : test_expected_messages_wrong_warning (void)
     584                 :            : {
     585                 :          0 :   g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL,
     586                 :            :                          "*should not be *");
     587                 :          0 :   test_expected_messages_warning ();
     588                 :          0 : }
     589                 :            : 
     590                 :            : static void
     591                 :          1 : test_expected_messages_expected (void)
     592                 :            : {
     593                 :          1 :   g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_WARNING,
     594                 :            :                          "This is a * warning");
     595                 :          1 :   g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL,
     596                 :            :                          "*should not be reached");
     597                 :            : 
     598                 :          1 :   test_expected_messages_warning ();
     599                 :            : 
     600                 :          1 :   g_test_assert_expected_messages ();
     601                 :          1 :   exit (0);
     602                 :            : }
     603                 :            : 
     604                 :            : static void
     605                 :          1 : test_expected_messages_null_domain (void)
     606                 :            : {
     607                 :          1 :   g_test_expect_message (NULL, G_LOG_LEVEL_WARNING, "no domain");
     608                 :          1 :   g_log (NULL, G_LOG_LEVEL_WARNING, "no domain");
     609                 :          1 :   g_test_assert_expected_messages ();
     610                 :          1 : }
     611                 :            : 
     612                 :            : static void
     613                 :          1 : test_expected_messages_expect_error (void)
     614                 :            : {
     615                 :            :   /* make sure we can't try to expect a g_error() */
     616                 :          1 :   g_test_expect_message ("GLib", G_LOG_LEVEL_CRITICAL, "*G_LOG_LEVEL_ERROR*");
     617                 :          1 :   g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_ERROR, "this won't work");
     618                 :          1 :   g_test_assert_expected_messages ();
     619                 :          1 : }
     620                 :            : 
     621                 :            : static void
     622                 :          1 : test_expected_messages_extra_warning (void)
     623                 :            : {
     624                 :          1 :   g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_WARNING,
     625                 :            :                          "This is a * warning");
     626                 :          1 :   g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL,
     627                 :            :                          "*should not be reached");
     628                 :          1 :   g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL,
     629                 :            :                          "nope");
     630                 :            : 
     631                 :          1 :   test_expected_messages_warning ();
     632                 :            : 
     633                 :            :   /* If we don't assert, it won't notice the missing message */
     634                 :          1 :   exit (0);
     635                 :            : }
     636                 :            : 
     637                 :            : static void
     638                 :          0 : test_expected_messages_unexpected_extra_warning (void)
     639                 :            : {
     640                 :          0 :   g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_WARNING,
     641                 :            :                          "This is a * warning");
     642                 :          0 :   g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL,
     643                 :            :                          "*should not be reached");
     644                 :          0 :   g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL,
     645                 :            :                          "nope");
     646                 :            : 
     647                 :          0 :   test_expected_messages_warning ();
     648                 :            : 
     649                 :          0 :   g_test_assert_expected_messages ();
     650                 :          0 :   exit (0);
     651                 :            : }
     652                 :            : 
     653                 :            : static void
     654                 :          1 : test_expected_messages (void)
     655                 :            : {
     656                 :          1 :   g_test_trap_subprocess ("/misc/expected-messages/subprocess/warning", 0,
     657                 :            :                           G_TEST_SUBPROCESS_DEFAULT);
     658                 :          1 :   g_test_trap_assert_failed ();
     659                 :          1 :   g_test_trap_assert_stderr ("*This is a * warning*");
     660                 :          1 :   g_test_trap_assert_stderr_unmatched ("*should not be reached*");
     661                 :            : 
     662                 :          1 :   g_test_trap_subprocess ("/misc/expected-messages/subprocess/expect-warning", 0,
     663                 :            :                           G_TEST_SUBPROCESS_DEFAULT);
     664                 :          1 :   g_test_trap_assert_failed ();
     665                 :          1 :   g_test_trap_assert_stderr_unmatched ("*This is a * warning*");
     666                 :          1 :   g_test_trap_assert_stderr ("*should not be reached*");
     667                 :            : 
     668                 :          1 :   g_test_trap_subprocess ("/misc/expected-messages/subprocess/wrong-warning", 0,
     669                 :            :                           G_TEST_SUBPROCESS_DEFAULT);
     670                 :          1 :   g_test_trap_assert_failed ();
     671                 :          1 :   g_test_trap_assert_stderr_unmatched ("*should not be reached*");
     672                 :          1 :   g_test_trap_assert_stderr ("*GLib-CRITICAL*Did not see expected message testing-CRITICAL*should not be *WARNING*This is a * warning*");
     673                 :            : 
     674                 :          1 :   g_test_trap_subprocess ("/misc/expected-messages/subprocess/expected", 0,
     675                 :            :                           G_TEST_SUBPROCESS_DEFAULT);
     676                 :          1 :   g_test_trap_assert_passed ();
     677                 :          1 :   g_test_trap_assert_stderr ("");
     678                 :            : 
     679                 :          1 :   g_test_trap_subprocess ("/misc/expected-messages/subprocess/null-domain", 0,
     680                 :            :                           G_TEST_SUBPROCESS_DEFAULT);
     681                 :          1 :   g_test_trap_assert_passed ();
     682                 :          1 :   g_test_trap_assert_stderr ("");
     683                 :            : 
     684                 :          1 :   g_test_trap_subprocess ("/misc/expected-messages/subprocess/extra-warning", 0,
     685                 :            :                           G_TEST_SUBPROCESS_DEFAULT);
     686                 :          1 :   g_test_trap_assert_passed ();
     687                 :          1 :   g_test_trap_assert_stderr ("");
     688                 :            : 
     689                 :          1 :   g_test_trap_subprocess ("/misc/expected-messages/subprocess/unexpected-extra-warning", 0,
     690                 :            :                           G_TEST_SUBPROCESS_DEFAULT);
     691                 :          1 :   g_test_trap_assert_failed ();
     692                 :          1 :   g_test_trap_assert_stderr ("*GLib:ERROR*Did not see expected message testing-CRITICAL*nope*");
     693                 :          1 : }
     694                 :            : 
     695                 :            : static void
     696                 :          1 : test_messages (void)
     697                 :            : {
     698                 :          1 :   g_test_trap_subprocess ("/misc/messages/subprocess/use-stderr", 0,
     699                 :            :                           G_TEST_SUBPROCESS_DEFAULT);
     700                 :          1 :   g_test_trap_assert_stderr ("*message is in stderr*");
     701                 :          1 :   g_test_trap_assert_stderr ("*warning is in stderr*");
     702                 :          1 :   g_test_trap_has_passed ();
     703                 :          1 : }
     704                 :            : 
     705                 :            : static void
     706                 :          0 : test_messages_use_stderr (void)
     707                 :            : {
     708                 :          0 :   g_message ("message is in stderr");
     709                 :          0 :   g_warning ("warning is in stderr");
     710                 :          0 : }
     711                 :            : 
     712                 :            : static void
     713                 :          1 : test_expected_messages_debug (void)
     714                 :            : {
     715                 :          1 :   g_test_expect_message ("Test", G_LOG_LEVEL_WARNING, "warning message");
     716                 :          1 :   g_log ("Test", G_LOG_LEVEL_DEBUG, "should be ignored");
     717                 :          1 :   g_log ("Test", G_LOG_LEVEL_WARNING, "warning message");
     718                 :          1 :   g_test_assert_expected_messages ();
     719                 :            : 
     720                 :          1 :   g_test_expect_message ("Test", G_LOG_LEVEL_DEBUG, "debug message");
     721                 :          1 :   g_log ("Test", G_LOG_LEVEL_DEBUG, "debug message");
     722                 :          1 :   g_test_assert_expected_messages ();
     723                 :          1 : }
     724                 :            : 
     725                 :            : static void
     726                 :          1 : test_dash_p_hidden (void)
     727                 :            : {
     728         [ -  + ]:          1 :   if (!g_test_subprocess ())
     729                 :            :     g_assert_not_reached ();
     730                 :            : 
     731                 :          1 :   g_print ("Test /misc/dash-p/subprocess/hidden ran\n");
     732                 :          1 : }
     733                 :            : 
     734                 :            : static void
     735                 :          1 : test_dash_p_hidden_sub (void)
     736                 :            : {
     737         [ -  + ]:          1 :   if (!g_test_subprocess ())
     738                 :            :     g_assert_not_reached ();
     739                 :            : 
     740                 :          1 :   g_print ("Test /misc/dash-p/subprocess/hidden/sub ran\n");
     741                 :          1 : }
     742                 :            : 
     743                 :            : /* The rest of the dash_p tests will get run by the toplevel test
     744                 :            :  * process, but they shouldn't do anything there.
     745                 :            :  */
     746                 :            : 
     747                 :            : static void
     748                 :          2 : test_dash_p_child (void)
     749                 :            : {
     750         [ +  + ]:          2 :   if (!g_test_subprocess ())
     751                 :          1 :     return;
     752                 :            : 
     753                 :          1 :   g_print ("Test /misc/dash-p/child ran\n");
     754                 :            : }
     755                 :            : 
     756                 :            : static void
     757                 :          3 : test_dash_p_child_sub (void)
     758                 :            : {
     759         [ +  + ]:          3 :   if (!g_test_subprocess ())
     760                 :          1 :     return;
     761                 :            : 
     762                 :          2 :   g_print ("Test /misc/dash-p/child/sub ran\n");
     763                 :            : }
     764                 :            : 
     765                 :            : static void
     766                 :          2 : test_dash_p_child_sub2 (void)
     767                 :            : {
     768         [ +  + ]:          2 :   if (!g_test_subprocess ())
     769                 :          1 :     return;
     770                 :            : 
     771                 :          1 :   g_print ("Test /misc/dash-p/child/sub2 ran\n");
     772                 :            : }
     773                 :            : 
     774                 :            : static void
     775                 :          0 : test_dash_p_child_sub_child (void)
     776                 :            : {
     777         [ #  # ]:          0 :   if (!g_test_subprocess ())
     778                 :          0 :     return;
     779                 :            : 
     780                 :          0 :   g_print ("Test /misc/dash-p/child/subprocess ran\n");
     781                 :            : }
     782                 :            : 
     783                 :            : static void
     784                 :          1 : test_dash_p (void)
     785                 :            : {
     786                 :          1 :   g_test_trap_subprocess ("/misc/dash-p/subprocess/hidden", 0,
     787                 :            :                           G_TEST_SUBPROCESS_DEFAULT);
     788                 :          1 :   g_test_trap_assert_passed ();
     789                 :          1 :   g_test_trap_assert_stdout ("*Test /misc/dash-p/subprocess/hidden ran*");
     790                 :          1 :   g_test_trap_assert_stdout_unmatched ("*Test /misc/dash-p/subprocess/hidden/sub ran*");
     791                 :          1 :   g_test_trap_assert_stdout_unmatched ("*Test /misc/dash-p/subprocess/hidden/sub2 ran*");
     792                 :          1 :   g_test_trap_assert_stdout_unmatched ("*Test /misc/dash-p/subprocess/hidden/sub/subprocess ran*");
     793                 :          1 :   g_test_trap_assert_stdout_unmatched ("*Test /misc/dash-p/child*");
     794                 :            : 
     795                 :          1 :   g_test_trap_subprocess ("/misc/dash-p/subprocess/hidden/sub", 0,
     796                 :            :                           G_TEST_SUBPROCESS_DEFAULT);
     797                 :          1 :   g_test_trap_assert_passed ();
     798                 :          1 :   g_test_trap_assert_stdout ("*Test /misc/dash-p/subprocess/hidden/sub ran*");
     799                 :          1 :   g_test_trap_assert_stdout_unmatched ("*Test /misc/dash-p/subprocess/hidden ran*");
     800                 :          1 :   g_test_trap_assert_stdout_unmatched ("*Test /misc/dash-p/subprocess/hidden/sub2 ran*");
     801                 :          1 :   g_test_trap_assert_stdout_unmatched ("*Test /misc/dash-p/subprocess/hidden/subprocess ran*");
     802                 :          1 :   g_test_trap_assert_stdout_unmatched ("*Test /misc/dash-p/child*");
     803                 :            : 
     804                 :          1 :   g_test_trap_subprocess ("/misc/dash-p/child", 0,
     805                 :            :                           G_TEST_SUBPROCESS_DEFAULT);
     806                 :          1 :   g_test_trap_assert_passed ();
     807                 :          1 :   g_test_trap_assert_stdout ("*Test /misc/dash-p/child ran*");
     808                 :          1 :   g_test_trap_assert_stdout ("*Test /misc/dash-p/child/sub ran*");
     809                 :          1 :   g_test_trap_assert_stdout ("*Test /misc/dash-p/child/sub2 ran*");
     810                 :          1 :   g_test_trap_assert_stdout_unmatched ("*Test /misc/dash-p/child/subprocess ran*");
     811                 :          1 :   g_test_trap_assert_stdout_unmatched ("*Test /misc/dash-p/subprocess/hidden*");
     812                 :            : 
     813                 :          1 :   g_test_trap_subprocess ("/misc/dash-p/child/sub", 0,
     814                 :            :                           G_TEST_SUBPROCESS_DEFAULT);
     815                 :          1 :   g_test_trap_assert_passed ();
     816                 :          1 :   g_test_trap_assert_stdout ("*Test /misc/dash-p/child/sub ran*");
     817                 :          1 :   g_test_trap_assert_stdout_unmatched ("*Test /misc/dash-p/child ran*");
     818                 :          1 :   g_test_trap_assert_stdout_unmatched ("*Test /misc/dash-p/child/sub2 ran*");
     819                 :          1 :   g_test_trap_assert_stdout_unmatched ("*Test /misc/dash-p/child/subprocess ran*");
     820                 :          1 :   g_test_trap_assert_stdout_unmatched ("*Test /misc/dash-p/subprocess/hidden*");
     821                 :          1 : }
     822                 :            : 
     823                 :            : static void
     824                 :          2 : test_nonfatal (void)
     825                 :            : {
     826         [ +  + ]:          2 :   if (g_test_subprocess ())
     827                 :            :     {
     828                 :          1 :       g_test_set_nonfatal_assertions ();
     829                 :          1 :       g_assert_cmpint (4, ==, 5);
     830                 :          1 :       g_print ("The End\n");
     831                 :          1 :       return;
     832                 :            :     }
     833                 :          1 :   g_test_trap_subprocess (NULL, 0, G_TEST_SUBPROCESS_DEFAULT);
     834                 :          1 :   g_test_trap_assert_failed ();
     835                 :          1 :   g_test_trap_assert_stderr ("*assertion failed*4 == 5*");
     836                 :          1 :   g_test_trap_assert_stdout ("*The End*");
     837                 :            : }
     838                 :            : 
     839                 :            : static void
     840                 :         11 : test_skip (void)
     841                 :            : {
     842                 :         11 :   g_test_skip ("Skipped should count as passed, not failed");
     843                 :            :   /* This function really means "the test concluded with a non-successful
     844                 :            :    * status" rather than "the test failed": it is documented to return
     845                 :            :    * true for skipped and incomplete tests, not just for failures. */
     846                 :         11 :   g_assert_true (g_test_failed ());
     847                 :         11 : }
     848                 :            : 
     849                 :            : static void
     850                 :          3 : test_pass (void)
     851                 :            : {
     852                 :          3 : }
     853                 :            : 
     854                 :            : static void
     855                 :          4 : subprocess_fail (void)
     856                 :            : {
     857                 :            :   /* Exit 1 instead of raising SIGABRT so that we can make assertions about
     858                 :            :    * how this combines with skipped/incomplete tests */
     859                 :          4 :   g_test_set_nonfatal_assertions ();
     860                 :          4 :   g_test_fail ();
     861                 :          4 :   g_assert_true (g_test_failed ());
     862                 :          4 : }
     863                 :            : 
     864                 :            : static void
     865                 :          2 : test_fail (void)
     866                 :            : {
     867         [ +  + ]:          2 :   if (g_test_subprocess ())
     868                 :            :     {
     869                 :          1 :       subprocess_fail ();
     870                 :          1 :       return;
     871                 :            :     }
     872                 :          1 :   g_test_trap_subprocess (NULL, 0, G_TEST_SUBPROCESS_DEFAULT);
     873                 :          1 :   g_test_trap_assert_failed ();
     874                 :            : }
     875                 :            : 
     876                 :            : static void
     877                 :          6 : subprocess_incomplete (void)
     878                 :            : {
     879                 :          6 :   g_test_incomplete ("not done");
     880                 :            :   /* This function really means "the test concluded with a non-successful
     881                 :            :    * status" rather than "the test failed": it is documented to return
     882                 :            :    * true for skipped and incomplete tests, not just for failures. */
     883                 :          6 :   g_assert_true (g_test_failed ());
     884                 :          6 : }
     885                 :            : 
     886                 :            : static void
     887                 :          2 : test_incomplete (void)
     888                 :            : {
     889         [ +  + ]:          2 :   if (g_test_subprocess ())
     890                 :            :     {
     891                 :          1 :       subprocess_incomplete ();
     892                 :          1 :       return;
     893                 :            :     }
     894                 :          1 :   g_test_trap_subprocess (NULL, 0, G_TEST_SUBPROCESS_DEFAULT);
     895                 :            :   /* An incomplete test represents functionality that is known not to be
     896                 :            :    * implemented yet (an expected failure), so it does not cause test
     897                 :            :    * failure; but it does count as the test having been skipped, which
     898                 :            :    * causes nonzero exit status 77, which is treated as failure by
     899                 :            :    * g_test_trap_subprocess(). */
     900                 :          1 :   g_test_trap_assert_failed ();
     901                 :            : }
     902                 :            : 
     903                 :            : static void
     904                 :          1 : test_path_first (void)
     905                 :            : {
     906                 :          1 :   g_assert_cmpstr (g_test_get_path (), ==, "/misc/path/first");
     907                 :          1 : }
     908                 :            : 
     909                 :            : static void
     910                 :          1 : test_path_second (void)
     911                 :            : {
     912                 :          1 :   g_assert_cmpstr (g_test_get_path (), ==, "/misc/path/second");
     913                 :          1 : }
     914                 :            : 
     915                 :            : static const char *argv0;
     916                 :            : 
     917                 :            : static void
     918                 :          1 : test_combining (void)
     919                 :            : {
     920                 :            :   GPtrArray *argv;
     921                 :          1 :   GError *error = NULL;
     922                 :            :   int status;
     923                 :            : 
     924                 :          1 :   g_test_message ("single test case skipped -> overall status 77");
     925                 :          1 :   argv = g_ptr_array_new ();
     926                 :          1 :   g_ptr_array_add (argv, (char *) argv0);
     927                 :          1 :   g_ptr_array_add (argv, "--GTestSubprocess");
     928                 :          1 :   g_ptr_array_add (argv, "-p");
     929                 :          1 :   g_ptr_array_add (argv, "/misc/skip");
     930                 :          1 :   g_ptr_array_add (argv, NULL);
     931                 :            : 
     932                 :          1 :   g_spawn_sync (NULL, (char **) argv->pdata, NULL,
     933                 :            :                 G_SPAWN_STDOUT_TO_DEV_NULL | G_SPAWN_STDERR_TO_DEV_NULL,
     934                 :            :                 NULL, NULL, NULL, NULL, &status,
     935                 :            :                 &error);
     936                 :          1 :   g_assert_no_error (error);
     937                 :            : 
     938                 :          1 :   g_spawn_check_wait_status (status, &error);
     939                 :          1 :   g_assert_error (error, G_SPAWN_EXIT_ERROR, 77);
     940                 :          1 :   g_clear_error (&error);
     941                 :            : 
     942                 :          1 :   g_test_message ("each test case skipped -> overall status 77");
     943                 :          1 :   g_ptr_array_set_size (argv, 0);
     944                 :          1 :   g_ptr_array_add (argv, (char *) argv0);
     945                 :          1 :   g_ptr_array_add (argv, "--GTestSubprocess");
     946                 :          1 :   g_ptr_array_add (argv, "-p");
     947                 :          1 :   g_ptr_array_add (argv, "/misc/skip");
     948                 :          1 :   g_ptr_array_add (argv, "-p");
     949                 :          1 :   g_ptr_array_add (argv, "/misc/combining/subprocess/skip1");
     950                 :          1 :   g_ptr_array_add (argv, "-p");
     951                 :          1 :   g_ptr_array_add (argv, "/misc/combining/subprocess/skip2");
     952                 :          1 :   g_ptr_array_add (argv, NULL);
     953                 :            : 
     954                 :          1 :   g_spawn_sync (NULL, (char **) argv->pdata, NULL,
     955                 :            :                 G_SPAWN_STDOUT_TO_DEV_NULL | G_SPAWN_STDERR_TO_DEV_NULL,
     956                 :            :                 NULL, NULL, NULL, NULL, &status,
     957                 :            :                 &error);
     958                 :          1 :   g_assert_no_error (error);
     959                 :            : 
     960                 :          1 :   g_spawn_check_wait_status (status, &error);
     961                 :          1 :   g_assert_error (error, G_SPAWN_EXIT_ERROR, 77);
     962                 :          1 :   g_clear_error (&error);
     963                 :            : 
     964                 :          1 :   g_test_message ("single test case incomplete -> overall status 77");
     965                 :          1 :   g_ptr_array_set_size (argv, 0);
     966                 :          1 :   g_ptr_array_add (argv, (char *) argv0);
     967                 :          1 :   g_ptr_array_add (argv, "--GTestSubprocess");
     968                 :          1 :   g_ptr_array_add (argv, "-p");
     969                 :          1 :   g_ptr_array_add (argv, "/misc/combining/subprocess/incomplete");
     970                 :          1 :   g_ptr_array_add (argv, NULL);
     971                 :            : 
     972                 :          1 :   g_spawn_sync (NULL, (char **) argv->pdata, NULL,
     973                 :            :                 G_SPAWN_STDOUT_TO_DEV_NULL | G_SPAWN_STDERR_TO_DEV_NULL,
     974                 :            :                 NULL, NULL, NULL, NULL, &status,
     975                 :            :                 &error);
     976                 :          1 :   g_assert_no_error (error);
     977                 :            : 
     978                 :          1 :   g_spawn_check_wait_status (status, &error);
     979                 :          1 :   g_assert_error (error, G_SPAWN_EXIT_ERROR, 77);
     980                 :          1 :   g_clear_error (&error);
     981                 :            : 
     982                 :          1 :   g_test_message ("one pass and some skipped -> overall status 0");
     983                 :          1 :   g_ptr_array_set_size (argv, 0);
     984                 :          1 :   g_ptr_array_add (argv, (char *) argv0);
     985                 :          1 :   g_ptr_array_add (argv, "--GTestSubprocess");
     986                 :          1 :   g_ptr_array_add (argv, "-p");
     987                 :          1 :   g_ptr_array_add (argv, "/misc/skip");
     988                 :          1 :   g_ptr_array_add (argv, "-p");
     989                 :          1 :   g_ptr_array_add (argv, "/misc/combining/subprocess/pass");
     990                 :          1 :   g_ptr_array_add (argv, "-p");
     991                 :          1 :   g_ptr_array_add (argv, "/misc/combining/subprocess/skip1");
     992                 :          1 :   g_ptr_array_add (argv, NULL);
     993                 :            : 
     994                 :          1 :   g_spawn_sync (NULL, (char **) argv->pdata, NULL,
     995                 :            :                 G_SPAWN_STDOUT_TO_DEV_NULL | G_SPAWN_STDERR_TO_DEV_NULL,
     996                 :            :                 NULL, NULL, NULL, NULL, &status,
     997                 :            :                 &error);
     998                 :          1 :   g_assert_no_error (error);
     999                 :            : 
    1000                 :          1 :   g_spawn_check_wait_status (status, &error);
    1001                 :          1 :   g_assert_no_error (error);
    1002                 :            : 
    1003                 :          1 :   g_test_message ("one pass and some incomplete -> overall status 0");
    1004                 :          1 :   g_ptr_array_set_size (argv, 0);
    1005                 :          1 :   g_ptr_array_add (argv, (char *) argv0);
    1006                 :          1 :   g_ptr_array_add (argv, "--GTestSubprocess");
    1007                 :          1 :   g_ptr_array_add (argv, "-p");
    1008                 :          1 :   g_ptr_array_add (argv, "/misc/combining/subprocess/pass");
    1009                 :          1 :   g_ptr_array_add (argv, "-p");
    1010                 :          1 :   g_ptr_array_add (argv, "/misc/combining/subprocess/incomplete");
    1011                 :          1 :   g_ptr_array_add (argv, NULL);
    1012                 :            : 
    1013                 :          1 :   g_spawn_sync (NULL, (char **) argv->pdata, NULL,
    1014                 :            :                 G_SPAWN_STDOUT_TO_DEV_NULL | G_SPAWN_STDERR_TO_DEV_NULL,
    1015                 :            :                 NULL, NULL, NULL, NULL, &status,
    1016                 :            :                 &error);
    1017                 :          1 :   g_assert_no_error (error);
    1018                 :            : 
    1019                 :          1 :   g_spawn_check_wait_status (status, &error);
    1020                 :          1 :   g_assert_no_error (error);
    1021                 :            : 
    1022                 :          1 :   g_test_message ("one pass and mix of skipped and incomplete -> overall status 0");
    1023                 :          1 :   g_ptr_array_set_size (argv, 0);
    1024                 :          1 :   g_ptr_array_add (argv, (char *) argv0);
    1025                 :          1 :   g_ptr_array_add (argv, "--GTestSubprocess");
    1026                 :          1 :   g_ptr_array_add (argv, "-p");
    1027                 :          1 :   g_ptr_array_add (argv, "/misc/combining/subprocess/pass");
    1028                 :          1 :   g_ptr_array_add (argv, "-p");
    1029                 :          1 :   g_ptr_array_add (argv, "/misc/combining/subprocess/skip1");
    1030                 :          1 :   g_ptr_array_add (argv, "-p");
    1031                 :          1 :   g_ptr_array_add (argv, "/misc/combining/subprocess/incomplete");
    1032                 :          1 :   g_ptr_array_add (argv, NULL);
    1033                 :            : 
    1034                 :          1 :   g_spawn_sync (NULL, (char **) argv->pdata, NULL,
    1035                 :            :                 G_SPAWN_STDOUT_TO_DEV_NULL | G_SPAWN_STDERR_TO_DEV_NULL,
    1036                 :            :                 NULL, NULL, NULL, NULL, &status,
    1037                 :            :                 &error);
    1038                 :          1 :   g_assert_no_error (error);
    1039                 :            : 
    1040                 :          1 :   g_spawn_check_wait_status (status, &error);
    1041                 :          1 :   g_assert_no_error (error);
    1042                 :            : 
    1043                 :          1 :   g_test_message ("one fail and some skipped -> overall status fail");
    1044                 :          1 :   g_ptr_array_set_size (argv, 0);
    1045                 :          1 :   g_ptr_array_add (argv, (char *) argv0);
    1046                 :          1 :   g_ptr_array_add (argv, "--GTestSubprocess");
    1047                 :          1 :   g_ptr_array_add (argv, "-p");
    1048                 :          1 :   g_ptr_array_add (argv, "/misc/skip");
    1049                 :          1 :   g_ptr_array_add (argv, "-p");
    1050                 :          1 :   g_ptr_array_add (argv, "/misc/combining/subprocess/fail");
    1051                 :          1 :   g_ptr_array_add (argv, "-p");
    1052                 :          1 :   g_ptr_array_add (argv, "/misc/combining/subprocess/skip1");
    1053                 :          1 :   g_ptr_array_add (argv, NULL);
    1054                 :            : 
    1055                 :          1 :   g_spawn_sync (NULL, (char **) argv->pdata, NULL,
    1056                 :            :                 G_SPAWN_STDOUT_TO_DEV_NULL | G_SPAWN_STDERR_TO_DEV_NULL,
    1057                 :            :                 NULL, NULL, NULL, NULL, &status,
    1058                 :            :                 &error);
    1059                 :          1 :   g_assert_no_error (error);
    1060                 :            : 
    1061                 :          1 :   g_spawn_check_wait_status (status, &error);
    1062                 :          1 :   g_assert_error (error, G_SPAWN_EXIT_ERROR, 1);
    1063                 :          1 :   g_clear_error (&error);
    1064                 :            : 
    1065                 :          1 :   g_test_message ("one fail and some incomplete -> overall status fail");
    1066                 :          1 :   g_ptr_array_set_size (argv, 0);
    1067                 :          1 :   g_ptr_array_add (argv, (char *) argv0);
    1068                 :          1 :   g_ptr_array_add (argv, "--GTestSubprocess");
    1069                 :          1 :   g_ptr_array_add (argv, "-p");
    1070                 :          1 :   g_ptr_array_add (argv, "/misc/combining/subprocess/fail");
    1071                 :          1 :   g_ptr_array_add (argv, "-p");
    1072                 :          1 :   g_ptr_array_add (argv, "/misc/combining/subprocess/incomplete");
    1073                 :          1 :   g_ptr_array_add (argv, NULL);
    1074                 :            : 
    1075                 :          1 :   g_spawn_sync (NULL, (char **) argv->pdata, NULL,
    1076                 :            :                 G_SPAWN_STDOUT_TO_DEV_NULL | G_SPAWN_STDERR_TO_DEV_NULL,
    1077                 :            :                 NULL, NULL, NULL, NULL, &status,
    1078                 :            :                 &error);
    1079                 :          1 :   g_assert_no_error (error);
    1080                 :            : 
    1081                 :          1 :   g_spawn_check_wait_status (status, &error);
    1082                 :          1 :   g_assert_error (error, G_SPAWN_EXIT_ERROR, 1);
    1083                 :          1 :   g_clear_error (&error);
    1084                 :            : 
    1085                 :          1 :   g_test_message ("one fail and mix of skipped and incomplete -> overall status fail");
    1086                 :          1 :   g_ptr_array_set_size (argv, 0);
    1087                 :          1 :   g_ptr_array_add (argv, (char *) argv0);
    1088                 :          1 :   g_ptr_array_add (argv, "--GTestSubprocess");
    1089                 :          1 :   g_ptr_array_add (argv, "-p");
    1090                 :          1 :   g_ptr_array_add (argv, "/misc/combining/subprocess/fail");
    1091                 :          1 :   g_ptr_array_add (argv, "-p");
    1092                 :          1 :   g_ptr_array_add (argv, "/misc/combining/subprocess/skip1");
    1093                 :          1 :   g_ptr_array_add (argv, "-p");
    1094                 :          1 :   g_ptr_array_add (argv, "/misc/combining/subprocess/incomplete");
    1095                 :          1 :   g_ptr_array_add (argv, NULL);
    1096                 :            : 
    1097                 :          1 :   g_spawn_sync (NULL, (char **) argv->pdata, NULL,
    1098                 :            :                 G_SPAWN_STDOUT_TO_DEV_NULL | G_SPAWN_STDERR_TO_DEV_NULL,
    1099                 :            :                 NULL, NULL, NULL, NULL, &status,
    1100                 :            :                 &error);
    1101                 :          1 :   g_assert_no_error (error);
    1102                 :            : 
    1103                 :          1 :   g_spawn_check_wait_status (status, &error);
    1104                 :          1 :   g_assert_error (error, G_SPAWN_EXIT_ERROR, 1);
    1105                 :          1 :   g_clear_error (&error);
    1106                 :            : 
    1107                 :          1 :   g_ptr_array_unref (argv);
    1108                 :          1 : }
    1109                 :            : 
    1110                 :            : /* Test the TAP output when a test suite is run with --tap. */
    1111                 :            : static void
    1112                 :          1 : test_tap (void)
    1113                 :            : {
    1114                 :            :   const char *testing_helper;
    1115                 :            :   GPtrArray *argv;
    1116                 :          1 :   GError *error = NULL;
    1117                 :            :   int status;
    1118                 :            :   gchar *output;
    1119                 :            :   char **envp;
    1120                 :            : 
    1121                 :          1 :   testing_helper = g_test_get_filename (G_TEST_BUILT, "testing-helper" EXEEXT, NULL);
    1122                 :            : 
    1123                 :          1 :   g_test_message ("pass");
    1124                 :          1 :   argv = g_ptr_array_new ();
    1125                 :          1 :   g_ptr_array_add (argv, (char *) testing_helper);
    1126                 :          1 :   g_ptr_array_add (argv, "pass");
    1127                 :          1 :   g_ptr_array_add (argv, "--tap");
    1128                 :          1 :   g_ptr_array_add (argv, NULL);
    1129                 :            : 
    1130                 :            :   /* Remove the G_TEST_ROOT_PROCESS env so it will be considered a standalone test */
    1131                 :          1 :   envp = g_get_environ ();
    1132                 :          1 :   g_assert_nonnull (g_environ_getenv (envp, "G_TEST_ROOT_PROCESS"));
    1133                 :          1 :   envp = g_environ_unsetenv (g_steal_pointer (&envp), "G_TEST_ROOT_PROCESS");
    1134                 :            : 
    1135                 :          1 :   g_spawn_sync (NULL, (char **) argv->pdata, envp,
    1136                 :            :                 G_SPAWN_STDERR_TO_DEV_NULL,
    1137                 :            :                 NULL, NULL, &output, NULL, &status,
    1138                 :            :                 &error);
    1139                 :          1 :   g_assert_no_error (error);
    1140                 :            : 
    1141                 :          1 :   g_spawn_check_wait_status (status, &error);
    1142                 :          1 :   g_assert_no_error (error);
    1143                 :          1 :   g_assert_true (g_str_has_prefix (output, "TAP version " TAP_VERSION));
    1144                 :          1 :   g_assert_null (strstr (output, "# Subtest: "));
    1145                 :          1 :   g_assert_nonnull (strstr (output, "\nok 1 /pass\n"));
    1146                 :          1 :   g_free (output);
    1147                 :          1 :   g_ptr_array_unref (argv);
    1148                 :            : 
    1149                 :          1 :   g_test_message ("skip");
    1150                 :          1 :   argv = g_ptr_array_new ();
    1151                 :          1 :   g_ptr_array_add (argv, (char *) testing_helper);
    1152                 :          1 :   g_ptr_array_add (argv, "skip");
    1153                 :          1 :   g_ptr_array_add (argv, "--tap");
    1154                 :          1 :   g_ptr_array_add (argv, NULL);
    1155                 :            : 
    1156                 :          1 :   g_spawn_sync (NULL, (char **) argv->pdata, envp,
    1157                 :            :                 G_SPAWN_STDERR_TO_DEV_NULL,
    1158                 :            :                 NULL, NULL, &output, NULL, &status,
    1159                 :            :                 &error);
    1160                 :          1 :   g_assert_no_error (error);
    1161                 :            : 
    1162                 :          1 :   g_spawn_check_wait_status (status, &error);
    1163                 :          1 :   g_assert_no_error (error);
    1164                 :          1 :   g_assert_true (g_str_has_prefix (output, "TAP version " TAP_VERSION));
    1165                 :          1 :   g_assert_null (strstr (output, "# Subtest: "));
    1166                 :          1 :   g_assert_nonnull (strstr (output, "\nok 1 /skip # SKIP not enough tea\n"));
    1167                 :          1 :   g_free (output);
    1168                 :          1 :   g_ptr_array_unref (argv);
    1169                 :            : 
    1170                 :          1 :   g_test_message ("skip with printf format");
    1171                 :          1 :   argv = g_ptr_array_new ();
    1172                 :          1 :   g_ptr_array_add (argv, (char *) testing_helper);
    1173                 :          1 :   g_ptr_array_add (argv, "skip-printf");
    1174                 :          1 :   g_ptr_array_add (argv, "--tap");
    1175                 :          1 :   g_ptr_array_add (argv, NULL);
    1176                 :            : 
    1177                 :          1 :   g_spawn_sync (NULL, (char **) argv->pdata, envp,
    1178                 :            :                 G_SPAWN_STDERR_TO_DEV_NULL,
    1179                 :            :                 NULL, NULL, &output, NULL, &status,
    1180                 :            :                 &error);
    1181                 :          1 :   g_assert_no_error (error);
    1182                 :            : 
    1183                 :          1 :   g_spawn_check_wait_status (status, &error);
    1184                 :          1 :   g_assert_no_error (error);
    1185                 :          1 :   g_assert_true (g_str_has_prefix (output, "TAP version " TAP_VERSION));
    1186                 :          1 :   g_assert_null (strstr (output, "# Subtest: "));
    1187                 :          1 :   g_assert_nonnull (strstr (output, "\nok 1 /skip-printf # SKIP not enough coffee\n"));
    1188                 :          1 :   g_free (output);
    1189                 :          1 :   g_ptr_array_unref (argv);
    1190                 :            : 
    1191                 :          1 :   g_test_message ("incomplete");
    1192                 :          1 :   argv = g_ptr_array_new ();
    1193                 :          1 :   g_ptr_array_add (argv, (char *) testing_helper);
    1194                 :          1 :   g_ptr_array_add (argv, "incomplete");
    1195                 :          1 :   g_ptr_array_add (argv, "--tap");
    1196                 :          1 :   g_ptr_array_add (argv, NULL);
    1197                 :            : 
    1198                 :          1 :   g_spawn_sync (NULL, (char **) argv->pdata, envp,
    1199                 :            :                 G_SPAWN_STDERR_TO_DEV_NULL,
    1200                 :            :                 NULL, NULL, &output, NULL, &status,
    1201                 :            :                 &error);
    1202                 :          1 :   g_assert_no_error (error);
    1203                 :            : 
    1204                 :          1 :   g_spawn_check_wait_status (status, &error);
    1205                 :          1 :   g_assert_no_error (error);
    1206                 :          1 :   g_assert_true (g_str_has_prefix (output, "TAP version " TAP_VERSION));
    1207                 :          1 :   g_assert_null (strstr (output, "# Subtest: "));
    1208                 :          1 :   g_assert_nonnull (strstr (output, "\nnot ok 1 /incomplete # TODO mind reading not implemented yet\n"));
    1209                 :          1 :   g_free (output);
    1210                 :          1 :   g_ptr_array_unref (argv);
    1211                 :            : 
    1212                 :          1 :   g_test_message ("incomplete with printf format");
    1213                 :          1 :   argv = g_ptr_array_new ();
    1214                 :          1 :   g_ptr_array_add (argv, (char *) testing_helper);
    1215                 :          1 :   g_ptr_array_add (argv, "incomplete-printf");
    1216                 :          1 :   g_ptr_array_add (argv, "--tap");
    1217                 :          1 :   g_ptr_array_add (argv, NULL);
    1218                 :            : 
    1219                 :          1 :   g_spawn_sync (NULL, (char **) argv->pdata, envp,
    1220                 :            :                 G_SPAWN_STDERR_TO_DEV_NULL,
    1221                 :            :                 NULL, NULL, &output, NULL, &status,
    1222                 :            :                 &error);
    1223                 :          1 :   g_assert_no_error (error);
    1224                 :            : 
    1225                 :          1 :   g_spawn_check_wait_status (status, &error);
    1226                 :          1 :   g_assert_no_error (error);
    1227                 :          1 :   g_assert_true (g_str_has_prefix (output, "TAP version " TAP_VERSION));
    1228                 :          1 :   g_assert_null (strstr (output, "# Subtest: "));
    1229                 :          1 :   g_assert_nonnull (strstr (output, "\nnot ok 1 /incomplete-printf # TODO telekinesis not implemented yet\n"));
    1230                 :          1 :   g_free (output);
    1231                 :          1 :   g_ptr_array_unref (argv);
    1232                 :            : 
    1233                 :          1 :   g_test_message ("fail");
    1234                 :          1 :   argv = g_ptr_array_new ();
    1235                 :          1 :   g_ptr_array_add (argv, (char *) testing_helper);
    1236                 :          1 :   g_ptr_array_add (argv, "fail");
    1237                 :          1 :   g_ptr_array_add (argv, "--tap");
    1238                 :          1 :   g_ptr_array_add (argv, NULL);
    1239                 :            : 
    1240                 :          1 :   g_spawn_sync (NULL, (char **) argv->pdata, envp,
    1241                 :            :                 G_SPAWN_STDERR_TO_DEV_NULL,
    1242                 :            :                 NULL, NULL, &output, NULL, &status,
    1243                 :            :                 &error);
    1244                 :          1 :   g_assert_no_error (error);
    1245                 :            : 
    1246                 :          1 :   g_spawn_check_wait_status (status, &error);
    1247                 :          1 :   g_assert_error (error, G_SPAWN_EXIT_ERROR, 1);
    1248                 :          1 :   g_assert_true (g_str_has_prefix (output, "TAP version " TAP_VERSION));
    1249                 :          1 :   g_assert_null (strstr (output, "# Subtest: "));
    1250                 :          1 :   g_assert_nonnull (strstr (output, "\nnot ok 1 /fail\n"));
    1251                 :          1 :   g_free (output);
    1252                 :          1 :   g_clear_error (&error);
    1253                 :          1 :   g_ptr_array_unref (argv);
    1254                 :            : 
    1255                 :          1 :   g_test_message ("fail with message");
    1256                 :          1 :   argv = g_ptr_array_new ();
    1257                 :          1 :   g_ptr_array_add (argv, (char *) testing_helper);
    1258                 :          1 :   g_ptr_array_add (argv, "fail-printf");
    1259                 :          1 :   g_ptr_array_add (argv, "--tap");
    1260                 :          1 :   g_ptr_array_add (argv, NULL);
    1261                 :            : 
    1262                 :          1 :   g_spawn_sync (NULL, (char **) argv->pdata, envp,
    1263                 :            :                 G_SPAWN_STDERR_TO_DEV_NULL,
    1264                 :            :                 NULL, NULL, &output, NULL, &status,
    1265                 :            :                 &error);
    1266                 :          1 :   g_assert_no_error (error);
    1267                 :            : 
    1268                 :          1 :   g_spawn_check_wait_status (status, &error);
    1269                 :          1 :   g_assert_error (error, G_SPAWN_EXIT_ERROR, 1);
    1270                 :          1 :   g_assert_true (g_str_has_prefix (output, "TAP version " TAP_VERSION));
    1271                 :          1 :   g_assert_null (strstr (output, "# Subtest: "));
    1272                 :          1 :   g_assert_nonnull (strstr (output, "\nnot ok 1 /fail-printf - this test intentionally left failing\n"));
    1273                 :          1 :   g_free (output);
    1274                 :          1 :   g_clear_error (&error);
    1275                 :          1 :   g_ptr_array_unref (argv);
    1276                 :            : 
    1277                 :          1 :   g_test_message ("all");
    1278                 :          1 :   argv = g_ptr_array_new ();
    1279                 :          1 :   g_ptr_array_add (argv, (char *) testing_helper);
    1280                 :          1 :   g_ptr_array_add (argv, "all");
    1281                 :          1 :   g_ptr_array_add (argv, "--tap");
    1282                 :          1 :   g_ptr_array_add (argv, NULL);
    1283                 :            : 
    1284                 :          1 :   g_spawn_sync (NULL, (char **) argv->pdata, envp,
    1285                 :            :                 G_SPAWN_STDOUT_TO_DEV_NULL | G_SPAWN_STDERR_TO_DEV_NULL,
    1286                 :            :                 NULL, NULL, NULL, NULL, &status,
    1287                 :            :                 &error);
    1288                 :          1 :   g_assert_no_error (error);
    1289                 :            : 
    1290                 :          1 :   g_spawn_check_wait_status (status, &error);
    1291                 :          1 :   g_assert_error (error, G_SPAWN_EXIT_ERROR, 1);
    1292                 :          1 :   g_clear_error (&error);
    1293                 :          1 :   g_ptr_array_unref (argv);
    1294                 :            : 
    1295                 :          1 :   g_test_message ("all-non-failures");
    1296                 :          1 :   argv = g_ptr_array_new ();
    1297                 :          1 :   g_ptr_array_add (argv, (char *) testing_helper);
    1298                 :          1 :   g_ptr_array_add (argv, "all-non-failures");
    1299                 :          1 :   g_ptr_array_add (argv, "--tap");
    1300                 :          1 :   g_ptr_array_add (argv, NULL);
    1301                 :            : 
    1302                 :          1 :   g_spawn_sync (NULL, (char **) argv->pdata, envp,
    1303                 :            :                 G_SPAWN_STDOUT_TO_DEV_NULL | G_SPAWN_STDERR_TO_DEV_NULL,
    1304                 :            :                 NULL, NULL, NULL, NULL, &status,
    1305                 :            :                 &error);
    1306                 :          1 :   g_assert_no_error (error);
    1307                 :            : 
    1308                 :          1 :   g_spawn_check_wait_status (status, &error);
    1309                 :          1 :   g_assert_no_error (error);
    1310                 :            : 
    1311                 :          1 :   g_ptr_array_unref (argv);
    1312                 :            : 
    1313                 :          1 :   g_test_message ("--GTestSkipCount");
    1314                 :          1 :   argv = g_ptr_array_new ();
    1315                 :          1 :   g_ptr_array_add (argv, (char *) testing_helper);
    1316                 :          1 :   g_ptr_array_add (argv, "skip-options");
    1317                 :          1 :   g_ptr_array_add (argv, "--tap");
    1318                 :          1 :   g_ptr_array_add (argv, "--GTestSkipCount");
    1319                 :          1 :   g_ptr_array_add (argv, "2");
    1320                 :          1 :   g_ptr_array_add (argv, NULL);
    1321                 :            : 
    1322                 :          1 :   g_spawn_sync (NULL, (char **) argv->pdata, envp,
    1323                 :            :                 G_SPAWN_STDERR_TO_DEV_NULL,
    1324                 :            :                 NULL, NULL, &output, NULL, &status,
    1325                 :            :                 &error);
    1326                 :          1 :   g_assert_no_error (error);
    1327                 :          1 :   g_assert_true (g_str_has_prefix (output, "TAP version " TAP_VERSION));
    1328                 :          1 :   g_assert_null (strstr (output, "# Subtest: "));
    1329                 :          1 :   g_assert_nonnull (strstr (output, "1..10\n"));
    1330                 :          1 :   g_assert_nonnull (strstr (output, "\nok 1 /a # SKIP\n"));
    1331                 :          1 :   g_assert_nonnull (strstr (output, "\nok 2 /b # SKIP\n"));
    1332                 :          1 :   g_assert_nonnull (strstr (output, "\nok 3 /b/a\n"));
    1333                 :          1 :   g_assert_nonnull (strstr (output, "\nok 4 /b/b\n"));
    1334                 :          1 :   g_assert_nonnull (strstr (output, "\nok 5 /b/b/a\n"));
    1335                 :          1 :   g_assert_nonnull (strstr (output, "\nok 6 /prefix/a\n"));
    1336                 :          1 :   g_assert_nonnull (strstr (output, "\nok 7 /prefix/b/b\n"));
    1337                 :          1 :   g_assert_nonnull (strstr (output, "\nok 8 /prefix-long/a\n"));
    1338                 :          1 :   g_assert_nonnull (strstr (output, "\nok 9 /c/a\n"));
    1339                 :          1 :   g_assert_nonnull (strstr (output, "\nok 10 /d/a\n"));
    1340                 :            : 
    1341                 :          1 :   g_spawn_check_wait_status (status, &error);
    1342                 :          1 :   g_assert_no_error (error);
    1343                 :            : 
    1344                 :          1 :   g_free (output);
    1345                 :          1 :   g_ptr_array_unref (argv);
    1346                 :            : 
    1347                 :          1 :   g_test_message ("--GTestSkipCount=0 is the same as omitting it");
    1348                 :          1 :   argv = g_ptr_array_new ();
    1349                 :          1 :   g_ptr_array_add (argv, (char *) testing_helper);
    1350                 :          1 :   g_ptr_array_add (argv, "skip-options");
    1351                 :          1 :   g_ptr_array_add (argv, "--tap");
    1352                 :          1 :   g_ptr_array_add (argv, "--GTestSkipCount");
    1353                 :          1 :   g_ptr_array_add (argv, "0");
    1354                 :          1 :   g_ptr_array_add (argv, NULL);
    1355                 :            : 
    1356                 :          1 :   g_spawn_sync (NULL, (char **) argv->pdata, envp,
    1357                 :            :                 G_SPAWN_STDERR_TO_DEV_NULL,
    1358                 :            :                 NULL, NULL, &output, NULL, &status,
    1359                 :            :                 &error);
    1360                 :          1 :   g_assert_no_error (error);
    1361                 :          1 :   g_assert_true (g_str_has_prefix (output, "TAP version " TAP_VERSION));
    1362                 :          1 :   g_assert_null (strstr (output, "# Subtest: "));
    1363                 :          1 :   g_assert_nonnull (strstr (output, "1..10\n"));
    1364                 :          1 :   g_assert_nonnull (strstr (output, "\nok 1 /a\n"));
    1365                 :          1 :   g_assert_nonnull (strstr (output, "\nok 2 /b\n"));
    1366                 :          1 :   g_assert_nonnull (strstr (output, "\nok 3 /b/a\n"));
    1367                 :          1 :   g_assert_nonnull (strstr (output, "\nok 4 /b/b\n"));
    1368                 :          1 :   g_assert_nonnull (strstr (output, "\nok 5 /b/b/a\n"));
    1369                 :          1 :   g_assert_nonnull (strstr (output, "\nok 6 /prefix/a\n"));
    1370                 :          1 :   g_assert_nonnull (strstr (output, "\nok 7 /prefix/b/b\n"));
    1371                 :          1 :   g_assert_nonnull (strstr (output, "\nok 8 /prefix-long/a\n"));
    1372                 :          1 :   g_assert_nonnull (strstr (output, "\nok 9 /c/a\n"));
    1373                 :          1 :   g_assert_nonnull (strstr (output, "\nok 10 /d/a\n"));
    1374                 :            : 
    1375                 :          1 :   g_spawn_check_wait_status (status, &error);
    1376                 :          1 :   g_assert_no_error (error);
    1377                 :            : 
    1378                 :          1 :   g_free (output);
    1379                 :          1 :   g_ptr_array_unref (argv);
    1380                 :            : 
    1381                 :          1 :   g_test_message ("--GTestSkipCount > number of tests skips all");
    1382                 :          1 :   argv = g_ptr_array_new ();
    1383                 :          1 :   g_ptr_array_add (argv, (char *) testing_helper);
    1384                 :          1 :   g_ptr_array_add (argv, "skip-options");
    1385                 :          1 :   g_ptr_array_add (argv, "--tap");
    1386                 :          1 :   g_ptr_array_add (argv, "--GTestSkipCount");
    1387                 :          1 :   g_ptr_array_add (argv, "11");
    1388                 :          1 :   g_ptr_array_add (argv, NULL);
    1389                 :            : 
    1390                 :          1 :   g_spawn_sync (NULL, (char **) argv->pdata, envp,
    1391                 :            :                 G_SPAWN_STDERR_TO_DEV_NULL,
    1392                 :            :                 NULL, NULL, &output, NULL, &status,
    1393                 :            :                 &error);
    1394                 :          1 :   g_assert_no_error (error);
    1395                 :          1 :   g_assert_true (g_str_has_prefix (output, "TAP version " TAP_VERSION));
    1396                 :          1 :   g_assert_null (strstr (output, "# Subtest: "));
    1397                 :          1 :   g_assert_nonnull (strstr (output, "1..10\n"));
    1398                 :          1 :   g_assert_nonnull (strstr (output, "\nok 1 /a # SKIP\n"));
    1399                 :          1 :   g_assert_nonnull (strstr (output, "\nok 2 /b # SKIP\n"));
    1400                 :          1 :   g_assert_nonnull (strstr (output, "\nok 3 /b/a # SKIP\n"));
    1401                 :          1 :   g_assert_nonnull (strstr (output, "\nok 4 /b/b # SKIP\n"));
    1402                 :          1 :   g_assert_nonnull (strstr (output, "\nok 5 /b/b/a # SKIP\n"));
    1403                 :          1 :   g_assert_nonnull (strstr (output, "\nok 6 /prefix/a # SKIP\n"));
    1404                 :          1 :   g_assert_nonnull (strstr (output, "\nok 7 /prefix/b/b # SKIP\n"));
    1405                 :          1 :   g_assert_nonnull (strstr (output, "\nok 8 /prefix-long/a # SKIP\n"));
    1406                 :          1 :   g_assert_nonnull (strstr (output, "\nok 9 /c/a # SKIP\n"));
    1407                 :          1 :   g_assert_nonnull (strstr (output, "\nok 10 /d/a # SKIP\n"));
    1408                 :            : 
    1409                 :          1 :   g_spawn_check_wait_status (status, &error);
    1410                 :          1 :   g_assert_no_error (error);
    1411                 :            : 
    1412                 :          1 :   g_free (output);
    1413                 :          1 :   g_ptr_array_unref (argv);
    1414                 :            : 
    1415                 :          1 :   g_test_message ("-p");
    1416                 :          1 :   argv = g_ptr_array_new ();
    1417                 :          1 :   g_ptr_array_add (argv, (char *) testing_helper);
    1418                 :          1 :   g_ptr_array_add (argv, "skip-options");
    1419                 :          1 :   g_ptr_array_add (argv, "--tap");
    1420                 :          1 :   g_ptr_array_add (argv, "-p");
    1421                 :          1 :   g_ptr_array_add (argv, "/c/a");
    1422                 :          1 :   g_ptr_array_add (argv, "-p");
    1423                 :          1 :   g_ptr_array_add (argv, "/c/a");
    1424                 :          1 :   g_ptr_array_add (argv, "-p");
    1425                 :          1 :   g_ptr_array_add (argv, "/b");
    1426                 :          1 :   g_ptr_array_add (argv, NULL);
    1427                 :            : 
    1428                 :          1 :   g_spawn_sync (NULL, (char **) argv->pdata, envp,
    1429                 :            :                 G_SPAWN_STDERR_TO_DEV_NULL,
    1430                 :            :                 NULL, NULL, &output, NULL, &status,
    1431                 :            :                 &error);
    1432                 :          1 :   g_assert_no_error (error);
    1433                 :          1 :   g_assert_true (g_str_has_prefix (output, "TAP version " TAP_VERSION));
    1434                 :          1 :   g_assert_null (strstr (output, "# Subtest: "));
    1435                 :          1 :   g_assert_nonnull (strstr (output, "\nok 1 /c/a\n"));
    1436                 :          1 :   g_assert_nonnull (strstr (output, "\nok 2 /c/a\n"));
    1437                 :          1 :   g_assert_nonnull (strstr (output, "\nok 3 /b\n"));
    1438                 :          1 :   g_assert_nonnull (strstr (output, "\nok 4 /b/a\n"));
    1439                 :          1 :   g_assert_nonnull (strstr (output, "\nok 5 /b/b\n"));
    1440                 :          1 :   g_assert_nonnull (strstr (output, "\n1..5\n"));
    1441                 :            : 
    1442                 :          1 :   g_spawn_check_wait_status (status, &error);
    1443                 :          1 :   g_assert_no_error (error);
    1444                 :            : 
    1445                 :          1 :   g_free (output);
    1446                 :          1 :   g_ptr_array_unref (argv);
    1447                 :            : 
    1448                 :          1 :   g_test_message ("--run-prefix");
    1449                 :          1 :   argv = g_ptr_array_new ();
    1450                 :          1 :   g_ptr_array_add (argv, (char *) testing_helper);
    1451                 :          1 :   g_ptr_array_add (argv, "skip-options");
    1452                 :          1 :   g_ptr_array_add (argv, "--tap");
    1453                 :          1 :   g_ptr_array_add (argv, "-r");
    1454                 :          1 :   g_ptr_array_add (argv, "/c/a");
    1455                 :          1 :   g_ptr_array_add (argv, "-r");
    1456                 :          1 :   g_ptr_array_add (argv, "/c/a");
    1457                 :          1 :   g_ptr_array_add (argv, "--run-prefix");
    1458                 :          1 :   g_ptr_array_add (argv, "/b");
    1459                 :          1 :   g_ptr_array_add (argv, NULL);
    1460                 :            : 
    1461                 :          1 :   g_spawn_sync (NULL, (char **) argv->pdata, envp,
    1462                 :            :                 G_SPAWN_STDERR_TO_DEV_NULL,
    1463                 :            :                 NULL, NULL, &output, NULL, &status,
    1464                 :            :                 &error);
    1465                 :          1 :   g_assert_no_error (error);
    1466                 :          1 :   g_assert_true (g_str_has_prefix (output, "TAP version " TAP_VERSION));
    1467                 :          1 :   g_assert_null (strstr (output, "# Subtest: "));
    1468                 :          1 :   g_assert_nonnull (strstr (output, "\nok 1 /c/a\n"));
    1469                 :          1 :   g_assert_nonnull (strstr (output, "\nok 2 /c/a\n"));
    1470                 :          1 :   g_assert_nonnull (strstr (output, "\nok 3 /b\n"));
    1471                 :          1 :   g_assert_nonnull (strstr (output, "\nok 4 /b/a\n"));
    1472                 :          1 :   g_assert_nonnull (strstr (output, "\nok 5 /b/b\n"));
    1473                 :          1 :   g_assert_nonnull (strstr (output, "\nok 6 /b/b/a\n"));
    1474                 :          1 :   g_assert_nonnull (strstr (output, "\n1..6\n"));
    1475                 :            : 
    1476                 :          1 :   g_spawn_check_wait_status (status, &error);
    1477                 :          1 :   g_assert_no_error (error);
    1478                 :            : 
    1479                 :          1 :   g_free (output);
    1480                 :          1 :   g_ptr_array_unref (argv);
    1481                 :            : 
    1482                 :          1 :   g_test_message ("--run-prefix 2");
    1483                 :          1 :   argv = g_ptr_array_new ();
    1484                 :          1 :   g_ptr_array_add (argv, (char *) testing_helper);
    1485                 :          1 :   g_ptr_array_add (argv, "skip-options");
    1486                 :          1 :   g_ptr_array_add (argv, "--tap");
    1487                 :          1 :   g_ptr_array_add (argv, "-r");
    1488                 :          1 :   g_ptr_array_add (argv, "/pre");
    1489                 :          1 :   g_ptr_array_add (argv, "--run-prefix");
    1490                 :          1 :   g_ptr_array_add (argv, "/b/b");
    1491                 :          1 :   g_ptr_array_add (argv, NULL);
    1492                 :            : 
    1493                 :          1 :   g_spawn_sync (NULL, (char **) argv->pdata, envp,
    1494                 :            :                 G_SPAWN_STDERR_TO_DEV_NULL,
    1495                 :            :                 NULL, NULL, &output, NULL, &status,
    1496                 :            :                 &error);
    1497                 :          1 :   g_assert_no_error (error);
    1498                 :          1 :   g_assert_true (g_str_has_prefix (output, "TAP version " TAP_VERSION));
    1499                 :          1 :   g_assert_null (strstr (output, "# Subtest: "));
    1500                 :          1 :   g_assert_nonnull (strstr (output, "\nok 1 /b/b\n"));
    1501                 :          1 :   g_assert_nonnull (strstr (output, "\nok 2 /b/b/a\n"));
    1502                 :          1 :   g_assert_nonnull (strstr (output, "\n1..2\n"));
    1503                 :            : 
    1504                 :          1 :   g_spawn_check_wait_status (status, &error);
    1505                 :          1 :   g_assert_no_error (error);
    1506                 :            : 
    1507                 :          1 :   g_free (output);
    1508                 :          1 :   g_ptr_array_unref (argv);
    1509                 :            : 
    1510                 :          1 :   g_test_message ("--run-prefix conflict");
    1511                 :          1 :   argv = g_ptr_array_new ();
    1512                 :          1 :   g_ptr_array_add (argv, (char *) testing_helper);
    1513                 :          1 :   g_ptr_array_add (argv, "skip-options");
    1514                 :          1 :   g_ptr_array_add (argv, "--tap");
    1515                 :          1 :   g_ptr_array_add (argv, "-r");
    1516                 :          1 :   g_ptr_array_add (argv, "/c/a");
    1517                 :          1 :   g_ptr_array_add (argv, "-p");
    1518                 :          1 :   g_ptr_array_add (argv, "/c/a");
    1519                 :          1 :   g_ptr_array_add (argv, "--run-prefix");
    1520                 :          1 :   g_ptr_array_add (argv, "/b");
    1521                 :          1 :   g_ptr_array_add (argv, NULL);
    1522                 :            : 
    1523                 :          1 :   g_spawn_sync (NULL, (char **) argv->pdata, envp,
    1524                 :            :                 G_SPAWN_STDERR_TO_DEV_NULL,
    1525                 :            :                 NULL, NULL, &output, NULL, &status,
    1526                 :            :                 &error);
    1527                 :          1 :   g_assert_no_error (error);
    1528                 :          1 :   g_spawn_check_wait_status (status, &error);
    1529                 :          1 :   g_assert_nonnull (error);
    1530                 :          1 :   g_assert_false (g_str_has_prefix (output, "TAP version " TAP_VERSION));
    1531                 :          1 :   g_assert_nonnull (strstr (output, "do not mix [-r | --run-prefix] with '-p'\n"));
    1532                 :          1 :   g_clear_error (&error);
    1533                 :            : 
    1534                 :          1 :   g_free (output);
    1535                 :          1 :   g_ptr_array_unref (argv);
    1536                 :            : 
    1537                 :          1 :   g_test_message ("-s");
    1538                 :          1 :   argv = g_ptr_array_new ();
    1539                 :          1 :   g_ptr_array_add (argv, (char *) testing_helper);
    1540                 :          1 :   g_ptr_array_add (argv, "skip-options");
    1541                 :          1 :   g_ptr_array_add (argv, "--tap");
    1542                 :          1 :   g_ptr_array_add (argv, "-s");
    1543                 :          1 :   g_ptr_array_add (argv, "/a");
    1544                 :          1 :   g_ptr_array_add (argv, "-s");
    1545                 :          1 :   g_ptr_array_add (argv, "/b");
    1546                 :          1 :   g_ptr_array_add (argv, "-s");
    1547                 :          1 :   g_ptr_array_add (argv, "/pre");
    1548                 :          1 :   g_ptr_array_add (argv, "-s");
    1549                 :          1 :   g_ptr_array_add (argv, "/c/a");
    1550                 :          1 :   g_ptr_array_add (argv, NULL);
    1551                 :            : 
    1552                 :          1 :   g_spawn_sync (NULL, (char **) argv->pdata, envp,
    1553                 :            :                 G_SPAWN_STDERR_TO_DEV_NULL,
    1554                 :            :                 NULL, NULL, &output, NULL, &status,
    1555                 :            :                 &error);
    1556                 :          1 :   g_assert_no_error (error);
    1557                 :          1 :   g_assert_true (g_str_has_prefix (output, "TAP version " TAP_VERSION));
    1558                 :          1 :   g_assert_null (strstr (output, "# Subtest: "));
    1559                 :          1 :   g_assert_nonnull (strstr (output, "1..10\n"));
    1560                 :          1 :   g_assert_nonnull (strstr (output, "\nok 1 /a # SKIP by request"));
    1561                 :          1 :   g_assert_nonnull (strstr (output, "\nok 2 /b # SKIP by request"));
    1562                 :            :   /* "-s /b" would skip a test named exactly /b, but not a test named
    1563                 :            :    * /b/anything */
    1564                 :          1 :   g_assert_nonnull (strstr (output, "\nok 3 /b/a\n"));
    1565                 :          1 :   g_assert_nonnull (strstr (output, "\nok 4 /b/b\n"));
    1566                 :          1 :   g_assert_nonnull (strstr (output, "\nok 5 /b/b/a\n"));
    1567                 :          1 :   g_assert_nonnull (strstr (output, "\nok 6 /prefix/a\n"));
    1568                 :          1 :   g_assert_nonnull (strstr (output, "\nok 7 /prefix/b/b\n"));
    1569                 :          1 :   g_assert_nonnull (strstr (output, "\nok 8 /prefix-long/a\n"));
    1570                 :          1 :   g_assert_nonnull (strstr (output, "\nok 9 /c/a # SKIP by request"));
    1571                 :          1 :   g_assert_nonnull (strstr (output, "\nok 10 /d/a\n"));
    1572                 :            : 
    1573                 :          1 :   g_spawn_check_wait_status (status, &error);
    1574                 :          1 :   g_assert_no_error (error);
    1575                 :            : 
    1576                 :          1 :   g_free (output);
    1577                 :          1 :   g_ptr_array_unref (argv);
    1578                 :            : 
    1579                 :          1 :   g_test_message ("--skip-prefix");
    1580                 :          1 :   argv = g_ptr_array_new ();
    1581                 :          1 :   g_ptr_array_add (argv, (char *) testing_helper);
    1582                 :          1 :   g_ptr_array_add (argv, "skip-options");
    1583                 :          1 :   g_ptr_array_add (argv, "--tap");
    1584                 :          1 :   g_ptr_array_add (argv, "-x");
    1585                 :          1 :   g_ptr_array_add (argv, "/a");
    1586                 :          1 :   g_ptr_array_add (argv, "--skip-prefix");
    1587                 :          1 :   g_ptr_array_add (argv, "/pre");
    1588                 :          1 :   g_ptr_array_add (argv, "-x");
    1589                 :          1 :   g_ptr_array_add (argv, "/c/a");
    1590                 :          1 :   g_ptr_array_add (argv, NULL);
    1591                 :            : 
    1592                 :          1 :   g_spawn_sync (NULL, (char **) argv->pdata, envp,
    1593                 :            :                 G_SPAWN_STDERR_TO_DEV_NULL,
    1594                 :            :                 NULL, NULL, &output, NULL, &status,
    1595                 :            :                 &error);
    1596                 :          1 :   g_assert_no_error (error);
    1597                 :          1 :   g_assert_true (g_str_has_prefix (output, "TAP version " TAP_VERSION));
    1598                 :          1 :   g_assert_null (strstr (output, "# Subtest: "));
    1599                 :          1 :   g_assert_nonnull (strstr (output, "1..10\n"));
    1600                 :          1 :   g_assert_nonnull (strstr (output, "\nok 1 /a # SKIP by request"));
    1601                 :          1 :   g_assert_nonnull (strstr (output, "\nok 2 /b\n"));
    1602                 :          1 :   g_assert_nonnull (strstr (output, "\nok 3 /b/a\n"));
    1603                 :          1 :   g_assert_nonnull (strstr (output, "\nok 4 /b/b\n"));
    1604                 :          1 :   g_assert_nonnull (strstr (output, "\nok 5 /b/b/a\n"));
    1605                 :            :   /* "--skip-prefix /pre" will skip all test path which begins with /pre */
    1606                 :          1 :   g_assert_nonnull (strstr (output, "\nok 6 /prefix/a # SKIP by request"));
    1607                 :          1 :   g_assert_nonnull (strstr (output, "\nok 7 /prefix/b/b # SKIP by request"));
    1608                 :          1 :   g_assert_nonnull (strstr (output, "\nok 8 /prefix-long/a # SKIP by request"));
    1609                 :          1 :   g_assert_nonnull (strstr (output, "\nok 9 /c/a # SKIP by request"));
    1610                 :          1 :   g_assert_nonnull (strstr (output, "\nok 10 /d/a\n"));
    1611                 :            : 
    1612                 :          1 :   g_spawn_check_wait_status (status, &error);
    1613                 :          1 :   g_assert_no_error (error);
    1614                 :            : 
    1615                 :          1 :   g_free (output);
    1616                 :          1 :   g_ptr_array_unref (argv);
    1617                 :            : 
    1618                 :          1 :   g_test_message ("--skip-prefix conflict");
    1619                 :          1 :   argv = g_ptr_array_new ();
    1620                 :          1 :   g_ptr_array_add (argv, (char *) testing_helper);
    1621                 :          1 :   g_ptr_array_add (argv, "skip-options");
    1622                 :          1 :   g_ptr_array_add (argv, "--tap");
    1623                 :          1 :   g_ptr_array_add (argv, "-s");
    1624                 :          1 :   g_ptr_array_add (argv, "/a");
    1625                 :          1 :   g_ptr_array_add (argv, "--skip-prefix");
    1626                 :          1 :   g_ptr_array_add (argv, "/pre");
    1627                 :          1 :   g_ptr_array_add (argv, "-x");
    1628                 :          1 :   g_ptr_array_add (argv, "/c/a");
    1629                 :          1 :   g_ptr_array_add (argv, NULL);
    1630                 :            : 
    1631                 :          1 :   g_spawn_sync (NULL, (char **) argv->pdata, envp,
    1632                 :            :                 G_SPAWN_STDERR_TO_DEV_NULL,
    1633                 :            :                 NULL, NULL, &output, NULL, &status,
    1634                 :            :                 &error);
    1635                 :          1 :   g_assert_no_error (error);
    1636                 :          1 :   g_spawn_check_wait_status (status, &error);
    1637                 :          1 :   g_assert_nonnull (error);
    1638                 :          1 :   g_assert_false (g_str_has_prefix (output, "TAP version " TAP_VERSION));
    1639                 :          1 :   g_assert_nonnull (strstr (output, "do not mix [-x | --skip-prefix] with '-s'\n"));
    1640                 :          1 :   g_clear_error (&error);
    1641                 :            : 
    1642                 :          1 :   g_free (output);
    1643                 :          1 :   g_ptr_array_unref (argv);
    1644                 :          1 :   g_strfreev (envp);
    1645                 :          1 : }
    1646                 :            : 
    1647                 :            : /* Test the TAP output when a test suite is run with --tap. */
    1648                 :            : static void
    1649                 :          1 : test_tap_subtest (void)
    1650                 :            : {
    1651                 :            :   const char *testing_helper;
    1652                 :            :   GPtrArray *argv;
    1653                 :          1 :   GError *error = NULL;
    1654                 :            :   int status;
    1655                 :            :   gchar *output;
    1656                 :          1 :   char** envp = NULL;
    1657                 :            : 
    1658                 :          1 :   testing_helper = g_test_get_filename (G_TEST_BUILT, "testing-helper" EXEEXT, NULL);
    1659                 :            : 
    1660                 :          1 :   g_test_message ("pass");
    1661                 :          1 :   argv = g_ptr_array_new ();
    1662                 :          1 :   g_ptr_array_add (argv, (char *) testing_helper);
    1663                 :          1 :   g_ptr_array_add (argv, "pass");
    1664                 :          1 :   g_ptr_array_add (argv, "--tap");
    1665                 :          1 :   g_ptr_array_add (argv, NULL);
    1666                 :            : 
    1667                 :          1 :   envp = g_get_environ ();
    1668                 :          1 :   g_assert_nonnull (g_environ_getenv (envp, "G_TEST_ROOT_PROCESS"));
    1669                 :          1 :   g_clear_pointer (&envp, g_strfreev);
    1670                 :            : 
    1671                 :          1 :   g_spawn_sync (NULL, (char **) argv->pdata, envp,
    1672                 :            :                 G_SPAWN_STDERR_TO_DEV_NULL,
    1673                 :            :                 NULL, NULL, &output, NULL, &status,
    1674                 :            :                 &error);
    1675                 :          1 :   g_assert_no_error (error);
    1676                 :            : 
    1677                 :          1 :   g_spawn_check_wait_status (status, &error);
    1678                 :          1 :   g_assert_no_error (error);
    1679                 :          1 :   g_assert_null (strstr (output, "TAP version " TAP_VERSION));
    1680                 :          1 :   g_assert_true (g_str_has_prefix (output, "# Subtest: "));
    1681                 :          1 :   g_assert_nonnull (strstr (output,
    1682                 :            :     "\n" TAP_SUBTEST_PREFIX "ok 1 /pass\n"));
    1683                 :          1 :   g_free (output);
    1684                 :          1 :   g_ptr_array_unref (argv);
    1685                 :            : 
    1686                 :          1 :   g_test_message ("skip");
    1687                 :          1 :   argv = g_ptr_array_new ();
    1688                 :          1 :   g_ptr_array_add (argv, (char *) testing_helper);
    1689                 :          1 :   g_ptr_array_add (argv, "skip");
    1690                 :          1 :   g_ptr_array_add (argv, "--tap");
    1691                 :          1 :   g_ptr_array_add (argv, NULL);
    1692                 :            : 
    1693                 :          1 :   g_spawn_sync (NULL, (char **) argv->pdata, envp,
    1694                 :            :                 G_SPAWN_STDERR_TO_DEV_NULL,
    1695                 :            :                 NULL, NULL, &output, NULL, &status,
    1696                 :            :                 &error);
    1697                 :          1 :   g_assert_no_error (error);
    1698                 :            : 
    1699                 :          1 :   g_spawn_check_wait_status (status, &error);
    1700                 :          1 :   g_assert_no_error (error);
    1701                 :          1 :   g_assert_null (strstr (output, "TAP version " TAP_VERSION));
    1702                 :          1 :   g_assert_true (g_str_has_prefix (output, "# Subtest: "));
    1703                 :          1 :   g_assert_nonnull (strstr (output,
    1704                 :            :     "\n" TAP_SUBTEST_PREFIX "ok 1 /skip # SKIP not enough tea\n"));
    1705                 :          1 :   g_free (output);
    1706                 :          1 :   g_ptr_array_unref (argv);
    1707                 :            : 
    1708                 :          1 :   g_test_message ("skip with printf format");
    1709                 :          1 :   argv = g_ptr_array_new ();
    1710                 :          1 :   g_ptr_array_add (argv, (char *) testing_helper);
    1711                 :          1 :   g_ptr_array_add (argv, "skip-printf");
    1712                 :          1 :   g_ptr_array_add (argv, "--tap");
    1713                 :          1 :   g_ptr_array_add (argv, NULL);
    1714                 :            : 
    1715                 :          1 :   g_spawn_sync (NULL, (char **) argv->pdata, envp,
    1716                 :            :                 G_SPAWN_STDERR_TO_DEV_NULL,
    1717                 :            :                 NULL, NULL, &output, NULL, &status,
    1718                 :            :                 &error);
    1719                 :          1 :   g_assert_no_error (error);
    1720                 :            : 
    1721                 :          1 :   g_spawn_check_wait_status (status, &error);
    1722                 :          1 :   g_assert_no_error (error);
    1723                 :          1 :   g_assert_null (strstr (output, "TAP version " TAP_VERSION));
    1724                 :          1 :   g_assert_true (g_str_has_prefix (output, "# Subtest: "));
    1725                 :          1 :   g_assert_nonnull (strstr (output,
    1726                 :            :     "\n" TAP_SUBTEST_PREFIX "ok 1 /skip-printf # SKIP not enough coffee\n"));
    1727                 :          1 :   g_free (output);
    1728                 :          1 :   g_ptr_array_unref (argv);
    1729                 :            : 
    1730                 :          1 :   g_test_message ("incomplete");
    1731                 :          1 :   argv = g_ptr_array_new ();
    1732                 :          1 :   g_ptr_array_add (argv, (char *) testing_helper);
    1733                 :          1 :   g_ptr_array_add (argv, "incomplete");
    1734                 :          1 :   g_ptr_array_add (argv, "--tap");
    1735                 :          1 :   g_ptr_array_add (argv, NULL);
    1736                 :            : 
    1737                 :          1 :   g_spawn_sync (NULL, (char **) argv->pdata, envp,
    1738                 :            :                 G_SPAWN_STDERR_TO_DEV_NULL,
    1739                 :            :                 NULL, NULL, &output, NULL, &status,
    1740                 :            :                 &error);
    1741                 :          1 :   g_assert_no_error (error);
    1742                 :            : 
    1743                 :          1 :   g_spawn_check_wait_status (status, &error);
    1744                 :          1 :   g_assert_no_error (error);
    1745                 :          1 :   g_assert_null (strstr (output, "TAP version " TAP_VERSION));
    1746                 :          1 :   g_assert_null (strstr (output, "\n# Subtest: "));
    1747                 :          1 :   g_assert_nonnull (strstr (output,
    1748                 :            :     "\n" TAP_SUBTEST_PREFIX "not ok 1 /incomplete # TODO mind reading not implemented yet\n"));
    1749                 :          1 :   g_free (output);
    1750                 :          1 :   g_ptr_array_unref (argv);
    1751                 :            : 
    1752                 :          1 :   g_test_message ("incomplete with printf format");
    1753                 :          1 :   argv = g_ptr_array_new ();
    1754                 :          1 :   g_ptr_array_add (argv, (char *) testing_helper);
    1755                 :          1 :   g_ptr_array_add (argv, "incomplete-printf");
    1756                 :          1 :   g_ptr_array_add (argv, "--tap");
    1757                 :          1 :   g_ptr_array_add (argv, NULL);
    1758                 :            : 
    1759                 :          1 :   g_spawn_sync (NULL, (char **) argv->pdata, envp,
    1760                 :            :                 G_SPAWN_STDERR_TO_DEV_NULL,
    1761                 :            :                 NULL, NULL, &output, NULL, &status,
    1762                 :            :                 &error);
    1763                 :          1 :   g_assert_no_error (error);
    1764                 :            : 
    1765                 :          1 :   g_spawn_check_wait_status (status, &error);
    1766                 :          1 :   g_assert_no_error (error);
    1767                 :          1 :   g_assert_null (strstr (output, "TAP version " TAP_VERSION));
    1768                 :          1 :   g_assert_null( strstr (output, "\n# Subtest: "));
    1769                 :          1 :   g_assert_nonnull (strstr (output,
    1770                 :            :     "\n" TAP_SUBTEST_PREFIX "not ok 1 /incomplete-printf # TODO telekinesis not implemented yet\n"));
    1771                 :          1 :   g_free (output);
    1772                 :          1 :   g_ptr_array_unref (argv);
    1773                 :            : 
    1774                 :          1 :   g_test_message ("fail");
    1775                 :          1 :   argv = g_ptr_array_new ();
    1776                 :          1 :   g_ptr_array_add (argv, (char *) testing_helper);
    1777                 :          1 :   g_ptr_array_add (argv, "fail");
    1778                 :          1 :   g_ptr_array_add (argv, "--tap");
    1779                 :          1 :   g_ptr_array_add (argv, NULL);
    1780                 :            : 
    1781                 :          1 :   g_spawn_sync (NULL, (char **) argv->pdata, envp,
    1782                 :            :                 G_SPAWN_STDERR_TO_DEV_NULL,
    1783                 :            :                 NULL, NULL, &output, NULL, &status,
    1784                 :            :                 &error);
    1785                 :          1 :   g_assert_no_error (error);
    1786                 :            : 
    1787                 :          1 :   g_spawn_check_wait_status (status, &error);
    1788                 :          1 :   g_assert_error (error, G_SPAWN_EXIT_ERROR, 1);
    1789                 :          1 :   g_assert_null (strstr (output, "TAP version " TAP_VERSION));
    1790                 :          1 :   g_assert_null( strstr (output, "\n# Subtest: "));
    1791                 :          1 :   g_assert_nonnull (strstr (output,
    1792                 :            :     "\n" TAP_SUBTEST_PREFIX "not ok 1 /fail\n"));
    1793                 :          1 :   g_free (output);
    1794                 :          1 :   g_clear_error (&error);
    1795                 :          1 :   g_ptr_array_unref (argv);
    1796                 :            : 
    1797                 :          1 :   g_test_message ("fail with message");
    1798                 :          1 :   argv = g_ptr_array_new ();
    1799                 :          1 :   g_ptr_array_add (argv, (char *) testing_helper);
    1800                 :          1 :   g_ptr_array_add (argv, "fail-printf");
    1801                 :          1 :   g_ptr_array_add (argv, "--tap");
    1802                 :          1 :   g_ptr_array_add (argv, NULL);
    1803                 :            : 
    1804                 :          1 :   g_spawn_sync (NULL, (char **) argv->pdata, envp,
    1805                 :            :                 G_SPAWN_STDERR_TO_DEV_NULL,
    1806                 :            :                 NULL, NULL, &output, NULL, &status,
    1807                 :            :                 &error);
    1808                 :          1 :   g_assert_no_error (error);
    1809                 :            : 
    1810                 :          1 :   g_spawn_check_wait_status (status, &error);
    1811                 :          1 :   g_assert_error (error, G_SPAWN_EXIT_ERROR, 1);
    1812                 :          1 :   g_assert_null (strstr (output, "TAP version " TAP_VERSION));
    1813                 :          1 :   g_assert_null( strstr (output, "\n# Subtest: "));
    1814                 :          1 :   g_assert_nonnull (strstr (output,
    1815                 :            :     "\n" TAP_SUBTEST_PREFIX "not ok 1 /fail-printf - this test intentionally left failing\n"));
    1816                 :          1 :   g_free (output);
    1817                 :          1 :   g_clear_error (&error);
    1818                 :          1 :   g_ptr_array_unref (argv);
    1819                 :            : 
    1820                 :          1 :   g_test_message ("all");
    1821                 :          1 :   argv = g_ptr_array_new ();
    1822                 :          1 :   g_ptr_array_add (argv, (char *) testing_helper);
    1823                 :          1 :   g_ptr_array_add (argv, "all");
    1824                 :          1 :   g_ptr_array_add (argv, "--tap");
    1825                 :          1 :   g_ptr_array_add (argv, NULL);
    1826                 :            : 
    1827                 :          1 :   g_spawn_sync (NULL, (char **) argv->pdata, envp,
    1828                 :            :                 G_SPAWN_STDOUT_TO_DEV_NULL | G_SPAWN_STDERR_TO_DEV_NULL,
    1829                 :            :                 NULL, NULL, NULL, NULL, &status,
    1830                 :            :                 &error);
    1831                 :          1 :   g_assert_no_error (error);
    1832                 :            : 
    1833                 :          1 :   g_spawn_check_wait_status (status, &error);
    1834                 :          1 :   g_assert_error (error, G_SPAWN_EXIT_ERROR, 1);
    1835                 :          1 :   g_clear_error (&error);
    1836                 :          1 :   g_ptr_array_unref (argv);
    1837                 :            : 
    1838                 :          1 :   g_test_message ("all-non-failures");
    1839                 :          1 :   argv = g_ptr_array_new ();
    1840                 :          1 :   g_ptr_array_add (argv, (char *) testing_helper);
    1841                 :          1 :   g_ptr_array_add (argv, "all-non-failures");
    1842                 :          1 :   g_ptr_array_add (argv, "--tap");
    1843                 :          1 :   g_ptr_array_add (argv, NULL);
    1844                 :            : 
    1845                 :          1 :   g_spawn_sync (NULL, (char **) argv->pdata, envp,
    1846                 :            :                 G_SPAWN_STDOUT_TO_DEV_NULL | G_SPAWN_STDERR_TO_DEV_NULL,
    1847                 :            :                 NULL, NULL, NULL, NULL, &status,
    1848                 :            :                 &error);
    1849                 :          1 :   g_assert_no_error (error);
    1850                 :            : 
    1851                 :          1 :   g_spawn_check_wait_status (status, &error);
    1852                 :          1 :   g_assert_no_error (error);
    1853                 :            : 
    1854                 :          1 :   g_ptr_array_unref (argv);
    1855                 :            : 
    1856                 :          1 :   g_test_message ("--GTestSkipCount");
    1857                 :          1 :   argv = g_ptr_array_new ();
    1858                 :          1 :   g_ptr_array_add (argv, (char *) testing_helper);
    1859                 :          1 :   g_ptr_array_add (argv, "skip-options");
    1860                 :          1 :   g_ptr_array_add (argv, "--tap");
    1861                 :          1 :   g_ptr_array_add (argv, "--GTestSkipCount");
    1862                 :          1 :   g_ptr_array_add (argv, "2");
    1863                 :          1 :   g_ptr_array_add (argv, NULL);
    1864                 :            : 
    1865                 :          1 :   g_spawn_sync (NULL, (char **) argv->pdata, envp,
    1866                 :            :                 G_SPAWN_STDERR_TO_DEV_NULL,
    1867                 :            :                 NULL, NULL, &output, NULL, &status,
    1868                 :            :                 &error);
    1869                 :          1 :   g_assert_no_error (error);
    1870                 :          1 :   g_assert_null (strstr (output, "TAP version " TAP_VERSION));
    1871                 :          1 :   g_assert_null( strstr (output, "\n# Subtest: "));
    1872                 :          1 :   g_assert_nonnull (strstr (output, TAP_SUBTEST_PREFIX "1..10\n"));
    1873                 :          1 :   g_assert_nonnull (strstr (output,
    1874                 :            :     "\n" TAP_SUBTEST_PREFIX "ok 1 /a # SKIP\n"));
    1875                 :          1 :   g_assert_nonnull (strstr (output,
    1876                 :            :     "\n" TAP_SUBTEST_PREFIX "ok 2 /b # SKIP\n"));
    1877                 :          1 :   g_assert_nonnull (strstr (output,
    1878                 :            :     "\n" TAP_SUBTEST_PREFIX "ok 3 /b/a\n"));
    1879                 :          1 :   g_assert_nonnull (strstr (output,
    1880                 :            :     "\n" TAP_SUBTEST_PREFIX "ok 4 /b/b\n"));
    1881                 :          1 :   g_assert_nonnull (strstr (output,
    1882                 :            :     "\n" TAP_SUBTEST_PREFIX "ok 5 /b/b/a\n"));
    1883                 :          1 :   g_assert_nonnull (strstr (output,
    1884                 :            :     "\n" TAP_SUBTEST_PREFIX "ok 6 /prefix/a\n"));
    1885                 :          1 :   g_assert_nonnull (strstr (output,
    1886                 :            :     "\n" TAP_SUBTEST_PREFIX "ok 7 /prefix/b/b\n"));
    1887                 :          1 :   g_assert_nonnull (strstr (output,
    1888                 :            :     "\n" TAP_SUBTEST_PREFIX "ok 8 /prefix-long/a\n"));
    1889                 :          1 :   g_assert_nonnull (strstr (output,
    1890                 :            :     "\n" TAP_SUBTEST_PREFIX "ok 9 /c/a\n"));
    1891                 :          1 :   g_assert_nonnull (strstr (output,
    1892                 :            :     "\n" TAP_SUBTEST_PREFIX "ok 10 /d/a\n"));
    1893                 :            : 
    1894                 :          1 :   g_spawn_check_wait_status (status, &error);
    1895                 :          1 :   g_assert_no_error (error);
    1896                 :            : 
    1897                 :          1 :   g_free (output);
    1898                 :          1 :   g_ptr_array_unref (argv);
    1899                 :            : 
    1900                 :          1 :   g_test_message ("--GTestSkipCount=0 is the same as omitting it");
    1901                 :          1 :   argv = g_ptr_array_new ();
    1902                 :          1 :   g_ptr_array_add (argv, (char *) testing_helper);
    1903                 :          1 :   g_ptr_array_add (argv, "skip-options");
    1904                 :          1 :   g_ptr_array_add (argv, "--tap");
    1905                 :          1 :   g_ptr_array_add (argv, "--GTestSkipCount");
    1906                 :          1 :   g_ptr_array_add (argv, "0");
    1907                 :          1 :   g_ptr_array_add (argv, NULL);
    1908                 :            : 
    1909                 :          1 :   g_spawn_sync (NULL, (char **) argv->pdata, envp,
    1910                 :            :                 G_SPAWN_STDERR_TO_DEV_NULL,
    1911                 :            :                 NULL, NULL, &output, NULL, &status,
    1912                 :            :                 &error);
    1913                 :          1 :   g_assert_no_error (error);
    1914                 :          1 :   g_assert_null (strstr (output, "TAP version " TAP_VERSION));
    1915                 :          1 :   g_assert_null( strstr (output, "\n# Subtest: "));
    1916                 :          1 :   g_assert_nonnull (strstr (output, TAP_SUBTEST_PREFIX "1..10\n"));
    1917                 :          1 :   g_assert_nonnull (strstr (output,
    1918                 :            :     "\n" TAP_SUBTEST_PREFIX "ok 1 /a\n"));
    1919                 :          1 :   g_assert_nonnull (strstr (output,
    1920                 :            :     "\n" TAP_SUBTEST_PREFIX "ok 2 /b\n"));
    1921                 :          1 :   g_assert_nonnull (strstr (output,
    1922                 :            :     "\n" TAP_SUBTEST_PREFIX "ok 3 /b/a\n"));
    1923                 :          1 :   g_assert_nonnull (strstr (output,
    1924                 :            :     "\n" TAP_SUBTEST_PREFIX "ok 4 /b/b\n"));
    1925                 :          1 :   g_assert_nonnull (strstr (output,
    1926                 :            :     "\n" TAP_SUBTEST_PREFIX "ok 5 /b/b/a\n"));
    1927                 :          1 :   g_assert_nonnull (strstr (output,
    1928                 :            :     "\n" TAP_SUBTEST_PREFIX "ok 6 /prefix/a\n"));
    1929                 :          1 :   g_assert_nonnull (strstr (output,
    1930                 :            :     "\n" TAP_SUBTEST_PREFIX "ok 7 /prefix/b/b\n"));
    1931                 :          1 :   g_assert_nonnull (strstr (output,
    1932                 :            :     "\n" TAP_SUBTEST_PREFIX "ok 8 /prefix-long/a\n"));
    1933                 :          1 :   g_assert_nonnull (strstr (output,
    1934                 :            :     "\n" TAP_SUBTEST_PREFIX "ok 9 /c/a\n"));
    1935                 :          1 :   g_assert_nonnull (strstr (output,
    1936                 :            :     "\n" TAP_SUBTEST_PREFIX "ok 10 /d/a\n"));
    1937                 :            : 
    1938                 :          1 :   g_spawn_check_wait_status (status, &error);
    1939                 :          1 :   g_assert_no_error (error);
    1940                 :            : 
    1941                 :          1 :   g_free (output);
    1942                 :          1 :   g_ptr_array_unref (argv);
    1943                 :            : 
    1944                 :          1 :   g_test_message ("--GTestSkipCount > number of tests skips all");
    1945                 :          1 :   argv = g_ptr_array_new ();
    1946                 :          1 :   g_ptr_array_add (argv, (char *) testing_helper);
    1947                 :          1 :   g_ptr_array_add (argv, "skip-options");
    1948                 :          1 :   g_ptr_array_add (argv, "--tap");
    1949                 :          1 :   g_ptr_array_add (argv, "--GTestSkipCount");
    1950                 :          1 :   g_ptr_array_add (argv, "11");
    1951                 :          1 :   g_ptr_array_add (argv, NULL);
    1952                 :            : 
    1953                 :          1 :   g_spawn_sync (NULL, (char **) argv->pdata, envp,
    1954                 :            :                 G_SPAWN_STDERR_TO_DEV_NULL,
    1955                 :            :                 NULL, NULL, &output, NULL, &status,
    1956                 :            :                 &error);
    1957                 :          1 :   g_assert_no_error (error);
    1958                 :          1 :   g_assert_null (strstr (output, "TAP version " TAP_VERSION));
    1959                 :          1 :   g_assert_null( strstr (output, "\n# Subtest: "));
    1960                 :          1 :   g_assert_nonnull (strstr (output, TAP_SUBTEST_PREFIX "1..10\n"));
    1961                 :          1 :   g_assert_nonnull (strstr (output,
    1962                 :            :     "\n" TAP_SUBTEST_PREFIX "ok 1 /a # SKIP\n"));
    1963                 :          1 :   g_assert_nonnull (strstr (output,
    1964                 :            :     "\n" TAP_SUBTEST_PREFIX "ok 2 /b # SKIP\n"));
    1965                 :          1 :   g_assert_nonnull (strstr (output,
    1966                 :            :     "\n" TAP_SUBTEST_PREFIX "ok 3 /b/a # SKIP\n"));
    1967                 :          1 :   g_assert_nonnull (strstr (output,
    1968                 :            :     "\n" TAP_SUBTEST_PREFIX "ok 4 /b/b # SKIP\n"));
    1969                 :          1 :   g_assert_nonnull (strstr (output,
    1970                 :            :     "\n" TAP_SUBTEST_PREFIX "ok 5 /b/b/a # SKIP\n"));
    1971                 :          1 :   g_assert_nonnull (strstr (output,
    1972                 :            :     "\n" TAP_SUBTEST_PREFIX "ok 6 /prefix/a # SKIP\n"));
    1973                 :          1 :   g_assert_nonnull (strstr (output,
    1974                 :            :     "\n" TAP_SUBTEST_PREFIX "ok 7 /prefix/b/b # SKIP\n"));
    1975                 :          1 :   g_assert_nonnull (strstr (output,
    1976                 :            :     "\n" TAP_SUBTEST_PREFIX "ok 8 /prefix-long/a # SKIP\n"));
    1977                 :          1 :   g_assert_nonnull (strstr (output,
    1978                 :            :     "\n" TAP_SUBTEST_PREFIX "ok 9 /c/a # SKIP\n"));
    1979                 :          1 :   g_assert_nonnull (strstr (output,
    1980                 :            :     "\n" TAP_SUBTEST_PREFIX "ok 10 /d/a # SKIP\n"));
    1981                 :            : 
    1982                 :          1 :   g_spawn_check_wait_status (status, &error);
    1983                 :          1 :   g_assert_no_error (error);
    1984                 :            : 
    1985                 :          1 :   g_free (output);
    1986                 :          1 :   g_ptr_array_unref (argv);
    1987                 :            : 
    1988                 :          1 :   g_test_message ("-p");
    1989                 :          1 :   argv = g_ptr_array_new ();
    1990                 :          1 :   g_ptr_array_add (argv, (char *) testing_helper);
    1991                 :          1 :   g_ptr_array_add (argv, "skip-options");
    1992                 :          1 :   g_ptr_array_add (argv, "--tap");
    1993                 :          1 :   g_ptr_array_add (argv, "-p");
    1994                 :          1 :   g_ptr_array_add (argv, "/c/a");
    1995                 :          1 :   g_ptr_array_add (argv, "-p");
    1996                 :          1 :   g_ptr_array_add (argv, "/c/a");
    1997                 :          1 :   g_ptr_array_add (argv, "-p");
    1998                 :          1 :   g_ptr_array_add (argv, "/b");
    1999                 :          1 :   g_ptr_array_add (argv, NULL);
    2000                 :            : 
    2001                 :          1 :   g_spawn_sync (NULL, (char **) argv->pdata, envp,
    2002                 :            :                 G_SPAWN_STDERR_TO_DEV_NULL,
    2003                 :            :                 NULL, NULL, &output, NULL, &status,
    2004                 :            :                 &error);
    2005                 :          1 :   g_assert_no_error (error);
    2006                 :          1 :   g_assert_null (strstr (output, "TAP version " TAP_VERSION));
    2007                 :          1 :   g_assert_null( strstr (output, "\n# Subtest: "));
    2008                 :          1 :   g_assert_nonnull (strstr (output,
    2009                 :            :     "\n" TAP_SUBTEST_PREFIX "ok 1 /c/a\n"));
    2010                 :          1 :   g_assert_nonnull (strstr (output,
    2011                 :            :     "\n" TAP_SUBTEST_PREFIX "ok 2 /c/a\n"));
    2012                 :          1 :   g_assert_nonnull (strstr (output,
    2013                 :            :     "\n" TAP_SUBTEST_PREFIX "ok 3 /b\n"));
    2014                 :          1 :   g_assert_nonnull (strstr (output,
    2015                 :            :     "\n" TAP_SUBTEST_PREFIX "ok 4 /b/a\n"));
    2016                 :          1 :   g_assert_nonnull (strstr (output,
    2017                 :            :     "\n" TAP_SUBTEST_PREFIX "ok 5 /b/b\n"));
    2018                 :          1 :   g_assert_nonnull (strstr (output,
    2019                 :            :     "\n" TAP_SUBTEST_PREFIX "1..5\n"));
    2020                 :            : 
    2021                 :          1 :   g_spawn_check_wait_status (status, &error);
    2022                 :          1 :   g_assert_no_error (error);
    2023                 :            : 
    2024                 :          1 :   g_free (output);
    2025                 :          1 :   g_ptr_array_unref (argv);
    2026                 :            : 
    2027                 :          1 :   g_test_message ("--run-prefix");
    2028                 :          1 :   argv = g_ptr_array_new ();
    2029                 :          1 :   g_ptr_array_add (argv, (char *) testing_helper);
    2030                 :          1 :   g_ptr_array_add (argv, "skip-options");
    2031                 :          1 :   g_ptr_array_add (argv, "--tap");
    2032                 :          1 :   g_ptr_array_add (argv, "-r");
    2033                 :          1 :   g_ptr_array_add (argv, "/c/a");
    2034                 :          1 :   g_ptr_array_add (argv, "-r");
    2035                 :          1 :   g_ptr_array_add (argv, "/c/a");
    2036                 :          1 :   g_ptr_array_add (argv, "--run-prefix");
    2037                 :          1 :   g_ptr_array_add (argv, "/b");
    2038                 :          1 :   g_ptr_array_add (argv, NULL);
    2039                 :            : 
    2040                 :          1 :   g_spawn_sync (NULL, (char **) argv->pdata, envp,
    2041                 :            :                 G_SPAWN_STDERR_TO_DEV_NULL,
    2042                 :            :                 NULL, NULL, &output, NULL, &status,
    2043                 :            :                 &error);
    2044                 :          1 :   g_assert_no_error (error);
    2045                 :          1 :   g_assert_null (strstr (output, "TAP version " TAP_VERSION));
    2046                 :          1 :   g_assert_null( strstr (output, "\n# Subtest: "));
    2047                 :          1 :   g_assert_nonnull (strstr (output,
    2048                 :            :     "\n" TAP_SUBTEST_PREFIX "ok 1 /c/a\n"));
    2049                 :          1 :   g_assert_nonnull (strstr (output,
    2050                 :            :     "\n" TAP_SUBTEST_PREFIX "ok 2 /c/a\n"));
    2051                 :          1 :   g_assert_nonnull (strstr (output,
    2052                 :            :     "\n" TAP_SUBTEST_PREFIX "ok 3 /b\n"));
    2053                 :          1 :   g_assert_nonnull (strstr (output,
    2054                 :            :     "\n" TAP_SUBTEST_PREFIX "ok 4 /b/a\n"));
    2055                 :          1 :   g_assert_nonnull (strstr (output,
    2056                 :            :     "\n" TAP_SUBTEST_PREFIX "ok 5 /b/b\n"));
    2057                 :          1 :   g_assert_nonnull (strstr (output,
    2058                 :            :     "\n" TAP_SUBTEST_PREFIX "ok 6 /b/b/a\n"));
    2059                 :          1 :   g_assert_nonnull (strstr (output,
    2060                 :            :     "\n" TAP_SUBTEST_PREFIX "1..6\n"));
    2061                 :            : 
    2062                 :          1 :   g_spawn_check_wait_status (status, &error);
    2063                 :          1 :   g_assert_no_error (error);
    2064                 :            : 
    2065                 :          1 :   g_free (output);
    2066                 :          1 :   g_ptr_array_unref (argv);
    2067                 :            : 
    2068                 :          1 :   g_test_message ("--run-prefix 2");
    2069                 :          1 :   argv = g_ptr_array_new ();
    2070                 :          1 :   g_ptr_array_add (argv, (char *) testing_helper);
    2071                 :          1 :   g_ptr_array_add (argv, "skip-options");
    2072                 :          1 :   g_ptr_array_add (argv, "--tap");
    2073                 :          1 :   g_ptr_array_add (argv, "-r");
    2074                 :          1 :   g_ptr_array_add (argv, "/pre");
    2075                 :          1 :   g_ptr_array_add (argv, "--run-prefix");
    2076                 :          1 :   g_ptr_array_add (argv, "/b/b");
    2077                 :          1 :   g_ptr_array_add (argv, NULL);
    2078                 :            : 
    2079                 :          1 :   g_spawn_sync (NULL, (char **) argv->pdata, envp,
    2080                 :            :                 G_SPAWN_STDERR_TO_DEV_NULL,
    2081                 :            :                 NULL, NULL, &output, NULL, &status,
    2082                 :            :                 &error);
    2083                 :          1 :   g_assert_no_error (error);
    2084                 :          1 :   g_assert_null (strstr (output, "TAP version " TAP_VERSION));
    2085                 :          1 :   g_assert_null( strstr (output, "\n# Subtest: "));
    2086                 :          1 :   g_assert_nonnull (strstr (output,
    2087                 :            :     "\n" TAP_SUBTEST_PREFIX "ok 1 /b/b\n"));
    2088                 :          1 :   g_assert_nonnull (strstr (output,
    2089                 :            :     "\n" TAP_SUBTEST_PREFIX "ok 2 /b/b/a\n"));
    2090                 :          1 :   g_assert_nonnull (strstr (output,
    2091                 :            :     "\n" TAP_SUBTEST_PREFIX "1..2\n"));
    2092                 :            : 
    2093                 :          1 :   g_spawn_check_wait_status (status, &error);
    2094                 :          1 :   g_assert_no_error (error);
    2095                 :            : 
    2096                 :          1 :   g_free (output);
    2097                 :          1 :   g_ptr_array_unref (argv);
    2098                 :            : 
    2099                 :          1 :   g_test_message ("--run-prefix conflict");
    2100                 :          1 :   argv = g_ptr_array_new ();
    2101                 :          1 :   g_ptr_array_add (argv, (char *) testing_helper);
    2102                 :          1 :   g_ptr_array_add (argv, "skip-options");
    2103                 :          1 :   g_ptr_array_add (argv, "--tap");
    2104                 :          1 :   g_ptr_array_add (argv, "-r");
    2105                 :          1 :   g_ptr_array_add (argv, "/c/a");
    2106                 :          1 :   g_ptr_array_add (argv, "-p");
    2107                 :          1 :   g_ptr_array_add (argv, "/c/a");
    2108                 :          1 :   g_ptr_array_add (argv, "--run-prefix");
    2109                 :          1 :   g_ptr_array_add (argv, "/b");
    2110                 :          1 :   g_ptr_array_add (argv, NULL);
    2111                 :            : 
    2112                 :          1 :   g_spawn_sync (NULL, (char **) argv->pdata, envp,
    2113                 :            :                 G_SPAWN_STDERR_TO_DEV_NULL,
    2114                 :            :                 NULL, NULL, &output, NULL, &status,
    2115                 :            :                 &error);
    2116                 :          1 :   g_assert_no_error (error);
    2117                 :          1 :   g_spawn_check_wait_status (status, &error);
    2118                 :          1 :   g_assert_nonnull (error);
    2119                 :          1 :   g_assert_null (strstr (output, "TAP version " TAP_VERSION));
    2120                 :          1 :   g_assert_null( strstr (output, "\n# Subtest: "));
    2121                 :          1 :   g_assert_nonnull (strstr (output, "do not mix [-r | --run-prefix] with '-p'\n"));
    2122                 :          1 :   g_clear_error (&error);
    2123                 :            : 
    2124                 :          1 :   g_free (output);
    2125                 :          1 :   g_ptr_array_unref (argv);
    2126                 :            : 
    2127                 :          1 :   g_test_message ("-s");
    2128                 :          1 :   argv = g_ptr_array_new ();
    2129                 :          1 :   g_ptr_array_add (argv, (char *) testing_helper);
    2130                 :          1 :   g_ptr_array_add (argv, "skip-options");
    2131                 :          1 :   g_ptr_array_add (argv, "--tap");
    2132                 :          1 :   g_ptr_array_add (argv, "-s");
    2133                 :          1 :   g_ptr_array_add (argv, "/a");
    2134                 :          1 :   g_ptr_array_add (argv, "-s");
    2135                 :          1 :   g_ptr_array_add (argv, "/b");
    2136                 :          1 :   g_ptr_array_add (argv, "-s");
    2137                 :          1 :   g_ptr_array_add (argv, "/pre");
    2138                 :          1 :   g_ptr_array_add (argv, "-s");
    2139                 :          1 :   g_ptr_array_add (argv, "/c/a");
    2140                 :          1 :   g_ptr_array_add (argv, NULL);
    2141                 :            : 
    2142                 :          1 :   g_spawn_sync (NULL, (char **) argv->pdata, envp,
    2143                 :            :                 G_SPAWN_STDERR_TO_DEV_NULL,
    2144                 :            :                 NULL, NULL, &output, NULL, &status,
    2145                 :            :                 &error);
    2146                 :          1 :   g_assert_no_error (error);
    2147                 :          1 :   g_assert_null (strstr (output, "TAP version " TAP_VERSION));
    2148                 :          1 :   g_assert_null( strstr (output, "\n# Subtest: "));
    2149                 :          1 :   g_assert_nonnull (strstr (output, TAP_SUBTEST_PREFIX "1..10\n"));
    2150                 :          1 :   g_assert_nonnull (strstr (output,
    2151                 :            :     "\n" TAP_SUBTEST_PREFIX "ok 1 /a # SKIP by request"));
    2152                 :          1 :   g_assert_nonnull (strstr (output,
    2153                 :            :     "\n" TAP_SUBTEST_PREFIX "ok 2 /b # SKIP by request"));
    2154                 :            :   /* "-s /b" would skip a test named exactly /b, but not a test named
    2155                 :            :    * /b/anything */
    2156                 :          1 :   g_assert_nonnull (strstr (output,
    2157                 :            :     "\n" TAP_SUBTEST_PREFIX "ok 3 /b/a\n"));
    2158                 :          1 :   g_assert_nonnull (strstr (output,
    2159                 :            :     "\n" TAP_SUBTEST_PREFIX "ok 4 /b/b\n"));
    2160                 :          1 :   g_assert_nonnull (strstr (output,
    2161                 :            :     "\n" TAP_SUBTEST_PREFIX "ok 5 /b/b/a\n"));
    2162                 :          1 :   g_assert_nonnull (strstr (output,
    2163                 :            :     "\n" TAP_SUBTEST_PREFIX "ok 6 /prefix/a\n"));
    2164                 :          1 :   g_assert_nonnull (strstr (output,
    2165                 :            :     "\n" TAP_SUBTEST_PREFIX "ok 7 /prefix/b/b\n"));
    2166                 :          1 :   g_assert_nonnull (strstr (output,
    2167                 :            :     "\n" TAP_SUBTEST_PREFIX "ok 8 /prefix-long/a\n"));
    2168                 :          1 :   g_assert_nonnull (strstr (output,
    2169                 :            :     "\n" TAP_SUBTEST_PREFIX "ok 9 /c/a # SKIP by request"));
    2170                 :          1 :   g_assert_nonnull (strstr (output,
    2171                 :            :     "\n" TAP_SUBTEST_PREFIX "ok 10 /d/a\n"));
    2172                 :            : 
    2173                 :          1 :   g_spawn_check_wait_status (status, &error);
    2174                 :          1 :   g_assert_no_error (error);
    2175                 :            : 
    2176                 :          1 :   g_free (output);
    2177                 :          1 :   g_ptr_array_unref (argv);
    2178                 :            : 
    2179                 :          1 :   g_test_message ("--skip-prefix");
    2180                 :          1 :   argv = g_ptr_array_new ();
    2181                 :          1 :   g_ptr_array_add (argv, (char *) testing_helper);
    2182                 :          1 :   g_ptr_array_add (argv, "skip-options");
    2183                 :          1 :   g_ptr_array_add (argv, "--tap");
    2184                 :          1 :   g_ptr_array_add (argv, "-x");
    2185                 :          1 :   g_ptr_array_add (argv, "/a");
    2186                 :          1 :   g_ptr_array_add (argv, "--skip-prefix");
    2187                 :          1 :   g_ptr_array_add (argv, "/pre");
    2188                 :          1 :   g_ptr_array_add (argv, "-x");
    2189                 :          1 :   g_ptr_array_add (argv, "/c/a");
    2190                 :          1 :   g_ptr_array_add (argv, NULL);
    2191                 :            : 
    2192                 :          1 :   g_spawn_sync (NULL, (char **) argv->pdata, envp,
    2193                 :            :                 G_SPAWN_STDERR_TO_DEV_NULL,
    2194                 :            :                 NULL, NULL, &output, NULL, &status,
    2195                 :            :                 &error);
    2196                 :          1 :   g_assert_no_error (error);
    2197                 :          1 :   g_assert_null (strstr (output, "TAP version " TAP_VERSION));
    2198                 :          1 :   g_assert_true (g_str_has_prefix (output, "# Subtest: "));
    2199                 :          1 :   g_assert_nonnull (strstr (output, TAP_SUBTEST_PREFIX "1..10\n"));
    2200                 :          1 :   g_assert_nonnull (strstr (output,
    2201                 :            :     "\n" TAP_SUBTEST_PREFIX "ok 1 /a # SKIP by request"));
    2202                 :          1 :   g_assert_nonnull (strstr (output,
    2203                 :            :     "\n" TAP_SUBTEST_PREFIX "ok 2 /b\n"));
    2204                 :          1 :   g_assert_nonnull (strstr (output,
    2205                 :            :     "\n" TAP_SUBTEST_PREFIX "ok 3 /b/a\n"));
    2206                 :          1 :   g_assert_nonnull (strstr (output,
    2207                 :            :     "\n" TAP_SUBTEST_PREFIX "ok 4 /b/b\n"));
    2208                 :          1 :   g_assert_nonnull (strstr (output,
    2209                 :            :     "\n" TAP_SUBTEST_PREFIX "ok 5 /b/b/a\n"));
    2210                 :            :   /* "--skip-prefix /pre" will skip all test path which begins with /pre */
    2211                 :          1 :   g_assert_nonnull (strstr (output,
    2212                 :            :     "\n" TAP_SUBTEST_PREFIX "ok 6 /prefix/a # SKIP by request"));
    2213                 :          1 :   g_assert_nonnull (strstr (output,
    2214                 :            :     "\n" TAP_SUBTEST_PREFIX "ok 7 /prefix/b/b # SKIP by request"));
    2215                 :          1 :   g_assert_nonnull (strstr (output,
    2216                 :            :     "\n" TAP_SUBTEST_PREFIX "ok 8 /prefix-long/a # SKIP by request"));
    2217                 :          1 :   g_assert_nonnull (strstr (output,
    2218                 :            :     "\n" TAP_SUBTEST_PREFIX "ok 9 /c/a # SKIP by request"));
    2219                 :          1 :   g_assert_nonnull (strstr (output,
    2220                 :            :     "\n" TAP_SUBTEST_PREFIX "ok 10 /d/a\n"));
    2221                 :            : 
    2222                 :          1 :   g_spawn_check_wait_status (status, &error);
    2223                 :          1 :   g_assert_no_error (error);
    2224                 :            : 
    2225                 :          1 :   g_free (output);
    2226                 :          1 :   g_ptr_array_unref (argv);
    2227                 :          1 : }
    2228                 :            : 
    2229                 :            : static void
    2230                 :          1 : test_tap_summary (void)
    2231                 :            : {
    2232                 :            :   const char *testing_helper;
    2233                 :            :   GPtrArray *argv;
    2234                 :          1 :   GError *error = NULL;
    2235                 :            :   int status;
    2236                 :            :   gchar *output;
    2237                 :            :   char **envp;
    2238                 :            : 
    2239                 :          1 :   g_test_summary ("Test the output of g_test_summary() from the TAP output of a test.");
    2240                 :            : 
    2241                 :          1 :   testing_helper = g_test_get_filename (G_TEST_BUILT, "testing-helper" EXEEXT, NULL);
    2242                 :            : 
    2243                 :          1 :   argv = g_ptr_array_new ();
    2244                 :          1 :   g_ptr_array_add (argv, (char *) testing_helper);
    2245                 :          1 :   g_ptr_array_add (argv, "summary");
    2246                 :          1 :   g_ptr_array_add (argv, "--tap");
    2247                 :          1 :   g_ptr_array_add (argv, NULL);
    2248                 :            : 
    2249                 :            :   /* Remove the G_TEST_ROOT_PROCESS env so it will be considered a standalone test */
    2250                 :          1 :   envp = g_get_environ ();
    2251                 :          1 :   g_assert_nonnull (g_environ_getenv (envp, "G_TEST_ROOT_PROCESS"));
    2252                 :          1 :   envp = g_environ_unsetenv (g_steal_pointer (&envp), "G_TEST_ROOT_PROCESS");
    2253                 :            : 
    2254                 :          1 :   g_spawn_sync (NULL, (char **) argv->pdata, envp,
    2255                 :            :                 G_SPAWN_STDERR_TO_DEV_NULL,
    2256                 :            :                 NULL, NULL, &output, NULL, &status,
    2257                 :            :                 &error);
    2258                 :          1 :   g_assert_no_error (error);
    2259                 :            : 
    2260                 :          1 :   g_spawn_check_wait_status (status, &error);
    2261                 :          1 :   g_assert_no_error (error);
    2262                 :          1 :   g_assert_null (strstr (output, "# Subtest: "));
    2263                 :            : 
    2264                 :            :   /* Note: The test path in the output is not `/tap/summary` because it’s the
    2265                 :          1 :    * test path from testing-helper, not from this function. */g_assert_null (strstr (output, "# Subtest: "));
    2266                 :          1 :   g_assert_nonnull (strstr (output, "\n# /summary summary: Tests that g_test_summary() "
    2267                 :            :                                     "works with TAP, by outputting a known "
    2268                 :            :                                     "summary message in testing-helper, and "
    2269                 :            :                                     "checking for it in the TAP output later.\n"));
    2270                 :          1 :   g_free (output);
    2271                 :          1 :   g_ptr_array_unref (argv);
    2272                 :          1 :   g_strfreev (envp);
    2273                 :          1 : }
    2274                 :            : 
    2275                 :            : static void
    2276                 :          1 : test_tap_subtest_summary (void)
    2277                 :            : {
    2278                 :            :   const char *testing_helper;
    2279                 :            :   GPtrArray *argv;
    2280                 :          1 :   GError *error = NULL;
    2281                 :            :   int status;
    2282                 :            :   gchar *output;
    2283                 :            : 
    2284                 :          1 :   g_test_summary ("Test the output of g_test_summary() from the TAP output of a test.");
    2285                 :            : 
    2286                 :          1 :   testing_helper = g_test_get_filename (G_TEST_BUILT, "testing-helper" EXEEXT, NULL);
    2287                 :            : 
    2288                 :          1 :   argv = g_ptr_array_new ();
    2289                 :          1 :   g_ptr_array_add (argv, (char *) testing_helper);
    2290                 :          1 :   g_ptr_array_add (argv, "summary");
    2291                 :          1 :   g_ptr_array_add (argv, "--tap");
    2292                 :          1 :   g_ptr_array_add (argv, NULL);
    2293                 :            : 
    2294                 :          1 :   g_spawn_sync (NULL, (char **) argv->pdata, NULL,
    2295                 :            :                 G_SPAWN_STDERR_TO_DEV_NULL,
    2296                 :            :                 NULL, NULL, &output, NULL, &status,
    2297                 :            :                 &error);
    2298                 :          1 :   g_assert_no_error (error);
    2299                 :            : 
    2300                 :          1 :   g_spawn_check_wait_status (status, &error);
    2301                 :          1 :   g_assert_no_error (error);
    2302                 :            :   /* Note: The test path in the output is not `/tap/summary` because it’s the
    2303                 :            :    * test path from testing-helper, not from this function. */
    2304                 :          1 :   g_assert_true (g_str_has_prefix (output, "# Subtest: "));
    2305                 :          1 :   g_assert_nonnull (strstr (output,
    2306                 :            :     "\n" TAP_SUBTEST_PREFIX
    2307                 :            :     "# /summary summary: Tests that g_test_summary() "
    2308                 :            :     "works with TAP, by outputting a known "
    2309                 :            :     "summary message in testing-helper, and "
    2310                 :            :     "checking for it in the TAP output later.\n"));
    2311                 :          1 :   g_free (output);
    2312                 :          1 :   g_ptr_array_unref (argv);
    2313                 :          1 : }
    2314                 :            : 
    2315                 :            : static void
    2316                 :          1 : test_tap_message (void)
    2317                 :            : {
    2318                 :            :   const char *testing_helper;
    2319                 :            :   GPtrArray *argv;
    2320                 :          1 :   GError *error = NULL;
    2321                 :            :   int status;
    2322                 :            :   gchar *output;
    2323                 :            :   char **output_lines;
    2324                 :            :   char **envp;
    2325                 :            : 
    2326                 :          1 :   g_test_summary ("Test the output of g_test_message() from the TAP output of a test.");
    2327                 :            : 
    2328                 :          1 :   testing_helper = g_test_get_filename (G_TEST_BUILT, "testing-helper" EXEEXT, NULL);
    2329                 :            : 
    2330                 :          1 :   argv = g_ptr_array_new ();
    2331                 :          1 :   g_ptr_array_add (argv, (char *) testing_helper);
    2332                 :          1 :   g_ptr_array_add (argv, "message");
    2333                 :          1 :   g_ptr_array_add (argv, "--tap");
    2334                 :          1 :   g_ptr_array_add (argv, NULL);
    2335                 :            : 
    2336                 :            :   /* Remove the G_TEST_ROOT_PROCESS env so it will be considered a standalone test */
    2337                 :          1 :   envp = g_get_environ ();
    2338                 :          1 :   g_assert_nonnull (g_environ_getenv (envp, "G_TEST_ROOT_PROCESS"));
    2339                 :          1 :   envp = g_environ_unsetenv (g_steal_pointer (&envp), "G_TEST_ROOT_PROCESS");
    2340                 :            : 
    2341                 :          1 :   g_spawn_sync (NULL, (char **) argv->pdata, envp,
    2342                 :            :                 G_SPAWN_STDERR_TO_DEV_NULL,
    2343                 :            :                 NULL, NULL, &output, NULL, &status,
    2344                 :            :                 &error);
    2345                 :          1 :   g_assert_no_error (error);
    2346                 :            : 
    2347                 :          1 :   g_spawn_check_wait_status (status, &error);
    2348                 :          1 :   g_assert_no_error (error);
    2349                 :            : 
    2350                 :          1 :   g_assert_null (strstr (output, "# Subtest: "));
    2351                 :            : 
    2352                 :          1 :   const char *expected_tap_header = "\n1..1\n";
    2353                 :          1 :   const char *interesting_lines = strstr (output, expected_tap_header);
    2354                 :          1 :   g_assert_nonnull (interesting_lines);
    2355                 :          1 :   interesting_lines += strlen (expected_tap_header);
    2356                 :            : 
    2357                 :          1 :   output_lines = g_strsplit (interesting_lines, "\n", -1);
    2358                 :          1 :   g_assert_cmpuint (g_strv_length (output_lines), >=, 12);
    2359                 :            : 
    2360                 :          1 :   guint i = 0;
    2361                 :          1 :   g_assert_cmpstr (output_lines[i++], ==, "# Tests that single line message works");
    2362                 :          1 :   g_assert_cmpstr (output_lines[i++], ==, "# Tests that multi");
    2363                 :          1 :   g_assert_cmpstr (output_lines[i++], ==, "# ");
    2364                 :          1 :   g_assert_cmpstr (output_lines[i++], ==, "# line");
    2365                 :          1 :   g_assert_cmpstr (output_lines[i++], ==, "# message");
    2366                 :          1 :   g_assert_cmpstr (output_lines[i++], ==, "# works");
    2367                 :          1 :   g_assert_cmpstr (output_lines[i++], ==, "# ");
    2368                 :          1 :   g_assert_cmpstr (output_lines[i++], ==, "# Tests that multi");
    2369                 :          1 :   g_assert_cmpstr (output_lines[i++], ==, "# line");
    2370                 :          1 :   g_assert_cmpstr (output_lines[i++], ==, "# message");
    2371                 :          1 :   g_assert_cmpstr (output_lines[i++], ==, "# works with leading and trailing too");
    2372                 :          1 :   g_assert_cmpstr (output_lines[i++], ==, "# ");
    2373                 :            : 
    2374                 :          1 :   g_free (output);
    2375                 :          1 :   g_strfreev (output_lines);
    2376                 :          1 :   g_strfreev (envp);
    2377                 :          1 :   g_ptr_array_unref (argv);
    2378                 :          1 : }
    2379                 :            : 
    2380                 :            : static void
    2381                 :          1 : test_tap_subtest_message (void)
    2382                 :            : {
    2383                 :            :   const char *testing_helper;
    2384                 :            :   GPtrArray *argv;
    2385                 :          1 :   GError *error = NULL;
    2386                 :            :   int status;
    2387                 :            :   gchar *output;
    2388                 :            :   char **output_lines;
    2389                 :            : 
    2390                 :          1 :   g_test_summary ("Test the output of g_test_message() from the TAP output of a sub-test.");
    2391                 :            : 
    2392                 :          1 :   testing_helper = g_test_get_filename (G_TEST_BUILT, "testing-helper" EXEEXT, NULL);
    2393                 :            : 
    2394                 :          1 :   argv = g_ptr_array_new ();
    2395                 :          1 :   g_ptr_array_add (argv, (char *) testing_helper);
    2396                 :          1 :   g_ptr_array_add (argv, "message");
    2397                 :          1 :   g_ptr_array_add (argv, "--tap");
    2398                 :          1 :   g_ptr_array_add (argv, NULL);
    2399                 :            : 
    2400                 :          1 :   g_spawn_sync (NULL, (char **) argv->pdata, NULL,
    2401                 :            :                 G_SPAWN_STDERR_TO_DEV_NULL,
    2402                 :            :                 NULL, NULL, &output, NULL, &status,
    2403                 :            :                 &error);
    2404                 :          1 :   g_assert_no_error (error);
    2405                 :            : 
    2406                 :          1 :   g_spawn_check_wait_status (status, &error);
    2407                 :          1 :   g_assert_no_error (error);
    2408                 :            : 
    2409                 :          1 :   g_assert_true (g_str_has_prefix (output, "# Subtest: "));
    2410                 :            : 
    2411                 :          1 :   const char *expected_tap_header = "\n" TAP_SUBTEST_PREFIX "1..1\n";
    2412                 :          1 :   const char *interesting_lines = strstr (output, expected_tap_header);
    2413                 :          1 :   g_assert_nonnull (interesting_lines);
    2414                 :          1 :   interesting_lines += strlen (expected_tap_header);
    2415                 :            : 
    2416                 :          1 :   output_lines = g_strsplit (interesting_lines, "\n", -1);
    2417                 :          1 :   g_assert_cmpuint (g_strv_length (output_lines), >=, 12);
    2418                 :            : 
    2419                 :          1 :   guint i = 0;
    2420                 :          1 :   g_assert_cmpstr (output_lines[i++], ==, TAP_SUBTEST_PREFIX "# Tests that single line message works");
    2421                 :          1 :   g_assert_cmpstr (output_lines[i++], ==, TAP_SUBTEST_PREFIX "# Tests that multi");
    2422                 :          1 :   g_assert_cmpstr (output_lines[i++], ==, TAP_SUBTEST_PREFIX "# ");
    2423                 :          1 :   g_assert_cmpstr (output_lines[i++], ==, TAP_SUBTEST_PREFIX "# line");
    2424                 :          1 :   g_assert_cmpstr (output_lines[i++], ==, TAP_SUBTEST_PREFIX "# message");
    2425                 :          1 :   g_assert_cmpstr (output_lines[i++], ==, TAP_SUBTEST_PREFIX "# works");
    2426                 :          1 :   g_assert_cmpstr (output_lines[i++], ==, TAP_SUBTEST_PREFIX "# ");
    2427                 :          1 :   g_assert_cmpstr (output_lines[i++], ==, TAP_SUBTEST_PREFIX "# Tests that multi");
    2428                 :          1 :   g_assert_cmpstr (output_lines[i++], ==, TAP_SUBTEST_PREFIX "# line");
    2429                 :          1 :   g_assert_cmpstr (output_lines[i++], ==, TAP_SUBTEST_PREFIX "# message");
    2430                 :          1 :   g_assert_cmpstr (output_lines[i++], ==, TAP_SUBTEST_PREFIX "# works with leading and trailing too");
    2431                 :          1 :   g_assert_cmpstr (output_lines[i++], ==, TAP_SUBTEST_PREFIX "# ");
    2432                 :            : 
    2433                 :          1 :   g_free (output);
    2434                 :          1 :   g_strfreev (output_lines);
    2435                 :          1 :   g_ptr_array_unref (argv);
    2436                 :          1 : }
    2437                 :            : 
    2438                 :            : static void
    2439                 :          1 : test_tap_print (void)
    2440                 :            : {
    2441                 :            :   const char *testing_helper;
    2442                 :            :   GPtrArray *argv;
    2443                 :          1 :   GError *error = NULL;
    2444                 :            :   int status;
    2445                 :            :   gchar *output;
    2446                 :            :   char **output_lines;
    2447                 :            :   char **envp;
    2448                 :            : 
    2449                 :          1 :   g_test_summary ("Test the output of g_print() from the TAP output of a test.");
    2450                 :            : 
    2451                 :          1 :   testing_helper = g_test_get_filename (G_TEST_BUILT, "testing-helper" EXEEXT, NULL);
    2452                 :            : 
    2453                 :          1 :   argv = g_ptr_array_new ();
    2454                 :          1 :   g_ptr_array_add (argv, (char *) testing_helper);
    2455                 :          1 :   g_ptr_array_add (argv, "print");
    2456                 :          1 :   g_ptr_array_add (argv, "--tap");
    2457                 :          1 :   g_ptr_array_add (argv, NULL);
    2458                 :            : 
    2459                 :            :   /* Remove the G_TEST_ROOT_PROCESS env so it will be considered a standalone test */
    2460                 :          1 :   envp = g_get_environ ();
    2461                 :          1 :   g_assert_nonnull (g_environ_getenv (envp, "G_TEST_ROOT_PROCESS"));
    2462                 :          1 :   envp = g_environ_unsetenv (g_steal_pointer (&envp), "G_TEST_ROOT_PROCESS");
    2463                 :            : 
    2464                 :          1 :   g_spawn_sync (NULL, (char **) argv->pdata, envp,
    2465                 :            :                 G_SPAWN_STDERR_TO_DEV_NULL,
    2466                 :            :                 NULL, NULL, &output, NULL, &status,
    2467                 :            :                 &error);
    2468                 :          1 :   g_assert_no_error (error);
    2469                 :            : 
    2470                 :          1 :   g_spawn_check_wait_status (status, &error);
    2471                 :          1 :   g_assert_no_error (error);
    2472                 :            : 
    2473                 :          1 :   const char *expected_tap_header = "\n1..1\n";
    2474                 :          1 :   const char *interesting_lines = strstr (output, expected_tap_header);
    2475                 :          1 :   g_assert_nonnull (interesting_lines);
    2476                 :          1 :   interesting_lines += strlen (expected_tap_header);
    2477                 :            : 
    2478                 :          1 :   output_lines = g_strsplit (interesting_lines, "\n", -1);
    2479                 :          1 :   g_assert_cmpuint (g_strv_length (output_lines), >=, 3);
    2480                 :            : 
    2481                 :          1 :   guint i = 0;
    2482                 :          1 :   g_assert_cmpstr (output_lines[i++], ==, "# Tests that single line message works");
    2483                 :          1 :   g_assert_cmpstr (output_lines[i++], ==, "# test that multiple");
    2484                 :          1 :   g_assert_cmpstr (output_lines[i++], ==, "# lines can be written separately");
    2485                 :            : 
    2486                 :          1 :   g_free (output);
    2487                 :          1 :   g_strfreev (envp);
    2488                 :          1 :   g_strfreev (output_lines);
    2489                 :          1 :   g_ptr_array_unref (argv);
    2490                 :          1 : }
    2491                 :            : 
    2492                 :            : static void
    2493                 :          1 : test_tap_subtest_print (void)
    2494                 :            : {
    2495                 :            :   const char *testing_helper;
    2496                 :            :   GPtrArray *argv;
    2497                 :          1 :   GError *error = NULL;
    2498                 :            :   int status;
    2499                 :            :   gchar *output;
    2500                 :            :   char **output_lines;
    2501                 :            : 
    2502                 :          1 :   g_test_summary ("Test the output of g_test_print() from the TAP output of a sub-test.");
    2503                 :            : 
    2504                 :          1 :   testing_helper = g_test_get_filename (G_TEST_BUILT, "testing-helper" EXEEXT, NULL);
    2505                 :            : 
    2506                 :          1 :   argv = g_ptr_array_new ();
    2507                 :          1 :   g_ptr_array_add (argv, (char *) testing_helper);
    2508                 :          1 :   g_ptr_array_add (argv, "print");
    2509                 :          1 :   g_ptr_array_add (argv, "--tap");
    2510                 :          1 :   g_ptr_array_add (argv, NULL);
    2511                 :            : 
    2512                 :          1 :   g_spawn_sync (NULL, (char **) argv->pdata, NULL,
    2513                 :            :                 G_SPAWN_STDERR_TO_DEV_NULL,
    2514                 :            :                 NULL, NULL, &output, NULL, &status,
    2515                 :            :                 &error);
    2516                 :          1 :   g_assert_no_error (error);
    2517                 :            : 
    2518                 :          1 :   g_spawn_check_wait_status (status, &error);
    2519                 :          1 :   g_assert_no_error (error);
    2520                 :            : 
    2521                 :          1 :   const char *expected_tap_header = "\n" TAP_SUBTEST_PREFIX "1..1\n";
    2522                 :          1 :   const char *interesting_lines = strstr (output, expected_tap_header);
    2523                 :          1 :   g_assert_nonnull (interesting_lines);
    2524                 :          1 :   interesting_lines += strlen (expected_tap_header);
    2525                 :            : 
    2526                 :          1 :   output_lines = g_strsplit (interesting_lines, "\n", -1);
    2527                 :          1 :   g_assert_cmpuint (g_strv_length (output_lines), >=, 3);
    2528                 :            : 
    2529                 :          1 :   guint i = 0;
    2530                 :          1 :   g_assert_cmpstr (output_lines[i++], ==, TAP_SUBTEST_PREFIX "# Tests that single line message works");
    2531                 :          1 :   g_assert_cmpstr (output_lines[i++], ==, TAP_SUBTEST_PREFIX "# test that multiple");
    2532                 :          1 :   g_assert_cmpstr (output_lines[i++], ==, TAP_SUBTEST_PREFIX "# lines can be written separately");
    2533                 :            : 
    2534                 :          1 :   g_free (output);
    2535                 :          1 :   g_strfreev (output_lines);
    2536                 :          1 :   g_ptr_array_unref (argv);
    2537                 :          1 : }
    2538                 :            : 
    2539                 :            : static void
    2540                 :          1 : test_tap_subtest_stdout (void)
    2541                 :            : {
    2542                 :            :   const char *testing_helper;
    2543                 :            :   GPtrArray *argv;
    2544                 :          1 :   GError *error = NULL;
    2545                 :            :   int status;
    2546                 :            :   gchar *output;
    2547                 :            :   char **output_lines;
    2548                 :            : 
    2549                 :          1 :   g_test_summary ("Test the stdout from the TAP output of a sub-test.");
    2550                 :            : 
    2551                 :          1 :   testing_helper = g_test_get_filename (G_TEST_BUILT, "testing-helper" EXEEXT, NULL);
    2552                 :            : 
    2553                 :          1 :   argv = g_ptr_array_new ();
    2554                 :          1 :   g_ptr_array_add (argv, (char *) testing_helper);
    2555                 :          1 :   g_ptr_array_add (argv, "subprocess-stdout");
    2556                 :          1 :   g_ptr_array_add (argv, "--tap");
    2557                 :          1 :   g_ptr_array_add (argv, NULL);
    2558                 :            : 
    2559                 :          1 :   g_spawn_sync (NULL, (char **) argv->pdata, NULL,
    2560                 :            :                 G_SPAWN_STDERR_TO_DEV_NULL,
    2561                 :            :                 NULL, NULL, &output, NULL, &status,
    2562                 :            :                 &error);
    2563                 :          1 :   g_assert_no_error (error);
    2564                 :            : 
    2565                 :          1 :   g_spawn_check_wait_status (status, &error);
    2566                 :          1 :   g_assert_no_error (error);
    2567                 :            : 
    2568                 :          1 :   const char *expected_tap_header = "\n" TAP_SUBTEST_PREFIX "1..1\n";
    2569                 :          1 :   const char *interesting_lines = strstr (output, expected_tap_header);
    2570                 :          1 :   g_assert_nonnull (interesting_lines);
    2571                 :            : 
    2572                 :          1 :   interesting_lines = strstr (interesting_lines, TAP_SUBTEST_PREFIX "# /sub-stdout");
    2573                 :          1 :   g_assert_nonnull (interesting_lines);
    2574                 :            : 
    2575                 :          1 :   output_lines = g_strsplit (interesting_lines, "\n", -1);
    2576                 :          1 :   g_assert_cmpuint (g_strv_length (output_lines), >=, 5);
    2577                 :            : 
    2578                 :          1 :   guint i = 0;
    2579                 :          1 :   g_assert_cmpstr (output_lines[i++], ==,
    2580                 :            :                    TAP_SUBTEST_PREFIX "# /sub-stdout: Tests that single line message works");
    2581                 :          1 :   g_assert_cmpstr (output_lines[i++], ==,
    2582                 :            :                    TAP_SUBTEST_PREFIX "# test that multiple");
    2583                 :          1 :   g_assert_cmpstr (output_lines[i++], ==,
    2584                 :            :                    TAP_SUBTEST_PREFIX "# lines can be written separately");
    2585                 :          1 :   g_assert_cmpstr (output_lines[i++], ==,
    2586                 :            :                    TAP_SUBTEST_PREFIX "# And another line has been put");
    2587                 :          1 :   g_assert_cmpstr (output_lines[i++], ==,
    2588                 :            :                    TAP_SUBTEST_PREFIX "ok 1 /sub-stdout");
    2589                 :            : 
    2590                 :          1 :   g_free (output);
    2591                 :          1 :   g_strfreev (output_lines);
    2592                 :          1 :   g_ptr_array_unref (argv);
    2593                 :          1 : }
    2594                 :            : 
    2595                 :            : static void
    2596                 :          1 : test_tap_subtest_stdout_no_new_line (void)
    2597                 :            : {
    2598                 :            :   const char *testing_helper;
    2599                 :            :   GPtrArray *argv;
    2600                 :          1 :   GError *error = NULL;
    2601                 :            :   int status;
    2602                 :            :   gchar *output;
    2603                 :            :   char **output_lines;
    2604                 :            : 
    2605                 :          1 :   g_test_summary ("Test the stdout from the TAP output of a sub-test.");
    2606                 :            : 
    2607                 :          1 :   testing_helper = g_test_get_filename (G_TEST_BUILT, "testing-helper" EXEEXT, NULL);
    2608                 :            : 
    2609                 :          1 :   argv = g_ptr_array_new ();
    2610                 :          1 :   g_ptr_array_add (argv, (char *) testing_helper);
    2611                 :          1 :   g_ptr_array_add (argv, "subprocess-stdout-no-nl");
    2612                 :          1 :   g_ptr_array_add (argv, "--tap");
    2613                 :          1 :   g_ptr_array_add (argv, NULL);
    2614                 :            : 
    2615                 :          1 :   g_spawn_sync (NULL, (char **) argv->pdata, NULL,
    2616                 :            :                 G_SPAWN_STDERR_TO_DEV_NULL,
    2617                 :            :                 NULL, NULL, &output, NULL, &status,
    2618                 :            :                 &error);
    2619                 :          1 :   g_assert_no_error (error);
    2620                 :            : 
    2621                 :          1 :   g_spawn_check_wait_status (status, &error);
    2622                 :          1 :   g_assert_no_error (error);
    2623                 :            : 
    2624                 :          1 :   const char *expected_tap_header = "\n" TAP_SUBTEST_PREFIX "1..1\n";
    2625                 :          1 :   const char *interesting_lines = strstr (output, expected_tap_header);
    2626                 :          1 :   g_assert_nonnull (interesting_lines);
    2627                 :            : 
    2628                 :          1 :   interesting_lines = strstr (interesting_lines, TAP_SUBTEST_PREFIX "# /sub-stdout-no-nl");
    2629                 :          1 :   g_assert_nonnull (interesting_lines);
    2630                 :            : 
    2631                 :          1 :   output_lines = g_strsplit (interesting_lines, "\n", -1);
    2632                 :          1 :   g_assert_cmpuint (g_strv_length (output_lines), >=, 2);
    2633                 :            : 
    2634                 :          1 :   guint i = 0;
    2635                 :          1 :   g_assert_cmpstr (output_lines[i++], ==,
    2636                 :            :                    TAP_SUBTEST_PREFIX "# /sub-stdout-no-nl: A message without trailing new line");
    2637                 :          1 :   g_assert_cmpstr (output_lines[i++], ==,
    2638                 :            :                    TAP_SUBTEST_PREFIX "ok 1 /sub-stdout-no-nl");
    2639                 :            : 
    2640                 :          1 :   g_free (output);
    2641                 :          1 :   g_strfreev (output_lines);
    2642                 :          1 :   g_ptr_array_unref (argv);
    2643                 :          1 : }
    2644                 :            : 
    2645                 :            : static void
    2646                 :          1 : test_tap_error (void)
    2647                 :            : {
    2648                 :            :   const char *testing_helper;
    2649                 :            :   GPtrArray *argv;
    2650                 :          1 :   GError *error = NULL;
    2651                 :            :   int status;
    2652                 :            :   gchar *output;
    2653                 :            :   char **envp;
    2654                 :            : 
    2655                 :          1 :   g_test_summary ("Test that g_error() generates Bail out TAP output of a test.");
    2656                 :            : 
    2657                 :          1 :   testing_helper = g_test_get_filename (G_TEST_BUILT, "testing-helper" EXEEXT, NULL);
    2658                 :            : 
    2659                 :          1 :   argv = g_ptr_array_new ();
    2660                 :          1 :   g_ptr_array_add (argv, (char *) testing_helper);
    2661                 :          1 :   g_ptr_array_add (argv, "error");
    2662                 :          1 :   g_ptr_array_add (argv, "--tap");
    2663                 :          1 :   g_ptr_array_add (argv, NULL);
    2664                 :            : 
    2665                 :            :   /* Remove the G_TEST_ROOT_PROCESS env so it will be considered a standalone test */
    2666                 :          1 :   envp = g_get_environ ();
    2667                 :          1 :   g_assert_nonnull (g_environ_getenv (envp, "G_TEST_ROOT_PROCESS"));
    2668                 :          1 :   envp = g_environ_unsetenv (g_steal_pointer (&envp), "G_TEST_ROOT_PROCESS");
    2669                 :            : 
    2670                 :          1 :   g_spawn_sync (NULL, (char **) argv->pdata, envp,
    2671                 :            :                 G_SPAWN_STDERR_TO_DEV_NULL,
    2672                 :            :                 NULL, NULL, &output, NULL, &status,
    2673                 :            :                 &error);
    2674                 :          1 :   g_assert_no_error (error);
    2675                 :            : 
    2676                 :          1 :   g_spawn_check_wait_status (status, &error);
    2677                 :          1 :   g_assert_nonnull (error);
    2678                 :            : 
    2679                 :          1 :   g_assert_false (g_str_has_prefix (output, "# Subtest: "));
    2680                 :            : 
    2681                 :          1 :   const char *expected_tap_header = "\n1..1\n";
    2682                 :          1 :   const char *interesting_lines = strstr (output, expected_tap_header);
    2683                 :          1 :   g_assert_nonnull (interesting_lines);
    2684                 :          1 :   interesting_lines += strlen (expected_tap_header);
    2685                 :            : 
    2686                 :          1 :   g_assert_cmpstr (interesting_lines, ==, "not ok /error - GLib-FATAL-ERROR: This should error out "
    2687                 :            :                    "Because it's just wrong!\n"
    2688                 :            :                    "Bail out!\n");
    2689                 :            : 
    2690                 :          1 :   g_free (output);
    2691                 :          1 :   g_strfreev (envp);
    2692                 :          1 :   g_ptr_array_unref (argv);
    2693                 :          1 :   g_clear_error (&error);
    2694                 :          1 : }
    2695                 :            : 
    2696                 :            : static void
    2697                 :          1 : test_tap_subtest_error (void)
    2698                 :            : {
    2699                 :            :   const char *testing_helper;
    2700                 :            :   GPtrArray *argv;
    2701                 :          1 :   GError *error = NULL;
    2702                 :            :   int status;
    2703                 :            :   gchar *output;
    2704                 :            : 
    2705                 :          1 :   g_test_summary ("Test that g_error() generates Bail out TAP output of a test.");
    2706                 :            : 
    2707                 :          1 :   testing_helper = g_test_get_filename (G_TEST_BUILT, "testing-helper" EXEEXT, NULL);
    2708                 :            : 
    2709                 :          1 :   argv = g_ptr_array_new ();
    2710                 :          1 :   g_ptr_array_add (argv, (char *) testing_helper);
    2711                 :          1 :   g_ptr_array_add (argv, "error");
    2712                 :          1 :   g_ptr_array_add (argv, "--tap");
    2713                 :          1 :   g_ptr_array_add (argv, NULL);
    2714                 :            : 
    2715                 :          1 :   g_spawn_sync (NULL, (char **) argv->pdata, NULL,
    2716                 :            :                 G_SPAWN_STDERR_TO_DEV_NULL,
    2717                 :            :                 NULL, NULL, &output, NULL, &status,
    2718                 :            :                 &error);
    2719                 :          1 :   g_assert_no_error (error);
    2720                 :            : 
    2721                 :          1 :   g_spawn_check_wait_status (status, &error);
    2722                 :          1 :   g_assert_nonnull (error);
    2723                 :            : 
    2724                 :          1 :   g_assert_true (g_str_has_prefix (output, "# Subtest: "));
    2725                 :            : 
    2726                 :          1 :   const char *expected_tap_header = "\n" TAP_SUBTEST_PREFIX "1..1\n";
    2727                 :          1 :   const char *interesting_lines = strstr (output, expected_tap_header);
    2728                 :          1 :   g_assert_nonnull (interesting_lines);
    2729                 :          1 :   interesting_lines += strlen (expected_tap_header);
    2730                 :            : 
    2731                 :          1 :   g_assert_cmpstr (interesting_lines, ==,
    2732                 :            :                    TAP_SUBTEST_PREFIX "not ok /error - GLib-FATAL-ERROR: This should error out "
    2733                 :            :                    "Because it's just wrong!\n"
    2734                 :            :                    TAP_SUBTEST_PREFIX "Bail out!\n");
    2735                 :            : 
    2736                 :          1 :   g_free (output);
    2737                 :          1 :   g_ptr_array_unref (argv);
    2738                 :          1 :   g_clear_error (&error);
    2739                 :          1 : }
    2740                 :            : 
    2741                 :            : static void
    2742                 :          1 : test_tap_error_and_pass (void)
    2743                 :            : {
    2744                 :            :   const char *testing_helper;
    2745                 :            :   GPtrArray *argv;
    2746                 :          1 :   GError *error = NULL;
    2747                 :            :   int status;
    2748                 :            :   gchar *output;
    2749                 :            :   char **envp;
    2750                 :            : 
    2751                 :          1 :   g_test_summary ("Test that g_error() generates Bail out TAP output of a test.");
    2752                 :            : 
    2753                 :          1 :   testing_helper = g_test_get_filename (G_TEST_BUILT, "testing-helper" EXEEXT, NULL);
    2754                 :            : 
    2755                 :            :   /* Remove the G_TEST_ROOT_PROCESS env so it will be considered a standalone test */
    2756                 :          1 :   envp = g_get_environ ();
    2757                 :          1 :   g_assert_nonnull (g_environ_getenv (envp, "G_TEST_ROOT_PROCESS"));
    2758                 :          1 :   envp = g_environ_unsetenv (g_steal_pointer (&envp), "G_TEST_ROOT_PROCESS");
    2759                 :            : 
    2760                 :          1 :   argv = g_ptr_array_new ();
    2761                 :          1 :   g_ptr_array_add (argv, (char *) testing_helper);
    2762                 :          1 :   g_ptr_array_add (argv, "error-and-pass");
    2763                 :          1 :   g_ptr_array_add (argv, "--tap");
    2764                 :          1 :   g_ptr_array_add (argv, NULL);
    2765                 :            : 
    2766                 :          1 :   g_spawn_sync (NULL, (char **) argv->pdata, envp,
    2767                 :            :                 G_SPAWN_STDERR_TO_DEV_NULL,
    2768                 :            :                 NULL, NULL, &output, NULL, &status,
    2769                 :            :                 &error);
    2770                 :          1 :   g_assert_no_error (error);
    2771                 :            : 
    2772                 :          1 :   g_spawn_check_wait_status (status, &error);
    2773                 :          1 :   g_assert_nonnull (error);
    2774                 :            : 
    2775                 :          1 :   const char *expected_tap_header = "\n1..2\n";
    2776                 :          1 :   const char *interesting_lines = strstr (output, expected_tap_header);
    2777                 :          1 :   g_assert_nonnull (interesting_lines);
    2778                 :          1 :   interesting_lines += strlen (expected_tap_header);
    2779                 :            : 
    2780                 :          1 :   g_assert_cmpstr (interesting_lines, ==, "not ok /error - GLib-FATAL-ERROR: This should error out "
    2781                 :            :                    "Because it's just wrong!\n"
    2782                 :            :                    "Bail out!\n");
    2783                 :            : 
    2784                 :          1 :   g_free (output);
    2785                 :          1 :   g_strfreev (envp);
    2786                 :          1 :   g_ptr_array_unref (argv);
    2787                 :          1 :   g_clear_error (&error);
    2788                 :          1 : }
    2789                 :            : 
    2790                 :            : static void
    2791                 :          1 : test_tap_subtest_error_and_pass (void)
    2792                 :            : {
    2793                 :            :   const char *testing_helper;
    2794                 :            :   GPtrArray *argv;
    2795                 :          1 :   GError *error = NULL;
    2796                 :            :   int status;
    2797                 :            :   gchar *output;
    2798                 :            : 
    2799                 :          1 :   g_test_summary ("Test that g_error() generates Bail out TAP output of a test.");
    2800                 :            : 
    2801                 :          1 :   testing_helper = g_test_get_filename (G_TEST_BUILT, "testing-helper" EXEEXT, NULL);
    2802                 :            : 
    2803                 :          1 :   argv = g_ptr_array_new ();
    2804                 :          1 :   g_ptr_array_add (argv, (char *) testing_helper);
    2805                 :          1 :   g_ptr_array_add (argv, "error-and-pass");
    2806                 :          1 :   g_ptr_array_add (argv, "--tap");
    2807                 :          1 :   g_ptr_array_add (argv, NULL);
    2808                 :            : 
    2809                 :          1 :   g_spawn_sync (NULL, (char **) argv->pdata, NULL,
    2810                 :            :                 G_SPAWN_STDERR_TO_DEV_NULL,
    2811                 :            :                 NULL, NULL, &output, NULL, &status,
    2812                 :            :                 &error);
    2813                 :          1 :   g_assert_no_error (error);
    2814                 :            : 
    2815                 :          1 :   g_spawn_check_wait_status (status, &error);
    2816                 :          1 :   g_assert_nonnull (error);
    2817                 :            : 
    2818                 :          1 :   g_assert_true (g_str_has_prefix (output, "# Subtest: "));
    2819                 :            : 
    2820                 :          1 :   const char *expected_tap_header = "\n" TAP_SUBTEST_PREFIX "1..2\n";
    2821                 :          1 :   const char *interesting_lines = strstr (output, expected_tap_header);
    2822                 :          1 :   g_assert_nonnull (interesting_lines);
    2823                 :          1 :   interesting_lines += strlen (expected_tap_header);
    2824                 :            : 
    2825                 :          1 :   g_assert_cmpstr (interesting_lines, ==,
    2826                 :            :                    TAP_SUBTEST_PREFIX "not ok /error - GLib-FATAL-ERROR: This should error out "
    2827                 :            :                    "Because it's just wrong!\n"
    2828                 :            :                    TAP_SUBTEST_PREFIX "Bail out!\n");
    2829                 :            : 
    2830                 :          1 :   g_free (output);
    2831                 :          1 :   g_ptr_array_unref (argv);
    2832                 :          1 :   g_clear_error (&error);
    2833                 :          1 : }
    2834                 :            : 
    2835                 :            : static void
    2836                 :          1 : test_init_no_argv0 (void)
    2837                 :            : {
    2838                 :            :   const char *testing_helper;
    2839                 :            :   GPtrArray *argv;
    2840                 :          1 :   GError *error = NULL;
    2841                 :            :   int status;
    2842                 :            :   gchar *output;
    2843                 :            : 
    2844                 :          1 :   g_test_summary ("Test that g_test_init() can be called safely with argc == 0.");
    2845                 :            : 
    2846                 :          1 :   testing_helper = g_test_get_filename (G_TEST_BUILT, "testing-helper" EXEEXT, NULL);
    2847                 :            : 
    2848                 :          1 :   argv = g_ptr_array_new ();
    2849                 :          1 :   g_ptr_array_add (argv, (char *) testing_helper);
    2850                 :          1 :   g_ptr_array_add (argv, "init-null-argv0");
    2851                 :          1 :   g_ptr_array_add (argv, NULL);
    2852                 :            : 
    2853                 :            :   /* This has to be spawned manually and can’t be run with g_test_subprocess()
    2854                 :            :    * because the test helper can’t be run after `g_test_init()` has been called
    2855                 :            :    * in the process. */
    2856                 :          1 :   g_spawn_sync (NULL, (char **) argv->pdata, NULL,
    2857                 :            :                 G_SPAWN_STDERR_TO_DEV_NULL,
    2858                 :            :                 NULL, NULL, &output, NULL, &status,
    2859                 :            :                 &error);
    2860                 :          1 :   g_assert_no_error (error);
    2861                 :            : 
    2862                 :          1 :   g_spawn_check_wait_status (status, &error);
    2863                 :          1 :   g_assert_no_error (error);
    2864                 :          1 :   g_assert_nonnull (strstr (output, "# random seed:"));
    2865                 :          1 :   g_free (output);
    2866                 :          1 :   g_ptr_array_unref (argv);
    2867                 :          1 : }
    2868                 :            : 
    2869                 :            : int
    2870                 :         23 : main (int   argc,
    2871                 :            :       char *argv[])
    2872                 :            : {
    2873                 :            :   int ret;
    2874                 :            :   char *filename, *filename2;
    2875                 :            : 
    2876                 :         23 :   argv0 = argv[0];
    2877                 :            : 
    2878                 :         23 :   setlocale (LC_ALL, "");
    2879                 :            : 
    2880                 :         23 :   g_test_init (&argc, &argv, NULL);
    2881                 :            : 
    2882                 :            :   /* Part of a test for
    2883                 :            :    * https://gitlab.gnome.org/GNOME/glib/-/issues/2563, see below */
    2884                 :         23 :   filename = g_test_build_filename (G_TEST_BUILT, "nonexistent", NULL);
    2885                 :            : 
    2886                 :         23 :   g_test_add_func ("/random-generator/rand-1", test_rand1);
    2887                 :         23 :   g_test_add_func ("/random-generator/rand-2", test_rand2);
    2888                 :         23 :   g_test_add_func ("/random-generator/random-conversions", test_random_conversions);
    2889                 :         23 :   g_test_add_func ("/misc/assertions", test_assertions);
    2890                 :         23 :   g_test_add_func ("/misc/assertions/subprocess/bad_cmpvariant_types", test_assertions_bad_cmpvariant_types);
    2891                 :         23 :   g_test_add_func ("/misc/assertions/subprocess/bad_cmpvariant_values", test_assertions_bad_cmpvariant_values);
    2892                 :         23 :   g_test_add_func ("/misc/assertions/subprocess/bad_cmpstr", test_assertions_bad_cmpstr);
    2893                 :         23 :   g_test_add_func ("/misc/assertions/subprocess/bad_cmpstrv_null1", test_assertions_bad_cmpstrv_null1);
    2894                 :         23 :   g_test_add_func ("/misc/assertions/subprocess/bad_cmpstrv_null2", test_assertions_bad_cmpstrv_null2);
    2895                 :         23 :   g_test_add_func ("/misc/assertions/subprocess/bad_cmpstrv_length", test_assertions_bad_cmpstrv_length);
    2896                 :         23 :   g_test_add_func ("/misc/assertions/subprocess/bad_cmpstrv_values", test_assertions_bad_cmpstrv_values);
    2897                 :         23 :   g_test_add_func ("/misc/assertions/subprocess/bad_cmpint", test_assertions_bad_cmpint);
    2898                 :         23 :   g_test_add_func ("/misc/assertions/subprocess/bad_cmpmem_len", test_assertions_bad_cmpmem_len);
    2899                 :         23 :   g_test_add_func ("/misc/assertions/subprocess/bad_cmpmem_data", test_assertions_bad_cmpmem_data);
    2900                 :         23 :   g_test_add_func ("/misc/assertions/subprocess/bad_cmpmem_null", test_assertions_bad_cmpmem_null);
    2901                 :         23 :   g_test_add_func ("/misc/assertions/subprocess/bad_cmpfloat_epsilon", test_assertions_bad_cmpfloat_epsilon);
    2902                 :         23 :   g_test_add_func ("/misc/assertions/subprocess/bad_no_errno", test_assertions_bad_no_errno);
    2903                 :         23 :   g_test_add_data_func ("/misc/test-data", (void*) 0xc0c0baba, test_data_test);
    2904                 :         23 :   g_test_add ("/misc/primetoul", Fixturetest, (void*) 0xc0cac01a, fixturetest_setup, fixturetest_test, fixturetest_teardown);
    2905         [ -  + ]:         23 :   if (g_test_perf())
    2906                 :          0 :     g_test_add_func ("/misc/timer", test_timer);
    2907                 :            : 
    2908                 :            : #ifdef G_OS_UNIX
    2909                 :         23 :   g_test_add_func ("/forking/fail assertion", test_fork_fail);
    2910                 :         23 :   g_test_add_func ("/forking/patterns", test_fork_patterns);
    2911         [ -  + ]:         23 :   if (g_test_slow())
    2912                 :          0 :     g_test_add_func ("/forking/timeout", test_fork_timeout);
    2913                 :            : #endif
    2914                 :            : 
    2915                 :         23 :   g_test_add_func ("/trap_subprocess/fail", test_subprocess_fail);
    2916                 :         23 :   g_test_add_func ("/trap_subprocess/no-such-test", test_subprocess_no_such_test);
    2917                 :         23 :   g_test_add_func ("/trap_subprocess/timeout", test_subprocess_timeout);
    2918                 :         23 :   g_test_add_func ("/trap_subprocess/envp", test_subprocess_envp);
    2919                 :            : 
    2920                 :         23 :   g_test_add_func ("/trap_subprocess/patterns", test_subprocess_patterns);
    2921                 :            : 
    2922                 :         23 :   g_test_add_func ("/misc/fatal-log-handler", test_fatal_log_handler);
    2923                 :         23 :   g_test_add_func ("/misc/fatal-log-handler/subprocess/critical-pass", test_fatal_log_handler_critical_pass);
    2924                 :         23 :   g_test_add_func ("/misc/fatal-log-handler/subprocess/error-fail", test_fatal_log_handler_error_fail);
    2925                 :         23 :   g_test_add_func ("/misc/fatal-log-handler/subprocess/critical-fail", test_fatal_log_handler_critical_fail);
    2926                 :            : 
    2927                 :         23 :   g_test_add_func ("/misc/expected-messages", test_expected_messages);
    2928                 :         23 :   g_test_add_func ("/misc/expected-messages/subprocess/warning", test_expected_messages_warning);
    2929                 :         23 :   g_test_add_func ("/misc/expected-messages/subprocess/expect-warning", test_expected_messages_expect_warning);
    2930                 :         23 :   g_test_add_func ("/misc/expected-messages/subprocess/wrong-warning", test_expected_messages_wrong_warning);
    2931                 :         23 :   g_test_add_func ("/misc/expected-messages/subprocess/expected", test_expected_messages_expected);
    2932                 :         23 :   g_test_add_func ("/misc/expected-messages/subprocess/null-domain", test_expected_messages_null_domain);
    2933                 :         23 :   g_test_add_func ("/misc/expected-messages/subprocess/extra-warning", test_expected_messages_extra_warning);
    2934                 :         23 :   g_test_add_func ("/misc/expected-messages/subprocess/unexpected-extra-warning", test_expected_messages_unexpected_extra_warning);
    2935                 :         23 :   g_test_add_func ("/misc/expected-messages/expect-error", test_expected_messages_expect_error);
    2936                 :         23 :   g_test_add_func ("/misc/expected-messages/skip-debug", test_expected_messages_debug);
    2937                 :            : 
    2938                 :         23 :   g_test_add_func ("/misc/messages", test_messages);
    2939                 :         23 :   g_test_add_func ("/misc/messages/subprocess/use-stderr", test_messages_use_stderr);
    2940                 :            : 
    2941                 :         23 :   g_test_add_func ("/misc/dash-p", test_dash_p);
    2942                 :         23 :   g_test_add_func ("/misc/dash-p/child", test_dash_p_child);
    2943                 :         23 :   g_test_add_func ("/misc/dash-p/child/sub", test_dash_p_child_sub);
    2944                 :         23 :   g_test_add_func ("/misc/dash-p/child/sub/subprocess", test_dash_p_child_sub_child);
    2945                 :         23 :   g_test_add_func ("/misc/dash-p/child/sub/subprocess/child", test_dash_p_child_sub_child);
    2946                 :         23 :   g_test_add_func ("/misc/dash-p/child/sub2", test_dash_p_child_sub2);
    2947                 :         23 :   g_test_add_func ("/misc/dash-p/subprocess/hidden", test_dash_p_hidden);
    2948                 :         23 :   g_test_add_func ("/misc/dash-p/subprocess/hidden/sub", test_dash_p_hidden_sub);
    2949                 :            : 
    2950                 :         23 :   g_test_add_func ("/misc/nonfatal", test_nonfatal);
    2951                 :            : 
    2952                 :         23 :   g_test_add_func ("/misc/skip", test_skip);
    2953                 :         23 :   g_test_add_func ("/misc/combining", test_combining);
    2954                 :         23 :   g_test_add_func ("/misc/combining/subprocess/fail", subprocess_fail);
    2955                 :         23 :   g_test_add_func ("/misc/combining/subprocess/skip1", test_skip);
    2956                 :         23 :   g_test_add_func ("/misc/combining/subprocess/skip2", test_skip);
    2957                 :         23 :   g_test_add_func ("/misc/combining/subprocess/incomplete", subprocess_incomplete);
    2958                 :         23 :   g_test_add_func ("/misc/combining/subprocess/pass", test_pass);
    2959                 :         23 :   g_test_add_func ("/misc/fail", test_fail);
    2960                 :         23 :   g_test_add_func ("/misc/incomplete", test_incomplete);
    2961                 :            : 
    2962                 :         23 :   g_test_add_func ("/misc/path/first", test_path_first);
    2963                 :         23 :   g_test_add_func ("/misc/path/second", test_path_second);
    2964                 :            : 
    2965                 :         23 :   g_test_add_func ("/tap", test_tap);
    2966                 :         23 :   g_test_add_func ("/tap/subtest", test_tap_subtest);
    2967                 :         23 :   g_test_add_func ("/tap/summary", test_tap_summary);
    2968                 :         23 :   g_test_add_func ("/tap/subtest/summary", test_tap_subtest_summary);
    2969                 :         23 :   g_test_add_func ("/tap/message", test_tap_message);
    2970                 :         23 :   g_test_add_func ("/tap/subtest/message", test_tap_subtest_message);
    2971                 :         23 :   g_test_add_func ("/tap/print", test_tap_print);
    2972                 :         23 :   g_test_add_func ("/tap/subtest/print", test_tap_subtest_print);
    2973                 :         23 :   g_test_add_func ("/tap/subtest/stdout", test_tap_subtest_stdout);
    2974                 :         23 :   g_test_add_func ("/tap/subtest/stdout-no-new-line", test_tap_subtest_stdout_no_new_line);
    2975                 :         23 :   g_test_add_func ("/tap/error", test_tap_error);
    2976                 :         23 :   g_test_add_func ("/tap/subtest/error", test_tap_subtest_error);
    2977                 :         23 :   g_test_add_func ("/tap/error-and-pass", test_tap_error_and_pass);
    2978                 :         23 :   g_test_add_func ("/tap/subtest/error-and-pass", test_tap_subtest_error_and_pass);
    2979                 :            : 
    2980                 :         23 :   g_test_add_func ("/init/no_argv0", test_init_no_argv0);
    2981                 :            : 
    2982                 :         23 :   ret = g_test_run ();
    2983                 :            : 
    2984                 :            :   /* We can't test for https://gitlab.gnome.org/GNOME/glib/-/issues/2563
    2985                 :            :    * from a test-case, because the whole point of that issue is that it's
    2986                 :            :    * about whether certain patterns are valid after g_test_run() has
    2987                 :            :    * returned... so put an ad-hoc test here, and just crash if it fails. */
    2988                 :         19 :   filename2 = g_test_build_filename (G_TEST_BUILT, "nonexistent", NULL);
    2989                 :         19 :   g_assert_cmpstr (filename, ==, filename2);
    2990                 :            : 
    2991                 :         19 :   g_free (filename);
    2992                 :         19 :   g_free (filename2);
    2993                 :         19 :   return ret;
    2994                 :            : }

Generated by: LCOV version 1.14