#!/bin/sh set -eu verbose=false if [ "$#" -gt 0 ] then case "$1" in verbose | -v | --verbose) verbose=true ;; esac fi hideok= if command -v chronic > /dev/null then hideok=chronic fi quiet=-q if $verbose then quiet= hideok= fi TOPDIR=$(pwd) _codegen() { $hideok cargo run $quiet --package subplot --bin sp-codegen -- \ "$1" --output "$2" --resources "${TOPDIR}/share" } codegen() { _codegen "$1" "$2" rm -f test.log template="$(sed -n '/^template: /s///p' "$1" | tail -n1)" case "$template" in python) $hideok python3 "$2" --log test.log ;; bash) $hideok bash "$2" ;; *) echo "Don't know interpreter for $2" ; exit 1 ;; esac } docgen() { cargo run $quiet --package subplot --bin sp-docgen -- "$1" --output "$2" --resources "${TOPDIR}/share" } # Run unit tests for the Python template. (set -eu cd share/python/template for x in *_tests.py do $hideok echo "Unit tests: $x" $hideok python3 "$x" $hideok echo done) if command -v flake8 > /dev/null then $hideok flake8 share/python/template share/python/lib/*.py fi if command -v shellcheck > /dev/null then shellcheck check ./*.sh find share/bash/template -name '*.sh' -exec shellcheck '{}' + fi $hideok cargo build --all-targets if cargo --list | awk '{ print $1 }' | grep 'clippy$' > /dev/null then cargo clippy $quiet fi $hideok cargo test $quiet if command -v rustfmt > /dev/null then cargo fmt --all -- --check fi if command -v black > /dev/null then $hideok find . -type f -name '*.py' ! -name template.py ! -name test.py \ -exec black --check '{}' + fi (cd subplotlib; $hideok cargo test --lib for md in [!CR]*.md; do $hideok echo "subplotlib/$md =====================================" $hideok mkdir -p tests _codegen "$md" "tests/$(basename "$md" .md).rs" "" # This formatting is fine because we checked --all earlier # so all it'll do is tidy up the test suite cargo fmt docgen "$md" "$(basename "$md" .md).pdf" docgen "$md" "$(basename "$md" .md).html" $hideok cargo test --test "$(basename "$md" .md)" $hideok echo done ) for md in [!CR]*.md share/python/lib/*.md do $hideok echo "$md =====================================" codegen "$md" test.py docgen "$md" "$(basename "$md" .md).pdf" docgen "$md" "$(basename "$md" .md).html" $hideok echo done echo "Everything seems to be in order."