Skip to content

Commit

Permalink
Improve functional tests
Browse files Browse the repository at this point in the history
1. Consolidate 'run maybe exception' functions.
2. When something goes wrong, always print logs.
3. Read IORefs in runner fn.
  • Loading branch information
tbidne committed May 10, 2024
1 parent bc3560e commit 10b91f9
Show file tree
Hide file tree
Showing 11 changed files with 101 additions and 105 deletions.
2 changes: 1 addition & 1 deletion test/functional/Functional/Buffering.hs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ specs =
logsNoBuffer :: TestTree
logsNoBuffer =
testCase "Command logs should not buffer" $ do
results <- L.reverse <$> (readIORef =<< run args)
results <- L.reverse <$> run args

assertLogsEq expectedOrdered results

Expand Down
4 changes: 2 additions & 2 deletions test/functional/Functional/Examples.hs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ specs args =
gif :: TestTree
gif =
testCase "Runs gif example" $ do
results <- fmap MkResultText <$> (readIORef =<< runExitFailure args)
results <- fmap MkResultText <$> runExitFailure args
V.verifyExpected results expected
where
args =
Expand Down Expand Up @@ -61,7 +61,7 @@ gif =
core :: TestTree
core =
testCase "Runs core example" $ do
results <- fmap MkResultText <$> (readIORef =<< runExitFailure args)
results <- fmap MkResultText <$> runExitFailure args
V.verifyExpected results expected
where
args =
Expand Down
4 changes: 2 additions & 2 deletions test/functional/Functional/Examples/CommandLogging.hs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ tests =
readSizeDefault :: TestTree
readSizeDefault =
testCase "Default --read-size splits 1000" $ do
results <- fmap MkResultText <$> (readIORef =<< run args)
results <- fmap MkResultText <$> run args
V.verifyExpected results expected
where
args =
Expand All @@ -39,7 +39,7 @@ readSizeDefault =
readSize :: TestTree
readSize =
testCase "Runs --command-log-read-size example" $ do
results <- fmap MkResultText <$> (readIORef =<< run args)
results <- fmap MkResultText <$> run args
V.verifyExpected results expected
where
args =
Expand Down
4 changes: 2 additions & 2 deletions test/functional/Functional/Examples/CommonLogging.hs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ tests =
keyHideOn :: TestTree
keyHideOn =
testCase "Runs key hide example with --common-log-key-hide" $ do
results <- fmap MkResultText <$> (readIORef =<< run args)
results <- fmap MkResultText <$> run args
V.verifyExpectedUnexpected results expected unexpected
where
args =
Expand All @@ -37,7 +37,7 @@ keyHideOn =
keyHideOff :: TestTree
keyHideOff =
testCase "Runs key hide example without --common-log-key-hide" $ do
results <- fmap MkResultText <$> (readIORef =<< run args)
results <- fmap MkResultText <$> run args
V.verifyExpectedUnexpected results expected unexpected
where
args =
Expand Down
24 changes: 12 additions & 12 deletions test/functional/Functional/Examples/ConsoleLogging.hs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ tests =
commandLogOn :: TestTree
commandLogOn =
testCase "Runs commandLog example with --console-log-command" $ do
results <- fmap MkResultText <$> (readIORef =<< run args)
results <- fmap MkResultText <$> run args
V.verifyExpected results expected
where
args =
Expand All @@ -42,7 +42,7 @@ commandLogOn =
commandLogOnDefault :: TestTree
commandLogOnDefault =
testCase "Runs --console-log-command with no output shows default message" $ do
results <- fmap MkResultText <$> (readIORef =<< run args)
results <- fmap MkResultText <$> run args
V.verifyExpected results expected
where
args =
Expand All @@ -57,7 +57,7 @@ commandLogOnDefault =
commandLogOff :: TestTree
commandLogOff =
testCase "Runs commandLog example without --console-log-command" $ do
results <- fmap MkResultText <$> (readIORef =<< run args)
results <- fmap MkResultText <$> run args
V.verifyUnexpected results unexpected
where
args =
Expand All @@ -68,7 +68,7 @@ commandLogOff =

