9unit/test/run-test.c

149 lines
2.9 KiB
C

/*
9unit
Copyright (C) Jonathan Lamothe <jonathan@jlamothe.net>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this program. If not, see
<http://www.gnu.org/licenses/>.
*/
#include <u.h>
#include <libc.h>
#include "../9unit.h"
#include "util.h"
#include "run-test.h"
// Internal Prototypes
static void test_pass(TestState *);
static void test_fail(TestState *);
static void test_pend(TestState *);
static TestResult null_state(TestState *);
static void null_test(TestState *);
static TestResult always_passes(TestState *);
static TestResult always_fails(TestState *);
static TestResult always_pends(TestState *);
// Public Functions
void
test_run_test(TestState *s)
{
test_context(s, "passing", test_pass);
test_context(s, "failing", test_fail);
test_context(s, "pending", test_pend);
single_test_context(s, "null state", null_state);
test_context(s, "null test", null_test);
}
// Internal Functions
static void
test_pass(TestState *s)
{
TestState actual, expected;
// actual result
mk_sample_state(&actual);
run_test(&actual, always_passes);
// expected result
mk_sample_state(&expected);
expected.passed = 2;
expected.run = 7;
chk_TestState_eq(s, 0, &actual, &expected);
}
static void
test_fail(TestState *s)
{
TestState actual, expected;
// actual result
mk_sample_state(&actual);
run_test(&actual, always_fails);
// expected result
mk_sample_state(&expected);
expected.failed = 3;
expected.run = 7;
chk_TestState_eq(s, 0, &actual, &expected);
}
static void
test_pend(TestState *s)
{
TestState actual, expected;
// actual result
mk_sample_state(&actual);
run_test(&actual, always_pends);
// expected result
mk_sample_state(&expected);
expected.pending = 4;
expected.run = 7;
chk_TestState_eq(s, 0, &actual, &expected);
}
static TestResult
null_state(TestState *)
{
// make sure it doesn't crash
run_test(0, always_passes);
return test_success;
}
static void
null_test(TestState *s)
{
TestState actual, expected;
// actual value
mk_sample_state(&actual);
run_test(&actual, 0);
// expected value
mk_sample_state(&expected);
expected.pending = 4;
expected.run = 7;
chk_TestState_eq(s, 0, &actual, &expected);
}
static TestResult
always_passes(TestState *)
{
return test_success;
}
static TestResult
always_fails(TestState *)
{
return test_failure;
}
static TestResult
always_pends(TestState *)
{
return test_pending;
}
//jl