Skip to content

Commit 8e99af9

Browse files
committed
tests(3926): fix test [on linux]
1 parent f68fc0f commit 8e99af9

File tree

2 files changed

+18
-22
lines changed

2 files changed

+18
-22
lines changed

tests/integration/lib/StackTest.hs

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@ module StackTest
5151

5252
import Control.Monad ( forever, unless, void, when )
5353
import Control.Monad.IO.Class ( liftIO )
54-
import Control.Monad.Trans.Reader ( ReaderT, ask, runReaderT )
54+
import Control.Monad.Trans.Reader ( ReaderT, ask, asks, runReaderT )
55+
import qualified Control.Monad.Trans.State as State
56+
import Control.Monad.Trans ( lift )
5557
import Control.Concurrent ( forkIO )
5658
import Control.Exception
5759
( Exception (..), IOException, bracket_, catch, throw
@@ -157,14 +159,16 @@ data ReplConnection = ReplConnection
157159
}
158160

159161
nextPrompt :: Repl ()
160-
nextPrompt = do
161-
(ReplConnection _ replStdoutHandle) <- ask
162-
c <- liftIO $ hGetChar replStdoutHandle
163-
if c == '>'
164-
then do
165-
-- Skip next character
166-
void $ liftIO $ hGetChar replStdoutHandle
167-
else nextPrompt
162+
nextPrompt = State.evalStateT poll "" where
163+
poll = do
164+
c <- lift (asks replStdout) >>= liftIO . hGetChar
165+
State.modify (++ [c]) -- FIXME crap perf
166+
when (c == '\n') $ do
167+
State.get >>= liftIO . putStr . ("ghci> " <>)
168+
State.put ""
169+
buf <- State.get
170+
unless (buf == "ghci> ")
171+
poll
168172

169173
replCommand :: String -> Repl ()
170174
replCommand cmd = do

tests/integration/tests/3926-ghci-with-sublibraries/Main.hs

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import Control.Concurrent
21
import Control.Monad.IO.Class
32
import Control.Monad
43
import Data.List
@@ -14,7 +13,6 @@ main
1413
copy "src/Lib.v1" "src/Lib.hs"
1514
copy "src-internal/Internal.v1" "src-internal/Internal.hs"
1615
stack ["build"] -- need a build before ghci at the moment, see #4148
17-
forkIO fileEditingThread
1816
replThread
1917

2018
replThread :: IO ()
@@ -23,33 +21,27 @@ replThread = repl ["--ghci-options=-ignore-dot-ghci"] $ do
2321
-- otherwise, on Windows from msys2-20230526, `stack repl` encounters a EOF
2422
-- and terminates gracefully.
2523
replCommand ":main"
24+
liftIO $ putStrLn "Awaiting prompt..."
2625
nextPrompt
26+
liftIO $ putStrLn "Initial prompt received"
2727
line <- replGetLine
2828
let expected = "hello world"
2929
when (line /= expected) $
3030
error $
3131
"Main module didn't load correctly.\n"
3232
<> "Expected: " <> expected <> "\n"
3333
<> "Actual : " <> line <> "\n"
34-
liftIO $ threadDelay 1000000 -- wait for an edit of the internal library
34+
liftIO $ copy "src-internal/Internal.v2" "src-internal/Internal.hs"
3535
reloadAndTest "testInt" "42" "Internal library didn't reload."
36-
liftIO $ threadDelay 1000000 -- wait for an edit of the internal library
36+
liftIO $ copy "src/Lib.v2" "src/Lib.hs"
3737
reloadAndTest "testStr" "\"OK\"" "Main library didn't reload."
3838

39-
fileEditingThread :: IO ()
40-
fileEditingThread = do
41-
threadDelay 1000000
42-
-- edit the internal library and pure to ghci
43-
copy "src-internal/Internal.v2" "src-internal/Internal.hs"
44-
threadDelay 1000000
45-
-- edit the internal library and end thread, returning to ghci
46-
copy "src/Lib.v2" "src/Lib.hs"
47-
4839
reloadAndTest :: String -> String -> String -> Repl ()
4940
reloadAndTest cmd exp err = do
5041
reload
5142
replCommand cmd
5243
line <- replGetLine
44+
liftIO . putStrLn $ line
5345
unless (exp `isSuffixOf` line) $ error err
5446

5547
reload :: Repl ()

0 commit comments

Comments
 (0)