···
15
-
import Control.Exception
16
+
import Control.Monad.IO.Class
import Data.Aeson as A hiding (Options, defaultOptions)
import qualified Data.Aeson.Key as A
import qualified Data.Aeson.KeyMap as HM
···
import qualified Data.Vector as V
import qualified Data.Yaml as Yaml
27
-
import Options.Applicative
27
+
import Options.Applicative hiding (info)
30
-
import Test.Sandwich hiding (info)
30
+
import Test.Sandwich
31
+
import UnliftIO.Exception
34
+
import UnliftIO.QSem
···
Left err -> throwIO $ userError ("Couldn't decode names and counts YAML file: " <> show err)
70
-
runSandwichWithCommandLineArgs' defaultOptions argsParser $ do
72
+
runSandwichWithCommandLineArgs' defaultOptions argsParser $ parallel $ do
describe ("Building environments for top " <> show topN <> " Julia packages") $
74
-
parallelN parallelism $
75
-
forM_ (L.take topN namesAndCounts) $ \(NameAndCount {..}) ->
76
-
testExpr args name [i|#{juliaAttr}.withPackages ["#{name}"]|]
76
+
introduce "Introduce parallel semaphore" parallelSemaphore (liftIO $ newQSem parallelism) (const $ return ()) $
78
+
forM_ (L.take topN namesAndCounts) $ \(NameAndCount {..}) ->
79
+
around "Claim semaphore" claimRunSlot $
80
+
testExpr args name [i|#{juliaAttr}.withPackages ["#{name}"]|]
miscTests :: Args -> SpecFree ctx IO ()
miscTests args@(Args {..}) = describe "Misc tests" $ do
···
96
+
describe "misc cases" $ do
97
+
testExpr args "Optimization" [iii|(#{juliaAttr}.withPackages) [ "Optimization" "OptimizationOptimJL" ]|]
testExpr :: Args -> Text -> String -> SpecFree ctx IO ()
···
let cp = proc "nix" ["build", "--impure", "--no-link", "--json", "--expr", [i|with import ../../../../. {}; #{expr}|]]
output <- readCreateProcessWithLogging cp ""
juliaPath <- case A.eitherDecode (BL8.pack output) of
101
-
Right (A.Array ((V.!? 0) -> Just (A.Object (aesonLookup "outputs" -> Just (A.Object (aesonLookup "out" -> Just (A.String t))))))) -> pure (JuliaPath ((T.unpack t) </> "bin" </> "julia"))
108
+
Right (A.Array ((V.!? 0) -> Just (A.Object (aesonLookup "outputs" -> Just (A.Object (aesonLookup "out" -> Just (A.String t))))))) -> do
109
+
info [i|built: #{t}|]
110
+
pure (JuliaPath ((T.unpack t) </> "bin" </> "julia"))
x -> expectationFailure ("Couldn't parse output: " <> show x)
getContext julia >>= flip modifyMVar_ (const $ return (Just juliaPath))
···
aesonLookup :: Text -> HM.KeyMap v -> Maybe v
aesonLookup = HM.lookup . A.fromText
126
+
claimRunSlot :: (HasParallelSemaphore ctx) => ExampleT ctx IO a -> ExampleT ctx IO ()
127
+
claimRunSlot f = do
128
+
s <- getContext parallelSemaphore
129
+
bracket_ (liftIO $ waitQSem s) (liftIO $ signalQSem s) (void f)