Skip to content

Commit

Permalink
Build jupyter runner once (#55)
Browse files Browse the repository at this point in the history
* Only build jupyter runner once at the beginning of tests

This should be more efficent. Also, saw a failure in a random test where the Nix build failed for some reason.

* Fix test build
  • Loading branch information
thomasjm authored Nov 29, 2023
1 parent 34d9d49 commit 392113c
Show file tree
Hide file tree
Showing 22 changed files with 99 additions and 70 deletions.
6 changes: 4 additions & 2 deletions tests/app/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ module Main where
import Test.Sandwich

import qualified Spec.Tests as Tests
import TestLib.Types

tests :: TopSpecWithOptions' Tests.SpecialOptions

tests :: TopSpecWithOptions' SpecialOptions
tests = Tests.tests


main :: IO ()
main = runSandwichWithCommandLineArgs' defaultOptions Tests.specialOptions tests
main = runSandwichWithCommandLineArgs' defaultOptions specialOptions tests
29 changes: 14 additions & 15 deletions tests/app/Spec/Tests.hs
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,24 @@ import Control.Monad.IO.Class
import Control.Monad.Trans.Control (MonadBaseControl)
import Options.Applicative hiding (action)
import Test.Sandwich
import TestLib.Types
import TestLib.JupyterRunnerContext

#insert_test_imports


tests :: TopSpecWithOptions' SpecialOptions
tests = introduce' (defaultNodeOptions { nodeOptionsCreateFolder = False }) "Introduce parallel semaphore" parallelSemaphore getQSem (const $ return ()) $ $(getSpecFromFolder $ defaultGetSpecFromFolderOptions {
getSpecCombiner = 'describeParallel
, getSpecIndividualSpecHooks = 'withParallelSemaphore
, getSpecWarnOnParseError = NoWarnOnParseError
})
tests :: forall context. (
HasBaseContext context
, HasCommandLineOptions context SpecialOptions
) => SpecFree context IO ()
tests =
introduceJupyterRunner $
introduce' (defaultNodeOptions { nodeOptionsCreateFolder = False }) "Introduce parallel semaphore" parallelSemaphore getQSem (const $ return ()) $
$(getSpecFromFolder $ defaultGetSpecFromFolderOptions {
getSpecCombiner = 'describeParallel
, getSpecIndividualSpecHooks = 'withParallelSemaphore
, getSpecWarnOnParseError = NoWarnOnParseError
})
where
getQSem = getCommandLineOptions >>= liftIO . newQSem . getParallelism

Expand All @@ -31,15 +39,6 @@ tests = introduce' (defaultNodeOptions { nodeOptionsCreateFolder = False }) "Int
getParallelism :: CommandLineOptions SpecialOptions -> Int
getParallelism = optTestParallelism . optUserOptions

data SpecialOptions = SpecialOptions {
optTestParallelism :: Int
}

specialOptions :: Parser SpecialOptions
specialOptions = SpecialOptions
<$> option auto (long "test-parallelism" <> short 'n' <> showDefault <> help "Test parallelism" <> value 4 <> metavar "INT")


describeParallel :: (
MonadBaseControl IO m, MonadIO m, MonadMask m, HasParallelSemaphore context
) => String -> SpecFree context m () -> SpecFree context m ()
Expand Down
5 changes: 3 additions & 2 deletions tests/app/Spec/Tests/Bash.hs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import TestLib.LSP
import TestLib.NixEnvironmentContext
import TestLib.NixTypes
import TestLib.TestSearchers
import TestLib.Types
import TestLib.Util


Expand All @@ -28,7 +29,7 @@ kernelSpec = NixKernelSpec {
]
}

tests :: TopSpec
tests :: LanguageSpec
tests = describe "Bash" $ introduceNixEnvironment [kernelSpec] [] "Bash" $ introduceJupyterRunner $ do
testKernelSearchersBuild "bash"

Expand All @@ -44,4 +45,4 @@ tests = describe "Bash" $ introduceNixEnvironment [kernelSpec] [] "Bash" $ intro
]

