New testing
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -2,3 +2,5 @@
|
||||
compile_commands.json
|
||||
.o
|
||||
.gz
|
||||
exp
|
||||
out
|
||||
|
||||
19
Makefile
19
Makefile
@@ -26,10 +26,23 @@ dist: clean
|
||||
tar -czf $(DIST).tar.gz $(DIST)
|
||||
rm -rf $(DIST)
|
||||
|
||||
test:
|
||||
@./t/basic
|
||||
check:
|
||||
@failed=0; \
|
||||
for f in ./t/*; do \
|
||||
[ "$$f" = "./t/init.sh" ] && continue; \
|
||||
[ -f "$$f" ] || continue; \
|
||||
name=$$(basename "$$f"); \
|
||||
sh "$$f"; rc=$$?; \
|
||||
if [ $$rc -eq 0 ]; then \
|
||||
printf '\e[0;32mPASS\e[0m: t/%s\n' "$$name"; \
|
||||
else \
|
||||
printf '\e[0;31mFAIL\e[0m: t/%s\n' "$$name"; \
|
||||
failed=1; \
|
||||
fi; \
|
||||
done; \
|
||||
if [ $$failed -ne 0 ]; then exit 1; fi
|
||||
|
||||
clean:
|
||||
rm -f $(SRC_OBJ) $(LIB_OBJ) $(BIN) *.gz
|
||||
|
||||
.PHONY: dist clean all
|
||||
.PHONY: dist clean all check
|
||||
|
||||
6
t/basic
6
t/basic
@@ -1,6 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
. t/lib.sh
|
||||
|
||||
check "" "tcpl: Hello, World!"
|
||||
check "foo" "tcpl: Hello, foo!"
|
||||
18
t/hello-1
Executable file
18
t/hello-1
Executable file
@@ -0,0 +1,18 @@
|
||||
#!/bin/sh
|
||||
# Testing standard Hello
|
||||
#
|
||||
# Copyright (C) 2026 fSD
|
||||
#
|
||||
# Permission to use, copy, modify, and/or distribute this software for any
|
||||
# purpose with or without fee is hereby granted, provided that the above
|
||||
# copyright notice and this permission notice appear in all copies.
|
||||
|
||||
. ./t/init.sh
|
||||
|
||||
cat <<EOF >exp || framework_failure_
|
||||
tcpl: Hello, World!
|
||||
EOF
|
||||
./tcpl >out || fail=1
|
||||
compare exp out || fail=1
|
||||
|
||||
exit $fail
|
||||
26
t/init.sh
Executable file
26
t/init.sh
Executable file
@@ -0,0 +1,26 @@
|
||||
#!/bin/sh
|
||||
|
||||
ME_=$(basename $0)
|
||||
|
||||
framework_failure_() {
|
||||
exit 99
|
||||
}
|
||||
|
||||
compare() {
|
||||
f1=${1:?file1 required}
|
||||
f2=${2:?file2 required}
|
||||
|
||||
if cmp -s -- "$f1" "$f2" 2>/dev/null; then
|
||||
return 0 # identical
|
||||
fi
|
||||
|
||||
if diff -u -- "$f1" "$f2" 2>/dev/null; then
|
||||
return 0
|
||||
else
|
||||
if diff -- "$f1" "$f2" 2>/dev/null; then
|
||||
return 0
|
||||
else
|
||||
return 1
|
||||
fi
|
||||
fi
|
||||
}
|
||||
55
t/lib.sh
55
t/lib.sh
@@ -1,55 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
scriptversion="1"
|
||||
me=$(basename "$0")
|
||||
version="$me/vxc v$scriptversion
|
||||
Copyright (C) 2026 vxc.
|
||||
This is free software; you are free to change and redistribute it.
|
||||
There is NO WARRANTY, to the extent permitted by law."
|
||||
|
||||
usage="Usage: $me [OPTION]... <arg1> <arg2>
|
||||
Does a thing
|
||||
|
||||
Options:
|
||||
--help print this help and exit
|
||||
--version output version information"
|
||||
|
||||
while [ $# -gt 0 ]; do
|
||||
case $1 in
|
||||
--help) echo "$usage"; exit 0 ;;
|
||||
--version) echo "$version"; exit 0 ;;
|
||||
-*) echo "$me: Unknown option '$1'." >&2; exit 1 ;;
|
||||
*) break ;;
|
||||
esac
|
||||
shift
|
||||
done
|
||||
|
||||
width=$(tput cols 2>/dev/null || echo 80)
|
||||
|
||||
INFO="\e[0;34m"
|
||||
RESET="\e[0m"
|
||||
OK="\e[0;32m"
|
||||
BAD="\e[0;31m"
|
||||
|
||||
good() {
|
||||
printf "%$((${width} + 25))s\r%s...\n" "$(echo -e "$INFO[ ${OK}ok $INFO]$RESET")" "$1"
|
||||
}
|
||||
|
||||
fail() {
|
||||
printf "%$((${width} + 25))s\r%s...\n" "$(echo -e "$INFO[${BAD}fail$INFO]$RESET")" "$1"
|
||||
}
|
||||
|
||||
make -s
|
||||
|
||||
check() {
|
||||
expected=$2
|
||||
output=$(./tcpl $1) || { fail "$1 (execution failed)"; return 1; }
|
||||
|
||||
if [ "$output" = "$expected" ]; then
|
||||
good "./tcpl $1"
|
||||
return 0
|
||||
else
|
||||
fail "./tcpl $1: unexpected: $output; wanted: $expected"
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
18
t/name-1
Executable file
18
t/name-1
Executable file
@@ -0,0 +1,18 @@
|
||||
#!/bin/sh
|
||||
# Testing standard Hello
|
||||
#
|
||||
# Copyright (C) 2026 fSD
|
||||
#
|
||||
# Permission to use, copy, modify, and/or distribute this software for any
|
||||
# purpose with or without fee is hereby granted, provided that the above
|
||||
# copyright notice and this permission notice appear in all copies.
|
||||
|
||||
. ./t/init.sh
|
||||
|
||||
cat <<EOF >exp || framework_failure_
|
||||
tcpl: Hello, Seaman!
|
||||
EOF
|
||||
./tcpl Seaman >out || fail=1
|
||||
compare exp out || fail=1
|
||||
|
||||
exit $fail
|
||||
Reference in New Issue
Block a user