Greetings,
Until now both clang/gcc compilers do not show detailed/verbose info for asserts. Consider:
Code:
// detailed asserts
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
int main(void)
{
int a=1;
int b=2;
assert(a==b);
return 0;
}
Output:
Code:
clang:
a.out: assert.c:11: int main(void): Assertion `a==b' failed.
Aborted (core dumped)
gcc:
a.out: assert.c:11: main: Assertion `a==b' failed.
Aborted (core dumped)
I want such addition:
Code:
a is 1
b is 2
or:
(1==2) failed
Considering CUnit testing library:
Code:
// Detailed CUnit asserts
// http://cunit.sourceforge.net/
#include <stdlib.h>
#include <stdio.h>
#include <stddef.h>
#include <stdnoreturn.h>
#include <CUnit/CUnit.h>
#include <CUnit/Basic.h>
#include <CUnit/Console.h>
int maxi(int i1, int i2)
{
return (i1 > i2) ? -i1 : -i2; // wrong
}
void test_maxi(void)
{
CU_ASSERT_EQUAL(maxi(0,2) , 2);
CU_ASSERT_EQUAL(maxi(-1,-2) , -1);
CU_ASSERT_EQUAL(maxi(2,2) , 2);
}
int main(void)
{
CU_initialize_registry();
CU_pSuite suite1 = CU_add_suite("suite1", NULL, NULL);
CU_add_test(suite1, "test_maxi", test_maxi);
CU_basic_set_mode(CU_BRM_VERBOSE);
//CU_automated_run_tests();
CU_basic_run_tests();
CU_cleanup_registry();
return 0;
}
Output:
Code:
CUnit - A unit testing framework for C - Version 2.1-3
http://cunit.sourceforge.net/
Suite: suite1
Test: test_maxi ...FAILED
1. cu_assert.c:21 - CU_ASSERT_EQUAL(maxi(0,2),2)
2. cu_assert.c:22 - CU_ASSERT_EQUAL(maxi(-1,-2),-1)
3. cu_assert.c:23 - CU_ASSERT_EQUAL(maxi(2,2),2)
Run Summary: Type Total Ran Passed Failed Inactive
suites 1 1 n/a 0 0
tests 1 1 0 1 0
asserts 3 3 0 3 n/a
Elapsed time = 0.000 seconds
I want computed values of maxi too. But they are not given in the above output. Some other testing libraries do it.