Skip to content

Commit

Permalink
Fixes to the test suite
Browse files Browse the repository at this point in the history
* The new process library reports signals as negative exit codes.
* Use --no-require-sandbox when calling cabal to install a test pkg.

There is still a test failing in 7.8 though, not sure if that's a bug in the
test suite or in ide-backend itself.
  • Loading branch information
edsko committed Mar 10, 2015
1 parent 1849924 commit 146b997
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 35 deletions.
27 changes: 14 additions & 13 deletions TestSuite/TestSuite/State.hs
Original file line number Diff line number Diff line change
Expand Up @@ -630,19 +630,12 @@ withInstalledPackage env pkgDir act =
-- This should not be used in isolation because it changes test global state.
packageInstall :: TestSuiteEnv -> FilePath -> IO ()
packageInstall env@TestSuiteEnv{..} pkgDir = do
cabalExe <- findExe env "cabal"
oldEnv <- System.Environment.getEnvironment
let oldEnvMap = Map.fromList oldEnv
adjustPATH oldPATH = extraPathDirs ++ ":" ++ oldPATH
newEnvMap = Map.adjust adjustPATH "PATH" oldEnvMap
newEnv = Map.toList newEnvMap
forM_ [ ["clean"]
, ["configure", "--package-db=" ++ packageDb, "--disable-library-profiling"]
, ["build"]
, ["copy"]
, ["register"]
] $ \cmd -> do
let opts = cmd ++ ["-v0"]
cabalExe <- findExe env "cabal"
oldEnv <- System.Environment.getEnvironment
let oldEnvMap = Map.fromList oldEnv
adjustPATH oldPATH = extraPathDirs ++ ":" ++ oldPATH
newEnvMap = Map.adjust adjustPATH "PATH" oldEnvMap
newEnv = Map.toList newEnvMap
(_,_,_,r2) <- createProcess (proc cabalExe opts)
{ cwd = Just pkgDir
, env = Just newEnv
Expand All @@ -660,6 +653,14 @@ packageInstall env@TestSuiteEnv{..} pkgDir = do
GHC_7_8 -> testSuiteConfigPackageDb78 testSuiteEnvConfig
GHC_7_10 -> testSuiteConfigPackageDb710 testSuiteEnvConfig

opts = [ "--no-require-sandbox"
, "install"
, "--package-db=" ++ packageDb
, "--disable-library-profiling"
, "-v0"
]


-- | Used only in the definition of 'withInstalledPackage'
--
-- This should not be used in isolation because it changes test global state.
Expand Down
8 changes: 4 additions & 4 deletions TestSuite/TestSuite/Tests/API.hs
Original file line number Diff line number Diff line change
Expand Up @@ -298,10 +298,10 @@ test_runWait_AfterTermination_Int env = withAvailableSession env $ \session -> d
interrupt runActionsExe
resOrEx <- runWait runActionsExe
case resOrEx of
Right result -> assertEqual "after runExe" (ExitFailure 2) result
Right result -> assertEqual "after runExe" (ExitFailure (-2)) result -- SIGINT
_ -> assertFailure $ "Unexpected run result: " ++ show resOrEx
result' <- runWait runActionsExe
assertEqual "" result' (Right $ ExitFailure 2)
assertEqual "" result' (Right $ ExitFailure (-2)) -- SIGINT
where
upd = (updateCodeGeneration True)
<> (updateSourceFile "M.hs" . L.unlines $
Expand Down Expand Up @@ -345,10 +345,10 @@ test_runWait_AfterTermination_Restarted env = withAvailableSession env $ \sessio
interrupt runActionsExe
resOrEx <- runWait runActionsExe
case resOrEx of
Right result -> assertEqual "after runExe" (ExitFailure 2) result
Right result -> assertEqual "after runExe" (ExitFailure (-2)) result -- SIGKILL
_ -> assertFailure $ "Unexpected run result: " ++ show resOrEx
result' <- runWait runActionsExe
assertEqual "" result' (Right $ ExitFailure 2)
assertEqual "" result' (Right $ ExitFailure (-2)) -- SIGKILL
where
upd = (updateCodeGeneration True)
<> (updateSourceFile "M.hs" . L.unlines $
Expand Down
2 changes: 1 addition & 1 deletion TestSuite/TestSuite/Tests/Integration.hs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ test_dontLoseFilesInRestart session originalUpdate lm = do
assertNoErrors session
updateSessionD session update3 0 -- 0: nothing to generate code from
exitCodeBefore <- getGhcExitCode serverBefore
assertEqual "exitCodeBefore" (Just ExitSuccess) exitCodeBefore
assertEqual "exitCodeBefore" (Just (ExitFailure (-9))) exitCodeBefore -- SIGKILL
where
update = originalUpdate <> updateCodeGeneration True
update2 = mconcat $ map updateSourceFileDelete lm
Expand Down
6 changes: 3 additions & 3 deletions TestSuite/TestSuite/Tests/InterruptRunExe.hs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ testAfter1sec env = withAvailableSession env $ \session -> do
interrupt runActionsExe
resOrEx <- runWait runActionsExe
case resOrEx of
Right result -> assertEqual "after runExe" (ExitFailure 2) result
Right result -> assertEqual "after runExe" (ExitFailure (-2)) result -- SIGINT
_ -> assertFailure $ "Unexpected run result: " ++ show resOrEx
where
upd = (updateCodeGeneration True)
Expand All @@ -56,7 +56,7 @@ testImmediately env = withAvailableSession env $ \session -> do
interrupt runActionsExe
resOrEx <- runWait runActionsExe
case resOrEx of
Right result -> assertEqual "after runExe" (ExitFailure 2) result
Right result -> assertEqual "after runExe" (ExitFailure (-2)) result -- SIGINT
_ -> assertFailure $ "Unexpected run result: " ++ show resOrEx
where
upd = (updateCodeGeneration True)
Expand Down Expand Up @@ -103,7 +103,7 @@ testManyTimes env = withAvailableSession env $ \session -> do
runActionsExe <- runExe session m
interrupt runActionsExe
(_output, result) <- runWaitAll runActionsExe
assertEqual "" (ExitFailure 2) result
assertEqual "" (ExitFailure (-2)) result -- SIGINT

-- This doesn't work, because the updateStdoutBufferMode above
-- is void for runExe.
Expand Down
13 changes: 6 additions & 7 deletions TestSuite/TestSuite/Tests/SessionRestart.hs
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,14 @@ test_WellBehaved env =
, "import Control.Concurrent (threadDelay)"
, "loop :: IO ()"
, "loop = threadDelay 10000 >> loop"
] ExitSuccess
] (ExitFailure (-9)) -- SIGKILL

test_Blackhole_DontSwallow :: TestSuiteEnv -> Assertion
test_Blackhole_DontSwallow env =
restartRun env [ "module M where"
, "loop :: IO ()"
, "loop = loop"
] ExitSuccess

] (ExitFailure (-9)) -- SIGKILL

