merge test script into makefile

This commit is contained in:
Lu Xu
2021-10-01 14:14:24 +08:00
parent 5289ac0a0e
commit 61a5a4daf6
3 changed files with 51 additions and 63 deletions
+51
View File
@@ -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)
-19
View File
@@ -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)
-44
View File
@@ -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