Skip to content

Commit

Permalink
Hook the new test infrastructure to cabal
Browse files Browse the repository at this point in the history
- 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.
  • Loading branch information
yacinehmito committed Jul 27, 2016
1 parent 54b94b9 commit 5186d6c
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 10 deletions.
6 changes: 3 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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'
###
Expand Down
22 changes: 17 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -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
Expand Down
29 changes: 29 additions & 0 deletions Setup.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -281,4 +305,9 @@ main = defaultMainWithHooks $ simpleUserHooks
NoCopyDest pkg local
, preSDist = idrisPreSDist
, postSDist = idrisPostSDist
#if __GLASGOW_HASKELL__ < 710
, testHook = idrisTestHook ()
#else
, testHook = idrisTestHook
#endif
}
6 changes: 4 additions & 2 deletions config.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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 :=
Expand Down

0 comments on commit 5186d6c

Please sign in to comment.