git » libfiu » commit f41f906

tests: Better assertions in the C tests

author Alberto Bertogli
2017-09-04 23:16:53 UTC
committer Alberto Bertogli
2017-09-04 23:22:57 UTC
parent 8dc3258bee8ebc5c5c9471b2df78798eef0aeebb

tests: Better assertions in the C tests

When the C tests' asserts fail, it's not possible to know which of the
many calls was the problematic one.

This patch changes the way the conditions are asserted so the line
numbers printed are meaningful and useful in diagnosing the problem.

tests/test-enable_stack.c +8 -11
tests/test-enable_stack_by_name.c +8 -11

diff --git a/tests/test-enable_stack.c b/tests/test-enable_stack.c
index e3e94f5..a5d2c54 100644
--- a/tests/test-enable_stack.c
+++ b/tests/test-enable_stack.c
@@ -6,10 +6,8 @@
 #include <fiu.h>
 #include <fiu-control.h>
 
-void func1(int should_fail)
+int func1()
 {
-	int failed;
-
 	/*
 	int nptrs;
 	void *buffer[100];
@@ -17,13 +15,12 @@ void func1(int should_fail)
 	backtrace_symbols_fd(buffer, nptrs, 1);
 	*/
 
-	failed = fiu_fail("fp-1") != 0;
-	assert(failed == should_fail);
+	return fiu_fail("fp-1") != 0;
 }
 
-void func2(int should_fail)
+int func2()
 {
-	func1(should_fail);
+	return func1();
 }
 
 
@@ -38,13 +35,13 @@ int main(void)
 		return 0;
 	}
 
-	func1(0);
-	func2(1);
+	assert(func1() == 0);
+	assert(func2() == 1);
 
 	fiu_disable("fp-1");
 
-	func1(0);
-	func2(0);
+	assert(func1() == 0);
+	assert(func2() == 0);
 
 	return 0;
 }
diff --git a/tests/test-enable_stack_by_name.c b/tests/test-enable_stack_by_name.c
index 0968aba..d769728 100644
--- a/tests/test-enable_stack_by_name.c
+++ b/tests/test-enable_stack_by_name.c
@@ -6,10 +6,8 @@
 #include <fiu.h>
 #include <fiu-control.h>
 
-void func1(int should_fail)
+int func1()
 {
-	int failed;
-
 	/*
 	int nptrs;
 	void *buffer[100];
@@ -17,13 +15,12 @@ void func1(int should_fail)
 	backtrace_symbols_fd(buffer, nptrs, 1);
 	*/
 
-	failed = fiu_fail("fp-1") != 0;
-	assert(failed == should_fail);
+	return fiu_fail("fp-1") != 0;
 }
 
-void func2(int should_fail)
+int func2()
 {
-	func1(should_fail);
+	return func1();
 }
 
 
@@ -39,13 +36,13 @@ int main(void)
 		return 0;
 	}
 
-	func1(0);
-	func2(1);
+	assert(func1() == 0);
+	assert(func2() == 1);
 
 	fiu_disable("fp-1");
 
-	func1(0);
-	func2(0);
+	assert(func1() == 0);
+	assert(func2() == 0);
 
 	return 0;
 }