Skip to content

Commit 1c78f66

Browse files
committed
Merge pull request purescript#1382 from phadej/test-random-order
Tests could be run in random order
2 parents 825e109 + fc8cea1 commit 1c78f66

File tree

6 files changed

+100
-49
lines changed

6 files changed

+100
-49
lines changed

.travis.yml

Lines changed: 39 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,32 @@
1+
language: c
12
sudo: false
2-
env:
3-
- GHCVER=7.8.4 COVERAGE_SUITE=tests
4-
- GHCVER=7.8.4 COVERAGE_SUITE=psci-tests
5-
- GHCVER=7.6.3
6-
- GHCVER=7.10.1
7-
- GHCVER=7.8.4 STACKAGE=lts-2.22
8-
# 7.10.2 Pending https://github.com/travis-ci/apt-package-whitelist/pull/686
9-
- GHCVER=7.10.1 STACKAGE=lts-3.1
10-
- GHCVER=7.10.1 STACKAGE=nightly-2015-08-12
3+
matrix:
4+
include:
5+
- env: GHCVER=7.8.4 COVERAGE_SUITE=tests
6+
compiler: ": #GHC 7.8.4 - tests"
7+
# ^ HACK before https://github.com/travis-ci/travis-ci/issues/4393 is resolved
8+
addons: {apt: {packages: [cabal-install-1.22,ghc-7.8.4,happy-1.19.5,alex-3.1.4], sources: [hvr-ghc]}}
9+
- env: GHCVER=7.8.4 COVERAGE_SUITE=psci-tests
10+
compiler: ": #GHC 7.8.4 - psci-tests"
11+
addons: {apt: {packages: [cabal-install-1.22,ghc-7.8.4,happy-1.19.5,alex-3.1.4], sources: [hvr-ghc]}}
12+
- env: GHCVER=7.8.4 STACKAGE=lts-22
13+
compiler: ": #GHC 7.8.4 - lts-2.22"
14+
addons: {apt: {packages: [cabal-install-1.22,ghc-7.8.4,happy-1.19.5,alex-3.1.4], sources: [hvr-ghc]}}
15+
- env: GHCVER=7.6.3
16+
compiler: ": #GHC 7.6.3"
17+
addons: {apt: {packages: [cabal-install-1.22,ghc-7.6.3,happy-1.19.5,alex-3.1.4], sources: [hvr-ghc]}}
18+
- env: GHCVER=7.10.1
19+
compiler: ": #GHC 7.10.1"
20+
addons: {apt: {packages: [cabal-install-1.22,ghc-7.10.1,happy-1.19.5,alex-3.1.4], sources: [hvr-ghc]}}
21+
# 7.10.2 Pending https://github.com/travis-ci/apt-package-whitelist/pull/686
22+
- env: GHCVER=7.10.1 STACKAGE=lts=3.1 RUNSDISTTESTS=YES
23+
compiler: ": #GHC 7.10.1 lts-3.1"
24+
addons: {apt: {packages: [cabal-install-1.22,ghc-7.10.1,happy-1.19.5,alex-3.1.4], sources: [hvr-ghc]}}
25+
- env: GHCVER=7.10.1 STACKAGE=nightly-2015-08-12
26+
compiler: ": #GHC 7.10.1 nightly-2015-08-12"
27+
addons: {apt: {packages: [cabal-install-1.22,ghc-7.10.1,happy-1.19.5,alex-3.1.4], sources: [hvr-ghc]}}
1128
before_install:
29+
- unset CC
1230
- export PATH="/opt/ghc/$GHCVER/bin:$PATH"
1331
- export PATH="/opt/cabal/1.22/bin:$PATH"
1432
- export PATH="$HOME/.cabal/bin:$PATH"
@@ -23,13 +41,20 @@ install:
2341
# cabal and ghc tries to use them all. Which is bad idea on a shared box.
2442
# See also: https://ghc.haskell.org/trac/ghc/ticket/9221
2543
- sed -i 's/^jobs:/-- jobs:/' ${HOME}/.cabal/config
26-
- mkdir -p sandboxes/$GHCVER/${STACKAGE:-none}
27-
- cabal sandbox init --sandbox sandboxes/$GHCVER/${STACKAGE:-none}
28-
# Download stackage cabal.config
29-
# Not sure whether filtering out purescript is necessary
44+
# Cache sandboxes in ~/cabal-sandboxes
45+
# Move right sandbox to .cabal-sandbox if exists
46+
- if [ -d ~/cabal-sandboxes/$GHCVER-${STACKAGE:-none} ]; then
47+
mv ~/cabal-sandboxes/$GHCVER-${STACKAGE:-none} .cabal-sandbox;
48+
fi
49+
- mkdir -p .cabal-sandbox
50+
- cabal sandbox init --sandbox .cabal-sandbox
51+
# Download stackage cabal.config, not sure whether filtering is necessary
3052
- if [ -n "$STACKAGE" ]; then curl http://www.stackage.org/$STACKAGE/cabal.config | grep -v purescript > cabal.config; fi
3153
- cabal install --only-dependencies --enable-tests
3254
- cabal install hpc-coveralls
55+
# Snapshot state of the sandbox now, so we don't need to make new one for test install
56+
- rm -rf ~/cabal-sandboxes/$GHCVER-${STACKAGE:-none}
57+
- cp -r .cabal-sandbox ~/cabal-sandboxes/$GHCVER-${STACKAGE:-none}
3358
script:
3459
- ./travis/configure.sh
3560
- cabal build
@@ -50,18 +75,6 @@ deploy:
5075
on:
5176
all_branches: true
5277
tags: true
53-
addons:
54-
apt:
55-
sources:
56-
- hvr-ghc
57-
packages:
58-
- cabal-install-1.22
59-
- ghc-7.6.3
60-
- ghc-7.8.4
61-
- ghc-7.10.1
62-
- happy-1.19.5
63-
- alex-3.1.4
6478
cache:
6579
directories:
66-
- sandboxes/
67-
- ../install-test/sandboxes/
80+
- ~/cabal-sandboxes

