Browse Source

[test] Include failing code within failed test result output

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 10 years ago
parent
commit
1312c467ee
2 changed files with 9 additions and 6 deletions
  1. 4
    3
      src/include/ipxe/test.h
  2. 5
    3
      src/tests/test.c

+ 4
- 3
src/include/ipxe/test.h View File

31
 /** Declare a self-test */
31
 /** Declare a self-test */
32
 #define __self_test __table_entry ( SELF_TESTS, 01 )
32
 #define __self_test __table_entry ( SELF_TESTS, 01 )
33
 
33
 
34
-extern void test_ok ( int success, const char *file, unsigned int line );
34
+extern void test_ok ( int success, const char *file, unsigned int line,
35
+		      const char *test );
35
 
36
 
36
 /**
37
 /**
37
  * Report test result
38
  * Report test result
38
  *
39
  *
39
  * @v success		Test succeeded
40
  * @v success		Test succeeded
40
  */
41
  */
41
-#define ok( success ) do {				\
42
-	test_ok ( (success), __FILE__, __LINE__ );	\
42
+#define ok( success ) do {					\
43
+	test_ok ( (success), __FILE__, __LINE__, #success );	\
43
 	} while ( 0 )
44
 	} while ( 0 )
44
 
45
 
45
 #endif /* _IPXE_TEST_H */
46
 #endif /* _IPXE_TEST_H */

+ 5
- 3
src/tests/test.c View File

45
  * @v success		Test succeeded
45
  * @v success		Test succeeded
46
  * @v file		Test code file
46
  * @v file		Test code file
47
  * @v line		Test code line
47
  * @v line		Test code line
48
+ * @v test		Test code
48
  */
49
  */
49
-void test_ok ( int success, const char *file, unsigned int line ) {
50
+void test_ok ( int success, const char *file, unsigned int line,
51
+	       const char *test ) {
50
 
52
 
51
 	/* Sanity check */
53
 	/* Sanity check */
52
 	assert ( current_tests != NULL );
54
 	assert ( current_tests != NULL );
57
 	/* Report failure if applicable */
59
 	/* Report failure if applicable */
58
 	if ( ! success ) {
60
 	if ( ! success ) {
59
 		current_tests->failures++;
61
 		current_tests->failures++;
60
-		printf ( "FAILURE: \"%s\" test failed at %s line %d\n",
61
-			 current_tests->name, file, line );
62
+		printf ( "FAILURE: \"%s\" test failed at %s line %d: ( %s )\n",
63
+			 current_tests->name, file, line, test );
62
 	}
64
 	}
63
 }
65
 }
64
 
66
 

Loading…
Cancel
Save