on master help sign in
Allow verbose output for tests
6004cfaAlexandre Esteves
default.nix+1−1
@@ -127,7 +127,7 @@ rec {
127
127
128 PATH="${ghcObelisk.obelisk-command}/bin:$PATH"
128 PATH="${ghcObelisk.obelisk-command}/bin:$PATH"
129 export OBELISK_IMPL="${hackGet ./.}"
129 export OBELISK_IMPL="${hackGet ./.}"
130− "${justStaticExecutables' ghcObelisk.obelisk-selftest}/bin/obelisk-selftest"
130+ "${justStaticExecutables' ghcObelisk.obelisk-selftest}/bin/obelisk-selftest" "$@"
131 '';
131 '';
132 #TODO: Why can't I build ./skeleton directly as a derivation? `nix-build -E ./.` doesn't work
132 #TODO: Why can't I build ./skeleton directly as a derivation? `nix-build -E ./.` doesn't work
133 skeleton = pkgs.runCommand "skeleton" {
133 skeleton = pkgs.runCommand "skeleton" {
lib/selftest/src/Obelisk/SelfTest.hs+9−3
@@ -6,6 +6,7 @@ module Obelisk.SelfTest where
6import Control.Exception (Exception, throw, bracket)
6import Control.Exception (Exception, throw, bracket)
7import Control.Monad
7import Control.Monad
8import Control.Monad.IO.Class
8import Control.Monad.IO.Class
9+import Data.Bool (bool)
9import Data.Function (fix)
10import Data.Function (fix)
10import Data.Semigroup ((<>))
11import Data.Semigroup ((<>))
11import qualified Data.Set as Set
12import qualified Data.Set as Set
@@ -18,7 +19,7 @@ import qualified Network.HTTP.Types as HTTP
18import qualified Network.Socket as Socket
19import qualified Network.Socket as Socket
19import Shelly
20import Shelly
20import System.Environment
21import System.Environment
21−import System.Exit (ExitCode (..))
22+import System.Exit (ExitCode (..), exitWith)
22import System.Info
23import System.Info
23import System.IO (Handle, hClose)
24import System.IO (Handle, hClose)
24import System.IO.Temp
25import System.IO.Temp
@@ -35,11 +36,16 @@ data ObRunState
35
36
36main :: IO ()
37main :: IO ()
37main = do
38main = 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
38 obeliskImpl <- fromString <$> getEnv "OBELISK_IMPL"
44 obeliskImpl <- fromString <$> getEnv "OBELISK_IMPL"
39 httpManager <- HTTP.newManager HTTP.defaultManagerSettings
45 httpManager <- HTTP.newManager HTTP.defaultManagerSettings
40 withSystemTempDirectory "blank-project" $ \blankProject ->
46 withSystemTempDirectory "blank-project" $ \blankProject ->
41 hspec $ do
47 hspec $ do
42− let shelly_ = void . shelly . silently
48+ let shelly_ = void . shelly . verbosity
43
49
44 inProj :: Sh a -> IO ()
50 inProj :: Sh a -> IO ()
45 inProj = shelly_ . chdir (fromString blankProject)
51 inProj = shelly_ . chdir (fromString blankProject)
@@ -132,7 +138,7 @@ main = do
132 assertRevNE e eu
138 assertRevNE e eu
133
139
134 it "can pack and unpack plain git repos" $ do
140 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
136 let repo = toTextIgnore $ dir </> ("repo" :: String)
142 let repo = toTextIgnore $ dir </> ("repo" :: String)
137 run_ "git" ["clone", "https://git.haskell.org/packages/primitive.git", repo]
143 run_ "git" ["clone", "https://git.haskell.org/packages/primitive.git", repo]
138 origHash <- chdir (fromText repo) revParseHead
144 origHash <- chdir (fromText repo) revParseHead