Skip to content

Commit

Permalink
create a totally separate elm project for elm/core tests
Browse files Browse the repository at this point in the history
elm/core is special because the compiler always inserts an implicit
dependency on it.  therefore it's impossible to have the tests
integrated in the elm/core project in the normal way -- if we try to
symlink out from $ELM_HOME to our project's source in the way that was
done for 0.18, the compiler gets into a deadlock.  other approaches
cause it to find two copies of all the code in elm/core and refuse to
proceed.

instead, this approach creates a logically independent project, with
no real code, only tests.
  • Loading branch information
jerith666 committed Feb 9, 2019
1 parent d28daec commit 2b9a88d
Show file tree
Hide file tree
Showing 18 changed files with 94 additions and 28 deletions.
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
elm-stuff
tests/test.js
node_modules/
node_modules/
*.dat
doc*.json
tests/.elm
*~
17 changes: 0 additions & 17 deletions tests/elm-package.json

This file was deleted.

28 changes: 28 additions & 0 deletions tests/elm.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"type": "application",
"source-directories": [
"src"
],
"elm-version": "0.19.0",
"dependencies": {
"direct": {
"elm/browser": "1.0.1",
"elm/core": "1.0.2",
"elm/html": "1.0.0"
},
"indirect": {
"elm/json": "1.1.2",
"elm/time": "1.0.0",
"elm/url": "1.0.0",
"elm/virtual-dom": "1.0.2"
}
},
"test-dependencies": {
"direct": {
"elm-explorations/test": "1.2.1"
},
"indirect": {
"elm/random": "1.0.0"
}
}
}
71 changes: 61 additions & 10 deletions tests/run-tests.sh
Original file line number Diff line number Diff line change
@@ -1,19 +1,70 @@
#!/bin/sh
#!/usr/bin/env bash

cd "$(dirname "$0")"
set -e
set -o errexit;
set -o nounset;

#let the caller supply an ELM_TEST binary if desired
if [ ! -v ELM_TEST ]; then
npm install elm-test;
ELM_TEST=node_modules/elm-test/bin/elm-test;
fi

elm-package install -y
# since elm/core 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/core source fetched from package.elm-lang.org.

VERSION_DIR="$(ls elm-stuff/packages/elm-lang/core/)"
CORE_PACKAGE_DIR="elm-stuff/packages/elm-lang/core/$VERSION_DIR"
# create a local directory where the compiler will look for the
# elm/core 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/core 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/core hosted on package.elm-lang.org
"${ELM_TEST}" tests/Main.elm > /dev/null || true;

# clear out the copy of elm-core fetched by the above and replace it
# with the local source code we want to actually test

VERSION_DIR="$(ls ${ELM_HOME}/0.19.0/package/elm/core/)"
CORE_PACKAGE_DIR="${ELM_HOME}/0.19.0/package/elm/core/$VERSION_DIR"
CORE_GIT_DIR="$(dirname $PWD)"

echo;
echo "Linking $CORE_PACKAGE_DIR to $CORE_GIT_DIR"
rm -rf $CORE_PACKAGE_DIR
ln -s $CORE_GIT_DIR $CORE_PACKAGE_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

elm-make --yes --output test.js Main.elm
echo;
echo "running tests ...";
echo;

elm-test Main.elm
"${ELM_TEST}" tests/Main.elm;
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 2b9a88d

Please sign in to comment.