commandNameTruncN :: TestTree
commandNameTruncN = testCase "Runs --console-log-command-name-trunc 10 example" $ do
results <- fmap MkResultText <$> (readIORef =<< run args)
results <- fmap MkResultText <$> run args
V.verifyExpected results expected
where
args =
Expand All @@ -85,7 +85,7 @@ commandNameTruncN = testCase "Runs --console-log-command-name-trunc 10 example"

commandLogLineTruncN :: TestTree
commandLogLineTruncN = testCase "Runs --console-log-line-trunc 80 example" $ do
results <- fmap MkResultText <$> (readIORef =<< run args)
results <- fmap MkResultText <$> run args
V.verifyExpected results expected
where
args =
Expand All @@ -101,7 +101,7 @@ commandLogLineTruncN = testCase "Runs --console-log-line-trunc 80 example" $ do

stripControlAll :: TestTree
stripControlAll = testCase "Runs --console-log-strip-control all example" $ do
results <- fmap MkResultText <$> (readIORef =<< run args)
results <- fmap MkResultText <$> run args
V.verifyExpected results expected
where
args =
Expand All @@ -122,7 +122,7 @@ stripControlAll = testCase "Runs --console-log-strip-control all example" $ do

stripControlNone :: TestTree
stripControlNone = testCase "Runs --console-log-strip-control none example" $ do
results <- fmap MkResultText <$> (readIORef =<< run args)
results <- fmap MkResultText <$> run args
V.verifyExpected results expected
where
args =
Expand All @@ -140,7 +140,7 @@ stripControlNone = testCase "Runs --console-log-strip-control none example" $ do

stripControlSmart :: TestTree
stripControlSmart = testCase "Runs --console-log-strip-control smart example" $ do
results <- fmap MkResultText <$> (readIORef =<< run args)
results <- fmap MkResultText <$> run args
V.verifyExpected results expected
where
args =
Expand All @@ -158,7 +158,7 @@ stripControlSmart = testCase "Runs --console-log-strip-control smart example" $
timerFormatDigitalCompact :: TestTree
timerFormatDigitalCompact =
testCase "Runs timer format with digital_compact" $ do
results <- fmap MkResultText <$> (readIORef =<< run args)
results <- fmap MkResultText <$> run args
V.verifyExpected results expected
where
args =
Expand All @@ -174,7 +174,7 @@ timerFormatDigitalCompact =
timerFormatDigitalFull :: TestTree
timerFormatDigitalFull =
testCase "Runs timer format with digital_full" $ do
results <- fmap MkResultText <$> (readIORef =<< run args)
results <- fmap MkResultText <$> run args
V.verifyExpected results expected
where
args =
Expand All @@ -190,7 +190,7 @@ timerFormatDigitalFull =
timerFormatProseCompact :: TestTree
timerFormatProseCompact =
testCase "Runs timer format with prose_compact" $ do
results <- fmap MkResultText <$> (readIORef =<< run args)
results <- fmap MkResultText <$> run args
V.verifyExpected results expected
where
args =
Expand All @@ -206,7 +206,7 @@ timerFormatProseCompact =
timerFormatProseFull :: TestTree
timerFormatProseFull =
testCase "Runs timer format with prose_full" $ do
results <- fmap MkResultText <$> (readIORef =<< run args)
results <- fmap MkResultText <$> run args
V.verifyExpected results expected
where
args =
Expand Down
6 changes: 3 additions & 3 deletions test/functional/Functional/Examples/Core.hs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ tests =
initOn :: TestTree
initOn =
testCase "Runs init successful example" $ do
results <- fmap MkResultText <$> (readIORef =<< run args)
results <- fmap MkResultText <$> run args
V.verifyExpected results expected
where
args =
Expand All @@ -36,7 +36,7 @@ initOn =
initOff :: TestTree
initOff =
testCase "Runs init failure example" $ do
results <- fmap MkResultText <$> (readIORef =<< runExitFailure args)
results <- fmap MkResultText <$> runExitFailure args
V.verifyExpected results expected
where
args =
Expand All @@ -51,7 +51,7 @@ initOff =
timeout :: TestTree
timeout =
testCase "Runs timeout example" $ do
results <- fmap MkResultText <$> (readIORef =<< runExitFailure args)
results <- fmap MkResultText <$> runExitFailure args
V.verifyExpected results expected
where
args =
Expand Down
16 changes: 8 additions & 8 deletions test/functional/Functional/Examples/FileLogging.hs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ fileLog testArgs = testCase "Runs file-log example" $ do
"for i in 1 2 3; do echo hi; sleep 1; done"
]

