summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ghc/GHCi/UI.hs5
-rw-r--r--testsuite/tests/ghci/scripts/GhciCurDir.script7
-rwxr-xr-xtestsuite/tests/ghci/scripts/all.T1
3 files changed, 13 insertions, 0 deletions
diff --git a/ghc/GHCi/UI.hs b/ghc/GHCi/UI.hs
index 71be20c20e..deee24ab33 100644
--- a/ghc/GHCi/UI.hs
+++ b/ghc/GHCi/UI.hs
@@ -1409,6 +1409,11 @@ changeDirectory dir = do
GHC.workingDirectoryChanged
dir' <- expandPath dir
liftIO $ setCurrentDirectory dir'
+ dflags <- getDynFlags
+ -- With -fexternal-interpreter, we have to change the directory of the subprocess too.
+ -- (this gives consistent behaviour with and without -fexternal-interpreter)
+ when (gopt Opt_ExternalInterpreter dflags) $
+ lift $ enqueueCommands ["System.Directory.setCurrentDirectory " ++ show dir']
trySuccess :: GHC.GhcMonad m => m SuccessFlag -> m SuccessFlag
trySuccess act =
diff --git a/testsuite/tests/ghci/scripts/GhciCurDir.script b/testsuite/tests/ghci/scripts/GhciCurDir.script
new file mode 100644
index 0000000000..785a773a0a
--- /dev/null
+++ b/testsuite/tests/ghci/scripts/GhciCurDir.script
@@ -0,0 +1,7 @@
+import System.Directory
+import Control.Monad
+
+createDirectory "test"
+createDirectory "test/test1"
+:cd test
+unless ("test1" `elem` getDirectoryContents ".") $ putStrLn "Uh oh."
diff --git a/testsuite/tests/ghci/scripts/all.T b/testsuite/tests/ghci/scripts/all.T
index 00d8d819bc..cde72e4d2d 100755
--- a/testsuite/tests/ghci/scripts/all.T
+++ b/testsuite/tests/ghci/scripts/all.T
@@ -251,3 +251,4 @@ test('StaticPtr', normal, ghci_script, ['StaticPtr.script'])
test('T13202', normal, ghci_script, ['T13202.script'])
test('T13202a', normal, ghci_script, ['T13202a.script'])
test('T13466', normal, ghci_script, ['T13466.script'])
+test('GhciCurDir', normal, ghci_script, ['GhciCurDir.script'])