Skip to content

Commit

Permalink
fixes elm#20
Browse files Browse the repository at this point in the history
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
elm/core#1017 to get these tests running.
  • Loading branch information
harrysarson authored and marc136 committed Nov 23, 2023
1 parent 24a7c9a commit eda02af
Show file tree
Hide file tree
Showing 5 changed files with 119 additions and 4 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
elm-stuff
elm-stuff/
/artifacts.dat
/docs.json
/tests/.elm
11 changes: 11 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
language: elm

elm:
- latest

elm_test: latest

elm_format: latest

script:
- bash tests/run-tests.sh
23 changes: 23 additions & 0 deletions tests/elm.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
}
71 changes: 71 additions & 0 deletions tests/run-tests.sh
Original file line number Diff line number Diff line change
@@ -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 "$@";
13 changes: 10 additions & 3 deletions tests/Json.elm → tests/tests/Test/Json.elm
Original file line number Diff line number Diff line change
Expand Up @@ -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) "[]")
)
]


Expand All @@ -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
Expand Down

0 comments on commit eda02af

Please sign in to comment.