Comment utiliser les fichiers .in et .out pour tester dans un environnement Unix ?

StackOverflow https://stackoverflow.com//questions/23020191

  •  21-12-2019
  •  | 
  •  

Question

J'ai un programme C++ et un tas de fichiers .in et .out pour des tests prédéfinis.Je me demandais comment exécuter mon programme C++ et y insérer ces éléments.

Était-ce utile?

La solution

Je suppose que vous avez une liste de fichiers comme test0.in et un correspondant test1.out.Peut-être voulez-vous un Makefile comme celui-ci :

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

Ensuite, tapez simplement make test -j pour les tests multithreads.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top