Skip to content

Commit

Permalink
Test relative paths in subdirectories
Browse files Browse the repository at this point in the history
  • Loading branch information
snoyberg committed Nov 13, 2016
1 parent e63f474 commit fc06dff
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 0 deletions.
1 change: 1 addition & 0 deletions exes/echo.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
echo parent
1 change: 1 addition & 0 deletions exes/subdir/echo.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
echo child
3 changes: 3 additions & 0 deletions process.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ extra-source-files:
configure.ac
include/HsProcessConfig.h.in
process.buildinfo
exes/echo.bat
exes/subdir/echo.bat

extra-tmp-files:
autom4te.cache
Expand Down Expand Up @@ -81,4 +83,5 @@ test-suite test
main-is: main.hs
type: exitcode-stdio-1.0
build-depends: base
, directory
, process
21 changes: 21 additions & 0 deletions test/main.hs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import Control.Exception
import Control.Monad (unless)
import System.Exit
import System.IO.Error
import System.Directory (getCurrentDirectory, setCurrentDirectory)
import System.Process

main :: IO ()
Expand All @@ -27,4 +29,23 @@ main = do
test "create_new_console" $ \cp -> cp { create_new_console = True }
test "new_session" $ \cp -> cp { new_session = True }

putStrLn "Testing subdirectories"

withCurrentDirectory "exes" $ do
res <- readCreateProcess (proc "./echo.bat" []) ""
unless (res == "parent\n") $ error $
"echo.bat with cwd failed: " ++ show res

res <- readCreateProcess (proc "./echo.bat" []) { cwd = Just "subdir" } ""
unless (res == "child\n") $ error $
"echo.bat with cwd failed: " ++ show res

putStrLn "Tests passed successfully"

withCurrentDirectory :: FilePath -> IO a -> IO a
withCurrentDirectory new inner = do
orig <- getCurrentDirectory
bracket_
(setCurrentDirectory new)
(setCurrentDirectory orig)
inner

0 comments on commit fc06dff

Please sign in to comment.