1 // test.cc -- simplistic test framework for gold.
3 // Copyright 2006, 2007 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;
64 // Let a test report an error.
67 Test_framework::error(const char* message)
69 printf("ERROR: %s: %s\n", this->testname_, message);
73 // Register_test methods.
75 // Linked list of all registered tests.
77 Register_test* Register_test::all_tests;
81 Register_test::Register_test(const char* name, bool (*pfn)(Test_report*))
82 : name_(name), pfn_(pfn), next_(Register_test::all_tests)
84 Register_test::all_tests = this;
87 // Run all registered tests.
90 Register_test::run_tests(Test_framework* tf)
92 for (Register_test* p = Register_test::all_tests;
95 tf->run(p->name_, p->pfn_);
98 } // End namespace gold_testsuite.