[commit: packages/directory] master: Add script to run the GHC test framework (47335ad)

git at git.haskell.org git at git.haskell.org
Thu Mar 19 11:38:12 UTC 2015


Repository : ssh://git@git.haskell.org/directory

On branch  : master
Link       : http://ghc.haskell.org/trac/ghc/changeset/47335adef0e5d801d9a1f323aaf5c50f186609e5/directory

>---------------------------------------------------------------

commit 47335adef0e5d801d9a1f323aaf5c50f186609e5
Author: Phil Ruffwind <rf at rufflewind.com>
Date:   Sun Mar 1 16:02:42 2015 -0500

    Add script to run the GHC test framework
    
    The script automatically clones the GHC repo and invokes the test
    framework with the correct arguments.  A patch for the GHC repo is also
    included to work around bugs/incompatbilities.
    
    Note that it requires an existing Cabal project to work, due to the need
    for Cabal-specific files and configuration.  Coupling the tests to Cabal
    allows them to be run using the version of project that is in the
    current working tree rather than whatever that's installed.  Note that
    the project must still be built beforehand.  Also, if a sandbox is used,
    the script must be run under `cabal exec`.


>---------------------------------------------------------------

47335adef0e5d801d9a1f323aaf5c50f186609e5
 tools/ghc.patch | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 tools/run-tests | 50 ++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 112 insertions(+)

diff --git a/tools/ghc.patch b/tools/ghc.patch
new file mode 100644
index 0000000..61ce567
--- /dev/null
+++ b/tools/ghc.patch
@@ -0,0 +1,62 @@
+# allow ghc and its tools to be located in different directories
+--- testsuite/mk/boilerplate.mk
++++ testsuite/mk/boilerplate.mk
+@@ -56,6 +56,7 @@ TEST_HC := $(STAGE2_GHC)
+ endif
+ 
+ else
++implicit_compiler = YES
+ IN_TREE_COMPILER = NO
+ TEST_HC := $(shell which ghc)
+ endif
+@@ -87,24 +88,30 @@ endif
+ # containing spaces
+ BIN_ROOT = $(shell dirname '$(TEST_HC)')
+ 
++ifeq "$(implicit_compiler)" "YES"
++find_tool = $(shell which $(1))
++else
++find_tool = $(BIN_ROOT)/$(1)
++endif
++
+ ifeq "$(GHC_PKG)" ""
+-GHC_PKG := $(BIN_ROOT)/ghc-pkg
++GHC_PKG := $(call find_tool,ghc-pkg)
+ endif
+ 
+ ifeq "$(RUNGHC)" ""
+-RUNGHC := $(BIN_ROOT)/runghc
++RUNGHC := $(call find_tool,runghc)
+ endif
+ 
+ ifeq "$(HSC2HS)" ""
+-HSC2HS := $(BIN_ROOT)/hsc2hs
++HSC2HS := $(call find_tool,hsc2hs)
+ endif
+ 
+ ifeq "$(HP2PS_ABS)" ""
+-HP2PS_ABS := $(BIN_ROOT)/hp2ps
++HP2PS_ABS := $(call find_tool,hp2ps)
+ endif
+ 
+ ifeq "$(HPC)" ""
+-HPC := $(BIN_ROOT)/hpc
++HPC := $(call find_tool,hpc)
+ endif
+ 
+ $(eval $(call canonicaliseExecutable,TEST_HC))
+
+# 'die' is not available until GHC 7.10
+--- testsuite/timeout/timeout.hs
++++ testsuite/timeout/timeout.hs
+@@ -30,8 +30,8 @@ main = do
+       [secs,cmd] ->
+           case reads secs of
+           [(secs', "")] -> run secs' cmd
+-          _ -> die ("Can't parse " ++ show secs ++ " as a number of seconds")
+-      _ -> die ("Bad arguments " ++ show args)
++          _ -> ((>> exitFailure) . hPutStrLn stderr) ("Can't parse " ++ show secs ++ " as a number of seconds")
++      _ -> ((>> exitFailure) . hPutStrLn stderr) ("Bad arguments " ++ show args)
+ 
+ timeoutMsg :: String
+ timeoutMsg = "Timeout happened...killing process..."
diff --git a/tools/run-tests b/tools/run-tests
new file mode 100755
index 0000000..c71b958
--- /dev/null
+++ b/tools/run-tests
@@ -0,0 +1,50 @@
+#!/bin/sh
+# run all of the tests under the `tests` directory using the GHC test
+# framework; for more info about this framework, see:
+# https://ghc.haskell.org/trac/ghc/wiki/Building/RunningTests
+#
+# arguments received by this script are passed as arguments to the `make`
+# invocation that initiates the tests
+set -e
+
+# check if `-package-db` is supported (didn't exist until 1.20)
+# note that we don't use `-package-db` directly because older versions will
+# interpret it as `-package -db`
+if ghc 2>&1 -no-user-package-db |
+   grep >/dev/null 2>&1 "ghc: unrecognised flags: -no-user-package-db"
+then db=conf
+else db=db
+fi
+
+[ -z "$HSFLAGS" ] || HSFLAGS=\ $HSFLAGS
+HSFLAGS="-package-$db ../dist/package.conf.inplace$HSFLAGS"
+HSFLAGS="-optP-include -optP../dist/build/autogen/cabal_macros.h $HSFLAGS"
+export HSFLAGS
+
+# download the GHC repository
+[ -f dist/testsuite/ghc.ok ] || {
+    rm -fr dist/testsuite/ghc
+    git clone --depth 1 https://github.com/ghc/ghc dist/testsuite/ghc
+    patch <tools/ghc.patch -d dist/testsuite/ghc -N -p 0 -r - || :
+    touch dist/testsuite/ghc.ok
+}
+
+# we can't just specify `TOP` as an argument for `make` because it will
+# override `TOP` for *every* included makefile
+sed >dist/testsuite/Makefile \
+    "s|^TOP=.*$|TOP=../dist/testsuite/ghc/testsuite|" \
+    tests/Makefile
+
+cd tests
+make -f ../dist/testsuite/Makefile WAY=normal EXTRA_HC_OPTS="$HSFLAGS" "$@" |
+    tee ../dist/testsuite/test.out
+
+# since the test framework doesn't report an exit status, we need to manually
+# find out whether the test had any failures>
+{
+    grep '^ *0 had missing libraries$'     ../dist/testsuite/test.out
+    grep '^ *0 caused framework failures$' ../dist/testsuite/test.out
+    grep '^ *0 unexpected passes$'         ../dist/testsuite/test.out
+    grep '^ *0 unexpected failures$'       ../dist/testsuite/test.out
+    grep '^ *0 unexpected stat failures$'  ../dist/testsuite/test.out
+} >/dev/null 2>/dev/null



More information about the ghc-commits mailing list