كيفية استخدام ملفات .in و .out للاختبار في بيئة يونكس؟

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

  •  21-12-2019
  •  | 
  •  

سؤال

لدي برنامج C++ ومجموعة من ملفات .in و .out للاختبار المسبق.كنت أتساءل عن كيفية تنفيذ برنامج c++ الخاص بي وإدخاله فيه.

هل كانت مفيدة؟

المحلول

أفترض أن لديك قائمة بالملفات مثل test0.in و المقابلة test1.out.ربما تريد ملف Makefile مثل هذا:

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

ثم اكتب فقط make test -j للاختبار متعدد الخيوط.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top