The test target in the Makefile compiles our test code binary and runs both the code tests and the main test bash file (tests/test.bash
). The test bash file enables strict mode (i.e. exit on error and use of undefined variables), then it runs the compilation and fail tests. If any tests fail, the test target fails altogether.
We have code-based tests that verify the return values of the scanner and parser for many cases. We don't have such tests for the code-gen since our only requirement for the code-gen is that GCC can compile the output, and we test this in the compilation tests.
We test token generation from some simple strings and verify the integrity of the output by checking the stored strings and types of tokens.
We run some simple cases and check if the returned parse tree is correct or not. We also stub the exit function and test the cases where the parser is supposed to emit an error.
We have 2 bash scripts in the folders compilation
and fails
, called run_tests.bash
. These scripts loop over all .mat
files in the directory and verify the behavior of our program.
- Loop over all
.mat
files - Compile the
.mat
file to C - Compile the output C program to
prog
viagcc {filename} -lm
- Run
prog
and compare its output to the provided output in{filename}.out
During these steps, we catch any error from gcc or matlang2c and print it to the tester. If any error is caught, we exit with code 1.
- Loop over all
.mat
files - Run
matlang2c
with the.mat
file - Expect the exit code of
matlang2c
to be 1 - Compare the error output to the output provided in
{filename}.out
If the code compiles successfully or we receive a different exit code from matlang2c, we exit with code 1.
The .github
folder contains our CI action which runs our test
make target on every commit to master. We use this to verify any regressions in master.