|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +set -o errexit; |
| 4 | +set -o nounset; |
| 5 | + |
| 6 | +#let the caller supply an ELM_TEST binary if desired |
| 7 | +if [ -z "${ELM_TEST:-}" ]; then |
| 8 | + ELM_TEST=elm-test; |
| 9 | +fi |
| 10 | + |
| 11 | +# since elm/json is treated specially by the compiler (it's always |
| 12 | +# inserted as a dependency even when not declared explicitly), we use |
| 13 | +# a bit of a hack to make the tests run against the local source code |
| 14 | +# rather than the elm/json source fetched from package.elm-lang.org. |
| 15 | + |
| 16 | +# create a local directory where the compiler will look for the |
| 17 | +# elm/json source code: |
| 18 | + |
| 19 | +DIR="$(dirname $0)"; |
| 20 | + |
| 21 | +cd "$DIR"; |
| 22 | + |
| 23 | +export ELM_HOME="$(pwd)/.elm"; |
| 24 | + |
| 25 | +rm -rf "$ELM_HOME" && mkdir -p "$ELM_HOME"; |
| 26 | + |
| 27 | +# elm-test also puts some things in elm-stuff, start with a clean |
| 28 | +# slate there as well |
| 29 | + |
| 30 | +rm -rf elm-stuff; |
| 31 | + |
| 32 | +# now make an initial run of the tests to populate .elm and elm-stuff; |
| 33 | +# this will test against elm/json from package.elm-lang.org, so we |
| 34 | +# don't really care what the results are; we just need to force all |
| 35 | +# the *other* dependencies to be fetched and set up. |
| 36 | + |
| 37 | +echo "seeding framework for test dependencies ..."; |
| 38 | + |
| 39 | +# '|| true' lets us ignore failures here and keep the script running. |
| 40 | +# useful when developing a fix for a bug that exists in the version of |
| 41 | +# elm/json hosted on package.elm-lang.org |
| 42 | + |
| 43 | +"${ELM_TEST}" tests/Test/Json.elm --fuzz=1 > /dev/null || true; |
| 44 | + |
| 45 | +# clear out the copy of elm/json fetched by the above and replace it |
| 46 | +# with the local source code we want to actually test |
| 47 | + |
| 48 | +VERSION_DIR="$(ls ${ELM_HOME}/0.19.1/packages/elm/json/)" |
| 49 | +CORE_PACKAGE_DIR="${ELM_HOME}/0.19.1/packages/elm/json/$VERSION_DIR" |
| 50 | +CORE_GIT_DIR="$(dirname $PWD)" |
| 51 | + |
| 52 | +echo; |
| 53 | +echo "Linking $CORE_PACKAGE_DIR to $CORE_GIT_DIR" |
| 54 | +echo; |
| 55 | + |
| 56 | +rm -rf "$CORE_PACKAGE_DIR" |
| 57 | +ln -sv "$CORE_GIT_DIR" "$CORE_PACKAGE_DIR" |
| 58 | +rm -vf "${CORE_GIT_DIR}"/*.dat "${CORE_GIT_DIR}"/doc*.json |
| 59 | + |
| 60 | +# we also need to clear out elm-test's elm-stuff dir, since otherwise |
| 61 | +# the compiler complains that its .dat files are out of sync |
| 62 | + |
| 63 | +rm -rf elm-stuff; |
| 64 | + |
| 65 | +# now we can run the tests against the symlinked source code for real |
| 66 | + |
| 67 | +echo; |
| 68 | +echo "running tests ..."; |
| 69 | +echo; |
| 70 | + |
| 71 | +"${ELM_TEST}" tests/Test/Json.elm "$@"; |
0 commit comments