5 * (c) 2023 Mark Wooding
8 /*----- Licensing notice --------------------------------------------------*
10 * This file is part of the `Finally' package.
12 * Finally is free software: you can redistribute it and/or modify it
13 * under the terms of the GNU Library General Public License as published
14 * by the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
17 * Finally is distributed in the hope that it will be useful, but WITHOUT
18 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
19 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
20 * License for more details.
22 * You should have received a copy of the GNU Library General Public
23 * License along with Finally. If not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
28 /*----- Header files ------------------------------------------------------*/
34 #include "finally-test.h"
36 /*----- Global variables --------------------------------------------------*/
38 const int secretly_true = 1;
40 /*----- Static variables --------------------------------------------------*/
42 static const char *curr;
43 static unsigned nrun = 0, nskip = 0, nlose = 0;
44 static unsigned flags = 0;
45 enum { HUMAN, TAP }; static unsigned outform = HUMAN;
50 /*----- Main code ---------------------------------------------------------*/
56 p = getenv("TEST_OUTFORM");
57 if (!p || strcmp(p, "human") == 0) outform = HUMAN;
58 else if (strcmp(p, "tap") == 0) outform = TAP;
59 else { fprintf(stderr, "unknown output format `%s'\n", p); exit(2); }
62 void begin_test(const char *name)
63 { step = 0; flags &= ~f_failthis; curr = name; }
65 void check_step(int s, const char *where)
71 case HUMAN: fp = stderr; break;
72 case TAP: fp = stdout; fputs("# ", stdout); break;
75 fprintf(fp, "%s (%s): misstep: expected %d but found %d\n",
76 where, curr, step, s);
84 nrun++; if (flags&f_failthis) nlose++;
88 printf("%s: %s\n", curr, flags&f_failthis ? "FAILED" : "ok");
91 printf("%s %u %s\n", flags&f_failthis ? "not ok" : "ok", nrun, curr);
98 void skip_test(const char *name, const char *excuse)
103 case HUMAN: printf("%s: (skipped: %s)\n", name, excuse); break;
104 case TAP: printf("ok %u %s # skip (%s)\n", nrun, name, excuse); break;
109 int test_report(void)
111 #define TESTS(n) ((n) == 1 ? "test" : "tests")
116 printf("FAILED %u out of %u %s", nlose, nrun, TESTS(nrun));
118 printf("passed %u out of %u %s",
119 nrun - nlose - nskip, nrun, TESTS(nrun));
121 printf("passed all %u %s", nrun, TESTS(nrun));
122 if (nskip) printf(" (skipped %u %s)", nskip, TESTS(nskip));
124 return (nlose ? 2 : 0);
126 printf("1..%u\n", nrun);
135 /*----- That's all, folks -------------------------------------------------*/