Add global parameters.
[deliverable/binutils-gdb.git] / gold / testsuite / test.cc
CommitLineData
5a6f7e2d
ILT
1// test.cc -- simplistic test framework for gold.
2
3#include "gold.h"
4
5#include <cstdio>
6
7#include "test.h"
8
9namespace gold_testsuite
10{
11
12// Test_framework methods.
13
14// The current test being run.
15
16Test_report* Test_framework::current_report;
17
18// Run a test.
19
20void
21Test_framework::run(const char *name, bool (*pfn)(Test_report*))
22{
23 this->testname_ = name;
24 this->current_fail_ = false;
25
26 Test_report tr(this);
27 Test_framework::current_report = &tr;
28
29 if ((*pfn)(&tr) && !this->current_fail_)
30 {
31 printf("PASS: %s\n", name);
32 ++this->passes_;
33 }
34 else
35 {
36 printf("FAIL: %s\n", name);
37 ++this->failures_;
38 }
39
40 Test_framework::current_report = NULL;
41 this->testname_ = NULL;
42}
43
44// Let a test report an error.
45
46void
47Test_framework::error(const char* message)
48{
49 printf("ERROR: %s: %s\n", this->testname_, message);
50 this->fail();
51}
52
53// Register_test methods.
54
55// Linked list of all registered tests.
56
57Register_test* Register_test::all_tests;
58
59// Register a test.
60
61Register_test::Register_test(const char* name, bool (*pfn)(Test_report*))
62 : name_(name), pfn_(pfn), next_(Register_test::all_tests)
63{
64 Register_test::all_tests = this;
65}
66
67// Run all registered tests.
68
69void
70Register_test::run_tests(Test_framework* tf)
71{
72 for (Register_test* p = Register_test::all_tests;
73 p != NULL;
74 p = p->next_)
75 tf->run(p->name_, p->pfn_);
76}
77
78} // End namespace gold_testsuite.
This page took 0.049054 seconds and 4 git commands to generate.