From 61a5a4daf664342243e5ef9b526fc8d12151273e Mon Sep 17 00:00:00 2001 From: Lu Xu Date: Fri, 1 Oct 2021 14:13:07 +0800 Subject: [PATCH] merge test script into makefile --- Makefile | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ makefile | 19 ------------------- test | 44 -------------------------------------------- 3 files changed, 51 insertions(+), 63 deletions(-) create mode 100644 Makefile delete mode 100644 makefile delete mode 100644 test diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..f60ae08 --- /dev/null +++ b/Makefile @@ -0,0 +1,51 @@ +SOURCES:=$(wildcard */*.c) +BINARIES:=$(SOURCES:.c=) + +.PHONY: all clean test debug + +all: $(BINARIES) + +%: %.c + gcc -g -DONLINE_JUDGE -fno-tree-ch -O2 -Wall -std=c99 -pipe $< -o $@ -lm + +clean: + rm -f $(BINARIES) + +test: + @mkdir -p temp; \ + tracked_files=$$(git ls-tree --name-only HEAD PAT*/); \ + for bin in $(BINARIES); do \ + [ "$$tracked_files" = "$${tracked_files%$$bin*}" ] && continue; \ + dir=$$(dirname "$$bin"); \ + id=$$(basename "$$bin"); \ + case "$$dir" in \ + PATAdvanced) cat=a;; \ + PATBasic) cat=b;; \ + PATTop) cat=t;; \ + esac; \ + for sample in "samples/$$cat$$id-"*.in; do \ + echo "testing $$bin, sample $$sample"; \ + printf "%s" "$$("$$dir/$$id" < "$$sample" | tr -d '\0')" > temp/out; \ + printf "%s" "$$(cat "$${sample%.in}.out")" > temp/ans; \ + diff temp/out temp/ans || failed="$$failed$$bin $$sample\n"; \ + done; \ + done; \ + rm -r temp + @str_check_output="Scroll back for answer and actuall output"; \ + cred="\033[1;31m"; \ + cgreen="\033[1;32m"; \ + creset="\033[1;0m"; \ + if [ -n "$$failed" ]; then \ + printf "$$failed%s" | while read -r b s; do \ + printf "$$cred%s failed for sample %s$$creset\n" "$$b" "$$s"; \ + done; \ + printf "$$cred%s$$creset\n" "$$str_check_output"; \ + exit 1; \ + else \ + printf "$$cgreen%s$$creset\n" "All passed!"; \ + fi + + +debug: + @echo $(SOURCES) + @echo $(BINARIES) diff --git a/makefile b/makefile deleted file mode 100644 index ae2c45a..0000000 --- a/makefile +++ /dev/null @@ -1,19 +0,0 @@ -SOURCES:=$(wildcard */*.c) -BINARIES:=$(SOURCES:.c=) - -.PHONY: all clean test debug - -all: $(BINARIES) - -%: %.c - gcc -g -DONLINE_JUDGE -fno-tree-ch -O2 -Wall -std=c99 -pipe $< -o $@ -lm - -clean: - rm -f $(BINARIES) - -test: - @sh ./test $(BINARIES) - -debug: - @echo $(SOURCES) - @echo $(BINARIES) diff --git a/test b/test deleted file mode 100644 index b03285e..0000000 --- a/test +++ /dev/null @@ -1,44 +0,0 @@ -#!/bin/sh - -mkdir -p temp -trap 'rm -r temp' EXIT QUIT TERM INT - -tracked_files=$(git ls-tree --name-only HEAD PAT*/) - -for bin in "$@"; do - # this problem has not been solved, so there is no code for it - [ "$tracked_files" = "${tracked_files%$bin*}" ] && continue - - # PATBasic/1001 -> b1001, etc. - dir=$(dirname "$bin") - id=$(basename "$bin") - case "$dir" in - PATAdvanced) cat=a;; - PATBasic) cat=b;; - PATTop) cat=t;; - esac - - # run test and compare output - for sample in "samples/$cat$id-"*.in; do - echo "testing $bin, sample $sample" - # use `printf "%s" output' to strip white spaces - printf "%s" "$("$dir/$id" < "$sample" | tr -d '\0')" > temp/out - printf "%s" "$(cat "${sample%.in}.out")" > temp/ans - diff temp/out temp/ans || failed="$failed$bin $sample\n" - done -done - -str_check_output="Scroll back for comparison between answer and actuall output" -color_red="\033[1;31m" -color_green="\033[1;32m" -color_reset="\033[1;0m" - -if [ -n "$failed" ]; then - printf "$failed%s" | while read -r b s; do - printf "$color_red%s failed for sample %s$color_reset\n" "$b" "$s" - done - printf "$color_red%s$color_reset\n" "$str_check_output" - exit 1 -else - printf "$color_green%s$color_reset\n" "All passed!" -fi