From 5186d6ce3ef531fb5c3a100688d7590b4197e095 Mon Sep 17 00:00:00 2001 From: gpyh Date: Wed, 27 Jul 2016 14:46:10 +0200 Subject: [PATCH] Hook the new test infrastructure to cabal - A test hook in `Setup.hs` allows using the new test infrastructure with `cabal test`. Without it, cabal couldn't find the idris libraries. - Make rules related to testing now call `cabal test`. - The `test_timed` rule is removed because timings are given by default - We introduce the `test_update` rule to update the golden files - We introduce the `test_clean` rule to remove artifacts created when running the test suite. This is far from perfect ; a careful `git clean -f` should remove whatever is left - The TEST-JOBS variable specifies the number of parallel jobs to the test program. By default, it relies on the Haskell RTS to find an optimal number. Set to 1 to disable parallelism. - The TEST-ARGS variable can be used to pass arguments to the test program. - Travis CI uses the new infrasctructure. It uses `travis_wait` to prevent timeouts because cabal only prints the output when the test suite is done running. --- .travis.yml | 6 +++--- Makefile | 22 +++++++++++++++++----- Setup.hs | 29 +++++++++++++++++++++++++++++ config.mk | 6 ++++-- 4 files changed, 53 insertions(+), 10 deletions(-) diff --git a/.travis.yml b/.travis.yml index 81eb8fecbb..c320593691 100644 --- a/.travis.yml +++ b/.travis.yml @@ -102,7 +102,7 @@ before_script: script: ### - echo 'Configure...' && echo -en 'travis_fold:start:script.configure\\r' - - cabal configure -f FFI -f CI + - cabal configure -f FFI -f CI --enable-tests - echo -en 'travis_fold:end:script.configure\\r' ### - echo 'Build...' && echo -en 'travis_fold:start:script.build\\r' @@ -125,8 +125,8 @@ script: ### - echo 'Tests...' && echo -en 'travis_fold:start:script.tests\\r' - for test in $TESTS; do - echo "make -j2 $test"; - make -j2 $test; + echo "make TEST-JOBS=2 $test"; + travis_wait make TEST-JOBS=2 $test; done - echo -en 'travis_fold:end:script.tests\\r' ### diff --git a/Makefile b/Makefile index ccd5e3ba68..6916b56830 100644 --- a/Makefile +++ b/Makefile @@ -1,10 +1,15 @@ -.PHONY: build configure doc install linecount nodefault pinstall lib_clean relib fast test_c test lib_doc lib_doc_clean user_doc_html user_doc_pdf user_docs +.PHONY: build configure doc install linecount nodefault pinstall lib_clean relib fast test_js test_c test test_clean lib_doc lib_doc_clean user_doc_html user_doc_pdf user_docs + +ARGS= +TEST-JOBS= +TEST-ARGS= include config.mk -include custom.mk ifdef CI CABALFLAGS += -f CI +TEST-ARGS += --color always endif install: @@ -20,13 +25,20 @@ build: dist/setup-config test: doc test_c test_c: - echo "test_c not supported" + $(CABAL) test $(ARGS) --test-options \ + "$(TEST-ARGS) --rerun-update +RTS -N$(TEST-JOBS) -RTS" test_js: - echo "test_js not supported" + $(CABAL) test $(ARGS) --test-options \ + "$(TEST-ARGS) --node --rerun-update +RTS -N$(TEST-JOBS) -RTS" + +test_update: + $(CABAL) test $(ARGS) --test-options \ + "$(TEST-ARGS) --accept +RTS -N$(TEST-JOBS) -RTS" -test_timed: - echo "test_timed not supported" +test_clean: + rm -f test/*~ + rm -f test/*/output lib_clean: $(MAKE) -C libs IDRIS=../../dist/build/idris/idris RTS=../../dist/build/rts/libidris_rts clean diff --git a/Setup.hs b/Setup.hs index b8e0a38720..2aa08a661d 100644 --- a/Setup.hs +++ b/Setup.hs @@ -263,6 +263,30 @@ idrisInstall verbosity copy pkg local = unless (execOnly (configFlags local)) $ makeInstall src target = make verbosity [ "-C", src, "install" , "TARGET=" ++ target, "IDRIS=" ++ idrisCmd local] +-- ----------------------------------------------------------------------------- +-- Test + +-- FIXME: We use the __GLASGOW_HASKELL__ macro because MIN_VERSION_cabal seems +-- to be broken ! + +-- There are two "dataDir" in cabal, and they don't relate to each other. +-- When fetching modules, idris uses the second path (in the pkg record), +-- which by default is the root folder of the project. +-- We want it to be the install directory where we put the idris libraries. +fixPkg pkg target = pkg { dataDir = target } + +-- The "Args" argument of the testHooks has been added in cabal 1.22.0, +-- and should therefore be ignored for prior versions. +#if __GLASGOW_HASKELL__ < 710 +originalTestHook _ = testHook simpleUserHooks +#else +originalTestHook = testHook simpleUserHooks +#endif + +idrisTestHook args pkg local hooks flags = do + let target = datadir $ L.absoluteInstallDirs pkg local NoCopyDest + originalTestHook args (fixPkg pkg target) local hooks flags + -- ----------------------------------------------------------------------------- -- Main @@ -281,4 +305,9 @@ main = defaultMainWithHooks $ simpleUserHooks NoCopyDest pkg local , preSDist = idrisPreSDist , postSDist = idrisPostSDist +#if __GLASGOW_HASKELL__ < 710 + , testHook = idrisTestHook () +#else + , testHook = idrisTestHook +#endif } diff --git a/config.mk b/config.mk index a5d60594a3..57f507d4e2 100644 --- a/config.mk +++ b/config.mk @@ -14,9 +14,11 @@ CABAL :=cabal # Any flags defined here which alter the RTS API must also be added to src/IRTS/CodegenC.hs CFLAGS :=-O2 -Wall -DHAS_PTHREAD -DIDRIS_ENABLE_STATS $(CFLAGS) -#CABALFLAGS := +# CABALFLAGS := +CABALFLAGS += --enable-tests ## Disable building of Effects -#CABALFLAGS :=-f NoEffects +#CABALFLAGS :=-f NoEffects $(CABALFLAGS) + ifneq (, $(findstring bsd, $(MACHINE))) GMP_INCLUDE_DIR :=