test_Swallow :: TestSuiteEnv -> Assertion
test_Swallow env =
Expand All @@ -52,7 +51,7 @@ test_Swallow env =
, ""
, "loop :: IO ()"
, "loop = Ex.catch innerLoop $ \\e -> let _ = e :: Ex.SomeException in loop"
] ExitSuccess
] (ExitFailure (-9)) -- SIGKILL

test_Blackhole_Swallow :: TestSuiteEnv -> Assertion
test_Blackhole_Swallow env =
Expand All @@ -66,7 +65,7 @@ test_Blackhole_Swallow env =
, ""
, "loop :: IO ()"
, "loop = Ex.catch innerLoop $ \\e -> let _ = e :: Ex.SomeException in loop"
] ExitSuccess
] (ExitFailure (-9)) -- SIGKILL

test_Evil :: TestSuiteEnv -> Assertion
test_Evil env =
Expand All @@ -76,7 +75,7 @@ test_Evil env =
, ""
, "loop :: IO ()"
, "loop = Ex.catch loop $ \\e -> let _ = e :: Ex.SomeException in loop"
] ExitSuccess
] (ExitFailure (-9)) -- SIGKILL

test_EnvRestored :: TestSuiteEnv -> Assertion
test_EnvRestored env = withAvailableSession env $ \session -> do
Expand Down Expand Up @@ -112,7 +111,7 @@ test_EnvRestored env = withAvailableSession env $ \session -> do

