mtest_overview(7)

bofc manual pages

mtest_overview(7)



 

NAME

mtest_overview - overview of mtest testing framework  

DESCRIPTION

mtest - very simple test framework for testing anything. mtest currently supports following languages:

For c/c++

mt_defs()
mt_defs_ext()
mt_run(function_name)
mt_run_named(function_name, test_name)
mt_assert(expression)
mt_fail(expression)
mt_fok(function_call)
mt_ferr(function_call, errno_value)
mt_return()

For shell

mt_run <function_name>
mt_fail <expression>
mt_return

Test output is compatible with TAP (which stands for Test Anything Protocol), so its output can be piped to another tool (like Jenkins or automake tests) for nice output.

Each test binary (written in c/c++) should contain call to mt_defs(3) anywhere in a global scope and mt_return(3) at the end of tests.

Tests in shell only requires mt_return(3) at the end of tests  

EXAMPLE


    #include <mtest.h>
    #include <stdlib.h>
    #include "file_to_test.h"


    mt_defs(); /* defines necessary variables for mtest */


    static void test_one(void)
    {
        mt_assert(foo() == 0);
        mt_assert(bar() == 0);
    }


    static void test_two(void)
    {
        unsigned char *mem;


        mt_assert((mem = malloc(100)) != NULL);
        mt_fok(baz(mem));
        mt_ferr(qux(mem), ENOSYS);


        free(mem);
    }


    int main(void)
    {
        mt_run(test_one);
        mt_run(test_two);


        mt_return();
    }

Example of using mt in posix 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_run(3), mt_assert(3), mt_fail(3), mt_fok(3), mt_ferr(3), mt_return(3)

bofc.pl

3 September 2018 (1.1.3)

mtest_overview(7)