defined runTests
This commit is contained in:
parent
07fcb5b103
commit
311eaa429d
22
9unit.c
22
9unit.c
|
@ -19,6 +19,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <u.h>
|
#include <u.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
#include "9unit.h"
|
#include "9unit.h"
|
||||||
|
|
||||||
|
@ -27,8 +28,8 @@ initTestState(TestState *s)
|
||||||
{
|
{
|
||||||
if (!s) return;
|
if (!s) return;
|
||||||
s->run = 0;
|
s->run = 0;
|
||||||
s->success = 0;
|
s->passed = 0;
|
||||||
s->failure = 0;
|
s->failed = 0;
|
||||||
s->postponed = 0;
|
s->postponed = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -40,10 +41,10 @@ runTest(TestState *s, TestResult (*t)(void))
|
||||||
switch ((*t)())
|
switch ((*t)())
|
||||||
{
|
{
|
||||||
case test_success:
|
case test_success:
|
||||||
s->success++;
|
s->passed++;
|
||||||
break;
|
break;
|
||||||
case test_failure:
|
case test_failure:
|
||||||
s->failure++;
|
s->failed++;
|
||||||
break;
|
break;
|
||||||
case test_postponed:
|
case test_postponed:
|
||||||
s->postponed++;
|
s->postponed++;
|
||||||
|
@ -51,4 +52,17 @@ runTest(TestState *s, TestResult (*t)(void))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
//jl
|
//jl
|
||||||
|
|
19
9unit.h
19
9unit.h
|
@ -22,11 +22,12 @@
|
||||||
typedef struct TestState
|
typedef struct TestState
|
||||||
{
|
{
|
||||||
int run; // number of tests run
|
int run; // number of tests run
|
||||||
int success; // number of successful tests
|
int passed; // number of successful tests
|
||||||
int failure; // number of failed tests
|
int failed; // number of failed tests
|
||||||
int postponed; // number of postponed tests
|
int postponed; // number of postponed tests
|
||||||
} TestState;
|
} TestState;
|
||||||
|
|
||||||
|
// Possible results of running a single test
|
||||||
typedef enum TestResult
|
typedef enum TestResult
|
||||||
{
|
{
|
||||||
test_success,
|
test_success,
|
||||||
|
@ -34,8 +35,20 @@ typedef enum TestResult
|
||||||
test_postponed
|
test_postponed
|
||||||
} TestResult;
|
} TestResult;
|
||||||
|
|
||||||
|
// Initializes a TestState value
|
||||||
extern void initTestState(TestState *);
|
extern void initTestState(TestState *);
|
||||||
|
|
||||||
extern void runTest(TestState *, TestResult (*)(void));
|
// Runs a single test
|
||||||
|
extern void runTest(
|
||||||
|
TestState *, // the TestState data
|
||||||
|
TestResult (*)(void) // the test to run
|
||||||
|
);
|
||||||
|
|
||||||
|
// Runs multiple tests
|
||||||
|
extern void runTests(
|
||||||
|
// function that runs the tests and updates the provided TestState
|
||||||
|
void (*)(TestState *)
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
//jl
|
//jl
|
||||||
|
|
Loading…
Reference in New Issue
Block a user