Skip to content

Commit eda02af

Browse files
harrysarsonmarc136
authored andcommitted
fixes elm#20
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.
1 parent 24a7c9a commit eda02af

File tree

5 files changed

+119
-4
lines changed

5 files changed

+119
-4
lines changed

.gitignore

+4-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
1-
elm-stuff
1+
elm-stuff/
2+
/artifacts.dat
3+
/docs.json
4+
/tests/.elm

.travis.yml

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
language: elm
2+
3+
elm:
4+
- latest
5+
6+
elm_test: latest
7+
8+
elm_format: latest
9+
10+
script:
11+
- bash tests/run-tests.sh

tests/elm.json

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"type": "application",
3+
"source-directories": [],
4+
"elm-version": "0.19.1",
5+
"dependencies": {
6+
"direct": {
7+
"elm/core": "1.0.4",
8+
"elm/json": "1.1.3"
9+
},
10+
"indirect": {}
11+
},
12+
"test-dependencies": {
13+
"direct": {
14+
"elm-explorations/test": "1.2.2"
15+
},
16+
"indirect": {
17+
"elm/html": "1.0.0",
18+
"elm/random": "1.0.0",
19+
"elm/time": "1.0.0",
20+
"elm/virtual-dom": "1.0.2"
21+
}
22+
}
23+
}

tests/run-tests.sh

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
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 "$@";

tests/Json.elm tests/tests/Test/Json.elm

+10-3
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,11 @@ intTests =
4949
, test "Decoder expects object finds array, was crashing runtime." <|
5050
\() ->
5151
Expect.equal
52-
(Err "Expecting an object but instead got: []")
53-
(Json.decodeString (Json.dict Json.float) "[]")
52+
(Err "Problem with the given value:\n\n[]\n\nExpecting an OBJECT")
53+
(Result.mapError
54+
Json.errorToString
55+
(Json.decodeString (Json.dict Json.float) "[]")
56+
)
5457
]
5558

5659

@@ -71,7 +74,11 @@ customTests =
7174
Ok _ ->
7275
Expect.fail "expected `customDecoder` to produce a value of type Err, but got Ok"
7376

74-
Err message ->
77+
Err error ->
78+
let
79+
message =
80+
Json.errorToString error
81+
in
7582
if String.contains customErrorMessage message then
7683
Expect.pass
7784
else

0 commit comments

Comments
 (0)