on master help sign in
Merge pull request #39 from alexfmpe/verbose-tests

Allow verbose output for tests

commit7dffae61fb91489f2047adaa6fcc855ed29d4597 authorLuigy Leon <luichi.19@gmail.com> dateThu 31 May 2018, 10:27 (8 years ago) parent45294fb6004cfa
2 files changed+10−4
default.nix+1−1 lib/selftest/src/Obelisk/SelfTest.hs+9−3
default.nix+1−1
@@ -127,7 +127,7 @@ rec {
127127
128128 PATH="${ghcObelisk.obelisk-command}/bin:$PATH"
129129 export OBELISK_IMPL="${hackGet ./.}"
130− "${justStaticExecutables' ghcObelisk.obelisk-selftest}/bin/obelisk-selftest"
130+ "${justStaticExecutables' ghcObelisk.obelisk-selftest}/bin/obelisk-selftest" "$@"
131131 '';
132132 #TODO: Why can't I build ./skeleton directly as a derivation? `nix-build -E ./.` doesn't work
133133 skeleton = pkgs.runCommand "skeleton" {
lib/selftest/src/Obelisk/SelfTest.hs+9−3
@@ -6,6 +6,7 @@ module Obelisk.SelfTest where
66import Control.Exception (Exception, throw, bracket)
77import Control.Monad
88import Control.Monad.IO.Class
9+import Data.Bool (bool)
910import Data.Function (fix)
1011import Data.Semigroup ((<>))
1112import qualified Data.Set as Set
@@ -18,7 +19,7 @@ import qualified Network.HTTP.Types as HTTP
1819import qualified Network.Socket as Socket
1920import Shelly
2021import System.Environment
21−import System.Exit (ExitCode (..))
22+import System.Exit (ExitCode (..), exitWith)
2223import System.Info
2324import System.IO (Handle, hClose)
2425import System.IO.Temp
@@ -35,11 +36,16 @@ data ObRunState
3536
3637main :: IO ()
3738main = do
39+ isVerbose <- getArgs >>= \case
40+ ["-v"] -> pure True
41+ [] -> putStrLn "Tests may take longer to run if there are unbuilt derivations: use -v for verbose output" *> pure False
42+ _ -> putStrLn "Usage: selftest [-v]" *> exitWith (ExitFailure 2)
43+ let verbosity = bool silently verbosely isVerbose
3844 obeliskImpl <- fromString <$> getEnv "OBELISK_IMPL"
3945 httpManager <- HTTP.newManager HTTP.defaultManagerSettings
4046 withSystemTempDirectory "blank-project" $ \blankProject ->
4147 hspec $ do
42− let shelly_ = void . shelly . silently
48+ let shelly_ = void . shelly . verbosity
4349
4450 inProj :: Sh a -> IO ()
4551 inProj = shelly_ . chdir (fromString blankProject)
@@ -132,7 +138,7 @@ main = do
132138 assertRevNE e eu
133139
134140 it "can pack and unpack plain git repos" $ do
135− withSystemTempDirectory "git-repo" $ \dir -> shelly @IO $ silently $ do
141+ withSystemTempDirectory "git-repo" $ \dir -> shelly_ $ do
136142 let repo = toTextIgnore $ dir </> ("repo" :: String)
137143 run_ "git" ["clone", "https://git.haskell.org/packages/primitive.git", repo]
138144 origHash <- chdir (fromText repo) revParseHead