Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
f7838b4
create a totally separate elm project for elm/core tests
jerith666 Feb 3, 2019
cc12e22
remove main and port functions in tests/Main.elm
jerith666 Feb 5, 2019
ec37018
there is no Test.Json, do not import it
jerith666 Feb 7, 2019
933097a
update Test.Basics for 0.19
jerith666 Feb 7, 2019
8558345
update Test.Array for 0.19
jerith666 Feb 7, 2019
e611180
update Test.Char for 0.19
jerith666 Feb 7, 2019
6102075
update Test.CodeGen for 0.19
jerith666 Feb 7, 2019
a833cc4
update Test.Equality for 0.19
jerith666 Feb 7, 2019
804c242
update Test.List for 0.19
jerith666 Feb 7, 2019
859af7b
update Test.Result for 0.19
jerith666 Feb 7, 2019
231183a
update Test.String for 0.19
jerith666 Feb 7, 2019
6ec09f3
new run-tests.sh
jerith666 Feb 8, 2019
e2974e2
fix run-tests to clean up .dat files
jerith666 Feb 8, 2019
5a1b7d0
remove main and port functions in tests/Main.elm
jerith666 Feb 5, 2019
52a34b9
there is no Test.Json, do not import it
jerith666 Feb 7, 2019
4c96b83
update Test.Basics for 0.19
jerith666 Feb 7, 2019
31150af
update Test.Array for 0.19
jerith666 Feb 7, 2019
eef6be1
update Test.Char for 0.19
jerith666 Feb 7, 2019
05a6de7
update Test.CodeGen for 0.19
jerith666 Feb 7, 2019
e8a228f
update Test.Equality for 0.19
jerith666 Feb 7, 2019
5fd4740
update Test.List for 0.19
jerith666 Feb 7, 2019
376c1df
update Test.Result for 0.19
jerith666 Feb 7, 2019
b967115
update Test.String for 0.19
jerith666 Feb 7, 2019
84ac7e5
Fix imports in tests.
harrysarson Feb 8, 2019
79ba7de
Run tests on local copy of elm/core
harrysarson Feb 8, 2019
6eadaf5
Merge branch 'update-019' into local-tests
harrysarson Feb 8, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
elm-stuff
tests/test.js
node_modules/
node_modules/
*.dat
doc*.json
tests/.elm
*~
3 changes: 3 additions & 0 deletions tests/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
elm-home/
src/
elm.js
17 changes: 0 additions & 17 deletions tests/elm-package.json

This file was deleted.

14 changes: 14 additions & 0 deletions tests/elm.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"type": "package",
"name": "elm/core",
"summary": "Elm's standard libraries",
"license": "BSD-3-Clause",
"version": "1.0.2",
"exposed-modules": [],
"elm-version": "0.19.0 <= v < 0.20.0",
"dependencies": {
"elm/random": "1.0.0 <= v < 2.0.0",
"elm-explorations/test": "1.2.1 <= v < 2.0.0"
},
"test-dependencies": {}
}
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;
109 changes: 109 additions & 0 deletions tests/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
'use strict';
const fs = require('fs');
const {promisify} = require('util');
const {exec} = require('child_process');
const path = require('path');

const mkdir = promisify(fs.mkdir);
const readdir = promisify(fs.readdir);
const lstat = promisify(fs.lstat);
const copyFile = promisify(fs.copyFile);
const unlink = promisify(fs.unlink);
const rmdir = promisify(fs.rmdir);


const remove = async dir => {
let files = [];
try {
files = await readdir(dir);
} catch (error) {
if (error.code === 'ENOENT') {
return;
} else {
throw error;
}
}

await Promise.all(files.map(async file => {
const filename = path.join(dir, file);
const stat = await lstat(filename);

if (filename == "." || filename == "..") {
// pass these files
} else if (stat.isDirectory()) {
// rmdir recursively
await remove(filename);
} else if (stat.isSymbolicLink()) {
throw new Error("Cannot remove symbolic link!");
} else {
await unlink(filename);
}
}));
await rmdir(dir);
};


const copyDir = async (src, dest) => {
try {
await mkdir(dest);
} catch (error) {
if (error.code !== "EEXIST") {
throw error;
}
}
const files = await readdir(src);

await Promise.all(files.map(async file => {
const current = await lstat(path.join(src, file));

if (current.isDirectory()) {
await copyDir(path.join(src, file), path.join(dest, file));
} else if (current.isSymbolicLink()) {
throw new Error("Cannot copy symbolic link!");
} else {
await copyFile(path.join(src, file), path.join(dest, file));
}
}));
};

(async () => {
try {
process.chdir(__dirname);

await remove('src');

await copyDir('../src', 'src');
await copyDir(path.join('tests'), path.join('src'));
} catch (error) {
console.error(" ** Error generating files **");
console.error(error);
process.exit(1);
return;
}
try {
await new Promise((resolve, reject) => {
exec('elm make src/Run.elm --output elm.js', (error, stdout, stderr) => {
if (error != null) {
reject(error);
} else {
process.stdout.write(stdout);
process.stderr.write(stderr);
resolve();
}
});
});
} catch (error) {
console.error(" ** Error compiling files **");
console.error(error);
process.exit(1);
return;
}
try {
require('./elm.js');
} catch (error) {
console.error(" ** Tests failed **");
console.error(error);
process.exit(1);
return;
}
})();
16 changes: 1 addition & 15 deletions tests/Main.elm → tests/tests/Main.elm
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
port module Main exposing (..)
module Main exposing (..)

import Basics exposing (..)
import Task exposing (..)
import Test exposing (..)
import Platform.Cmd exposing (Cmd)
import Json.Decode exposing (Value)
import Test.Runner.Node exposing (run, TestProgram)
import Test.Array as Array
import Test.Basics as Basics
import Test.Bitwise as Bitwise
Expand All @@ -14,7 +9,6 @@ import Test.CodeGen as CodeGen
import Test.Dict as Dict
import Test.Maybe as Maybe
import Test.Equality as Equality
import Test.Json as Json
import Test.List as List
import Test.Result as Result
import Test.Set as Set
Expand All @@ -39,11 +33,3 @@ tests =
, Maybe.tests
, Tuple.tests
]


main : TestProgram
main =
run emit tests


port emit : ( String, Value ) -> Cmd msg
Loading