Compare commits
No commits in common. "55926ec0d8e5c6190b87c99e067f46fa51d2868a" and "291d25927c970f4e9e2d14a2d79a504cfbcdb528" have entirely different histories.
55926ec0d8
...
291d25927c
35
9unit.c
35
9unit.c
|
@ -28,7 +28,6 @@
|
||||||
// Internal Types
|
// Internal Types
|
||||||
|
|
||||||
typedef struct RunTestWith RunTestWith;
|
typedef struct RunTestWith RunTestWith;
|
||||||
typedef struct RunTestCompare RunTestCompare;
|
|
||||||
typedef struct ContextData ContextData;
|
typedef struct ContextData ContextData;
|
||||||
typedef struct TestContextWith TestContextWith;
|
typedef struct TestContextWith TestContextWith;
|
||||||
typedef struct SingleTestContextWith SingleTestContextWith;
|
typedef struct SingleTestContextWith SingleTestContextWith;
|
||||||
|
@ -42,14 +41,6 @@ struct RunTestWith
|
||||||
void *val; // the value passed in
|
void *val; // the value passed in
|
||||||
};
|
};
|
||||||
|
|
||||||
// data needed by run_test_compare()
|
|
||||||
struct RunTestCompare
|
|
||||||
{
|
|
||||||
TestResult (*test)(TestState *, void *, void *);
|
|
||||||
void *val1;
|
|
||||||
void *val2;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct ContextData
|
struct ContextData
|
||||||
{
|
{
|
||||||
const char *old_c; // previous context
|
const char *old_c; // previous context
|
||||||
|
@ -88,7 +79,6 @@ static void clear_log(TestState *);
|
||||||
static void reindex(TestState *);
|
static void reindex(TestState *);
|
||||||
static void report(const char *);
|
static void report(const char *);
|
||||||
static TestResult run_test_with_test(TestState *);
|
static TestResult run_test_with_test(TestState *);
|
||||||
static TestResult run_test_compare_test(TestState *, void *);
|
|
||||||
static void build_new_context(TestState *, ContextData *);
|
static void build_new_context(TestState *, ContextData *);
|
||||||
static void display_context(TestState *);
|
static void display_context(TestState *);
|
||||||
static void restore_context(TestState *, ContextData *);
|
static void restore_context(TestState *, ContextData *);
|
||||||
|
@ -149,21 +139,6 @@ run_test_with(
|
||||||
run_test(s, run_test_with_test);
|
run_test(s, run_test_with_test);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
|
||||||
run_test_compare(
|
|
||||||
TestState *s,
|
|
||||||
TestResult (*test)(TestState *, void *, void *),
|
|
||||||
void *val1,
|
|
||||||
void *val2
|
|
||||||
)
|
|
||||||
{
|
|
||||||
RunTestCompare d;
|
|
||||||
d.test = test;
|
|
||||||
d.val1 = val1;
|
|
||||||
d.val2 = val2;
|
|
||||||
run_test_with(s, run_test_compare_test, &d);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void
|
||||||
run_tests(void (*tests)(TestState *))
|
run_tests(void (*tests)(TestState *))
|
||||||
{
|
{
|
||||||
|
@ -398,16 +373,6 @@ run_test_with_test(TestState *s)
|
||||||
return (*d->test)(s, d->val);
|
return (*d->test)(s, d->val);
|
||||||
}
|
}
|
||||||
|
|
||||||
static TestResult
|
|
||||||
run_test_compare_test(
|
|
||||||
TestState *s,
|
|
||||||
void *ptr
|
|
||||||
)
|
|
||||||
{
|
|
||||||
RunTestCompare *d = ptr;
|
|
||||||
return (*d->test)(s, d->val1, d->val2);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
test_context_with_test(TestState *s)
|
test_context_with_test(TestState *s)
|
||||||
{
|
{
|
||||||
|
|
33
9unit.h
33
9unit.h
|
@ -21,14 +21,15 @@
|
||||||
|
|
||||||
// Types & Structs
|
// Types & Structs
|
||||||
|
|
||||||
|
// Tracks information about the tests being run.
|
||||||
|
typedef struct TestState TestState;
|
||||||
|
|
||||||
|
// Defines a log entry in a TestState struct
|
||||||
|
typedef struct TestLogEntry TestLogEntry;
|
||||||
|
|
||||||
// The following structures will typically be maintained by the
|
// The following structures will typically be maintained by the
|
||||||
// testing framework. You shouldn't need to concern yourself with
|
// testing framework. You shouldn't need to concern yourself with
|
||||||
// them.
|
// them.
|
||||||
|
|
||||||
typedef struct TestState TestState;
|
|
||||||
typedef struct TestLogEntry TestLogEntry;
|
|
||||||
|
|
||||||
// Tracks information about the tests being run.
|
|
||||||
struct TestState
|
struct TestState
|
||||||
{
|
{
|
||||||
int run; // number of tests run
|
int run; // number of tests run
|
||||||
|
@ -44,7 +45,6 @@ struct TestState
|
||||||
void (*report)(const char *); // prints a string immediately
|
void (*report)(const char *); // prints a string immediately
|
||||||
};
|
};
|
||||||
|
|
||||||
// Defines a log entry in a TestState struct
|
|
||||||
struct TestLogEntry
|
struct TestLogEntry
|
||||||
{
|
{
|
||||||
char *text; // the entry text
|
char *text; // the entry text
|
||||||
|
@ -74,25 +74,12 @@ extern void run_test_with(
|
||||||
void * // the value to pass in
|
void * // the value to pass in
|
||||||
);
|
);
|
||||||
|
|
||||||
// Runs a single test passing in two values to be compared
|
// Runs multiple tests, displaying a summary at the end
|
||||||
extern void run_test_compare(
|
extern void run_tests(
|
||||||
TestState *, // the current state
|
// runs the tests and updates a provided TestState
|
||||||
|
void (*)(TestState *)
|
||||||
// the test to be run
|
|
||||||
TestResult (*test)(
|
|
||||||
TestState *, // the current state
|
|
||||||
void *, // the first value
|
|
||||||
void * // the second value
|
|
||||||
),
|
|
||||||
|
|
||||||
void *, // the first value
|
|
||||||
void * // the second value
|
|
||||||
);
|
);
|
||||||
|
|
||||||
// Creates an initial TestState, passes it to the supplied function,
|
|
||||||
// and displays the resulting log and summary
|
|
||||||
extern void run_tests(void (*)(TestState *));
|
|
||||||
|
|
||||||
// Adds an entry to the log that is displayed after the tests have
|
// Adds an entry to the log that is displayed after the tests have
|
||||||
// completed
|
// completed
|
||||||
extern void append_test_log(
|
extern void append_test_log(
|
||||||
|
|
Loading…
Reference in New Issue
Block a user