Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests: Remove unused code from test script #250

Merged
merged 1 commit into from
Oct 16, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 15 additions & 45 deletions scripts/test
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,6 @@ DIR="$(dirname "${BASH_SOURCE[0]}")"
MODE="${1:-test}";
if (( $# > 1)); then shift; fi

FLAG_INSTALL=0

while :; do
case "${1:-}" in
'--install') FLAG_INSTALL=1 ;;
*) break
esac
shift
done


TYPST_VERSION="v0.8.0"
TYPST_BASE_URL="https://github.com/typst/typst/releases/download"
TYPST_ARCHIVE="typst-x86_64-unknown-linux-musl.tar.xz"

TYPST_ROOT="$(realpath "$DIR/..")"
export TYPST_ROOT
TEST_ROOT="$(realpath "$DIR/../tests")"
Expand All @@ -43,46 +28,22 @@ function typst_compile()
}
export -f typst_compile

function install_typst()
{
if [[ "$OSTYPE" != "linux"* ]]; then
>&2 echo "Automatic installation of typst on a non linux system is currently unsupported."
exit 1
fi

#TMP="$(mktemp -d)"
TMP="${TMP:-/tmp}/typst-${TYPST_VERSION}"
if mkdir -p "$TMP" 2> /dev/null ; then
local PKG="${TMP}/typst.tar.xz"

echo "Installing typst from $TYPST_BASE_URL/$TYPST_ARCHIVE"
wget "${TYPST_BASE_URL}/${TYPST_VERSION}/${TYPST_ARCHIVE}" \
--quiet \
-O "$PKG"
mkdir -p "${TMP}/typst"
tar -xf "$PKG" -C "${TMP}/typst" --strip-components=1
rm "$PKG"
fi

PATH="${TMP}/typst/:$PATH"
export PATH
}

if [[ "$FLAG_INSTALL" == "1" ]]; then
install_typst
fi

if ! hash typst; then
>&2 echo "Could not find 'typst' binary. Run this script with the --install argument to temporarily install typst."
>&2 echo "Could not find 'typst' binary."
exit 1
fi

# Compare two image files $1 and $2 using ImageMagick
function img_compare()
{
$MAGICK_COMPARE -metric rmse "$1" "$2" null: 2>&1 | cut -d\ -f1
}
export -f img_compare

# Update a single tests reference image
#
# Arguments
# - test_dir: Directory of the test to update. Must contain test.typ
function update_test_ref()
{
if [[ "$1" == "$TEST_ROOT" ]]; then
Expand All @@ -109,6 +70,10 @@ export -f update_test_ref
TEST_FAIL=0
TEST_OK=0

# Run a single test
#
# Arguments
# - test_dir: Directory of the test. Must contain test.typ + ref.png
function run_test()
{
if [[ "$1" == "$TEST_ROOT" ]]; then
Expand Down Expand Up @@ -145,15 +110,20 @@ export -f run_test

echo "Typst: $(typst --version)"

# If gnu-parallel is not installed,
# we fake it by forwarding it's call to xargs
if ! hash parallel 2>/dev/null; then
function parallel() {
xargs -n 1 -I {} bash -c "$1"
}
fi

# Collects all test directories. A directory is a test dir. if it
# contains a file called test.typ.
function tests() {
find "$TEST_ROOT" -type f -name "test.typ" -exec dirname {} \;
}

if [[ "$MODE" == "test" ]]; then
tests | parallel 'run_test {}'
elif [[ "$MODE" == "update" ]]; then
Expand Down