main :: IO ()
main = runSandwichWithCommandLineArgs Sandwich.defaultOptions tests
main = jupyterMain tests
5 changes: 3 additions & 2 deletions tests/app/Spec/Tests/Clojure.hs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import TestLib.LSP
import TestLib.NixEnvironmentContext
import TestLib.NixTypes
import TestLib.TestSearchers
import TestLib.Types


kernelSpec :: NixKernelSpec
Expand All @@ -24,7 +25,7 @@ kernelSpec = NixKernelSpec {
, nixKernelSettings = Nothing
}

tests :: TopSpec
tests :: LanguageSpec
tests = describe "Clojure" $ introduceNixEnvironment [kernelSpec] [] "Clojure" $ introduceJupyterRunner $ do
testKernelSearchersBuild "clojure"

Expand All @@ -35,4 +36,4 @@ tests = describe "Clojure" $ introduceNixEnvironment [kernelSpec] [] "Clojure" $


main :: IO ()
main = runSandwichWithCommandLineArgs Sandwich.defaultOptions tests
main = jupyterMain tests
5 changes: 3 additions & 2 deletions tests/app/Spec/Tests/Coq.hs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import TestLib.JupyterRunnerContext
import TestLib.NixEnvironmentContext
import TestLib.NixTypes
import TestLib.TestSearchers
import TestLib.Types


kernelSpec :: NixKernelSpec
Expand All @@ -24,7 +25,7 @@ kernelSpec = NixKernelSpec {
, nixKernelSettings = Nothing
}

tests :: TopSpec
tests :: LanguageSpec
tests = describe "Coq" $ introduceNixEnvironment [kernelSpec] [] "Coq" $ introduceJupyterRunner $ do
testKernelSearchersBuild "coq"

Expand All @@ -44,4 +45,4 @@ tests = describe "Coq" $ introduceNixEnvironment [kernelSpec] [] "Coq" $ introdu


main :: IO ()
main = runSandwichWithCommandLineArgs Sandwich.defaultOptions tests
main = jupyterMain tests
7 changes: 4 additions & 3 deletions tests/app/Spec/Tests/Cpp.hs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ import TestLib.JupyterRunnerContext
import TestLib.NixEnvironmentContext
import TestLib.NixTypes
import TestLib.TestSearchers
import TestLib.Types


tests :: TopSpec
tests :: LanguageSpec
tests = describe "C++" $ parallel $ do
-- tests' "cpp98"
tests' "cpp11"
Expand All @@ -21,7 +22,7 @@ tests = describe "C++" $ parallel $ do
tests' "cpp20"
tests' "cpp23"

tests' :: Text -> TopSpec
tests' :: Text -> LanguageSpec
tests' kernelName = describe [i|C++ (#{kernelName})|] $ introduceNixEnvironment [kernelSpec kernelName] [] "C++" $ introduceJupyterRunner $ do
testKernelSearchersBuild kernelName

Expand All @@ -43,4 +44,4 @@ kernelSpec kernelName = NixKernelSpec {
}

main :: IO ()
main = runSandwichWithCommandLineArgs Sandwich.defaultOptions tests
main = jupyterMain tests
5 changes: 3 additions & 2 deletions tests/app/Spec/Tests/Go.hs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import TestLib.LSP
import TestLib.NixEnvironmentContext
import TestLib.NixTypes
import TestLib.TestSearchers
import TestLib.Types


kernelSpec :: NixKernelSpec
Expand All @@ -24,7 +25,7 @@ kernelSpec = NixKernelSpec {
, nixKernelSettings = Nothing
}

tests :: TopSpec
tests :: LanguageSpec
tests = describe "Go" $ introduceNixEnvironment [kernelSpec] [] "Go" $ introduceJupyterRunner $ do
testKernelSearchersBuild "go"

Expand All @@ -39,4 +40,4 @@ tests = describe "Go" $ introduceNixEnvironment [kernelSpec] [] "Go" $ introduce
assertDiagnosticRanges diagnostics [(Range (Position 3 16) (Position 3 19), Just (InR "UndeclaredName"))]

main :: IO ()
main = runSandwichWithCommandLineArgs Sandwich.defaultOptions tests
main = jupyterMain tests
9 changes: 5 additions & 4 deletions tests/app/Spec/Tests/Haskell.hs
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ import TestLib.JupyterRunnerContext
import TestLib.JupyterTypes
import TestLib.NixEnvironmentContext
import TestLib.TestSearchers
import TestLib.Types


