9unit/9unit.c

82 lines
1.6 KiB
C
Raw Normal View History

2023-11-06 00:04:12 -05:00
/*
9unit
Copyright (C) 2023 Jonathan Lamothe <jonathan@jlamothe.net>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or (at
your option) any later version.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
2023-11-06 13:59:19 -05:00
#include <u.h>
#include <libc.h>
2023-11-06 15:20:09 -05:00
#include <stdio.h>
2023-11-06 13:59:19 -05:00
#include "9unit.h"
// Internal Prototypes
static void init_TestState(TestState *s);
// Public Functions
2023-11-06 14:46:01 -05:00
void
run_test(TestState *s, TestResult (*t)(TestState *))
2023-11-06 14:46:01 -05:00
{
if (!(s && t)) return;
s->run++;
switch ((*t)(s))
2023-11-06 14:26:55 -05:00
{
2023-11-06 14:46:01 -05:00
case test_success:
2023-11-06 15:20:09 -05:00
s->passed++;
2023-11-06 14:46:01 -05:00
break;
case test_failure:
2023-11-06 15:20:09 -05:00
s->failed++;
2023-11-06 14:46:01 -05:00
break;
case test_postponed:
s->postponed++;
break;
default:
exits("test returned an invalid response");
2023-11-06 14:26:55 -05:00
}
}
2023-11-06 15:20:09 -05:00
void
run_tests(void (*tests)(TestState *))
2023-11-06 15:20:09 -05:00
{
if(!tests) return;
TestState s;
init_TestState(&s);
2023-11-06 15:20:09 -05:00
(*tests)(&s);
printf("Tests run: %d\n", s.run);
printf("Tests passed: %d\n", s.passed);
printf("Tests failed: %d\n", s.failed);
printf("Tests postponed: %d\n", s.postponed);
}
// Internal Functions
static void
init_TestState(TestState *s)
{
if (!s) return;
s->run = 0;
s->passed = 0;
s->failed = 0;
s->postponed = 0;
s->first_log = 0;
s->last_log = 0;
}
2023-11-06 00:04:12 -05:00
//jl