1 // test.cc -- simplistic test framework for gold.
9 namespace gold_testsuite
12 // Test_framework methods.
14 // The current test being run.
16 Test_report
* Test_framework::current_report
;
21 Test_framework::run(const char *name
, bool (*pfn
)(Test_report
*))
23 this->testname_
= name
;
24 this->current_fail_
= false;
27 Test_framework::current_report
= &tr
;
29 if ((*pfn
)(&tr
) && !this->current_fail_
)
31 printf("PASS: %s\n", name
);
36 printf("FAIL: %s\n", name
);
40 Test_framework::current_report
= NULL
;
41 this->testname_
= NULL
;
44 // Let a test report an error.
47 Test_framework::error(const char* message
)
49 printf("ERROR: %s: %s\n", this->testname_
, message
);
53 // Register_test methods.
55 // Linked list of all registered tests.
57 Register_test
* Register_test::all_tests
;
61 Register_test::Register_test(const char* name
, bool (*pfn
)(Test_report
*))
62 : name_(name
), pfn_(pfn
), next_(Register_test::all_tests
)
64 Register_test::all_tests
= this;
67 // Run all registered tests.
70 Register_test::run_tests(Test_framework
* tf
)
72 for (Register_test
* p
= Register_test::all_tests
;
75 tf
->run(p
->name_
, p
->pfn_
);
78 } // End namespace gold_testsuite.