libcester icon indicating copy to clipboard operation
libcester copied to clipboard

Add functionality to test whether a test case compiles or not, and to execute an external app

Open Thecarisma opened this issue 4 years ago • 2 comments

Test compilation

Add magic and an awesome feature where you can test whether a test case compiles or not if it does not output the error message. The compiled source can be any language, This can be achieved by setting the compilation executable, options for that test case then cester try to execute that with exec or similar function, then capture the output. This should be optional and can be disabled with #define CESTER_IGNORE_COMPILATION_TEST

Sample format

CESTER_COMPILE_TEST(does_this_so_code_compiles, inst, "gcc", "-ansi --pedantic-errors", {
    #include <stdio>
    int main() {
        printf("yahoo\n");
    }
})
CESTER_COMPILE_TEST(does_this_python_code_runs, inst, "python", "", {
    import io
    print("hello python")
})

The first argument is the test case, the second is the test instance, the third is the compiler executable, the fourth is the code to compile (this is converted to string so there should be a way to remove the enclosing { and };

Test execution

cester should be able to test whether a program runs and validates the output is what is expected similar to CESTER_COMPILE_TEST

CESTER_EXECUTE_TEST(execute_program, inst, "program.exe", "--op", {
    cester_assert_program_output_eq(execute_program, "Unknow option --op");
})

the first argument is the test case name, the second is the test instance, the third is the program or full path to the program o execute, the fourth is the argument to send to the program, the last is the test case body

Thecarisma avatar Feb 27 '21 12:02 Thecarisma

Allow adding paths and set working directory before test case

Proposed format

CESTER_EXECUTE_COMPILER_SET_WORKING_DIR("C:/User/test/");
CESTER_EXECUTE_COMPILER_ADD_PATH("C:/User/test/app1/bin");
CESTER_EXECUTE_COMPILER_ADD_PATH("C:/User/test/app2/bin");
CESTER_EXECUTE_COMPILER_ADD_PATH("C:/program/bin");

Thecarisma avatar Dec 02 '21 07:12 Thecarisma

in CESTER_TEST_COMPILE test case, allow running the command that output the text to compile, and also extra arg to test the compilation output

E.g.

CESTER_TEST_COMPILE(does_this_python_code_runs, inst, "python", "", {
    import io
    print("hello python")
}, {
    cester_assert_compile_output_eq("hello python");
})

Thecarisma avatar Dec 02 '21 07:12 Thecarisma