[Git][ghc/ghc][wip/T24040-ghci-timeout-squashed] 2 commits: style changes based on feedback for #24040
Hassan Al-Awwadi (@hassan.awwadi)
gitlab at gitlab.haskell.org
Mon Feb 5 14:13:09 UTC 2024
Hassan Al-Awwadi pushed to branch wip/T24040-ghci-timeout-squashed at Glasgow Haskell Compiler / GHC
Commits:
a569078f by Hassan Al-Awwadi at 2024-02-05T15:11:11+01:00
style changes based on feedback for #24040
- - - - -
aa5a497b by Hassan Al-Awwadi at 2024-02-05T15:11:23+01:00
added test casefor #24040
- - - - -
5 changed files:
- ghc/GHCi/UI.hs
- + testsuite/tests/ghci/scripts/T24040.hs
- + testsuite/tests/ghci/scripts/T24040.script
- + testsuite/tests/ghci/scripts/T24040.stderr
- + testsuite/tests/ghci/scripts/T24040.stdout
Changes:
=====================================
ghc/GHCi/UI.hs
=====================================
@@ -2385,18 +2385,14 @@ exceptT = ExceptT . pure
-----------------------------------------------------------------------------
-- | @:timeout@ command.
timeoutCmd :: GhciMonad m => String -> m ()
-timeoutCmd str = handleSourceError printErrAndMaybeExit $ if null str
- then unbounded
- else (case readMaybe str of
- (Just lim) -> if lim > 0
- then set_time lim
- else unbounded
- Nothing -> unbounded) where
- unbounded = printForUser (text "Resetting timeout to unbounded execution time")
- *> modifyGHCiState (\st -> st{ time_limit = Nothing })
- set_time l = printForUser (text "setting timeout length to" <+> text (show l) <+> text "seconds")
- *> modifyGHCiState (\st -> st{ time_limit = Just l })
-
+timeoutCmd str = handleSourceError printErrAndMaybeExit $ set_time (readMaybe str) where
+ set_time (Just l)
+ | l == 1 = printForUser (text "setting timeout length to" <+> text (show l) <+> text "second")
+ *> modifyGHCiState (\st -> st{ time_limit = Just l })
+ | l > 0 = printForUser (text "setting timeout length to" <+> text (show l) <+> text "seconds")
+ *> modifyGHCiState (\st -> st{ time_limit = Just l })
+ set_time _ = printForUser (text "setting timeout to unbounded execution time")
+ *> modifyGHCiState (\st -> st{ time_limit = Nothing })
-----------------------------------------------------------------------------
-- | @:type@ command. See also Note [TcRnExprMode] in GHC.Tc.Module.
=====================================
testsuite/tests/ghci/scripts/T24040.hs
=====================================
@@ -0,0 +1,5 @@
+module T24040 where
+import Control.Concurrent(threadDelay)
+
+delayNSeconds :: Int -> IO String
+delayNSeconds n = threadDelay (n * 1000000) >> pure ("Finished in: " ++ show n ++ " seconds")
=====================================
testsuite/tests/ghci/scripts/T24040.script
=====================================
@@ -0,0 +1,11 @@
+:load T24040
+:timeout 5
+delayNSeconds 10
+delayNSeconds 2
+:timeout
+delayNSeconds 10
+:timeout 1
+delayNSeconds 5
+delayNSeconds 2
+:timeout
+delayNSeconds 5
\ No newline at end of file
=====================================
testsuite/tests/ghci/scripts/T24040.stderr
=====================================
@@ -0,0 +1,3 @@
+*** Exception: GhciTimedOut
+*** Exception: GhciTimedOut
+*** Exception: GhciTimedOut
\ No newline at end of file
=====================================
testsuite/tests/ghci/scripts/T24040.stdout
=====================================
@@ -0,0 +1,7 @@
+setting timeout length to 5 seconds
+Finished in: 2 seconds
+setting timeout to unbounded execution time
+Finished in: 10 seconds
+setting timeout length to 1 second
+setting timeout to unbounded execution time
+Finished in: 5 seconds
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/39866f26a0c1c66e9383a6c6926739f5ed8957d3...aa5a497bf0be57a37b27c557f5b147346f6daa4c
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/39866f26a0c1c66e9383a6c6926739f5ed8957d3...aa5a497bf0be57a37b27c557f5b147346f6daa4c
You're receiving this email because of your account on gitlab.haskell.org.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-commits/attachments/20240205/a0488d9e/attachment-0001.html>
More information about the ghc-commits
mailing list