diff options
Diffstat (limited to 'pkgs/development/julia-modules/tests/julia-top-n/app/Main.hs')
-rw-r--r-- | pkgs/development/julia-modules/tests/julia-top-n/app/Main.hs | 70 |
1 files changed, 46 insertions, 24 deletions
diff --git a/pkgs/development/julia-modules/tests/julia-top-n/app/Main.hs b/pkgs/development/julia-modules/tests/julia-top-n/app/Main.hs index 55f5fd3cfeef8..c8d935a608b83 100644 --- a/pkgs/development/julia-modules/tests/julia-top-n/app/Main.hs +++ b/pkgs/development/julia-modules/tests/julia-top-n/app/Main.hs @@ -5,6 +5,7 @@ {-# LANGUAGE LambdaCase #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE QuasiQuotes #-} +{-# LANGUAGE RankNTypes #-} {-# LANGUAGE RecordWildCards #-} {-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE ViewPatterns #-} @@ -19,7 +20,7 @@ import qualified Data.Aeson.KeyMap as HM import qualified Data.ByteString.Lazy.Char8 as BL8 import qualified Data.List as L import Data.String.Interpolate -import Data.Text as T +import Data.Text as T hiding (count) import qualified Data.Vector as V import qualified Data.Yaml as Yaml import GHC.Generics @@ -60,34 +61,55 @@ julia = Label main :: IO () main = do clo <- parseCommandLineArgs argsParser (return ()) - let Args {..} = optUserOptions clo + let args@(Args {..}) = optUserOptions clo namesAndCounts :: [NameAndCount] <- Yaml.decodeFileEither countFilePath >>= \case Left err -> throwIO $ userError ("Couldn't decode names and counts YAML file: " <> show err) Right x -> pure x - runSandwichWithCommandLineArgs' defaultOptions argsParser $ + runSandwichWithCommandLineArgs' defaultOptions argsParser $ do + miscTests args + describe ("Building environments for top " <> show topN <> " Julia packages") $ parallelN parallelism $ forM_ (L.take topN namesAndCounts) $ \(NameAndCount {..}) -> - introduce' (defaultNodeOptions { nodeOptionsVisibilityThreshold = 0 }) (T.unpack name) julia (newMVar Nothing) (const $ return ()) $ do - it "Builds" $ do - let cp = proc "nix" ["build", "--impure", "--no-link", "--json", "--expr" - , [i|with import ../../../../. {}; #{juliaAttr}.withPackages ["#{name}"]|] - ] - output <- readCreateProcessWithLogging cp "" - juliaPath <- case A.eitherDecode (BL8.pack output) of - 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")) - x -> expectationFailure ("Couldn't parse output: " <> show x) - - getContext julia >>= flip modifyMVar_ (const $ return (Just juliaPath)) - - it "Uses" $ do - getContext julia >>= readMVar >>= \case - Nothing -> expectationFailure "Build step failed." - Just (JuliaPath juliaPath) -> do - let cp = proc juliaPath ["-e", "using " <> T.unpack name] - createProcessWithLogging cp >>= waitForProcess >>= (`shouldBe` ExitSuccess) - -aesonLookup :: Text -> HM.KeyMap v -> Maybe v -aesonLookup = HM.lookup . A.fromText + testExpr args name [i|#{juliaAttr}.withPackages ["#{name}"]|] + +miscTests :: Args -> SpecFree ctx IO () +miscTests args@(Args {..}) = describe "Misc tests" $ do + describe "works for a package outside the General registry" $ do + testExpr args "HelloWorld" [iii|(#{juliaAttr}.withPackages.override { + packageOverrides = { + "HelloWorld" = pkgs.fetchFromGitHub { + owner = "codedownio"; + repo = "HelloWorld.jl"; + rev = "9b41c55df76eb87830dd3bd0b5601ee2582a37c6"; + sha256 = "sha256-G+xpMRb0RopW/xWA8KCFF/S8wuHTQbpj0qwm9CihfSc="; + }; + }; + }) [ "HelloWorld" ]|] + +-- * Low-level + +testExpr :: Args -> Text -> String -> SpecFree ctx IO () +testExpr _args name expr = do + introduce' (defaultNodeOptions { nodeOptionsVisibilityThreshold = 0 }) (T.unpack name) julia (newMVar Nothing) (const $ return ()) $ do + it "Builds" $ do + 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 + 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")) + x -> expectationFailure ("Couldn't parse output: " <> show x) + + getContext julia >>= flip modifyMVar_ (const $ return (Just juliaPath)) + + it "Uses" $ do + getContext julia >>= readMVar >>= \case + Nothing -> expectationFailure "Build step failed." + Just (JuliaPath juliaPath) -> do + let cp = proc juliaPath ["-e", "using " <> T.unpack name] + createProcessWithLogging cp >>= waitForProcess >>= (`shouldBe` ExitSuccess) + + where + aesonLookup :: Text -> HM.KeyMap v -> Maybe v + aesonLookup = HM.lookup . A.fromText |