Kaynağa Gözat

[test] Include failing code within failed test result output

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 11 yıl önce
ebeveyn
işleme
1312c467ee
2 değiştirilmiş dosya ile 9 ekleme ve 6 silme
  1. 4
    3
      src/include/ipxe/test.h
  2. 5
    3
      src/tests/test.c

+ 4
- 3
src/include/ipxe/test.h Dosyayı Görüntüle

@@ -31,15 +31,16 @@ struct self_test {
31 31
 /** Declare a self-test */
32 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 38
  * Report test result
38 39
  *
39 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 44
 	} while ( 0 )
44 45
 
45 46
 #endif /* _IPXE_TEST_H */

+ 5
- 3
src/tests/test.c Dosyayı Görüntüle

@@ -45,8 +45,10 @@ static struct self_test *current_tests;
45 45
  * @v success		Test succeeded
46 46
  * @v file		Test code file
47 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 53
 	/* Sanity check */
52 54
 	assert ( current_tests != NULL );
@@ -57,8 +59,8 @@ void test_ok ( int success, const char *file, unsigned int line ) {
57 59
 	/* Report failure if applicable */
58 60
 	if ( ! success ) {
59 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…
İptal
Kaydet