Question

I have C++ program, and a bunch of .in and .out files for premade testing. I was wondering how to execute my c++ program and feed these into it.

Was it helpful?

Solution

I assume you have a list of files like test0.in and a corrosponding test1.out. Perhaps you want a Makefile like this:

#Put rules/variables to actually make the program

SRC = test.cpp
TARGET = program

INPUTS = $(shell ls *.in)
OUTPUTS = $(patsubst %.in, %.out, $(INPUTS))
TESTS = $(patsubst %.in, %.test, $(INPUTS))

#This build rule is just for showcase.  You will probably need your own, more sophisticated build rules
$(TARGET): $(SRC)
    g++ $^ -o $@ -std=c++11

.PHONY: test
test: $(TESTS)

%.test : %.in %.out $(TARGET)
    @./$(TARGET) < $*.in > $@;
    @if cmp -s $@ $*.out; then \
        echo "PASS: $*"; \
    else \
        echo "FAIL: $*"; \
    fi
    @rm $@

Then, just type make test -j for multithreaded testing.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top