@@ -5,12 +5,17 @@ module TestLib.TestBuilding where
5
5
import Conduit as C
6
6
import Control.Monad.Logger
7
7
import Control.Monad.Reader
8
+ import Data.Aeson as A
9
+ import Data.ByteString.Lazy.Char8 as BL8
8
10
import Data.Function
9
11
import qualified Data.List as L
12
+ import Data.String.Interpolate
13
+ import Data.Text as T
10
14
import GHC.Stack
11
15
import System.Exit
12
16
import System.FilePath
13
17
import Test.Sandwich
18
+ import TestLib.JupyterRunnerContext
14
19
import TestLib.Types
15
20
import TestLib.Util
16
21
import UnliftIO.Directory
@@ -21,22 +26,37 @@ import UnliftIO.Process
21
26
testBuild :: (
22
27
HasCallStack , MonadUnliftIO m , MonadLogger m , MonadReader context m
23
28
, HasBaseContext context , HasBootstrapNixpkgs context
24
- ) => String -> m ()
29
+ ) => String -> m FilePath
25
30
testBuild = testBuild' LevelDebug
26
31
27
32
testBuild' :: (
28
33
HasCallStack , MonadUnliftIO m , MonadLogger m , MonadReader context m
29
34
, HasBaseContext context , HasBootstrapNixpkgs context
30
- ) => LogLevel -> String -> m ()
35
+ ) => LogLevel -> String -> m FilePath
31
36
testBuild' logLevel expr = do
32
37
rootDir <- findFirstParentMatching (\ x -> doesPathExist (x </> " .git" ))
33
38
env <- getEnvWithNixPath
39
+ let cp = (proc " nix-build" [" ." , " -A" , expr, " --no-out-link" ]) {
40
+ cwd = Just rootDir
41
+ , env = Just env
42
+ }
43
+ (T. unpack . T. strip . T. pack) <$> (readCreateProcessWithLogging' logLevel cp " " )
34
44
35
- p <- createProcessWithLogging' logLevel $ (proc " nix-build" [" ." , " -A" , expr, " --no-out-link" ]) {
36
- cwd = Just rootDir
37
- , env = Just env
38
- }
39
- waitForProcess p >>= (`shouldBe` ExitSuccess )
45
+ testBuildUsingFlake :: (
46
+ HasCallStack , MonadUnliftIO m , MonadLogger m , MonadReader context m
47
+ , HasBaseContext context , HasBootstrapNixpkgs context
48
+ ) => String -> m FilePath
49
+ testBuildUsingFlake expr = do
50
+ rootDir <- findFirstParentMatching (\ x -> doesPathExist (x </> " .git" ))
51
+ let cp = (proc " nix" [" build" , expr, " --no-link" , " --json" ]) {
52
+ cwd = Just rootDir
53
+ , std_err = CreatePipe
54
+ }
55
+ out <- readCreateProcessWithLogging cp " "
56
+ case parseNixBuildJson <$> (A. eitherDecode (BL8. pack out)) of
57
+ Left err -> expectationFailure [i |Failed to parse bin paths: #{err}. JSON: #{out}|]
58
+ Right Nothing -> expectationFailure [i |Didn't find Nix output in: #{out}|]
59
+ Right (Just output) -> pure $ T. unpack output
40
60
41
61
testEval :: (
42
62
HasCallStack , MonadUnliftIO m , MonadLogger m , MonadReader context m
0 commit comments