diff options
| author | Roman Smrž <roman.smrz@seznam.cz> | 2026-01-14 20:02:29 +0100 |
|---|---|---|
| committer | Roman Smrž <roman.smrz@seznam.cz> | 2026-01-14 20:02:29 +0100 |
| commit | 379d88e72a66eb876dfdf452d79081f5e4277979 (patch) | |
| tree | 8f8ca97d960f994df450cf73d1c4c810d93d8e1a | |
| parent | ea8109cef731b2c876b9effa759763bf59d878aa (diff) | |
Print test names in verbose output
Changelog: Verbose output now includes test names.
| -rw-r--r-- | src/Output.hs | 78 | ||||
| -rw-r--r-- | src/Run.hs | 5 | ||||
| -rw-r--r-- | test/script/definition.et | 1 |
3 files changed, 55 insertions, 29 deletions
diff --git a/src/Output.hs b/src/Output.hs index 2cddabf..1201d72 100644 --- a/src/Output.hs +++ b/src/Output.hs @@ -50,7 +50,9 @@ data OutputStyle deriving (Eq) data OutputType - = OutputChildStdout + = OutputGlobalInfo + | OutputGlobalError + | OutputChildStdout | OutputChildStderr | OutputChildStdin | OutputChildExec @@ -82,39 +84,50 @@ resetOutputTime Output {..} = do modifyMVar_ outStartedAt . const $ getTime Monotonic outColor :: OutputType -> Text -outColor OutputChildStdout = T.pack "0" -outColor OutputChildStderr = T.pack "31" -outColor OutputChildStdin = T.pack "0" -outColor OutputChildExec = T.pack "33" -outColor OutputChildInfo = T.pack "0" -outColor OutputChildFail = T.pack "31" -outColor OutputMatch = T.pack "32" -outColor OutputMatchFail {} = T.pack "31" -outColor OutputIgnored = "90" -outColor OutputError = T.pack "31" -outColor OutputAlways = "0" -outColor OutputTestRaw = "0" +outColor = \case + OutputGlobalInfo -> "0" + OutputGlobalError -> "31" + OutputChildStdout -> "0" + OutputChildStderr -> "31" + OutputChildStdin -> "0" + OutputChildExec -> "33" + OutputChildInfo -> "0" + OutputChildFail -> "31" + OutputMatch -> "32" + OutputMatchFail {} -> "31" + OutputIgnored -> "90" + OutputError -> "31" + OutputAlways -> "0" + OutputTestRaw -> "0" outSign :: OutputType -> Text -outSign OutputChildStdout = " " -outSign OutputChildStderr = T.pack "!" -outSign OutputChildStdin = T.empty -outSign OutputChildExec = "*" -outSign OutputChildInfo = T.pack "." -outSign OutputChildFail = T.pack "!!" -outSign OutputMatch = T.pack "+" -outSign OutputMatchFail {} = T.pack "/" -outSign OutputIgnored = "-" -outSign OutputError = T.pack "!!" -outSign OutputAlways = T.empty -outSign OutputTestRaw = T.empty +outSign = \case + OutputGlobalInfo -> "" + OutputGlobalError -> "" + OutputChildStdout -> " " + OutputChildStderr -> "!" + OutputChildStdin -> T.empty + OutputChildExec -> "*" + OutputChildInfo -> "." + OutputChildFail -> "!!" + OutputMatch -> "+" + OutputMatchFail {} -> "/" + OutputIgnored -> "-" + OutputError -> "!!" + OutputAlways -> T.empty + OutputTestRaw -> T.empty outArr :: OutputType -> Text -outArr OutputChildStdin = "<" -outArr _ = ">" +outArr = \case + OutputGlobalInfo -> "" + OutputGlobalError -> "" + OutputChildStdin -> "<" + _ -> ">" outTestLabel :: OutputType -> Text outTestLabel = \case + OutputGlobalInfo -> "global-info" + OutputGlobalError -> "global-error" OutputChildStdout -> "child-stdout" OutputChildStderr -> "child-stderr" OutputChildStdin -> "child-stdin" @@ -130,6 +143,7 @@ outTestLabel = \case printWhenQuiet :: OutputType -> Bool printWhenQuiet = \case + OutputGlobalError -> True OutputChildStderr -> True OutputChildFail -> True OutputMatchFail {} -> True @@ -137,6 +151,12 @@ printWhenQuiet = \case OutputAlways -> True _ -> False +includeTestTime :: OutputType -> Bool +includeTestTime = \case + OutputGlobalInfo -> False + OutputGlobalError -> False + _ -> True + ioWithOutput :: MonadOutput m => (Output -> IO a) -> m a ioWithOutput act = liftIO . act =<< getOutput @@ -155,7 +175,9 @@ outLine otype prompt line = ioWithOutput $ \out -> withMVar (outState out) $ \st -> do forM_ (normalOutputLines otype line) $ \line' -> do outPrint st $ TL.fromChunks $ concat - [ [ T.pack $ printf "[% 2d.%03d] " (nsecs `quot` 1000000000) ((nsecs `quot` 1000000) `rem` 1000) ] + [ if includeTestTime otype + then [ T.pack $ printf "[% 2d.%03d] " (nsecs `quot` 1000000000) ((nsecs `quot` 1000000) `rem` 1000) ] + else [] , if outUseColor (outConfig out) then [ T.pack "\ESC[", outColor otype, T.pack "m" ] else [] @@ -107,6 +107,9 @@ runTest out opts gdefs test = do resetOutputTime out testRunResult <- newEmptyMVar + flip runReaderT out $ do + void $ outLine OutputGlobalInfo Nothing $ "Starting test ‘" <> testName test <> "’" + void $ forkOS $ do isolateFilesystem testDir >>= \case True -> do @@ -134,7 +137,7 @@ runTest out opts gdefs test = do return True _ -> do flip runReaderT out $ do - void $ outLine OutputError Nothing $ "Test ‘" <> testName test <> "’ failed." + void $ outLine OutputGlobalError Nothing $ "Test ‘" <> testName test <> "’ failed." return False diff --git a/test/script/definition.et b/test/script/definition.et index d2da737..3d84040 100644 --- a/test/script/definition.et +++ b/test/script/definition.et @@ -10,6 +10,7 @@ test Definition: expect /load-done/ send "run Test" + expect /global-info - Starting test ‘Test’/ expect /child-stdout p 4/ expect /match p 4/ expect /child-stdout p 11/ |