mt_run(3)

bofc manual pages

mt_run(3)



 

NAME

mt_run - runs specific test  

SYNOPSIS

c/c++

#include <mtest.h>

void (*function_name)(void)
mt_run(function_name)
mt_run_named(function_name, test_name)

static void (*mt_prepare_test)(void)
static void (*mt_cleanup_test)(void)

shell

mt_run <function_name>  

DESCRIPTION

mt_run(3) runs a single test specified in function_name. Inside function you can call mt_assert(3) and mt_fail(3). If none if these functions are called inside test function, mtest will mark test as successful. After function finishes its work, mt_run(3) will print test status and a function_name to know which test passed or failed.

mt_run_named(3) works similar, but also takes test_name, that will be printed instead of function_name when reporting test results. test_name should be simple

Optionally user can also set two function pointers mt_prepare_test and mt_cleanup_test that take no argument and return nothing. These functions will be called before and after calling test function_name.

When testing from shell, it is only neccessary to define functions mt_prepare_test and mt_cleanup_test and mtest will use then automatically  

EXAMPLE

c/c++


    #include <mtest.h>
    #include "foo.h"


    mt_defs();


    static void test(void)
    {
        mt_assert(foo() == 0);
    }


    int main(void)
    {
        mt_run(test);
        mt_run_named(test, "test param 1");
        mt_run_named(test, "test_param 2");


        mt_return();
    }

shell


    #!/bin/sh


    . ./mtest.sh


    test_one()
    {
        a=1
        a=$((a + 1))
        mt_fail "[ $a -eq 2 ]"
    }


    mt_run test_one
    mt_return  

SEE ALSO

mt_defs(3), mt_defs_ext(3), mt_assert(3), mt_fail(3), mt_fok(3), mt_ferr(3), mt_return(3) mtest_overview(7),

bofc.pl

3 September 2018 (1.1.3)

mt_run(3)