@@ -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
36main :: IO ()
37main :: IO ()
39+ isVerbose <- getArgs >>= \case
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
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
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