LCOV - code coverage report
Current view: top level - clients/examples/C - murltest.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 25 43 58.1 %
Date: 2024-04-25 20:03:45 Functions: 3 3 100.0 %

          Line data    Source code
       1             : /*
       2             :  * SPDX-License-Identifier: MPL-2.0
       3             :  *
       4             :  * This Source Code Form is subject to the terms of the Mozilla Public
       5             :  * License, v. 2.0.  If a copy of the MPL was not distributed with this
       6             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       7             :  *
       8             :  * Copyright 2024 MonetDB Foundation;
       9             :  * Copyright August 2008 - 2023 MonetDB B.V.;
      10             :  * Copyright 1997 - July 2008 CWI.
      11             :  */
      12             : 
      13             : #define _POSIX_C_SOURCE 200809L
      14             : 
      15             : #include "murltest.h"
      16             : 
      17             : #include <errno.h>
      18             : #include <stdbool.h>
      19             : #include <stdlib.h>
      20             : #include <string.h>
      21             : 
      22             : char *USAGE = "Usage: murltest TESTFILES..";
      23             : 
      24             : static bool
      25           1 : run_file(const char *filename, int verbose)
      26             : {
      27           1 :         stream *s;
      28           1 :         if (strcmp(filename, "-") == 0) {
      29           0 :                 s = stdin_rastream();
      30             :         } else {
      31           1 :                 s = open_rastream(filename);
      32           1 :                 if (!s || mnstr_errnr(s) != MNSTR_NO__ERROR) {
      33           0 :                         fprintf(stderr, "Could not open %s: %s\n", filename, mnstr_peek_error(s));
      34           0 :                         return false;
      35             :                 }
      36             :         }
      37             : 
      38           1 :         bool ok = run_tests(s, verbose);
      39             : 
      40           1 :         close_stream(s);
      41           1 :         return ok;
      42             : }
      43             : 
      44           1 : static bool run_files(char **files, int verbose)
      45             : {
      46           2 :         while (*files) {
      47           1 :                 if (!run_file(*files, verbose))
      48             :                         return false;
      49           1 :                 files++;
      50             :         }
      51             :         return true;
      52             : }
      53             : 
      54             : int
      55           1 : main(int argc, char **argv)
      56             : {
      57           1 :         int verbose = 0;
      58             : 
      59           1 :         if (mnstr_init() != 0) {
      60           0 :                 fprintf(stderr, "could not initialize libstream\n");
      61           0 :                 return 1;
      62             :         }
      63             : 
      64           1 :         char **files = calloc(argc + 1, sizeof(char*));
      65           1 :         if (!files)
      66             :                 return 3;
      67             :         char **next_slot = &files[0];
      68           2 :         for (int i = 1; i < argc; i++) {
      69           1 :                 char *arg = argv[i];
      70           1 :                 if (arg[0] != '-') {
      71           1 :                         *next_slot++ = arg;
      72           1 :                         continue;
      73             :                 }
      74           0 :                 if (arg[1] == 'v') {
      75           0 :                         char *p = &arg[1];
      76           0 :                         while (*p == 'v') {
      77           0 :                                 p++;
      78           0 :                                 verbose++;
      79             :                         }
      80           0 :                         if (*p == '\0')
      81           0 :                                 continue;
      82           0 :                         fprintf(stderr, "invalid letter %c in flag %s\n", *p, arg);
      83           0 :                         free(files);
      84           0 :                         return 1;
      85             :                 } else {
      86           0 :                         fprintf(stderr, "invalid flag %s\n", arg);
      87           0 :                         free(files);
      88           0 :                         return 1;
      89             :                 }
      90             :         }
      91             : 
      92           1 :         bool ok = run_files(files, verbose);
      93             : 
      94           1 :         free(files);
      95           1 :         return ok ? EXIT_SUCCESS : EXIT_FAILURE;
      96             : }

Generated by: LCOV version 1.14