tests :: TopSpec
tests :: LanguageSpec
tests = do
-- See languages/haskell/default.nix for details on what's available

Expand All @@ -34,9 +35,9 @@ tests = do
haskellCommonTests "haskell-ghc96"


haskellCommonTests :: Text -> TopSpec
haskellCommonTests :: Text -> LanguageSpec
haskellCommonTests lang = do
describe [i|Haskell #{lang} with hlint output|] $ introduceNixEnvironment [kernelSpecWithHlintOutput lang] [] "Haskell" $ introduceJupyterRunner $ do
describe [i|Haskell #{lang} with hlint output|] $ introduceNixEnvironment [kernelSpecWithHlintOutput lang] [] "Haskell" $ do
describe "Kernel" $ do
-- With the setting turned on, we should get hlint output
itHasDisplayTexts lang etaExpandCode [Just (A.Array $ V.fromList [
Expand Down Expand Up @@ -69,4 +70,4 @@ haskellCommonTests lang = do


main :: IO ()
main = runSandwichWithCommandLineArgs Sandwich.defaultOptions tests
main = jupyterMain tests
7 changes: 4 additions & 3 deletions tests/app/Spec/Tests/Julia.hs
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,17 @@ import TestLib.LSP
import TestLib.NixEnvironmentContext
import TestLib.NixTypes
import TestLib.TestSearchers
import TestLib.Types
import TestLib.Util


tests :: TopSpec
tests :: LanguageSpec
tests = do
juliaTests "julia16"
juliaTests "julia18"
juliaTests "julia19"

juliaTests :: Text -> TopSpec
juliaTests :: Text -> LanguageSpec
juliaTests lang = describe [i|Julia (#{lang})|] $ introduceNixEnvironment [kernelSpec lang] [] [i|Julia (#{lang})|] $ introduceJupyterRunner $ do
testKernelSearchersNonempty lang

Expand Down Expand Up @@ -79,4 +80,4 @@ kernelSpec lang = NixKernelSpec {
}

main :: IO ()
main = runSandwichWithCommandLineArgs Sandwich.defaultOptions tests
main = jupyterMain tests
5 changes: 3 additions & 2 deletions tests/app/Spec/Tests/Octave.hs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import TestLib.JupyterRunnerContext
import TestLib.NixEnvironmentContext
import TestLib.NixTypes
import TestLib.TestSearchers
import TestLib.Types


kernelSpec :: NixKernelSpec
Expand All @@ -22,12 +23,12 @@ kernelSpec = NixKernelSpec {
, nixKernelSettings = Nothing
}

tests :: TopSpec
tests :: LanguageSpec
tests = describe "Octave" $ introduceNixEnvironment [kernelSpec] [] "Octave" $ introduceJupyterRunner $ do
testKernelSearchersBuild "octave"

testKernelStdout "octave" [__i|printf('%s', 'hi')|] "hi"


main :: IO ()
main = runSandwichWithCommandLineArgs Sandwich.defaultOptions tests
main = jupyterMain tests
5 changes: 3 additions & 2 deletions tests/app/Spec/Tests/Postgres.hs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import TestLib.JupyterTypes
import TestLib.NixEnvironmentContext
import TestLib.NixTypes
import TestLib.TestSearchers
import TestLib.Types


kernelSpec :: NixKernelSpec
Expand All @@ -29,7 +30,7 @@ kernelSpec = NixKernelSpec {
, nixKernelSettings = Nothing
}

tests :: TopSpec
tests :: LanguageSpec
tests = describe "Postgres tests" $ introduceNixEnvironment [kernelSpec] [] "Postgres" $ introduceJupyterRunner $ do
testKernelSearchersBuild "postgres"

Expand All @@ -53,4 +54,4 @@ tests = describe "Postgres tests" $ introduceNixEnvironment [kernelSpec] [] "Pos
v -> expectationFailure [i|Expected single map with text/plain. Got: #{v}|]

main :: IO ()
main = runSandwichWithCommandLineArgs Sandwich.defaultOptions tests
main = jupyterMain tests
7 changes: 4 additions & 3 deletions tests/app/Spec/Tests/Python.hs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@ import TestLib.LSP
import TestLib.NixEnvironmentContext
import TestLib.NixTypes
import TestLib.TestSearchers
import TestLib.Types
import TestLib.Util


tests :: TopSpec
tests :: LanguageSpec
tests = describe "Python" $ parallel $ do
tests' "python3"

Expand All @@ -25,7 +26,7 @@ tests = describe "Python" $ parallel $ do
-- tests' "pypy3"


tests' :: Text -> TopSpec
tests' :: Text -> LanguageSpec
tests' kernelName = describe [i|Python (#{kernelName})|] $ introduceNixEnvironment [kernelSpec kernelName] [] "Python 3" $ introduceJupyterRunner $ do
testKernelSearchersNonempty kernelName

Expand Down Expand Up @@ -86,4 +87,4 @@ kernelSpec kernelName = NixKernelSpec {


main :: IO ()
main = runSandwichWithCommandLineArgs Sandwich.defaultOptions tests
main = jupyterMain tests
5 changes: 3 additions & 2 deletions tests/app/Spec/Tests/R.hs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import TestLib.JupyterRunnerContext
import TestLib.NixEnvironmentContext
import TestLib.NixTypes
import TestLib.TestSearchers
import TestLib.Types


kernelSpec :: NixKernelSpec
Expand All @@ -22,7 +23,7 @@ kernelSpec = NixKernelSpec {
, nixKernelSettings = Nothing
}

tests :: TopSpec
tests :: LanguageSpec
tests = describe "R" $ introduceNixEnvironment [kernelSpec] [] "R" $ introduceJupyterRunner $ do
testKernelSearchersNonempty "R"

Expand All @@ -31,4 +32,4 @@ tests = describe "R" $ introduceNixEnvironment [kernelSpec] [] "R" $ introduceJu


main :: IO ()
main = runSandwichWithCommandLineArgs Sandwich.defaultOptions tests
main = jupyterMain tests
7 changes: 4 additions & 3 deletions tests/app/Spec/Tests/Ruby.hs
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,19 @@ import TestLib.LSP
import TestLib.NixEnvironmentContext
import TestLib.NixTypes
import TestLib.TestSearchers
import TestLib.Types
import TestLib.Util (aesonFromList)


tests :: TopSpec
tests :: LanguageSpec
tests = describe "Ruby" $ do
kernelTests "ruby"
kernelTests "ruby_3_0"
kernelTests "ruby_3_1"
kernelTests "ruby_3_2"


kernelTests :: Text -> TopSpec
kernelTests :: Text -> LanguageSpec
kernelTests lang = do
describe (T.unpack lang) $ introduceNixEnvironment [kernelSpec lang] [] [i|Ruby (#{lang})|] $ introduceJupyterRunner $ do
testKernelSearchersNonempty lang
Expand All @@ -54,4 +55,4 @@ kernelSpec lang = NixKernelSpec {
}

main :: IO ()
main = runSandwichWithCommandLineArgs Sandwich.defaultOptions tests
main = jupyterMain tests
5 changes: 3 additions & 2 deletions tests/app/Spec/Tests/Rust.hs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@ import TestLib.JupyterRunnerContext
import TestLib.NixEnvironmentContext
import TestLib.NixTypes
import TestLib.TestSearchers
import TestLib.Types
import TestLib.Util


tests :: TopSpec
tests :: LanguageSpec
tests = describe "Rust" $ introduceNixEnvironment [kernelSpec] [] "Rust" $ introduceJupyterRunner $ do
testKernelSearchersBuild "rust"

Expand Down Expand Up @@ -57,4 +58,4 @@ kernelSpec = NixKernelSpec {
}

main :: IO ()
main = runSandwichWithCommandLineArgs Sandwich.defaultOptions tests
main = jupyterMain tests
2 changes: 0 additions & 2 deletions tests/app/Spec/Tests/Shells/Zsh.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
module Spec.Tests.Shells.Zsh (tests) where

import Data.String.Interpolate
import Language.LSP.Protocol.Types
import Test.Sandwich as Sandwich
import TestLib.LSP
import TestLib.NixEnvironmentContext
import TestLib.NixTypes
import TestLib.Types
Expand Down
Loading

0 comments on commit 392113c

Please sign in to comment.