Skip to content

Commit

Permalink
Merge pull request #22 from exoticlibraries/dev
Browse files Browse the repository at this point in the history
enable memory allocation validation for compiler greater than C99
  • Loading branch information
Thecarisma authored Sep 6, 2020
2 parents f38a05c + 0bd5cec commit 384b6d1
Show file tree
Hide file tree
Showing 17 changed files with 397 additions and 85 deletions.
4 changes: 0 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
language: sh

branches:
only:
- main

os:
- linux

Expand Down
9 changes: 0 additions & 9 deletions docs/_static/css/libcester.css
Original file line number Diff line number Diff line change
Expand Up @@ -131,22 +131,13 @@ code {
}

.two-sided pre {
max-height: 20pc;
overflow-y: scroll;
}

.bold {
font-weight: bold;
}

.note {
background: rgb(24,26,27) !important;
}

.warning {
background: rgb(24,26,27) !important;
}

.bodywrapper {
min-height: 100vh;
}
Expand Down
21 changes: 20 additions & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,24 @@
'index'
],
"source_root": "https://github.com/exoticlibraries/libcester/edit/main/docs",
"document_font_size": "17px"
"document_font_size": "17px",
"metadata": {
"enable": True,
"url": "https://exoticlibraries.github.io/libcester/",
"type": "website",
"title": "A robust header only unit testing framework for C programming language.",
"description": "libcester is a header only automated testing framework for the C programming language, it requires no dependency and can be downloaded and used in a project immediately.",
"image": "https://raw.githubusercontent.com/exoticlibraries/libcester/main/docs/libcester.png",
"keywords": "thecarisma, c, cpp, c++, unit testing, framework, exoticlibraries, exotic, libraries, regression, test",
"author": "Adewale Azeez"
},
"twitter_metadata": {
"enable": True,
"card": "summary",
"site": "@iamthecarisma",
"creator": "@iamthecarisma",
"title": "A robust header only unit testing framework for C programming language.",
"description": "libcester is a header only automated testing framework for the C programming language, it requires no dependency and can be downloaded and used in a project immediately.",
"image": "https://raw.githubusercontent.com/exoticlibraries/libcester/main/docs/libcester.png",
}
}
36 changes: 36 additions & 0 deletions docs/docs/macros.rst
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,28 @@ It should not begin or end in quote, escape characters is expanded when printed
before any test cases is executed.
)
CESTER_REPORT_SUCCESS_REGARDLESS
---------------------------------

Always mark the test as success even if the test cases failed or an error occur while running the test.

.. code:: c
CESTER_OPTIONS(
CESTER_REPORT_SUCCESS_REGARDLESS();
)
CESTER_REPORT_FAILURE_REGARDLESS
---------------------------------

Always mark the test as failure even if the test cases passes and no error occur.

.. code:: c
CESTER_OPTIONS(
CESTER_REPORT_FAILURE_REGARDLESS();
)
CESTER_REGISTER_TEST
----------------------
Expand Down Expand Up @@ -836,6 +858,20 @@ CESTER_TOTAL_TESTS_COUNT
The total number of test that is registered at the time.


CESTER_TOTAL_TEST_ERRORS_COUNT
-------------------------------

.. code:: text
printf("Total Test Error %d", CESTER_TOTAL_TEST_ERRORS_COUNT);
The total number of errors that occur during the test. The errors is not tied to the test
cases, the error is tied to cester fixtures, environment error and error that occur
outside a test case.

Error that occur within a test case is reported for that test case


CESTER_TOTAL_TESTS_RAN
-------------------------

Expand Down
99 changes: 92 additions & 7 deletions docs/docs/test_for_failure.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ to set a test case result:
- `CESTER_TEST_SHOULD_FAIL <./macros.html#cester-test-should-fail>`_
- `CESTER_TEST_SHOULD_BE_TERMINATED <./macros.html#cester-test-should-be-terminated>`_
- `CESTER_TEST_SHOULD_LEAK_MEMORY <./macros.html#cester-test-should-leak-memory>`_
- `CESTER_REPORT_SUCCESS_REGARDLESS <./macros.html#cester-report-success-regardless>`_
- `CESTER_REPORT_FAILURE_REGARDLESS <./macros.html#cester-report-failure-regardless>`_

