Brian Robert Callahan

submited by
Style Pass
2021-08-17 14:00:14

Today, let's write some infrastructure to make our lives easier when it comes to testing that our compiler works correctly. We will write a Makefile and a testing apparatus for our PL/0 compiler.

Since our PL/0 compiler is a single file C application, we have gotten away with just running the C compiler directly on our source code. Even so, make is fewer characters than cc pl0.c so a Makefile would be nice for that reason alone. It need not be fancy, it just has to work. Let's write the bare minimum to compile and clean up after ourselves:

Automated testing is great. I would like to be able to run make test and have a whole litany of tests fire off. Right now, it means we can make sure that our front end does the right thing of accepting correct code and rejecting incorrect code. In the future it means we can test the whole compiler.

Let's also keep our tests together in one place, separate from the compiler source code. I created a new directory named tests/ to hold all the test files. Inside the new directory, I will create a shell script that will handle running all the tests named test.sh. This shell script will be quite flexible and allow us to create an arbitrary number of tests, all of which will be automatically incorporated into the testing framework once created. This shell script looks like this:

Leave a Comment