libgrading
A simple library for grading C and C++ assignments.
|
Container for all libgrading names. More...
Classes | |
class | SharedMemory |
A representation of a shared memory object. More... | |
Enumerations | |
enum | TestResult : char { TestResult::Pass, TestResult::Fail, TestResult::Segfault, TestResult::Timeout, TestResult::OtherError } |
The result of running one test within a separate process. More... | |
Functions | |
CheckResult | operator&& (CheckResult &&, CheckResult &&) |
Combine the results of two checks using a product (AND): both must pass. More... | |
CheckResult | operator&& (CheckResult &&, CheckResult &) |
L-value version of above. More... | |
CheckResult | operator|| (CheckResult &&, CheckResult &&) |
Combine the results of two checks using a sum (OR): at least one must pass. More... | |
CheckResult | operator|| (CheckResult &&, CheckResult &) |
L-value version of above. More... | |
CheckResult | Check (bool, std::string description) |
Check an arbitrary condition, failing the test if false. More... | |
CheckResult | CheckInt (int expected, int actual) |
Check that two integers are equal, failing the test if they are not. More... | |
CheckResult | CheckFloat (double exp, double act, double tolerance=0.000001) |
Check that two floating-point numbers are equal within some tolerance. More... | |
CheckResult | CheckString (std::string expected, std::string actual, size_t maxEditDistance=0) |
Check that two strings are (approximately) equal. More... | |
std::ostream & | operator<< (std::ostream &, TestResult) |
Output a human-readable representation of a TestResult. More... | |
std::unique_ptr< SharedMemory > | MapSharedData (size_t size) |
Map data into the address space that can be shared with other processes. More... | |
TestResult | RunTest (std::function< TestResult()> test, std::string name="<unnamed test>", time_t timeout=0, std::ostream &errorStream=std::cerr) |
Run a test closure in a separate process, capturing segmentation faults and other errors that lead to termination. More... | |
template<class T > | |
TestResult | RunTest (std::function< TestResult(T &)> test, T &output, std::string name="<unnamed test>", time_t timeout=0, std::ostream &errorStream=std::cerr) |
Run a test with output but no explicit input. More... | |
template<class Expectation , class Output > | |
TestResult | RunTest (std::function< TestResult(const Expectation &, Output &)> t, const Expectation &expect, Output &output, std::string name="<unnamed test>", time_t timeout=0, std::ostream &errorStream=std::cerr) |
Run a test with input and output. More... | |
Container for all libgrading names.
|
strong |
The result of running one test within a separate process.
Enumerator | |
---|---|
Pass |
the test succeeded |
Fail |
the test failed |
Segfault |
the test caused a segmentation fault |
Timeout |
the test took too long to run |
OtherError |
the test terminated for another reason |
Definition at line 113 of file libgrading.h.
CheckResult grading::Check | ( | bool | condition, |
std::string | description | ||
) |
Check an arbitrary condition, failing the test if false.
Definition at line 156 of file checks.cpp.
CheckResult grading::CheckFloat | ( | double | exp, |
double | act, | ||
double | tolerance = 0.000001 |
||
) |
Check that two floating-point numbers are equal within some tolerance.
Definition at line 172 of file checks.cpp.
CheckResult grading::CheckInt | ( | int | expected, |
int | actual | ||
) |
Check that two integers are equal, failing the test if they are not.
Definition at line 164 of file checks.cpp.
CheckResult grading::CheckString | ( | std::string | expected, |
std::string | actual, | ||
size_t | maxEditDistance = 0 |
||
) |
Check that two strings are (approximately) equal.
expected | the string we expected |
actual | the string we got |
maxEditDistance | how fuzzy the match can be: the maximum Levenshtein distance between them |
Definition at line 187 of file checks.cpp.
unique_ptr< SharedMemory > grading::MapSharedData | ( | size_t | size | ) |
CheckResult grading::operator&& | ( | CheckResult && | x, |
CheckResult && | y | ||
) |
Combine the results of two checks using a product (AND): both must pass.
Definition at line 66 of file checks.cpp.
CheckResult grading::operator&& | ( | CheckResult && | x, |
CheckResult & | y | ||
) |
L-value version of above.
Definition at line 99 of file checks.cpp.
std::ostream & grading::operator<< | ( | std::ostream & | out, |
TestResult | result | ||
) |
Output a human-readable representation of a TestResult.
Definition at line 26 of file TestResult.cpp.
CheckResult grading::operator|| | ( | CheckResult && | x, |
CheckResult && | y | ||
) |
Combine the results of two checks using a sum (OR): at least one must pass.
Definition at line 105 of file checks.cpp.
CheckResult grading::operator|| | ( | CheckResult && | x, |
CheckResult & | y | ||
) |
L-value version of above.
Definition at line 129 of file checks.cpp.
TestResult grading::RunTest | ( | std::function< TestResult()> | test, |
std::string | name = "<unnamed test>" , |
||
time_t | timeout = 0 , |
||
std::ostream & | errorStream = std::cerr |
||
) |
Run a test closure in a separate process, capturing segmentation faults and other errors that lead to termination.
test | the test to run |
name | a developer-friendly name |
timeout | the number of seconds to let the test run (default 0, meaning "no timeout, run forever") |
errorStream | where to write messages (e.g., "expected X, got Y") |
Definition at line 128 of file posix.cpp.
References Timeout.
Referenced by RunTest().
TestResult grading::RunTest | ( | std::function< TestResult(T &)> | test, |
T & | output, | ||
std::string | name = "<unnamed test>" , |
||
time_t | timeout = 0 , |
||
std::ostream & | errorStream = std::cerr |
||
) |
Run a test with output but no explicit input.
test | a test function that copies out an output value and returns a TestResult |
output | the output value produced by test (if it executes normally, e.g., without segfaulting) |
name | a developer-friendly name |
timeout | the number of seconds to let the test run (default 0, meaning "no timeout, run forever") |
errorStream | where to write messages (e.g., "expected X, got Y") |
Definition at line 185 of file libgrading.h.
References MapSharedData(), grading::SharedMemory::rawPointer(), and RunTest().
TestResult grading::RunTest | ( | std::function< TestResult(const Expectation &, Output &)> | t, |
const Expectation & | expect, | ||
Output & | output, | ||
std::string | name = "<unnamed test>" , |
||
time_t | timeout = 0 , |
||
std::ostream & | errorStream = std::cerr |
||
) |
Run a test with input and output.
t | a test function that takes an input expectation, copies out an output value and returns a TestResult |
expect | our test expectation (inputs, expected output, etc.) |
output | the output value produced by test (if it executes normally, e.g., without segfaulting) |
name | a developer-friendly name |
timeout | the number of seconds to let the test run (default 0, meaning "no timeout, run forever") |
errorStream | where to write messages (e.g., "expected X, got Y") |
Definition at line 219 of file libgrading.h.