resultsConsole <- fmap MkResultText <$> (readIORef =<< runExitFailure args)
resultsConsole <- fmap MkResultText <$> runExitFailure args
V.verifyExpected resultsConsole expectedConsole

resultsFile <- fmap MkResultText . T.lines <$> readFileUtf8ThrowM outFile
Expand Down Expand Up @@ -68,7 +68,7 @@ fileLogCommandNameTruncN testArgs = testCase desc $ do
"for i in 1 2 3; do echo hi; sleep 1; done"
]

resultsConsole <- fmap MkResultText <$> (readIORef =<< run args)
resultsConsole <- fmap MkResultText <$> run args
V.verifyExpected resultsConsole expectedConsole

resultsFile <- fmap MkResultText . T.lines <$> readFileUtf8ThrowM outFile
Expand Down Expand Up @@ -96,7 +96,7 @@ fileLogDeleteOnSuccess testArgs = testCase desc $ do
"sleep 2"
]

resultsConsole <- fmap MkResultText <$> (readIORef =<< run args)
resultsConsole <- fmap MkResultText <$> run args
V.verifyExpected resultsConsole expectedConsole

exists <- doesFileExist outFile
Expand All @@ -122,7 +122,7 @@ fileLogDeleteOnSuccessFail testArgs = testCase desc $ do
"sleep 2"
]

resultsConsole <- fmap MkResultText <$> (readIORef =<< runOuterExitFailure args)
resultsConsole <- fmap MkResultText <$> runExitFailure args
V.verifyExpected resultsConsole expectedConsole

exists <- doesFileExist outFile
Expand Down Expand Up @@ -153,7 +153,7 @@ fileLogLineTruncN testArgs = testCase "Runs --file-log-line-trunc 80 example" $
"echo 'some ridiculously long command i mean is this really necessary' && sleep 2"
]

_ <- fmap MkResultText <$> (readIORef =<< run args)
_ <- fmap MkResultText <$> run args

resultsFile <- fmap MkResultText . T.lines <$> readFileUtf8ThrowM outFile
V.verifyExpected resultsFile expectedFile
Expand All @@ -175,7 +175,7 @@ fileLogStripControlAll testArgs = testCase "Runs file-log strip-control all exam
"printf ' foo \ESC[35m hello \ESC[3D bye '; sleep 2"
]

_ <- fmap MkResultText <$> (readIORef =<< run args)
_ <- fmap MkResultText <$> run args

resultsFile <- fmap MkResultText . T.lines <$> readFileUtf8ThrowM outFile
V.verifyExpected resultsFile expectedFile
Expand All @@ -197,7 +197,7 @@ fileLogStripControlNone testArgs = testCase "Runs file-log strip-control none ex
"printf ' foo \ESC[35m hello \ESC[3D bye '; sleep 2"
]

_ <- fmap MkResultText <$> (readIORef =<< run args)
_ <- fmap MkResultText <$> run args

