|
| 1 | +#!/bin/sh |
| 2 | + |
| 3 | +# This script is intended to be sourced from test scripts. |
| 4 | +# |
| 5 | +# It provides a number of default config options corresponding |
| 6 | +# to the compiler versions the stdlib is being tested with |
| 7 | +# |
| 8 | +# Usage: . ../../config.sh |
| 9 | + |
| 10 | +set -eu |
| 11 | + |
| 12 | +# Ugh, paths are relative to the script sourcing this file! |
| 13 | +. ../../_config/version-numbers.sh |
| 14 | + |
| 15 | + |
| 16 | + |
| 17 | +# Main entry point to build and run an Agda program |
| 18 | +# |
| 19 | +# Typically called like `goldenTest "$1" "echo" "hello world"` |
| 20 | +# |
| 21 | +# INPUTS: |
| 22 | +# $1 is the agda executable (typically "$1" in the ̀ run` file |
| 23 | +# because this info is provided by the test runner |
| 24 | +# $2 the name of the test as a string |
| 25 | +# $3 is OPTIONAL and corresponds to the extra arguments to pass |
| 26 | +# to the executable obtained by compiling the Agda program |
| 27 | +# |
| 28 | +# LOGGING: |
| 29 | +# logs/agda-build for the trace produced by Agda |
| 30 | +# logs/cabal-build for the trace produced by cabal+ghc |
| 31 | +# |
| 32 | +# OUTPUT: |
| 33 | +# the output obtained by running the Agda program is stored in |
| 34 | +# the file named `output`. The test runner will then diff it |
| 35 | +# against the expected file. |
| 36 | +goldenTest () { |
| 37 | + |
| 38 | + AGDA=$1 |
| 39 | + TEST_NAME="stdlib-test-$2" |
| 40 | + |
| 41 | + # Taking extra args for the executable? |
| 42 | + if [ -z ${3-} ]; then |
| 43 | + EXTRA_ARGS="" |
| 44 | + else |
| 45 | + EXTRA_ARGS="-- $3" |
| 46 | + fi |
| 47 | + |
| 48 | + # Remember whether the script has an input -- ugh |
| 49 | + if [ -f input ]; then |
| 50 | + HAS_INPUT="true" |
| 51 | + else |
| 52 | + touch input |
| 53 | + HAS_INPUT="false" |
| 54 | + fi |
| 55 | + |
| 56 | + # Specialise template agda-lib & cabal files |
| 57 | + sed "s/TEST_NAME/$TEST_NAME/g" ../../_config/template.agda-lib > "$TEST_NAME".agda-lib |
| 58 | + sed "s/TEST_NAME/$TEST_NAME/g" ../../_config/template.cabal > "$TEST_NAME".cabal |
| 59 | + |
| 60 | + # Set up clean logs directory |
| 61 | + rm -rf logs/ |
| 62 | + mkdir logs |
| 63 | + |
| 64 | + # Use shared directories to avoid rechecking stdlib modules |
| 65 | + AGDA_BUILD_DIR=../../_config/_build |
| 66 | + CABAL_BUILD_DIR=../../_config/dist-newstyle |
| 67 | + |
| 68 | + mkdir -p "$AGDA_BUILD_DIR" |
| 69 | + ln -sf "$AGDA_BUILD_DIR" _build |
| 70 | + mkdir -p "$CABAL_BUILD_DIR" |
| 71 | + ln -sf "$CABAL_BUILD_DIR" dist-newstyle |
| 72 | + |
| 73 | + # Compile the Agda module and build the generated code |
| 74 | + $AGDA --library-file=../../_config/libraries --compile-dir=_build -c --ghc-dont-call-ghc Main.agda > logs/agda-build |
| 75 | + cabal build "$TEST_NAME" --with-compiler "$GHC_EXEC" > logs/cabal-build |
| 76 | + |
| 77 | + # Run the test |
| 78 | + cabal exec -v0 "$TEST_NAME" --with-compiler "$GHC_EXEC" $EXTRA_ARGS < input > output |
| 79 | + |
| 80 | + # Clean up after ourselves |
| 81 | + if ! "$HAS_INPUT"; then |
| 82 | + rm input |
| 83 | + fi |
| 84 | + rm "$TEST_NAME".cabal |
| 85 | + rm "$TEST_NAME".agda-lib |
| 86 | + rm _build |
| 87 | + rm dist-newstyle |
| 88 | +} |
0 commit comments