Testing

Unit Testing

Macros to facilitate unit testing.

Note

This file is part of Empirical, https://github.com/devosoft/Empirical

Copyright

Copyright (C) Michigan State University, MIT Software license; see doc/LICENSE.md

Date

2015-2019

Note

Status: RESURGENT (Was depricated; now back to ALPHA)

Defines

EMP_TEST_MACRO(MACRO, EXP_RESULT)

Input: A macro call and a strings indicating the expected result. Output: Code that tests of the macro result matches the expected results, and optionally print it (if in verbose mode or if the macro fails to produce the expected result.)

EMP_TEST_VALUE(VALUE, EXP_RESULT)

Take in an expression and a string representing the expected result; verify that the stringifyied result is the expected string AND print this info if -v flag is set. Input: An expression and an expected evaluation. Output: Code to evaluate the expression and optionally print it (if either in verbose mode or the macro does not produce the expected result).

EMP_REQUIRE(VALUE)
EMP_TEST_APPROX(...)
EMP_TEST_APPROX_impl(VALUE, EXP_RESULT, THRESHOLD, ...)
emp_test_main()

Functions

void SetupUnitTestArgs(emp::vector<std::string> args)
int ProcessUnitTestResults()
namespace emp

If we are in emscripten, make sure to include the header.

Functions

UnitTestOutput &GetUnitTestOutput()
void ResolveUnitTest(bool pass, const std::string &test_input, const std::string &result, const std::string &exp_result, const std::string &filename, size_t line_num, bool is_require = false)
struct UnitTestOutput

Public Types

enum Mode

Values:

enumerator SILENT
enumerator NORMAL
enumerator VERBOSE

Public Members

UnitTestOutput::Mode verbose = UnitTestOutput::Mode::NORMAL
size_t num_tests = 0
size_t errors = 0
bool abort = false