Skip to content

Commit

Permalink
Use aceunit for fixture generation for AceUnit_AbortRunner_Test and A…
Browse files Browse the repository at this point in the history
…ceUnit_ForkRunner_Test, make the tests more similar, and assert the method calls.
  • Loading branch information
christianhujer committed May 2, 2024
1 parent d512423 commit a016727
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 39 deletions.
26 changes: 9 additions & 17 deletions lib/AceUnit_AbortRunner_Test.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,18 @@
#include <stdlib.h>
#include <aceunit.h>

bool ran_tc_ok = false;
bool ran_test_failing = false;
bool ran_test_ok = false;

void tc_failing(void) {
void test_failing(void) {
ran_test_failing = true;
assert(false);
}

void tc_ok(void) {
ran_tc_ok = true;
void test_ok(void) {
ran_test_ok = true;
}

static const aceunit_func_t failing_test[] = {
tc_failing,
tc_ok,
NULL,
};

const AceUnit_Fixture_t failing_test_fixture = { NULL, NULL, NULL, NULL, failing_test };

const AceUnit_Fixture_t *fixtures[] = {
&failing_test_fixture,
NULL,
};

int main(void) {
#if defined(__BCC__)
AceUnit_Result_t result;
Expand All @@ -35,9 +24,12 @@ int main(void) {
AceUnit_Result_t result = { 0, 0, 0 };
#endif
AceUnit_run(fixtures, &result);
#undef assert
#include <assert.h>
assert(result.testCaseCount == 2);
assert(result.successCount == 1);
assert(result.failureCount == 1);
assert(ran_test_failing);
assert(ran_test_ok);
return EXIT_SUCCESS;
}
26 changes: 10 additions & 16 deletions lib/AceUnit_ForkRunner_Test.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,18 @@
#include <stdlib.h>
#include <aceunit.h>

bool ran_tc_ok = false;
bool ran_test_failing = false;
bool ran_test_ok = false;

void tc_failing(void) {
void test_failing(void) {
ran_test_failing = true;
assert(false);
}

void tc_ok(void) {
ran_tc_ok = true;
void test_ok(void) {
ran_test_ok = true;
}

static const aceunit_func_t failing_test[] = {
tc_failing,
tc_ok,
NULL,
};

const AceUnit_Fixture_t failing_test_fixture = { NULL, NULL, NULL, NULL, failing_test };
const AceUnit_Fixture_t *fixtures[] = {
&failing_test_fixture,
NULL,
};

int main(void) {
#if defined(__BCC__)
AceUnit_Result_t result;
Expand All @@ -34,9 +24,13 @@ int main(void) {
AceUnit_Result_t result = { 0, 0, 0 };
#endif
AceUnit_run(fixtures, &result);
#undef assert
#include <assert.h>
assert(result.testCaseCount == 2);
assert(result.successCount == 1);
assert(result.failureCount == 1);
// Do not assert these, they're modified in a child process, not here.
//assert(ran_test_failing);
//assert(ran_test_ok);
return EXIT_SUCCESS;
}
12 changes: 8 additions & 4 deletions lib/AceUnit_SetJmpRunner_Test.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@

extern jmp_buf *AceUnit_env;

bool ran_tc_ok = false;
bool ran_test_failing = false;
bool ran_test_ok = false;

void test_failing(void) {
ran_test_failing = true;
assert(false);
}

void test_ok(void) {
ran_tc_ok = true;
ran_test_ok = true;
}

#undef assert
#include <assert.h>
int main(void) {
#if defined(__BCC__)
AceUnit_Result_t result;
Expand All @@ -26,8 +26,12 @@ int main(void) {
AceUnit_Result_t result = { 0, 0, 0 };
#endif
AceUnit_run(fixtures, &result);
#undef assert
#include <assert.h>
assert(result.testCaseCount == 2);
assert(result.successCount == 1);
assert(result.failureCount == 1);
assert(ran_test_failing);
assert(ran_test_ok);
return EXIT_SUCCESS;
}
4 changes: 2 additions & 2 deletions lib/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ test_SetJmpRunner: AceUnit_SetJmpRunner_Test
./AceUnit_SetJmpRunner_Test

AceUnit_SimpleRunner_Test: AceUnit_SimpleRunner_Test.o libaceunit-simple.a
AceUnit_AbortRunner_Test: AceUnit_AbortRunner_Test.o libaceunit-abort.a
AceUnit_ForkRunner_Test: AceUnit_ForkRunner_Test.o libaceunit-fork.a
AceUnit_AbortRunner_Test: AceUnit_AbortRunner_Test.o AceUnit_AbortRunner_Fixture.o libaceunit-abort.a
AceUnit_ForkRunner_Test: AceUnit_ForkRunner_Test.o AceUnit_ForkRunner_Fixture.o libaceunit-fork.a
AceUnit_SetJmpRunner_Test: AceUnit_SetJmpRunner_Test.o AceUnit_SetJmpRunner_Fixture.o libaceunit-setjmp.a

%_Fixture.c: %_Test.o
Expand Down

0 comments on commit a016727

Please sign in to comment.