1 // test.cc -- simplistic test framework for gold.
3 // Copyright 2006, 2007, 2008 Free Software Foundation, Inc.
4 // Written by Ian Lance Taylor <iant@google.com>.
6 // This file is part of gold.
8 // This program is free software; you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation; either version 3 of the License, or
11 // (at your option) any later version.
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU General Public License for more details.
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the Free Software
20 // Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
21 // MA 02110-1301, USA.
29 namespace gold_testsuite
32 // Test_framework methods.
34 // The current test being run.
36 Test_report
* Test_framework::current_report
;
41 Test_framework::run(const char *name
, bool (*pfn
)(Test_report
*))
43 this->testname_
= name
;
44 this->current_fail_
= false;
47 Test_framework::current_report
= &tr
;
49 if ((*pfn
)(&tr
) && !this->current_fail_
)
51 printf("PASS: %s\n", name
);
56 printf("FAIL: %s\n", name
);
60 Test_framework::current_report
= NULL
;
61 this->testname_
= NULL
;
67 Test_framework::fail(const char* filename
, int lineno
)
69 printf("FAIL: %s: %s: %d\n", this->testname_
, filename
, lineno
);
70 this->current_fail_
= true;
73 // Let a test report an error.
76 Test_framework::error(const char* message
)
78 printf("ERROR: %s: %s\n", this->testname_
, message
);
79 this->current_fail_
= true;
82 // Register_test methods.
84 // Linked list of all registered tests.
86 Register_test
* Register_test::all_tests
;
90 Register_test::Register_test(const char* name
, bool (*pfn
)(Test_report
*))
91 : name_(name
), pfn_(pfn
), next_(Register_test::all_tests
)
93 Register_test::all_tests
= this;
96 // Run all registered tests.
99 Register_test::run_tests(Test_framework
* tf
)
101 for (Register_test
* p
= Register_test::all_tests
;
104 tf
->run(p
->name_
, p
->pfn_
);
107 } // End namespace gold_testsuite.