manual copyright year range of various GDB files to add 2023
[binutils-gdb.git] / gold / testsuite / test.cc
blob1da3c42741b55e0a2d0ca2f9dca8ec0530fb4a99
1 // test.cc -- simplistic test framework for gold.
3 // Copyright (C) 2006-2023 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.
23 #include "gold.h"
25 #include <cstdio>
27 #include "test.h"
29 namespace gold_testsuite
32 // Test_framework methods.
34 // The current test being run.
36 Test_report* Test_framework::current_report;
38 // Run a test.
40 void
41 Test_framework::run(const char *name, bool (*pfn)(Test_report*))
43 this->testname_ = name;
44 this->current_fail_ = false;
46 Test_report tr(this);
47 Test_framework::current_report = &tr;
49 if ((*pfn)(&tr) && !this->current_fail_)
51 printf("PASS: %s\n", name);
52 ++this->passes_;
54 else
56 printf("FAIL: %s\n", name);
57 ++this->failures_;
60 Test_framework::current_report = NULL;
61 this->testname_ = NULL;
64 // Report a failure.
66 void
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.
75 void
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;
88 // Register a test.
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.
98 void
99 Register_test::run_tests(Test_framework* tf)
101 for (Register_test* p = Register_test::all_tests;
102 p != NULL;
103 p = p->next_)
104 tf->run(p->name_, p->pfn_);
107 } // End namespace gold_testsuite.