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>
|
2023-11-06 15:20:09 -05:00
|
|
|
#include <stdio.h>
|
2023-11-06 13:59:19 -05:00
|
|
|
|
|
|
|
#include "9unit.h"
|
|
|
|
|
2023-11-06 14:26:55 -05:00
|
|
|
void
|
|
|
|
initTestState(TestState *s)
|
|
|
|
{
|
2023-11-06 14:46:01 -05:00
|
|
|
if (!s) return;
|
|
|
|
s->run = 0;
|
2023-11-06 15:20:09 -05:00
|
|
|
s->passed = 0;
|
|
|
|
s->failed = 0;
|
2023-11-06 14:46:01 -05:00
|
|
|
s->postponed = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
runTest(TestState *s, TestResult (*t)(void))
|
|
|
|
{
|
|
|
|
if (!(s && t)) return;
|
|
|
|
s->run++;
|
|
|
|
switch ((*t)())
|
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;
|
2023-11-06 14:26:55 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-11-06 15:20:09 -05:00
|
|
|
void
|
|
|
|
runTests(void (*tests)(TestState *))
|
|
|
|
{
|
|
|
|
if(!tests) return;
|
|
|
|
TestState s;
|
|
|
|
initTestState(&s);
|
|
|
|
(*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);
|
|
|
|
}
|
|
|
|
|
2023-11-06 00:04:12 -05:00
|
|
|
//jl
|