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