4#include "../Common/CompilerMacrosExport.h"
5#ifndef SC_EXPORT_LIBRARY_TESTING
6#define SC_EXPORT_LIBRARY_TESTING 0
8#define SC_TESTING_EXPORT SC_COMPILER_LIBRARY_EXPORT(SC_EXPORT_LIBRARY_TESTING)
10#include "../Common/Assert.h"
11#include "../Common/IGrowableBufferStringPath.h"
12#include "../Common/Result.h"
13#include "../Common/StringSpan.h"
17SC_DECLARE_ASSERT_PROVIDER(TestingAssert, SC_TESTING_EXPORT);
19#define SC_TESTING_ASSERT_RELEASE(e) SC_ASSERT_PROVIDER_RELEASE(SC::TestingAssert, e)
20#define SC_TESTING_ASSERT_DEBUG(e) SC_ASSERT_PROVIDER_DEBUG(SC::TestingAssert, e)
21#define SC_TESTING_TRUST_RESULT(expression) SC_TESTING_ASSERT_RELEASE(expression)
40 virtual void flush() = 0;
41 virtual void printLine(StringSpan text) = 0;
42 virtual void print(StringSpan text) = 0;
43 virtual void print(StringSpan text, StringSpan p0) = 0;
44 virtual void print(StringSpan text, StringSpan p0, StringSpan p1) = 0;
45 virtual void print(StringSpan text,
size_t p0) = 0;
46 virtual void print(StringSpan text,
size_t p0,
size_t p1) = 0;
49 template <
typename ConsoleType>
53 Output(ConsoleType& console) : console(console) {}
55 virtual void flush()
override { console.flush(); }
56 virtual void printLine(StringSpan text)
override { console.printLine(text); }
57 virtual void print(StringSpan text)
override { console.print(text); }
58 virtual void print(StringSpan text, StringSpan p0)
override { console.print(text, p0); }
59 virtual void print(StringSpan text, StringSpan p0, StringSpan p1)
override { console.print(text, p0, p1); }
60 virtual void print(StringSpan text,
size_t p0)
override { console.print(text, p0); }
61 virtual void print(StringSpan text,
size_t p0,
size_t p1)
override { console.print(text, p0, p1); }
92 [[nodiscard]] uint16_t
mapPort(uint16_t basePort)
const;
98 template <
typename Statistics>
99 void runGlobalMemoryReport(Statistics stats,
bool reportFailure =
true)
101 TestReport::MemoryStatistics memStats;
102 memStats.numAllocate = stats.numAllocate;
103 memStats.numReallocate = stats.numReallocate;
104 memStats.numRelease = stats.numRelease;
105 internalRunGlobalMemoryReport(memStats, reportFailure);
109 struct MemoryStatistics
111 size_t numAllocate = 0;
112 size_t numReallocate = 0;
113 size_t numRelease = 0;
117 void internalRunGlobalMemoryReport(MemoryStatistics stats,
bool reportFailure);
119 [[nodiscard]]
bool isTestEnabled(StringSpan testName)
const;
120 [[nodiscard]]
bool isSectionEnabled(StringSpan sectionName)
const;
122 void testCaseFinished(TestCase& testCase);
123 void printSectionResult(TestCase& testCase);
125 friend struct TestCase;
126 uint32_t numTestsSucceeded = 0;
127 uint32_t numTestsFailed = 0;
128 uint16_t portOffset = 0;
129 StringSpan currentSection;
130 StringSpan firstFailedTest;
131 StringSpan testToRun;
132 StringSpan sectionToRun;
133 bool startupFailure =
false;
154 bool recordExpectation(StringSpan expression,
bool status, StringSpan detailedError = StringSpan());
177 const StringSpan testName;
179 uint32_t numTestsSucceeded;
180 uint32_t numTestsFailed;
181 uint32_t numSectionTestsFailed;
187#define SC_TEST_EXPECT(e) recordExpectation(StringSpan(#e), (e)) ? (void)0 : (TestCase::report.debugBreakOnFailedTest ? SC_COMPILER_DEBUG_BREAK : (void)0)
A test case that can be split into multiple sections.
Definition Testing.h:142
bool recordExpectation(StringSpan expression, Result status)
Records an expectation for a given expression.
Execute
Definition Testing.h:163
@ OnlyExplicit
Test is executed only if explicitly requested with –test-section.
@ Default
Test is executed if all tests are enabled or if this specific one matches –test-section.
TestCase(TestReport &report, StringSpan testName)
Adds this TestCase to a TestReport with a name.
TestReport & report
The TestReport object passed in the constructor.
Definition Testing.h:174
bool recordExpectation(StringSpan expression, bool status, StringSpan detailedError=StringSpan())
Records an expectation for a given expression.
bool test_section(StringSpan sectionName, Execute execution=Execute::Default)
Starts a new test section.
Collects multiple TestCase and reports their results.
Definition Testing.h:35
StringPath applicationRootDirectory
Path to application (on macOS is different from executable path)
Definition Testing.h:67
bool hasStartupFailure() const
Returns true when startup path resolution failed before tests ran.
Definition Testing.h:87
StringPath executableFile
Path to current executable.
Definition Testing.h:66
uint16_t mapPort(uint16_t basePort) const
Applies an optional port offset configured through command line or environment.
int getTestReturnCode() const
Gets return code for this process.
bool isTestExplicitlySelected(StringSpan testName) const
Returns true only when --test explicitly matches testName.
bool quietMode
If true will not print recaps at start or end of the test.
Definition Testing.h:72
bool abortOnFirstFailedTest
If true will abort after first failed test.
Definition Testing.h:70
StringPath libraryRootDirectory
Path to sources directory for library.
Definition Testing.h:65
bool debugBreakOnFailedTest
If true will issue a debugger halt when a test fails.
Definition Testing.h:71
TestReport(IOutput &console, int argc, const char **argv)
Build from a console and executable arguments.
bool runAllTests
If true will run optional/slow tests that are skipped by default.
Definition Testing.h:73