Skip to content

Instantly share code, notes, and snippets.

@pandringa
Last active February 1, 2019 16:43
Show Gist options
  • Save pandringa/0430db89b1a215bc02e7ace910ed07d8 to your computer and use it in GitHub Desktop.
Save pandringa/0430db89b1a215bc02e7ace910ed07d8 to your computer and use it in GitHub Desktop.
A simple Makefile to automatically Comp 411 Lab tests

Comp 411 Lab Makefile

To set up, copy the file below as Makefile in your lab directory

Usage

  • make ex[N]: Compile exercise N (e.g. make ex1 will take ex1.c and generate an ex1 executable)
  • make test-ex[N]: Run all available tests for exercise N (will only work if the tests are formatted like testIO/ex1in1). This will place results in the results folder, and automatically run the diff commands. If it is fails, it will exit with "Error 123" and show your result on the left, and the offical result on the right. If you need to further compare the results, you can run diff -y results/ex1in1 testIO/ex1out1 (for whatever the test number is).
# COMP 411 Lab Makefile
# See https://gist.github.com/pandringa/0430db89b1a215bc02e7ace910ed07d8 for usage information
# Author: Peter Andringa <peter.andringa@unc.edu>
# Spring 2019
num = $(shell find $? | grep -oP '\d')
ex%: ex%.c
gcc $? -o ex$(num);
.PHONY: test
test-ex%: ex%.c
mkdir -p results/
find ./testIO/ex$(num)in* | grep -oP 'ex\din\d' | xargs -n1 -i bash -c './ex$(num) < testIO/{} > results/{}'
find ./results/ex$(num)in* | grep -oP '\d$$' | xargs -n1 -i bash -c 'diff --suppress-common-lines -y results/ex$(num)in{} testIO/ex$(num)out{}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment