2023-11-08 18:38:42 -05:00
|
|
|
/*
|
|
|
|
|
|
|
|
9unit
|
|
|
|
Copyright (C) Jonathan Lamothe <jonathan@jlamothe.net>
|
|
|
|
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
2023-11-09 18:24:48 -05:00
|
|
|
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.
|
2023-11-08 18:38:42 -05:00
|
|
|
|
|
|
|
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
|
2023-11-09 18:24:48 -05:00
|
|
|
Lesser General Public License for more details.
|
2023-11-08 18:38:42 -05:00
|
|
|
|
2023-11-09 18:24:48 -05:00
|
|
|
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/>.
|
2023-11-08 18:38:42 -05:00
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <u.h>
|
|
|
|
#include <libc.h>
|
|
|
|
|
|
|
|
#include "../9unit.h"
|
2023-11-09 15:48:51 -05:00
|
|
|
#include "util.h"
|
2023-11-08 18:38:42 -05:00
|
|
|
#include "run-test.h"
|
|
|
|
|
2023-11-08 19:06:18 -05:00
|
|
|
// Internal Prototypes
|
|
|
|
|
2023-11-09 18:51:51 -05:00
|
|
|
static void test_pass(TestState *);
|
|
|
|
static void test_fail(TestState *);
|
|
|
|
static void test_pend(TestState *);
|
2023-11-14 15:32:07 -05:00
|
|
|
decl_test(null_state);
|
2023-11-11 20:25:55 -05:00
|
|
|
static void null_test(TestState *);
|
2023-11-09 15:48:51 -05:00
|
|
|
decl_test(always_passes);
|
2023-11-09 18:39:13 -05:00
|
|
|
decl_test(always_fails);
|
2023-11-09 18:51:51 -05:00
|
|
|
decl_test(always_pends);
|
2023-11-08 19:06:18 -05:00
|
|
|
|
2023-11-08 18:38:42 -05:00
|
|
|
// Public Functions
|
|
|
|
|
|
|
|
void
|
2023-11-08 19:06:18 -05:00
|
|
|
test_run_test(TestState *s)
|
2023-11-08 18:38:42 -05:00
|
|
|
{
|
|
|
|
print("run_test()\n");
|
2023-11-09 18:51:51 -05:00
|
|
|
test_pass(s);
|
|
|
|
test_fail(s);
|
|
|
|
test_pend(s);
|
2023-11-14 15:32:07 -05:00
|
|
|
run_test(s, null_state);
|
2023-11-11 20:25:55 -05:00
|
|
|
null_test(s);
|
2023-11-08 19:06:18 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// Internal Functions
|
|
|
|
|
2023-11-09 15:48:51 -05:00
|
|
|
static void
|
2023-11-09 18:51:51 -05:00
|
|
|
test_pass(TestState *s)
|
2023-11-08 19:06:18 -05:00
|
|
|
{
|
2023-11-09 15:48:51 -05:00
|
|
|
TestState expected, actual;
|
2023-11-08 19:06:18 -05:00
|
|
|
print("\tpassing\n");
|
2023-11-09 15:48:51 -05:00
|
|
|
|
|
|
|
// expected result
|
2023-11-14 18:53:43 -05:00
|
|
|
mk_sample_state(&expected);
|
2023-11-09 15:48:51 -05:00
|
|
|
expected.passed = 2;
|
|
|
|
expected.run = 7;
|
|
|
|
|
|
|
|
// actual result
|
|
|
|
mk_sample_state(&actual);
|
|
|
|
run_test(&actual, always_passes);
|
|
|
|
|
2023-11-10 22:40:00 -05:00
|
|
|
chk_TestState_eq(
|
2023-11-09 15:48:51 -05:00
|
|
|
s,
|
|
|
|
"\t\t",
|
|
|
|
"ERROR: run_test(): passing:",
|
2023-11-10 22:40:00 -05:00
|
|
|
&actual,
|
|
|
|
&expected
|
2023-11-09 15:48:51 -05:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2023-11-09 18:39:13 -05:00
|
|
|
static void
|
2023-11-09 18:51:51 -05:00
|
|
|
test_fail(TestState *s)
|
2023-11-09 18:39:13 -05:00
|
|
|
{
|
|
|
|
TestState expected, actual;
|
|
|
|
print("\tfailing\n");
|
|
|
|
|
|
|
|
// expected result
|
2023-11-14 18:53:43 -05:00
|
|
|
mk_sample_state(&expected);
|
2023-11-09 18:39:13 -05:00
|
|
|
expected.failed = 3;
|
|
|
|
expected.run = 7;
|
|
|
|
|
|
|
|
// actual result
|
|
|
|
mk_sample_state(&actual);
|
|
|
|
run_test(&actual, always_fails);
|
|
|
|
|
2023-11-10 22:40:00 -05:00
|
|
|
chk_TestState_eq(
|
2023-11-09 18:39:13 -05:00
|
|
|
s,
|
|
|
|
"\t\t",
|
|
|
|
"ERROR: run_test(): failing:",
|
|
|
|
&expected,
|
|
|
|
&actual
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2023-11-09 18:51:51 -05:00
|
|
|
static void
|
|
|
|
test_pend(TestState *s)
|
|
|
|
{
|
|
|
|
TestState expected, actual;
|
|
|
|
print("\tpending\n");
|
|
|
|
|
|
|
|
// expected result
|
2023-11-14 18:53:43 -05:00
|
|
|
mk_sample_state(&expected);
|
2023-11-09 18:51:51 -05:00
|
|
|
expected.pending = 4;
|
|
|
|
expected.run = 7;
|
|
|
|
|
|
|
|
// actual result
|
|
|
|
mk_sample_state(&actual);
|
|
|
|
run_test(&actual, always_pends);
|
|
|
|
|
2023-11-10 22:40:00 -05:00
|
|
|
chk_TestState_eq(
|
2023-11-09 18:51:51 -05:00
|
|
|
s,
|
|
|
|
"\t\t",
|
|
|
|
"ERROR: run_test(): pending:",
|
|
|
|
&expected,
|
|
|
|
&actual
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2023-11-14 15:32:07 -05:00
|
|
|
decl_test(null_state)
|
2023-11-11 18:08:08 -05:00
|
|
|
{
|
|
|
|
print("\tnull state\n");
|
|
|
|
run_test(0, always_passes);
|
2023-11-14 15:32:07 -05:00
|
|
|
return test_success;
|
2023-11-11 18:08:08 -05:00
|
|
|
}
|
|
|
|
|
2023-11-11 20:25:55 -05:00
|
|
|
static void
|
|
|
|
null_test(TestState *s)
|
|
|
|
{
|
|
|
|
TestState actual, expected;
|
|
|
|
print("\tnull test\n");
|
|
|
|
|
|
|
|
// expected value
|
2023-11-14 18:53:43 -05:00
|
|
|
mk_sample_state(&expected);
|
2023-11-11 20:25:55 -05:00
|
|
|
expected.pending = 4;
|
|
|
|
expected.run = 7;
|
|
|
|
|
|
|
|
// actual value
|
|
|
|
mk_sample_state(&actual);
|
|
|
|
run_test(&actual, 0);
|
|
|
|
|
|
|
|
chk_TestState_eq(
|
|
|
|
s,
|
|
|
|
"\t\t",
|
|
|
|
"ERROR: run_test(): null_test:",
|
|
|
|
&actual,
|
|
|
|
&expected
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2023-11-09 15:48:51 -05:00
|
|
|
decl_test(always_passes)
|
|
|
|
{
|
|
|
|
return test_success;
|
2023-11-08 18:38:42 -05:00
|
|
|
}
|
|
|
|
|
2023-11-09 18:39:13 -05:00
|
|
|
decl_test(always_fails)
|
|
|
|
{
|
|
|
|
return test_failure;
|
|
|
|
}
|
|
|
|
|
2023-11-09 18:51:51 -05:00
|
|
|
decl_test(always_pends)
|
|
|
|
{
|
|
|
|
return test_pending;
|
|
|
|
}
|
|
|
|
|
2023-11-08 18:38:42 -05:00
|
|
|
//jl
|