test.sh
#!bin/bash assert(){ expected="$1" input="$2" ./9cc "$input" > tmp.s gcc -o tmp tmp.s ./tmp actual="$?" if [ "$actual" = "$expected" ]; then echo "$input => $actual" else echo "$input => $expected expected, but got $actual" exit 1 fi } assert 0 0 assert 42 42 echo OK
$ ls
9cc 9cc.c test.sh tmp tmp.s
$ sudo chmod a+x test.sh
$ sh test.sh
0 => 0
42 => 42
OK
Makefile
CFLAGS=-std=c11 -g -static 9cc: 9cc.c test: 9cc sh test.sh clean: rm -f 9cc *.o *~ tmp* .PHONY: test clean