-- Make sure the old server exited
exitCodeBefore <- getGhcExitCode serverBefore
assertEqual "exitCodeBefore" (Just ExitSuccess) exitCodeBefore
assertEqual "exitCodeBefore" (Just (ExitFailure (-9))) exitCodeBefore

-- Make sure the new server is still alive
serverAfter <- getGhcServer session
Expand Down
4 changes: 2 additions & 2 deletions TestSuite/TestSuite/Tests/StdIO.hs
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ test_Interleaved env = withAvailableSession env $ \session -> do
do interrupt runActionsExe
resOrEx <- runWait runActionsExe
case resOrEx of
Right result -> assertEqual "after runExe" (ExitFailure 2) result
Right result -> assertEqual "after runExe" (ExitFailure (-2)) result -- SIGINT
_ -> assertFailure $ "Unexpected run result: " ++ show resOrEx
where
upd = (updateCodeGeneration True)
Expand Down Expand Up @@ -320,7 +320,7 @@ test_Merge_runExe env = withAvailableSession env $ \session -> do
, "Hello World 7"
, "Hello World 8"
]
assertEqual "" result ExitSuccess
assertEqual "" ExitSuccess result
assertEqual "" expectedOutput output
where
-- Note that we have to set buffering here, to match the default
Expand Down
10 changes: 5 additions & 5 deletions setup/SETUP.md
Original file line number Diff line number Diff line change
Expand Up @@ -613,11 +613,11 @@ Running the tests
The safest way to run the test suite is to do:

```
PATH=/bin:/usr/bin \
dist/build/TestSuite/TestSuite \
--extra-paths-74 ~/path/to/patched/ghc/7.4.2:~/path/to/7.4.2/ide-backend-server:~/path/to/ide-backend/.cabal-sandbox/bin \
--extra-paths-78 ~/path/to/patched/ghc/7.8.4:~/path/to/7.8.4/ide-backend-server:~/path/to/ide-backend/.cabal-sandbox/bin \
--extra-paths-710 ~/path/to/patched/ghc/7.10:~/path/to/7.10/ide-backend-server:~/path/to/ide-backend/.cabal-sandbox/bin \
PATH=/bin:/usr/bin:~/path/to/ide-backend/.cabal-sandbox/bin:~/path/to/cabal \
dist/build/TestSuite/TestSuite: \
--extra-paths-74 ~/path/to/patched/ghc/7.4.2:~/path/to/7.4.2/ide-backend-server \
--extra-paths-78 ~/path/to/patched/ghc/7.8.4:~/path/to/7.8.4/ide-backend-server \
--extra-paths-710 ~/path/to/patched/ghc/7.10:~/path/to/7.10/ide-backend-server \
--package-db-74 ~/path/to/snippet-dbs/7.4.2/x86_64-osx-ghc-7.4.2.20140729-packages.conf.d \
--package-db-78 ~/path/to/snippet-dbs/7.8.4/x86_64-osx-ghc-7.8.4.20141229-packages.conf.d \
--package-db-710 ~/path/to/snippet-dbs/7.10/x86_64-osx-ghc-7.10.0.20150131-packages.conf.d \
Expand Down

0 comments on commit 146b997

Please sign in to comment.