Skip to content

Commit

Permalink
More info on failure, more reliable runs
Browse files Browse the repository at this point in the history
  • Loading branch information
snoyberg committed Aug 13, 2018
1 parent 2fd35a3 commit 0f20925
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
18 changes: 13 additions & 5 deletions test/integration/lib/StackTest.hs
Original file line number Diff line number Diff line change
Expand Up @@ -12,32 +12,33 @@ import System.IO.Error
import System.Process
import System.Exit
import System.Info (arch, os)
import GHC.Stack (HasCallStack)

run' :: FilePath -> [String] -> IO ExitCode
run' :: HasCallStack => FilePath -> [String] -> IO ExitCode
run' cmd args = do
logInfo $ "Running: " ++ cmd ++ " " ++ unwords (map showProcessArgDebug args)
(Nothing, Nothing, Nothing, ph) <- createProcess (proc cmd args)
waitForProcess ph

run :: FilePath -> [String] -> IO ()
run :: HasCallStack => FilePath -> [String] -> IO ()
run cmd args = do
ec <- run' cmd args
unless (ec == ExitSuccess) $ error $ "Exited with exit code: " ++ show ec

stackExe :: IO String
stackExe = getEnv "STACK_EXE"

stack' :: [String] -> IO ExitCode
stack' :: HasCallStack => [String] -> IO ExitCode
stack' args = do
stackEnv <- stackExe
run' stackEnv args

stack :: [String] -> IO ()
stack :: HasCallStack => [String] -> IO ()
stack args = do
ec <- stack' args
unless (ec == ExitSuccess) $ error $ "Exited with exit code: " ++ show ec

stackErr :: [String] -> IO ()
stackErr :: HasCallStack => [String] -> IO ()
stackErr args = do
ec <- stack' args
when (ec == ExitSuccess) $ error "stack was supposed to fail, but didn't"
Expand Down Expand Up @@ -216,3 +217,10 @@ removeFileIgnore fp = removeFile fp `catch` \e ->
if isDoesNotExistError e
then return ()
else throwIO e

-- | Remove a directory and ignore any warnings about missing files.
removeDirIgnore :: FilePath -> IO ()
removeDirIgnore fp = removeDirectoryRecursive fp `catch` \e ->
if isDoesNotExistError e
then return ()
else throwIO e
2 changes: 2 additions & 0 deletions test/integration/tests/2643-copy-compiler-tool/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ import System.Directory
main :: IO ()
main = do
-- init
removeFileIgnore "stack.yaml"
stack ["init", defaultResolverArg]

-- place to throw some exes
removeDirIgnore "binny"
createDirectory "binny"

-- check assumptions on exec and the build flags and clean
Expand Down

0 comments on commit 0f20925

Please sign in to comment.