libpulsar
A modular compiler for the pulsar programming language
Loading...
Searching...
No Matches
Testing Infrastructure

There are two parts of the testing infrastructure:

  • Unit testing
  • Snapshot testing

Both are handled in sync by the driver run.py program, which can be invoked via make test.

Unit Testing

My custom unit testing framework is best seen in context.

// file: sanity_test.c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "pulsar.h"
#include "util/notmain.h"
#include "util/unit_testing.h" // PS_UNIT_ASSERT
int MAIN(void) {
PS_UNIT_ASSERT(1 + 1 == 2,
"The universe should be holding together alright");
PS_UNIT_ASSERT_EQ(1 + 1, 2, "%d",
"The universe should be holding together alright (take 2)");
}
Enables programs to be located in the project directory.
#define MAIN
Defines a main function that should not be treated as a main function unless explicitly desired by th...
Definition notmain.h:15
Relevant public includes.
Provides assertion macros for unit tests.
#define PS_UNIT_ASSERT(result,...)
Assert that the result is true.
#define PS_BEGIN_UNIT_TESTS()
Begin unit tests.
#define PS_UNIT_ASSERT_EQ(exp, act, fmt, msg,...)
Assert that the two values are equal.

The driver program will generate a report from this file in sanity_test.c report.txt.

🤔 Unit test report for sanity_test.c
✅ sanity_test.c:main:14: 1 + 1 == 2
The universe should be holding together alright
✅ sanity_test.c:main:17: 1 + 1 == 2
Expected: 2
Actual: 2
The universe should be holding together alright (take 2)
🫡 Unit test report for sanity_test.c: PASSED

Snapshot Testing

The driver program has an array of programs to use for snapshot testing. It will invoke them with specified arguments. The input and output file for a specific test test are test.in and test.out. Each test will only pass if the output of the program is identical to test.out.

Relevant Files

Legacy Infrastructure

When I was writing my compiler in C a few years ago, I created a testing program similar to my snapshot testing but which could only match exit codes.

Relevant Files