Skip to content

Commit

Permalink
Merge pull request #250 from johannes-wolf/tests-remove-typst-install…
Browse files Browse the repository at this point in the history
…ation

tests: Remove unused code from test script
  • Loading branch information
johannes-wolf authored Oct 16, 2023
2 parents 62ef427 + 19a817c commit 0a92100
Showing 1 changed file with 15 additions and 45 deletions.
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

0 comments on commit 0a92100

Please sign in to comment.