ocean.core.Test

Defines base exception class thrown by test checks and set of helper functions to define actual test cases. These helpers are supposed to be used in unittest blocks instead of asserts.

There were three reasons why dedicated function got introduced:

1) Bultin assert throws an Error, which makes implementing test runner that doesn't stop on first failure illegal by language specification. 2) These test functions can provide more informational formatting compared to plain assert, for example test!("==")(a, b) will print a and b values on failure. 3) Having dedicated exception type for test failures makes possible to distinguish in test runners between contract failures and test failures.

Members

Classes

NamedTest
class NamedTest

Utility class useful in scenarios where actual testing code is reused in different contexts and file+line information is not enough to uniquely identify failed case.

TestException
class TestException

Exception class to be thrown from unot tests blocks.

Functions

test
void test(T ok, cstring msg, istring file, int line)
void test(T1 a, T2 b, istring file, int line)

Effectively partial specialization alias: test = enforceImpl!(TestException)

testNoAlloc
void testNoAlloc(void expr, istring file, int line)

Verifies that call to expr does not allocate GC memory

testThrown
void testThrown(void expr, bool strict, istring file, int line)

Verifies that given expression throws exception instance of expected type.

Meta

License

Boost Software License Version 1.0. See LICENSE_BOOST.txt for details. Alternatively, this file may be distributed under the terms of the Tango 3-Clause BSD License (see LICENSE_BSD.txt for details).