psci/tests/Main.hs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,11 @@ import PSCi
2424
import Completion
2525
import Types
2626

27+
import TestsSetup
28+
2729
main :: IO ()
2830
main = do
31+
fetchSupportCode
2932
Counts{..} <- runTestTT allTests
3033
when (errors + failures > 0) exitFailure
3134

purescript.cabal

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,8 +243,9 @@ test-suite tests
243243
Glob -any
244244
type: exitcode-stdio-1.0
245245
main-is: Main.hs
246+
other-modules: TestsSetup
246247
buildable: True
247-
hs-source-dirs: tests
248+
hs-source-dirs: tests tests/common
248249

249250
test-suite psci-tests
250251
build-depends: base >=4 && <5, containers -any, directory -any, filepath -any,
@@ -254,6 +255,7 @@ test-suite psci-tests
254255
Glob -any
255256
type: exitcode-stdio-1.0
256257
main-is: Main.hs
258+
other-modules: TestsSetup
257259
buildable: True
258-
hs-source-dirs: psci psci/tests
260+
hs-source-dirs: psci psci/tests tests/common
259261
ghc-options: -Wall

tests/Main.hs

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ import qualified System.FilePath.Glob as Glob
6666

6767
import Text.Parsec (ParseError)
6868

69+
import TestsSetup
70+
6971
modulesDir :: FilePath
7072
modulesDir = ".test_modules" </> "node_modules"
7173

@@ -166,11 +168,6 @@ assertDoesNotCompile inputFiles foreigns = do
166168
trim =
167169
dropWhile isSpace >>> reverse >>> dropWhile isSpace >>> reverse
168170

169-
findNodeProcess :: IO (Maybe String)
170-
findNodeProcess = runMaybeT . msum $ map (MaybeT . findExecutable) names
171-
where
172-
names = ["nodejs", "node"]
173-
174171
main :: IO ()
175172
main = do
176173
fetchSupportCode
@@ -205,16 +202,6 @@ main = do
205202
in putStrLn $ fp' ++ ": " ++ err
206203
exitFailure
207204

208-
fetchSupportCode :: IO ()
209-
fetchSupportCode = do
210-
setCurrentDirectory "tests/support"
211-
callProcess "npm" ["install"]
212-
-- Sometimes we run as a root (e.g. in simple docker containers)
213-
-- And we are non-interactive: https://github.com/bower/bower/issues/1162
214-
callProcess "node_modules/.bin/bower" ["--allow-root", "install", "--config.interactive=false"]
215-
callProcess "node" ["setup.js"]
216-
setCurrentDirectory "../.."
217-
218205
supportModules :: [String]
219206
supportModules =
220207
[ "Control.Monad.Eff.Class"

tests/common/TestsSetup.hs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
-----------------------------------------------------------------------------
2+
--
3+
-- Module : Main
4+
-- License : MIT (http://opensource.org/licenses/MIT)
5+
--
6+
-- Maintainer : Phil Freeman <paf31@cantab.net>
7+
-- Stability : experimental
8+
-- Portability :
9+
--
10+
-- |
11+
--
12+
-----------------------------------------------------------------------------
13+
module TestsSetup where
14+
15+
import Data.Maybe (fromMaybe)
16+
import Control.Applicative
17+
18+
import Control.Monad
19+
20+
import Control.Applicative
21+
22+
import Control.Monad.Trans.Maybe
23+
24+
import System.Process
25+
import System.Directory
26+
27+
findNodeProcess :: IO (Maybe String)
28+
findNodeProcess = runMaybeT . msum $ map (MaybeT . findExecutable) names
29+
where
30+
names = ["nodejs", "node"]
31+
32+
fetchSupportCode :: IO ()
33+
fetchSupportCode = do
34+
node <- fromMaybe (error "cannot find node executable") <$> findNodeProcess
35+
setCurrentDirectory "tests/support"
36+
callProcess "npm" ["install"]
37+
-- Sometimes we run as a root (e.g. in simple docker containers)
38+
-- And we are non-interactive: https://github.com/bower/bower/issues/1162
39+
callProcess "node_modules/.bin/bower" ["--allow-root", "install", "--config.interactive=false"]
40+
callProcess node ["setup.js"]
41+
setCurrentDirectory "../.."

travis/test-install.sh

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11
set -e
22

33
# Check that a source distribution can be successfully generated, and that
4-
# the generated source distribution can be installed
4+
# the generated source distribution can be installed and tested
55
cabal sdist
66
if SRC_TGZ="$PWD/dist/$(cabal info . | awk '{print $2;exit}').tar.gz"
77
then
8-
mkdir -p ../install-test
9-
cd ../install-test
10-
mkdir -p sandboxes/$GHCVER/${STACKAGE:-none}
11-
cabal sandbox init --sandbox sandboxes/$GHCVER/${STACKAGE:-none}
12-
cabal install -j2 --ghc-options='+RTS -A32m -RTS' "$SRC_TGZ"
8+
if [ "$RUNSDISTTESTS" = "YES" ]; then
9+
mkdir test-install
10+
cd test-install
11+
tar --strip-components=1 -xzf $SRC_TGZ
12+
cabal sandbox init --sandbox ../.cabal-sandbox
13+
cabal install --enable-tests --force-reinstalls
14+
cabal test
15+
else
16+
cabal install "$SRC_TGZ"
17+
fi
1318
fi

0 commit comments

Comments
 (0)