1 import Test
.Cabal
.Prelude
2 import qualified System
.Process
as Process
3 import Control
.Concurrent
(threadDelay
)
4 import System
.Directory
(removeFile)
5 import Control
.Exception
(catch, throwIO
)
6 import System
.IO.Error
(isDoesNotExistError)
9 This test verifies that 'cabal run' terminates its
10 child when it is killed. More generally, while we
11 use the same code path for all child processes, this
12 ensure that cabal-install cleans up after all children.
13 (That might change if 'cabal run' is changed to exec(3)
14 without forking in the future.)
19 skipIfWindows
-- test project relies on Posix
21 dir
<- fmap testCurrentDir getTestEnv
22 let runFile
= dir
</> "exe.run"
23 liftIO
$ removeFile runFile `catchNoExist`
return ()
25 cabal_raw_action
["v2-build", "exe"] (\_
-> return ())
26 r
<- fails
$ cabal_raw_action
["v2-run", "exe"] $ \cabalHandle
-> do
27 -- wait for "cabal run" to have started "exe"
28 waitFile total runFile
29 -- then kill "cabal run"
30 Process
.terminateProcess cabalHandle
32 -- "exe" should exit, and should have been interrupted before
33 -- finishing its sleep
34 assertOutputContains
"exiting" r
35 assertOutputDoesNotContain
"done sleeping" r
38 catchNoExist action handle
=
40 (\e
-> if isDoesNotExistError e
then handle
else throwIO e
)
42 | totalWait
<= 0 = error "waitFile timed out"
43 |
otherwise = readFile f `catchNoExist`
do
45 waitFile
(totalWait
- delta
) f
46 delta
= 50000 -- 0.05s
47 total
= 10000000 -- 10s
49 cabal_raw_action
:: [String] -> (Process
.ProcessHandle
-> IO ()) -> TestM Result
50 cabal_raw_action args action
= do
51 configured_prog
<- requireProgramM cabalProgram
53 r
<- liftIO
$ runAction
(testVerbosity env
)
54 (Just
(testCurrentDir env
))
56 (programPath configured_prog
)