LCOV - code coverage report
Current view: top level - ccache/test - main.c (source / functions) Hit Total Coverage
Test: ccache.lcov.info Lines: 17 24 70.8 %
Date: 2015-06-29 Functions: 1 1 100.0 %
Branches: 3 9 33.3 %

           Branch data     Line data    Source code
       1                 :            : /* Mode: -*-c-*- */
       2                 :            : /*
       3                 :            :  * Copyright (C) 2010 Joel Rosdahl
       4                 :            :  *
       5                 :            :  * This program is free software; you can redistribute it and/or modify it
       6                 :            :  * under the terms of the GNU General Public License as published by the Free
       7                 :            :  * Software Foundation; either version 3 of the License, or (at your option)
       8                 :            :  * any later version.
       9                 :            :  *
      10                 :            :  * This program is distributed in the hope that it will be useful, but WITHOUT
      11                 :            :  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
      12                 :            :  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
      13                 :            :  * more details.
      14                 :            :  *
      15                 :            :  * You should have received a copy of the GNU General Public License along with
      16                 :            :  * this program; if not, write to the Free Software Foundation, Inc., 51
      17                 :            :  * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
      18                 :            :  */
      19                 :            : 
      20                 :            : #include "test/framework.h"
      21                 :            : #ifdef HAVE_GETOPT_LONG
      22                 :            : #include <getopt.h>
      23                 :            : #else
      24                 :            : #include "getopt_long.h"
      25                 :            : #endif
      26                 :            : 
      27                 :            : #define SUITE(name) unsigned suite_##name(unsigned);
      28                 :            : #include "test/suites.h"
      29                 :            : #undef SUITE
      30                 :            : 
      31                 :            : const char USAGE_TEXT[] =
      32                 :            :         "Usage:\n"
      33                 :            :         "    test [options]\n"
      34                 :            :         "\n"
      35                 :            :         "Options:\n"
      36                 :            :         "    -h, --help      print this help text\n"
      37                 :            :         "    -v, --verbose   enable verbose logging of tests\n";
      38                 :            : 
      39                 :            : int
      40                 :          1 : main(int argc, char **argv)
      41                 :            : {
      42                 :            :         suite_fn suites[] = {
      43                 :            : #define SUITE(name) &suite_##name,
      44                 :            : #include "test/suites.h"
      45                 :            : #undef SUITE
      46                 :            :                 NULL
      47                 :          1 :         };
      48                 :            :         static const struct option options[] = {
      49                 :            :                 {"help", no_argument, NULL, 'h'},
      50                 :            :                 {"verbose", no_argument, NULL, 'v'},
      51                 :            :                 {NULL, 0, NULL, 0}
      52                 :            :         };
      53                 :          1 :         int verbose = 0;
      54                 :            :         int c;
      55                 :            :         char *testdir, *dir_before;
      56                 :            :         int result;
      57                 :            : 
      58                 :            : #ifdef _WIN32
      59                 :            :         putenv("CCACHE_DETECT_SHEBANG=1");
      60                 :            : #endif
      61                 :            : 
      62         [ -  + ]:          1 :         while ((c = getopt_long(argc, argv, "hv", options, NULL)) != -1) {
      63      [ #  #  # ]:          0 :                 switch (c) {
      64                 :            :                 case 'h':
      65                 :          0 :                         fprintf(stdout, USAGE_TEXT);
      66                 :          0 :                         return 0;
      67                 :            : 
      68                 :            :                 case 'v':
      69                 :          0 :                         verbose = 1;
      70                 :          0 :                         break;
      71                 :            : 
      72                 :            :                 default:
      73                 :          0 :                         fprintf(stderr, USAGE_TEXT);
      74                 :          0 :                         return 1;
      75                 :            :                 }
      76                 :            :         }
      77                 :            : 
      78         [ +  - ]:          1 :         if (getenv("RUN_FROM_BUILD_FARM")) {
      79                 :          1 :                 verbose = 1;
      80                 :            :         }
      81                 :            : 
      82                 :          1 :         testdir = format("testdir.%d", (int)getpid());
      83                 :          1 :         cct_create_fresh_dir(testdir);
      84                 :          1 :         dir_before = gnu_getcwd();
      85                 :          1 :         cct_chdir(testdir);
      86                 :          1 :         result = cct_run(suites, verbose);
      87         [ +  - ]:          1 :         if (result == 0) {
      88                 :          1 :                 cct_chdir(dir_before);
      89                 :          1 :                 cct_wipe(testdir);
      90                 :            :         }
      91                 :          1 :         free(testdir);
      92                 :          1 :         free(dir_before);
      93                 :          1 :         return result;
      94                 :            : }

Generated by: LCOV version 1.9