Skip to content

Commit 9cc1873

Browse files
committed
Try running shutdown after all of the bazel commands.
1 parent 8d6c11c commit 9cc1873

File tree

1 file changed

+129
-123
lines changed

1 file changed

+129
-123
lines changed

rules_haskell_tests/tests/RunTests.hs

Lines changed: 129 additions & 123 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import System.Environment (lookupEnv)
1414

1515
import qualified System.Process as Process
1616
import Test.Hspec.Core.Spec (SpecM)
17-
import Test.Hspec (context, hspec, it, describe, runIO)
17+
import Test.Hspec (context, hspec, it, describe, runIO, afterAll_)
1818

1919
import BinModule (b)
2020
import GenModule (a)
@@ -23,128 +23,130 @@ import IntegrationTesting
2323

2424
main :: IO ()
2525
main = hspec $ do
26-
it "bazel test" $ do
27-
assertSuccess (bazel ["test", "//..."])
28-
29-
it "bazel test prof" $ do
30-
ghcVersion <- lookupEnv "GHC_VERSION"
31-
32-
-- In .github/workflows/workflow.yaml we specify --test_tag_filters
33-
-- -dont_test_on_darwin. However, specifiying --test_tag_filters
34-
-- -requires_dynamic here alone would override that filter. So,
35-
-- we have to duplicate that filter here.
36-
let tagFilter | os == "darwin" = "-dont_test_on_darwin,-requires_dynamic,-skip_profiling" ++ (
37-
-- skip tests for specific GHC version, see https://github.com/tweag/rules_haskell/issues/2073
38-
maybe "" (",-dont_build_on_macos_with_ghc_" ++) ghcVersion)
39-
| otherwise = "-requires_dynamic,-skip_profiling"
40-
assertSuccess (bazel ["test", "-c", "dbg", "//...", "--build_tag_filters", tagFilter, "--test_tag_filters", tagFilter])
41-
42-
it "bazel build worker" $ do
43-
assertSuccess (bazel ["build", "@rules_haskell//tools/worker:bin"])
44-
45-
describe "stack_snapshot pinning" $
46-
it "handles packages in subdirectories correctly" $ do
47-
-- NOTE Keep in sync with
48-
-- .github/workflows/workflow.yaml
49-
let withBackup filename k =
50-
withSystemTempDirectory "bazel_backup" $ \tmp_dir -> do
51-
bracket_
52-
(copyFile filename (tmp_dir </> "backup"))
53-
(copyFile (tmp_dir </> "backup") filename)
54-
k
55-
-- Test that pinning works and produces buildable targets.
56-
-- Backup the lock file to avoid unintended changes when run locally.
57-
withBackup "stackage-pinning-test_snapshot.json" $ do
58-
assertSuccess (bazel ["run", "@stackage-pinning-test-unpinned//:pin"])
59-
assertSuccess (bazel ["build", "@stackage-pinning-test//:hspec"])
60-
61-
describe "repl" $ do
62-
it "for libraries" $ do
63-
assertSuccess (bazel ["run", "//tests/repl-targets:hs-lib-bad@repl", "--", "-ignore-dot-ghci", "-e", "1 + 2"])
64-
65-
it "for binaries" $ do
66-
assertSuccess (bazel ["run", "//tests/binary-indirect-cbits:binary-indirect-cbits@repl", "--", "-ignore-dot-ghci", "-e", ":main"])
67-
68-
assertSuccess (bazel ["run", "//tests/repl-targets:hs-test-bad@repl", "--", "-ignore-dot-ghci", "-e", "1 + 2"])
69-
70-
it "with rebindable syntax" $ do
71-
let p' (stdout, _stderr) = lines stdout == ["True"]
72-
outputSatisfy p' (bazel ["run", "//tests/repl-targets:rebindable-syntax@repl", "--", "-ignore-dot-ghci", "-e", "check"])
73-
74-
it "sets classpath" $ do
75-
assertSuccess (bazel ["run", "//tests/java_classpath:java_classpath@repl", "--", "-ignore-dot-ghci", "-e", ":main"])
76-
77-
-- Test `compiler_flags` from toolchain and rule for REPL
78-
it "compiler flags" $ do
79-
assertSuccess (bazel ["run", "//tests/repl-flags:compiler_flags@repl", "--", "-ignore-dot-ghci", "-e", ":main"])
80-
81-
-- Test make variable expansion in `compiler_flags` and `repl_ghci_args`.
82-
describe "make variables" $ do
83-
it "compiler flags" $ do
84-
assertSuccess (bazel ["run", "//tests/repl-make-variables:test-compiler-flags@repl", "--", "-ignore-dot-ghci", "-e", ":main"])
85-
it "indirect repl flags" $ do
86-
assertSuccess (bazel ["run", "//tests/repl-make-variables:repl-indirect-flags", "--", "-ignore-dot-ghci", "-e", ":main"])
87-
it "direct repl flags" $ do
88-
assertSuccess (bazel ["run", "//tests/repl-make-variables:repl-direct-flags", "--", "-ignore-dot-ghci", "-e", ":main"])
89-
90-
-- Test `repl_ghci_args` from toolchain and rule for REPL
91-
it "repl flags" $ do
92-
assertSuccess (bazel ["run", "//tests/repl-flags:repl_flags@repl", "--", "-ignore-dot-ghci", "-e", "foo"])
93-
94-
it "fails on multiple definitions" $ do
95-
assertSuccess (bazel ["run", "//tests/repl-multiple-definition:repl", "--", "-ignore-dot-ghci", "-e", "final"])
96-
97-
describe "multi_repl" $ do
98-
it "loads transitive library dependencies" $ do
99-
let p' (stdout, _stderr) = lines stdout == ["tests/multi_repl/bc/src/BC/C.hs"]
100-
outputSatisfy p' (bazel ["run", "//tests/multi_repl:c_only_repl", "--", "-ignore-dot-ghci", "-e", ":show targets"])
101-
it "loads transitive source dependencies" $ do
102-
let p' (stdout, _stderr) = sort (lines stdout) == ["tests/multi_repl/a/src/A/A.hs","tests/multi_repl/bc/src/BC/B.hs","tests/multi_repl/bc/src/BC/C.hs"]
103-
outputSatisfy p' (bazel ["run", "//tests/multi_repl:c_multi_repl", "--", "-ignore-dot-ghci", "-e", ":show targets"])
104-
it "loads core library dependencies" $ do
105-
let p' (stdout, _stderr) = sort (lines stdout) == ["tests/multi_repl/core_package_dep/Lib.hs"]
106-
outputSatisfy p' (bazel ["run", "//tests/multi_repl:core_package_dep", "--", "-ignore-dot-ghci", "-e", ":show targets"])
107-
it "doesn't allow to manually load modules" $ do
108-
assertFailure (bazel ["run", "//tests/multi_repl:c_multi_repl", "--", "-ignore-dot-ghci", "-e", ":load BC.C", "-e", "c"])
109-
110-
describe "ghcide" $ do
111-
it "loads RunTests.hs" $
112-
assertSuccess (Process.proc "./.ghcide" ["tests/RunTests.hs"])
113-
it "loads module with module dependency" $
114-
assertSuccess (Process.proc "./.ghcide" ["tests/binary-with-lib/Main.hs"])
115-
116-
describe "failures" $ do
117-
-- Make sure not to include haskell_repl (@repl) or alias (-repl) targets
118-
-- in the query. Those would not fail under bazel test.
119-
all_failure_tests <- bazelQuery "kind('haskell_library|haskell_binary|haskell_test', //tests/failures/...) intersect attr('tags', 'manual', //tests/failures/...)"
120-
121-
for_ all_failure_tests $ \test -> do
122-
it test $ do
123-
assertFailure (bazel ["build", test])
124-
125-
context "known issues" $ do
126-
it "haskell_doc fails with plugins #1549" $
127-
-- https://github.com/tweag/rules_haskell/issues/1549
128-
assertFailure (bazel ["build", "//tests/haddock-with-plugin"])
129-
it "transitive re-exports do not work #1145" $
130-
-- https://github.com/tweag/rules_haskell/issues/1145
131-
assertFailure (bazel ["build", "//tests/package-reexport-transitive"])
132-
it "doctest failure with foreign import #1559" $
133-
-- https://github.com/tweag/rules_haskell/issues/1559
134-
assertFailure (bazel ["build", "//tests/haskell_doctest_ffi_1559:doctest-a"])
135-
136-
-- Test that the repl still works if we shadow some Prelude functions
137-
it "repl name shadowing" $ do
138-
let p (stdout, stderr) = not $ any ("error" `isInfixOf`) [stdout, stderr]
139-
outputSatisfy p (bazel ["run", "//tests/repl-name-conflicts:lib@repl", "--", "-ignore-dot-ghci", "-e", "stdin"])
140-
141-
it "Repl works with remote_download_toplevel" $ do
142-
let p (stdout, stderr) = not $ any ("error" `isInfixOf`) [stdout, stderr]
143-
withSystemTempDirectory "bazel_disk_cache" $ \tmp_disk_cache -> do
144-
assertSuccess $ bazel ["run", "//tests/multi_repl:c_only_repl", "--disk_cache=" <> tmp_disk_cache]
145-
assertSuccess $ bazel ["clean"]
146-
outputSatisfy p
147-
(bazel ["run", "//tests/multi_repl:c_only_repl", "--disk_cache=" <> tmp_disk_cache, "--remote_download_toplevel"])
26+
afterAll_ shutdownBazel $
27+
describe "root workspace" $ do
28+
it "bazel test" $ do
29+
assertSuccess (bazel ["test", "//..."])
30+
31+
it "bazel test prof" $ do
32+
ghcVersion <- lookupEnv "GHC_VERSION"
33+
34+
-- In .github/workflows/workflow.yaml we specify --test_tag_filters
35+
-- -dont_test_on_darwin. However, specifiying --test_tag_filters
36+
-- -requires_dynamic here alone would override that filter. So,
37+
-- we have to duplicate that filter here.
38+
let tagFilter | os == "darwin" = "-dont_test_on_darwin,-requires_dynamic,-skip_profiling" ++ (
39+
-- skip tests for specific GHC version, see https://github.com/tweag/rules_haskell/issues/2073
40+
maybe "" (",-dont_build_on_macos_with_ghc_" ++) ghcVersion)
41+
| otherwise = "-requires_dynamic,-skip_profiling"
42+
assertSuccess (bazel ["test", "-c", "dbg", "//...", "--build_tag_filters", tagFilter, "--test_tag_filters", tagFilter])
43+
44+
it "bazel build worker" $ do
45+
assertSuccess (bazel ["build", "@rules_haskell//tools/worker:bin"])
46+
47+
describe "stack_snapshot pinning" $
48+
it "handles packages in subdirectories correctly" $ do
49+
-- NOTE Keep in sync with
50+
-- .github/workflows/workflow.yaml
51+
let withBackup filename k =
52+
withSystemTempDirectory "bazel_backup" $ \tmp_dir -> do
53+
bracket_
54+
(copyFile filename (tmp_dir </> "backup"))
55+
(copyFile (tmp_dir </> "backup") filename)
56+
k
57+
-- Test that pinning works and produces buildable targets.
58+
-- Backup the lock file to avoid unintended changes when run locally.
59+
withBackup "stackage-pinning-test_snapshot.json" $ do
60+
assertSuccess (bazel ["run", "@stackage-pinning-test-unpinned//:pin"])
61+
assertSuccess (bazel ["build", "@stackage-pinning-test//:hspec"])
62+
63+
describe "repl" $ do
64+
it "for libraries" $ do
65+
assertSuccess (bazel ["run", "//tests/repl-targets:hs-lib-bad@repl", "--", "-ignore-dot-ghci", "-e", "1 + 2"])
66+
67+
it "for binaries" $ do
68+
assertSuccess (bazel ["run", "//tests/binary-indirect-cbits:binary-indirect-cbits@repl", "--", "-ignore-dot-ghci", "-e", ":main"])
69+
70+
assertSuccess (bazel ["run", "//tests/repl-targets:hs-test-bad@repl", "--", "-ignore-dot-ghci", "-e", "1 + 2"])
71+
72+
it "with rebindable syntax" $ do
73+
let p' (stdout, _stderr) = lines stdout == ["True"]
74+
outputSatisfy p' (bazel ["run", "//tests/repl-targets:rebindable-syntax@repl", "--", "-ignore-dot-ghci", "-e", "check"])
75+
76+
it "sets classpath" $ do
77+
assertSuccess (bazel ["run", "//tests/java_classpath:java_classpath@repl", "--", "-ignore-dot-ghci", "-e", ":main"])
78+
79+
-- Test `compiler_flags` from toolchain and rule for REPL
80+
it "compiler flags" $ do
81+
assertSuccess (bazel ["run", "//tests/repl-flags:compiler_flags@repl", "--", "-ignore-dot-ghci", "-e", ":main"])
82+
83+
-- Test make variable expansion in `compiler_flags` and `repl_ghci_args`.
84+
describe "make variables" $ do
85+
it "compiler flags" $ do
86+
assertSuccess (bazel ["run", "//tests/repl-make-variables:test-compiler-flags@repl", "--", "-ignore-dot-ghci", "-e", ":main"])
87+
it "indirect repl flags" $ do
88+
assertSuccess (bazel ["run", "//tests/repl-make-variables:repl-indirect-flags", "--", "-ignore-dot-ghci", "-e", ":main"])
89+
it "direct repl flags" $ do
90+
assertSuccess (bazel ["run", "//tests/repl-make-variables:repl-direct-flags", "--", "-ignore-dot-ghci", "-e", ":main"])
91+
92+
-- Test `repl_ghci_args` from toolchain and rule for REPL
93+
it "repl flags" $ do
94+
assertSuccess (bazel ["run", "//tests/repl-flags:repl_flags@repl", "--", "-ignore-dot-ghci", "-e", "foo"])
95+
96+
it "fails on multiple definitions" $ do
97+
assertSuccess (bazel ["run", "//tests/repl-multiple-definition:repl", "--", "-ignore-dot-ghci", "-e", "final"])
98+
99+
describe "multi_repl" $ do
100+
it "loads transitive library dependencies" $ do
101+
let p' (stdout, _stderr) = lines stdout == ["tests/multi_repl/bc/src/BC/C.hs"]
102+
outputSatisfy p' (bazel ["run", "//tests/multi_repl:c_only_repl", "--", "-ignore-dot-ghci", "-e", ":show targets"])
103+
it "loads transitive source dependencies" $ do
104+
let p' (stdout, _stderr) = sort (lines stdout) == ["tests/multi_repl/a/src/A/A.hs","tests/multi_repl/bc/src/BC/B.hs","tests/multi_repl/bc/src/BC/C.hs"]
105+
outputSatisfy p' (bazel ["run", "//tests/multi_repl:c_multi_repl", "--", "-ignore-dot-ghci", "-e", ":show targets"])
106+
it "loads core library dependencies" $ do
107+
let p' (stdout, _stderr) = sort (lines stdout) == ["tests/multi_repl/core_package_dep/Lib.hs"]
108+
outputSatisfy p' (bazel ["run", "//tests/multi_repl:core_package_dep", "--", "-ignore-dot-ghci", "-e", ":show targets"])
109+
it "doesn't allow to manually load modules" $ do
110+
assertFailure (bazel ["run", "//tests/multi_repl:c_multi_repl", "--", "-ignore-dot-ghci", "-e", ":load BC.C", "-e", "c"])
111+
112+
describe "ghcide" $ do
113+
it "loads RunTests.hs" $
114+
assertSuccess (Process.proc "./.ghcide" ["tests/RunTests.hs"])
115+
it "loads module with module dependency" $
116+
assertSuccess (Process.proc "./.ghcide" ["tests/binary-with-lib/Main.hs"])
117+
118+
describe "failures" $ do
119+
-- Make sure not to include haskell_repl (@repl) or alias (-repl) targets
120+
-- in the query. Those would not fail under bazel test.
121+
all_failure_tests <- bazelQuery "kind('haskell_library|haskell_binary|haskell_test', //tests/failures/...) intersect attr('tags', 'manual', //tests/failures/...)"
122+
123+
for_ all_failure_tests $ \test -> do
124+
it test $ do
125+
assertFailure (bazel ["build", test])
126+
127+
context "known issues" $ do
128+
it "haskell_doc fails with plugins #1549" $
129+
-- https://github.com/tweag/rules_haskell/issues/1549
130+
assertFailure (bazel ["build", "//tests/haddock-with-plugin"])
131+
it "transitive re-exports do not work #1145" $
132+
-- https://github.com/tweag/rules_haskell/issues/1145
133+
assertFailure (bazel ["build", "//tests/package-reexport-transitive"])
134+
it "doctest failure with foreign import #1559" $
135+
-- https://github.com/tweag/rules_haskell/issues/1559
136+
assertFailure (bazel ["build", "//tests/haskell_doctest_ffi_1559:doctest-a"])
137+
138+
-- Test that the repl still works if we shadow some Prelude functions
139+
it "repl name shadowing" $ do
140+
let p (stdout, stderr) = not $ any ("error" `isInfixOf`) [stdout, stderr]
141+
outputSatisfy p (bazel ["run", "//tests/repl-name-conflicts:lib@repl", "--", "-ignore-dot-ghci", "-e", "stdin"])
142+
143+
it "Repl works with remote_download_toplevel" $ do
144+
let p (stdout, stderr) = not $ any ("error" `isInfixOf`) [stdout, stderr]
145+
withSystemTempDirectory "bazel_disk_cache" $ \tmp_disk_cache -> do
146+
assertSuccess $ bazel ["run", "//tests/multi_repl:c_only_repl", "--disk_cache=" <> tmp_disk_cache]
147+
assertSuccess $ bazel ["clean"]
148+
outputSatisfy p
149+
(bazel ["run", "//tests/multi_repl:c_only_repl", "--disk_cache=" <> tmp_disk_cache, "--remote_download_toplevel"])
148150

149151
it "bazel test examples" $ do
150152
assertSuccess $ (bazel ["build", "//..."]) { Process.cwd = Just "../examples" }
@@ -167,6 +169,10 @@ bazel args = Process.proc "bazel" args
167169
bazelQuery :: String -> SpecM a [String]
168170
bazelQuery q = lines <$> runIO (Process.readProcess "bazel" ["query", q] "")
169171

172+
shutdownBazel :: IO ()
173+
shutdownBazel = do
174+
assertSuccess (bazel ["shutdown"])
175+
pure ()
170176

171177
-- Generated dependencies for testing the ghcide support
172178
_ghciIDE :: Int

0 commit comments

Comments
 (0)