The macro CESTER_TEST_SHOULD accepts the test case name as the first parameter and the expected
result as the second parameter. By default the expected result for the test cases is
Expand Down Expand Up @@ -53,7 +55,7 @@ the expected result of the test case.
gcc test.c -I. -o test
./test --cester-minimal
+ (0.01s) definitely crahses
+ (0.01s) definitely crahses
Passed crash_test.c:5: in 'definitely_crahses' => Segfault as expected
Expand Down Expand Up @@ -107,11 +109,11 @@ are expected to fail.
gcc test.c -I. -o test
./test --cester-minimal
+ (0.00s) this should segfault
+ (0.00s) this should fail
+ (0.00s) this should pass
+ (0.00s) this should segfault also fail
+ (0.01s) this should leak memory
+ (0.00s) this should segfault
+ (0.00s) this should fail
+ (0.00s) this should pass
+ (0.00s) this should segfault also fail
+ (0.01s) this should leak memory
Passed crash_test.c:5: in 'this_should_segfault' => Segfault as expected
AssertionError crash_test.c:10: in 'this_should_fail' => not expecting 'NULL', received '((void*)0)'
Expand All @@ -121,4 +123,87 @@ are expected to fail.
Passed crash_test.c:21: in 'this_should_leak_memory' => Leaked memory as expected
Ran 5 test(s) in 0.02 Seconds
Synthesis: SUCCESS Tests: 5 | Passing: 5 | Failing: 0
Synthesis: SUCCESS Tests: 5 | Passing: 5 | Failing: 0
Example 3
''''''''''

The test case in the example below will fail and memory error will be reported. But the test
will still be reported as success since the option CESTER_REPORT_SUCCESS_REGARDLESS() is specified.

.. code:: c
//test.c
#include <exotic/cester.h>
CESTER_BEFORE_ALL(test_instance,
char *str = (char *) malloc(20);
)
CESTER_TEST(test_assert_true, test_instance,
cester_assert_false(2 > 1);
cester_assert_false(test_instance != NULL);
cester_assert_false(test_instance->argc > 0);
)
CESTER_OPTIONS(
CESTER_REPORT_SUCCESS_REGARDLESS();
)
.. code:: bash
gcc test.c -I. -o test
./test --cester-minimal
- (0.00s) test assert true
EvaluationError test_always_success.c:10: in 'test_assert_true' expr => '(2 > 1)'
EvaluationError test_always_success.c:11: in 'test_assert_true' expr => '(test_instance != NULL)'
EvaluationError test_always_success.c:12: in 'test_assert_true' expr => '(test_instance->argc > 0)'
MemoryLeakError test_always_success.c:6: in 'CESTER_BEFORE_ALL' => Memory allocated in line '6' not freed. Leaking '20' Bytes
Ran 1 test(s) in 0.00 Seconds
Synthesis: SUCCESS Tests: 1 | Passing: 0 | Failing: 1 | Errors: 1
echo $?
0
Example 4
''''''''''

The test case in the example below will pass with no error . But the test be reported as failure
since the option CESTER_REPORT_FAILURE_REGARDLESS() is specified.

.. code:: c
//test.c
#include <exotic/cester.h>
CESTER_TEST(test_assert_true, test_instance,
cester_assert_true(2 > 1);
cester_assert_true(test_instance != NULL);
cester_assert_true(test_instance->argc > 0);
)
CESTER_OPTIONS(
CESTER_REPORT_FAILURE_REGARDLESS();
)
.. code:: bash
gcc test.c -I. -o test
./test --cester-minimal
+ (0.00s) test assert true
Ran 1 test(s) in 0.00 Seconds
Synthesis: FAILURE Tests: 1 | Passing: 1 | Failing: 0
echo $?
1
Loading

0 comments on commit 384b6d1

Please sign in to comment.