MAINTAINERS (SH): Remove my entry.
[binutils.git] / gold / testsuite / test.cc
blob37a4ada9ab0621f603a4b8afc166b91eb28dd1c1
1 // test.cc -- simplistic test framework for gold.
3 #include "gold.h"
5 #include <cstdio>
7 #include "test.h"
9 namespace gold_testsuite
12 // Test_framework methods.
14 // The current test being run.
16 Test_report* Test_framework::current_report;
18 // Run a test.
20 void
21 Test_framework::run(const char *name, bool (*pfn)(Test_report*))
23 this->testname_ = name;
24 this->current_fail_ = false;
26 Test_report tr(this);
27 Test_framework::current_report = &tr;
29 if ((*pfn)(&tr) && !this->current_fail_)
31 printf("PASS: %s\n", name);
32 ++this->passes_;
34 else
36 printf("FAIL: %s\n", name);
37 ++this->failures_;
40 Test_framework::current_report = NULL;
41 this->testname_ = NULL;
44 // Let a test report an error.
46 void
47 Test_framework::error(const char* message)
49 printf("ERROR: %s: %s\n", this->testname_, message);
50 this->fail();
53 // Register_test methods.
55 // Linked list of all registered tests.
57 Register_test* Register_test::all_tests;
59 // Register a test.
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.
69 void
70 Register_test::run_tests(Test_framework* tf)
72 for (Register_test* p = Register_test::all_tests;
73 p != NULL;
74 p = p->next_)
75 tf->run(p->name_, p->pfn_);
78 } // End namespace gold_testsuite.