Files
dotfiles/aliases
Roman Volovoy 6d7fdefc22 test all <3
2026-06-03 19:12:55 +02:00

90 lines
1.5 KiB
Plaintext

cc-clean(){
rm -rf ./**/*.out 2>/dev/null
}
cc-delete-tests(){
rm -rf ./**/*.test.c
}
cc-run(){
local file
if [ -z "$1" ]; then
echo "Usage: cc-run <file> [args...]" >&2
return 1
fi
cc-clean
file="$1"
shift
cc -std=c99 "${file}" -o "${file}.out" -Wall -Wextra -Werror && \
"./${file}.out" "$@"
cc-clean
}
cc-run-test-inline(){
local file
if [ -z "$1" ]; then
echo "Usage: cc-run <file> [args...]" >&2
return 1
fi
cc-clean
file="$1"
shift
if command -v norminette &>/dev/null
then
norminette "${file}"
fi
cc -std=c99 "${file}" -o "${file}.out" -Wall -Wextra -Werror -DTEST=please && \
"./${file}.out" "$@"
cc-clean
}
cc-test(){
local file
if [ -z "$1" ]; then
echo "Usage: cc-run <file> [args...]" >&2
return 1
fi
cc-clean
file="$1"
shift
# remove trailing .c if present
base="${file%.*}"
if command -v norminette &>/dev/null; then
norminette "${base}.c"
fi
# compile base.test.c -> base.test.out and run it
cc -std=c99 "${base}.test.c" -o "${base}.test.out" -Wall -Wextra -Werror &&
"./${base}.test.out" "$@"
cc-clean
}
cc-test-all() {
# find .c files, exclude those ending with .test.c
find . -type f -name '*.c' ! -name '*.test.c' -print0 |
while IFS= read -r -d '' file; do
echo -e "----------$file: TESTING-------------\n"
cc-test "$file" || {
echo -e "\n----------$file: DONE (NOT OK)-------"
# echo "cc-test failed for $file" >&2
return 1
}
echo -e "\n----------$file: DONE (OK)-----------"
done
}