unittests

Module contains helper functions for unit tests.

License:
Boost License 1.0.

Authors:
Jonathan M Davis

Copyright Jonathan M Davis 2010. Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at ) http:
//www.boost.org/LICENSE_1_0.txt



struct LineInfo;
Allows file and line info to be passed to unittesting functions which have variadic arguments and thus can't use default arguments for file and line info. That way, the line with the test is the line where the error is reported rather than a line inside the unittesting function.

void assertExcThrown(E : Throwable, alias func, T...)(in LineInfo li, T args);
Asserts that the given function and arguments throws the given exception type. That exception is caught and does not escape assertExcThrown(). However, any other exceptions will escape. assertExcThrown() also works with Errors - including AssertError.

Params:
E The exception to test for.
func The function to be tested.
li LineInfo() is passed as the first argument so that the line where assertExcThrown() is called will be the line reported for test failures rather than a line internal to assertExcThrown().
args Arguments (if any) to be passed to the function being tested.

Examples:
    assertExcThrown!(Exception, myfunc)(LineInfo(), param1, param2);


void assertExcThrown(string msg, E : Throwable, alias func, T...)(in LineInfo li, T args);
Asserts that the given function and arguments throws the given exception type. That exception is caught and does not escape assertExcThrown(). However, any other exceptions will escape. assertExcThrown() also works with Errors - including AssertError.

Params:
msg Message to be printed when test fails.
E The exception to test for.
func The function to be tested.
li LineInfo() is passed as the first argument so that the line where assertExcThrown() is called will be the line reported for test failures rather than a line internal to assertExcThrown().
args Arguments (if any) to be passed to the function being tested.

Examples:
    assertExcThrown!("My test failed!", Exception, myfunc)(LineInfo(), param1, param2);


void assertExcNotThrown(E : Throwable, alias func, T...)(in LineInfo li, T args);
Asserts that the given function and arguments does not throw the given exception type. If that exception is thrown, it is caught and does not escape assertExcNotThrown(). Instead, the AssertError indicating test failure is thrown. Any other exceptions will escape assertExcNotThrown(). assertExcNotThrown() also works with Errors - including AssertError.

Params:
E The exception to test for.
func The function to be tested.
li LineInfo() is passed as the first argument so that the line where assertExcNotThrown() is called will be the line reported for test failures rather than a line internal to assertExcNotThrown().
args Arguments (if any) to be passed to the function being tested.

Examples:
    assertExcNotThrown!(Exception, myfunc)(LineInfo(), param1, param2);


void assertExcNotThrown(string msg, E : Throwable, alias func, T...)(in LineInfo li, T args);
Asserts that the given function and arguments does not throw the given exception type. If that exception is thrown, it is caught and does not escape assertExcNotThrown(). Instead, the AssertError indicating test failure is thrown. Any other exceptions will escape assertExcNotThrown(). assertExcNotThrown() also works with Errors - including AssertError.

Params:
msg Message to be printed when test fails.
E The exception to test for.
func The function to be tested.
li LineInfo() is passed as the first argument so that the line where assertExcNotThrown() is called will be the line reported for test failures rather than a line internal to assertExcNotThrown().
args Arguments (if any) to be passed to the function being tested.

Examples:
    assertExcNotThrown!("My test failed!", Exception, myfunc)(LineInfo(), param1, param2);


void assertEqual(T, U)(in T actual, in U expected, string msg = null, string file = __FILE__, size_t line = __LINE__);
Asserts that two values are equal according to ==. This function is useful over simply asserting that they're equal because it gives better error messages on test failure.

The file and line number parameters can be set, but they're really there so that the line number in the error message on test failure includes the file and line number where assertEqual() was called rather than the file and line number inside of assertEqual().

Params:
actual The value to test.
expected The value that actual is supposed to be equal to.
msg Optional message to output on test failure.
file The file to list on test failure.
line The line number to list on test failure.

Examples:
    assertEqual(myfunc(), 7);
    assertEqual(myfunc(), 7, "My test failed!");


void assertNotEqual(T, U)(in T actual, in U expected, string msg = null, string file = __FILE__, size_t line = __LINE__);
Asserts that two values are not equal according to ==. This function is useful over simply asserting that they're unequal because it gives better error messages on test failure.

The file and line number parameters can be set, but they're really there so that the line number in the error message on test failure includes the file and line number where assertEqual() was called rather than the file and line number inside of assertEqual().

Params:
actual The value to test.
expected The value that actual is not supposed to be equal to.
msg Optional message to output on test failure.
file The file to list on test failure.
line The line number to list on test failure.

Examples:
    assertNotEqual(myfunc(), 7);
    assertNotEqual(myfunc(), 7, "My test failed!");


void assertOpCmp(string op, T, U)(in T lhs, in U rhs, string msg = null, string file = __FILE__, size_t line = __LINE__);
Asserts that a value is equal, less than, or greater than another according to opCmp(). This function is useful over simply asserting on the results of opCmp() because it gives better error messages on test failure.

The file and line number parameters can be set, but they're really there so that the line number in the error message on test failure includes the file and line number where assertOpCmp() was called rather than the file and line number inside of assertOpCmp().

Params:
op The operation from opCmp() to test. Must be "==", "<", or ">".
rhs The value which will have opCmp() called on it.
lhs The value passed to opCmp().
msg Optional message to output on test failure.
file The file to list on test failure.
line The line number to list on test failure.

Examples:
    assertEqual!("<")(myfunc(), 7);
    assertEqual!("==")(myfunc(), 7);
    assertEqual!(">")(myfunc(), 7);
    assertEqual!("<")(myfunc(), 7, "My test failed!");
    assertEqual!(">")(myfunc(), 7, "My test failed!");
    assertEqual!("==")(myfunc(), 7, "My test failed!");



Page generated by Ddoc. Copyright Jonathan M Davis 2010