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;
102 template <
typename Statistics>
103 void runGlobalMemoryReport(Statistics stats,
bool reportFailure =
true)
105 TestReport::MemoryStatistics memStats;
106 memStats.numAllocate = stats.numAllocate;
107 memStats.numReallocate = stats.numReallocate;
108 memStats.numRelease = stats.numRelease;
109 internalRunGlobalMemoryReport(memStats, reportFailure);
113 struct MemoryStatistics
115 size_t numAllocate = 0;
116 size_t numReallocate = 0;
117 size_t numRelease = 0;
121 void internalRunGlobalMemoryReport(MemoryStatistics stats,
bool reportFailure);
123 [[nodiscard]]
bool isSectionEnabled(StringSpan sectionName)
const;
125 void testCaseFinished(TestCase& testCase);
126 void printSectionResult(TestCase& testCase);
128 friend struct TestCase;
129 uint32_t numTestsSucceeded = 0;
130 uint32_t numTestsFailed = 0;
131 uint16_t portOffset = 0;
132 StringSpan currentSection;
133 StringSpan firstFailedTest;
134 StringSpan testToRun;
135 StringSpan sectionToRun;
136 bool startupFailure =
false;
157 bool recordExpectation(StringSpan expression,
bool status, StringSpan detailedError = StringSpan());
180 const StringSpan testName;
182 uint32_t numTestsSucceeded;
183 uint32_t numTestsFailed;
184 uint32_t numSectionTestsFailed;
190#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:145
bool recordExpectation(StringSpan expression, Result status)
Records an expectation for a given expression.
Execute
Definition Testing.h:166
@ 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:177
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 isTestEnabled(StringSpan testName) const
Returns true when testName is enabled by the current test selection.
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