Pregunta

Tengo programa de C++, y un montón de .en y .los archivos de salida para prefabricados de pruebas.Me preguntaba cómo ejecutar mi programa de c++ y alimentar a estos en él.

¿Fue útil?

Solución

Supongo que usted tiene una lista de archivos, como test0.in y un corrosponding test1.out.Tal vez usted quiere un Makefile como este:

#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 $@

A continuación, sólo tienes que escribir make test -j para multiproceso pruebas.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top