Pergunta

Eu tenho um programa C++ e vários arquivos .in e .out para testes pré-fabricados.Eu queria saber como executar meu programa c++ e inseri-los nele.

Foi útil?

Solução

Presumo que você tenha uma lista de arquivos como test0.in e um correspondente test1.out.Talvez você queira um 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 $@

Depois é só digitar make test -j para testes multithread.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top