tikz-trackschematic/test/testing.sh

100 lines
2.2 KiB
Bash
Raw Normal View History

2022-01-16 16:27:22 +01:00
#!/usr/bin/env sh
# Copyright (c) 2018 - 2022, Martin Scheidt (ISC license)
# Permission to use, copy, modify, and/or distribute this file for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.
# Halt on error
set -e
2022-02-09 01:49:11 +01:00
## -- pass getopts
2022-01-16 16:27:22 +01:00
2022-02-09 01:49:11 +01:00
usage() { echo "Usage: dev-install.sh [-q]"; }
2022-01-16 16:27:22 +01:00
2022-02-09 01:49:11 +01:00
verbose=1
2022-01-16 16:27:22 +01:00
2022-02-09 01:49:11 +01:00
while getopts ":q" opt; do
case ${opt} in
q ) verbose=0
;;
\? ) usage
exit 1
;;
esac
done
2022-01-16 16:27:22 +01:00
## -- commands
2022-02-09 01:49:11 +01:00
2022-01-16 16:27:22 +01:00
check_tex_distro() {
# check for latexmk
status=0
command -v pdflatex >/dev/null 2>&1 || status=1
if [ $status = 0 ]; then
2022-02-09 01:49:11 +01:00
if [ "$verbose" -eq 1 ]; then
echo "pdflatex found"
fi
2022-01-16 16:27:22 +01:00
return 0
fi
2022-02-09 01:49:11 +01:00
echo "Program 'pdflatex' not found."
echo "Be sure to have texlive or mactex installed!"
2022-01-16 16:27:22 +01:00
exit 1
}
2022-02-09 02:11:02 +01:00
check_trackschematic() {
# check for tikz-trackschematic
status=0
TEXMFLOCAL=$(kpsewhich --var-value TEXMFLOCAL)
DEVDIR="tex/latex/tikz-trackschematic-dev"
ls $TEXMFLOCAL/$DEVDIR/tikz-trackschematic.sty >> /dev/null 2>&1 || status=1
if [ $status = 0 ]; then
if [ "$verbose" -eq 1 ]; then
echo "tikz-trackschematic found"
fi
return 0
fi
echo "Library 'tikz-trackschematic' not found."
echo "Be sure to have tikz-trackschematic installed!"
exit 1
}
2022-01-16 16:27:22 +01:00
check_imagemagick() {
2022-02-09 02:11:02 +01:00
# check for ImageMagick/compare
2022-01-16 16:27:22 +01:00
status=0
command -v compare >/dev/null 2>&1 || status=1
if [ $status = 0 ]; then
2022-02-09 01:49:11 +01:00
if [ "$verbose" -eq 1 ]; then
echo "compare found"
fi
2022-01-16 16:27:22 +01:00
return 0
fi
2022-02-09 01:49:11 +01:00
echo "Program 'compare' not found."
2022-02-09 02:11:02 +01:00
echo "Be sure to have ImageMagick installed!"
2022-01-16 16:27:22 +01:00
exit 1
}
#-------------------------------------------------------------------------------
check_tex_distro
2022-02-09 02:11:02 +01:00
check_trackschematic
2022-01-16 16:27:22 +01:00
check_imagemagick
mkdir -p .testing
2022-01-16 17:43:56 +01:00
for TEST in $1*.tex; do
2022-02-09 01:49:11 +01:00
if [ "$verbose" -eq 1 ]; then
echo "Testing: ${TEST%.*}"
fi
2022-02-09 02:11:02 +01:00
pdflatex -output-directory=.testing -interaction=batchmode -halt-on-error $TEST # 2>&1 > /dev/null
2022-01-16 17:43:56 +01:00
compare -metric DSSIM -colorspace RGB .testing/${TEST%.*}.pdf ${TEST%.*}_expected.pdf .testing/${TEST%.*}_diff.png
2022-02-09 01:49:11 +01:00
if [ "$verbose" -eq 1 ]; then
echo "% difference"
fi
2022-01-16 17:43:56 +01:00
done
2022-01-16 16:27:22 +01:00
2022-02-09 01:49:11 +01:00
if [ "$verbose" -eq 1 ]; then
echo "tests passed!"
fi