-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Code patched ready for a patch release v1.3.1
- Loading branch information
1 parent
b9482a1
commit 31f3ad3
Showing
23 changed files
with
343 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
C = cc | ||
CFLAGS = -Wall -Werror | ||
LDFLAGS = -lunittest | ||
TEST_DIR = dir | ||
TEST_OBJECTS = $(addprefix $(TEST_DIR)/, simpletest.o) | ||
|
||
all: testrunner | ||
|
||
testrunner: $(TEST_OBJECTS) testrunner.o | ||
$(C) $(LDFLAGS) $(TEST_OBJECTS) testrunner.o -o testrunner | ||
|
||
$(TEST_DIR)/simpletest.o: $(TEST_DIR)/simpletest.c | ||
$(C) $(CFLAGS) -c $(TEST_DIR)/simpletest.c -o $(TEST_DIR)/simpletest.o | ||
|
||
testrunner.o: testrunner.c | ||
$(C) $(CFLAGS) -c testrunner.c -o testrunner.o | ||
|
||
# Clean all the compiled things | ||
clean: | ||
rm -f $(TEST_OBJECTS) testrunner.o testrunner | ||
|
||
# To run the tests | ||
test: testrunner | ||
./testrunner |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// simpletest.c | ||
#include <unittest.h> | ||
|
||
TESTCASE(SimpleTest) { | ||
// Set up any boilerplate code for all tests in the test case | ||
int var = 1; | ||
|
||
// Define individual tests using the TEST macro | ||
TEST(Test1) { | ||
// Use ASSERT macro to check if var is equal to 1 | ||
ASSERT_EQ(var, 1, "It should be one"); | ||
} | ||
|
||
TEST(Test2) { | ||
ASSERT(var > 0, "It should be greater than zero"); | ||
} | ||
|
||
TEST(Test3) { | ||
ASSERT(var < 2, "It should be lesser than 2"); | ||
} | ||
|
||
TEST(Test4) { | ||
ASSERT(var != 0, "It should not be zero"); | ||
} | ||
} ENDTESTCASE | ||
|
||
|
||
TESTCASE(MyTestCases1) | ||
{ | ||
// Set up any boilerplate code for all tests in the test case | ||
int x = 42; | ||
|
||
// Define individual tests using the TEST macro | ||
TEST(Test1) { | ||
// Use ASSERT macro to check if x equals 42 | ||
ASSERT(x == 42, "x should equal 42"); | ||
} | ||
|
||
TEST(Test2) { | ||
// Use ASSERT macro to check if x is less than 100 | ||
ASSERT(x < 100, "x should be less than 100"); | ||
} | ||
|
||
} ENDTESTCASE | ||
|
||
TESTCASE(MyTestCases2) | ||
{ | ||
// Set up any boilerplate code for all tests in the test case | ||
int y = 100; | ||
|
||
// Define individual tests using the TEST macro | ||
TEST(Test3) { | ||
// Use ASSERT macro to check if y equals 100 | ||
ASSERT(y == 100, "y should equal 100"); | ||
} | ||
|
||
TEST(Test4) { | ||
// Use ASSERT macro to check if y is greater than or equal to 50 | ||
ASSERT(y >= 50, "y should be greater than or equal to 50"); | ||
} | ||
} ENDTESTCASE | ||
|
||
SUIT(MySuit, MyTestCases1, MyTestCases2); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
|
||
|
||
/* Simple example to test the foo */ | ||
|
||
#include <unittest.h> | ||
|
||
TESTCASE(TestingFoo) { | ||
|
||
extern int foo(void); | ||
|
||
TEST(FooReturn) { | ||
ASSERT_EQ(foo(), 1, "foo must to return 1"); | ||
} | ||
} ENDTESTCASE | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
|
||
#include <string.h> | ||
#include <malloc.h> | ||
|
||
/* Foo function */ | ||
|
||
int x; | ||
|
||
int foo(void) | ||
{ | ||
void *ptr = malloc(sizeof(x)); | ||
|
||
return 1; | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* To compile run: | ||
cc -o testrunner testrunner.c dir/simpletest.c -lunittest && ./testrunner | ||
*/ | ||
|
||
#include <stdio.h> | ||
|
||
#define TEST_DIR "dir/" | ||
#include <unittest.h> | ||
|
||
int main(void) | ||
{ | ||
// Include a testcase | ||
INCLUDE_TESTCASE("simpletest.c", SimpleTest); | ||
|
||
// Include a suit | ||
INCLUDE_SUIT("simpletest.c", MySuit); | ||
|
||
/* Run the selected testcases or suits */ | ||
RUN(SimpleTest, MySuit); | ||
|
||
return unittest_ret; | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* To compile run: | ||
cc -ggdb -c obj/foo.c -o obj/foo.o && cc -ggdb testrunner2.c -o testrunner2 -lunittest && ./testrunner2 | ||
*/ | ||
|
||
#include <stdio.h> | ||
|
||
#define TEST_DIR "dir/" | ||
#define UNITTEST_RECOMPILE | ||
#include <unittest.h> | ||
|
||
|
||
int main(void) | ||
{ | ||
INCLUDE_TESTCASE("simpletest.c", SimpleTest); | ||
INCLUDE_SUIT("simpletest.c", MySuit); | ||
INCLUDE_TESTCASE("test_foo.c", TestingFoo); | ||
|
||
ATTACH_EXTRA_COMPILE_FLAGS("-ggdb"); | ||
|
||
ATTACH_EXTRA_LINKING_FLAGS("obj/foo.o"); | ||
|
||
ACTIVE_VALGRIND(true); | ||
|
||
/* Run the selected testcases or suits */ | ||
RUN(SimpleTest, MySuit, TestingFoo); | ||
|
||
return unittest_ret; | ||
} | ||
|
||
|
||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.