Sane C++ Libraries
C++ Platform Abstraction Libraries
Loading...
Searching...
No Matches
Testing

🟨 Simple testing framework used by all of the other libraries

SaneCppTesting.h is a very simple test framework that allows splitting tests in sections and record successful/failed expectations.

Dependencies

Dependency Graph

Features

Class Description
SC::TestCase A test case that can be split into multiple sections.
SC::TestReport Collects multiple TestCase and reports their results.

Status

🟨 MVP
Testing library is minimal but it's useful as is for now.

Description

Testing integrates with the SC::Result object that is part of Foundation library. So far it doesn't support test discovery and all tests must be manually invoked in the main test file.

SC::TestCase

A test case that can be split into multiple sections.

To create a test case derive from SC::TestCase and run tests in the constructor

Example:

namespace SC
{
struct ConsoleTest;
}
struct SC::ConsoleTest : public SC::TestCase
{
ConsoleTest(SC::TestReport& report) : TestCase(report, "ConsoleTest")
{
using namespace SC;
// Totally optional conversion buffer for UTF conversions on Windows (default is 256 bytes)
char optionalConversionBuffer[512];
Console console(optionalConversionBuffer);
if (test_section("print"))
{
String str = StringView("Test Test\n");
console.print(str.view());
console.print({});
SC_TEST_EXPECT(console.print("test {}", 1));
SC_TEST_EXPECT(not console.print("test {}"_u16, 1));
SC_TEST_EXPECT(console.print("test {}", StringSpan("1")));
SC_TEST_EXPECT(not console.print("test {}"_u16, StringSpan("1")));
}
}
};
namespace SC
{
void runConsoleTest(SC::TestReport& report) { ConsoleTest test(report); }
} // namespace SC
An read-only view over a string (to avoid including Strings library when parsing is not needed).
Definition StringSpan.h:37

SC::TestReport

Collects multiple TestCase and reports their results.

This is passed as argument to SC::TestCase derived classes, and contains handle to globals like a console, paths to the library and application root, path to executable etc.

Roadmap

🟩 Usable

  • Test discovery

🟦 Complete Features:

  • IDE Integration

💡 Unplanned Features:

  • Template tests

Statistics

Type Lines Of Code Comments Sum
Headers 130 93 223
Sources 240 23 263
Sum 370 116 486