resultsFile <- fmap MkResultText . T.lines <$> readFileUtf8ThrowM outFile
V.verifyExpected resultsFile expectedFile
Expand All @@ -221,7 +221,7 @@ fileLogStripControlSmart testArgs = testCase "Runs file-log strip-control smart
"printf ' foo \ESC[35m hello \ESC[3D bye '; sleep 2"
]

_ <- fmap MkResultText <$> (readIORef =<< run args)
_ <- fmap MkResultText <$> run args

resultsFile <- fmap MkResultText . T.lines <$> readFileUtf8ThrowM outFile
V.verifyExpected resultsFile expectedFile
Expand Down
4 changes: 2 additions & 2 deletions test/functional/Functional/Examples/Notify.hs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ tests =

notifyActionFinal :: TestTree
notifyActionFinal = testCase "Runs --notify-action final" $ do
results <- readIORef =<< runNotes args
results <- runNotes args
expected @=? results
where
args =
Expand All @@ -56,7 +56,7 @@ notifyActionFinal = testCase "Runs --notify-action final" $ do

notifyTimeoutNever :: TestTree
notifyTimeoutNever = testCase "Runs --notify-timeout never" $ do
results <- readIORef =<< runNotes args
results <- runNotes args
expected @=? results
where
args =
Expand Down
6 changes: 3 additions & 3 deletions test/functional/Functional/Miscellaneous.hs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ specs =

splitNewlineLogs :: TestTree
splitNewlineLogs = testCase "Logs with newlines are split" $ do
results <- fmap MkResultText <$> (readIORef =<< run args)
results <- fmap MkResultText <$> run args
V.verifyExpectedUnexpected results expected unexpected
where
args =
Expand All @@ -40,7 +40,7 @@ splitNewlineLogs = testCase "Logs with newlines are split" $ do

spaceStderrLogs :: TestTree
spaceStderrLogs = testCase "Stderr Log with newlines is spaced" $ do
results <- fmap MkResultText <$> (readIORef =<< runExitFailure args)
results <- fmap MkResultText <$> runExitFailure args
V.verifyExpectedUnexpected results expected unexpected
where
args =
Expand All @@ -64,7 +64,7 @@ spaceStderrLogs = testCase "Stderr Log with newlines is spaced" $ do
-- markdown file as easy as possible. Thus we move it here.
stripControlAlwaysCmdNames :: TestTree
stripControlAlwaysCmdNames = testCase "Always strips command names" $ do
results <- fmap MkResultText <$> (readIORef =<< run args)
results <- fmap MkResultText <$> run args
V.verifyExpected results expected
where
args =
Expand Down
8 changes: 4 additions & 4 deletions test/functional/Functional/Notify.hs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ notifyTests =

notifySystem :: TestTree
notifySystem = testCase ("Runs --notify-system " <> notifySystemArg) $ do
results <- readIORef =<< runNotes args
results <- runNotes args
expected @=? results
where
args =
Expand Down Expand Up @@ -64,7 +64,7 @@ notifySystem = testCase ("Runs --notify-system " <> notifySystemArg) $ do

notifyActionCommand :: TestTree
notifyActionCommand = testCase "Runs --notify-action command" $ do
results <- readIORef =<< runNotes args
results <- runNotes args
expected @=? results
where
args =
Expand Down Expand Up @@ -93,7 +93,7 @@ notifyActionCommand = testCase "Runs --notify-action command" $ do

notifyActionAll :: TestTree
notifyActionAll = testCase "Runs --notify-action all" $ do
results <- readIORef =<< runNotes args
results <- runNotes args
expected @=? results
where
args =
Expand Down Expand Up @@ -128,7 +128,7 @@ notifyActionAll = testCase "Runs --notify-action all" $ do

notifyTimeout5 :: TestTree
notifyTimeout5 = testCase "Runs --notify-timeout 5" $ do
results <- readIORef =<< runNotes args
results <- runNotes args
expected @=? results
where
args =
Expand Down
Loading

0 comments on commit 10b91f9

Please sign in to comment.