.TH "MT_RUN" "3" " 2 December 2019 (v9999)" "bofc.pl" .SH NAME .PP .B mt_run - runs specific test .SH SYNOPSIS .PP c/c++ .PP .B #include .PP .BI "void (*" function_name ")(void)" .br .BI "void (*" function_name_param ")(void *" parameter ")" .PP .BI "mt_run(" function_name ")" .br .BI "mt_run_param(" function_name_param ", " parameter ")" .br .BI "mt_run_named(" function_name ", " test_name ")" .br .BI "mt_run_param_named(" function_name_param ", " parameter ", " test_name ")" .PP .BI "static void (*" mt_prepare_test ")(void)" .br .BI "static void (*" mt_cleanup_test ")(void)" .PP shell .PP .BI "mt_run <" function_name "> [" param1 "] [" ... "]" .br .BI "mt_run_named <" function_name "> <" test_name "> [" param1 "] \ [" ... "]" .SH DESCRIPTION .PP .BR mt_run (3) runs a single test specified in .IR function_name . Inside function you can call .BR mt_assert (3) and .BR mt_fail (3). If none if these functions are called inside test function, .B mtest will mark test as successful. After function finishes its work, .BR mt_run (3) will print test status and a .I function_name to know which test passed or failed. .PP .BR mt_run_named (3) works similar, but also takes .IR test_name , that will be printed instead of .I function_name when reporting test results. .I test_name should be simple .B const char *. .PP .BR mt_run_param (3) and .BR mt_run_param_named (3) works in the same way as they non-parameter counterpart, but .I parameter will be passed to .IR function_name_param . When using shell functions, there is no .I param functions, but you can pass unspecified number of parameters to both .BR mt_run (3) and .BR mt_run_named (3). Since .I function_name is run via .B eval program, when you want to pass parameter with spaces, you need to use double quotes like .BR """'parameter\ with\ spaces'""" . .PP Optionally user can also set two function pointers .I mt_prepare_test and .I mt_cleanup_test that take no argument and return nothing. These functions will be called before and after calling test .IR function_name . .PP When testing from shell, it is only neccessary to define functions .I mt_prepare_test and .I mt_cleanup_test and .B mtest will use then automatically .SH EXAMPLE .PP c/c++ .PP .EX #include #include "foo.h" mt_defs(); static void test_param(void *param) { mt_assert(bar((int *)i) == 0); } static void test(void) { mt_assert(foo() == 0); } int main(void) { int i; mt_run(test); mt_run_named(test, "test param 1"); mt_run_named(test, "test_param 2"); for (i = 0; i != 5; ++i) { mt_run_param(test_param, &i); } mt_return(); } .EX .PP shell .PP .EX #!/bin/sh . ./mtest.sh test_two() { a=$1 b=$2 c=$((a + b)) mt_fail "[ $b -eq $(( c - a )) ]" } test_one() { a=1 a=$((a + 1)) mt_fail "[ $a -eq 2 ]" } mt_run test_one mt_run test_two 5 3 mt_return .EE .SH "SEE ALSO" .PP .BR mt_defs (3), .BR mt_defs_ext (3), .BR mt_assert (3), .BR mt_fail (3), .BR mt_fok (3), .BR mt_ferr (3), .BR mt_return (3) .BR mtest_overview (7),