From e195be488eefd7b6feed42a6717c4fba2e7b644c Mon Sep 17 00:00:00 2001 From: Harry Sarson Date: Sat, 4 Jan 2020 09:05:55 +0000 Subject: [PATCH] fix tests With this commit, tests run again (I believe they last run with elm 0.18.0). I have used the same approach as https://github.com/elm/core/pull/1017/ to get these tests running. --- .gitignore | 5 ++- .travis.yml | 11 +++++ tests/elm.json | 23 +++++++++++ tests/run-tests.sh | 71 +++++++++++++++++++++++++++++++++ tests/{ => tests/Test}/Json.elm | 13 ++++-- 5 files changed, 119 insertions(+), 4 deletions(-) create mode 100644 .travis.yml create mode 100644 tests/elm.json create mode 100755 tests/run-tests.sh rename tests/{ => tests/Test}/Json.elm (86%) diff --git a/.gitignore b/.gitignore index e185314..2c90aac 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,4 @@ -elm-stuff \ No newline at end of file +elm-stuff/ +/artifacts.dat +/docs.json +/tests/.elm diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..9b59466 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,11 @@ +language: elm + +elm: + - latest + +elm_test: latest + +elm_format: latest + +script: + - bash tests/run-tests.sh diff --git a/tests/elm.json b/tests/elm.json new file mode 100644 index 0000000..3d3f51d --- /dev/null +++ b/tests/elm.json @@ -0,0 +1,23 @@ +{ + "type": "application", + "source-directories": [], + "elm-version": "0.19.1", + "dependencies": { + "direct": { + "elm/core": "1.0.4", + "elm/json": "1.1.3" + }, + "indirect": {} + }, + "test-dependencies": { + "direct": { + "elm-explorations/test": "1.2.2" + }, + "indirect": { + "elm/html": "1.0.0", + "elm/random": "1.0.0", + "elm/time": "1.0.0", + "elm/virtual-dom": "1.0.2" + } + } +} diff --git a/tests/run-tests.sh b/tests/run-tests.sh new file mode 100755 index 0000000..93aca4f --- /dev/null +++ b/tests/run-tests.sh @@ -0,0 +1,71 @@ +#!/usr/bin/env bash + +set -o errexit; +set -o nounset; + +#let the caller supply an ELM_TEST binary if desired +if [ -z "${ELM_TEST:-}" ]; then + ELM_TEST=elm-test; +fi + +# since elm/json is treated specially by the compiler (it's always +# inserted as a dependency even when not declared explicitly), we use +# a bit of a hack to make the tests run against the local source code +# rather than the elm/json source fetched from package.elm-lang.org. + +# create a local directory where the compiler will look for the +# elm/json source code: + +DIR="$(dirname $0)"; + +cd "$DIR"; + +export ELM_HOME="$(pwd)/.elm"; + +rm -rf "$ELM_HOME" && mkdir -p "$ELM_HOME"; + +# elm-test also puts some things in elm-stuff, start with a clean +# slate there as well + +rm -rf elm-stuff; + +# now make an initial run of the tests to populate .elm and elm-stuff; +# this will test against elm/json from package.elm-lang.org, so we +# don't really care what the results are; we just need to force all +# the *other* dependencies to be fetched and set up. + +echo "seeding framework for test dependencies ..."; + +# '|| true' lets us ignore failures here and keep the script running. +# useful when developing a fix for a bug that exists in the version of +# elm/json hosted on package.elm-lang.org + +"${ELM_TEST}" tests/Test/Json.elm --fuzz=1 > /dev/null || true; + +# clear out the copy of elm/json fetched by the above and replace it +# with the local source code we want to actually test + +VERSION_DIR="$(ls ${ELM_HOME}/0.19.1/packages/elm/json/)" +CORE_PACKAGE_DIR="${ELM_HOME}/0.19.1/packages/elm/json/$VERSION_DIR" +CORE_GIT_DIR="$(dirname $PWD)" + +echo; +echo "Linking $CORE_PACKAGE_DIR to $CORE_GIT_DIR" +echo; + +rm -rf "$CORE_PACKAGE_DIR" +ln -sv "$CORE_GIT_DIR" "$CORE_PACKAGE_DIR" +rm -vf "${CORE_GIT_DIR}"/*.dat "${CORE_GIT_DIR}"/doc*.json + +# we also need to clear out elm-test's elm-stuff dir, since otherwise +# the compiler complains that its .dat files are out of sync + +rm -rf elm-stuff; + +# now we can run the tests against the symlinked source code for real + +echo; +echo "running tests ..."; +echo; + +"${ELM_TEST}" tests/Test/Json.elm "$@"; diff --git a/tests/Json.elm b/tests/tests/Test/Json.elm similarity index 86% rename from tests/Json.elm rename to tests/tests/Test/Json.elm index 614a1dd..721f365 100644 --- a/tests/Json.elm +++ b/tests/tests/Test/Json.elm @@ -49,8 +49,11 @@ intTests = , test "Decoder expects object finds array, was crashing runtime." <| \() -> Expect.equal - (Err "Expecting an object but instead got: []") - (Json.decodeString (Json.dict Json.float) "[]") + (Err "Problem with the given value:\n\n[]\n\nExpecting an OBJECT") + (Result.mapError + Json.errorToString + (Json.decodeString (Json.dict Json.float) "[]") + ) ] @@ -71,7 +74,11 @@ customTests = Ok _ -> Expect.fail "expected `customDecoder` to produce a value of type Err, but got Ok" - Err message -> + Err error -> + let + message = + Json.errorToString error + in if String.contains customErrorMessage message then Expect.pass else