From 6c82b48abc6c16516024d690033ff1d07735b3b9 Mon Sep 17 00:00:00 2001 From: Tobias Boege Date: Mon, 24 Feb 2020 17:52:35 +0100 Subject: [PATCH] gb.test.tap: Add SkipAll and don't lose stderr [GB.TEST.TAP] * NEW: Support skipping all tests. * BUG: DO intercept a test process' stderr but forward it verbatim to the TAP stream. --- comp/src/gb.test.tap/.src/Assert.class | 15 ++++++++++- comp/src/gb.test.tap/.src/Main.module | 4 ++- .../src/gb.test.tap/.src/Tap/TapPrinter.class | 27 +++++++++++++++++-- comp/src/gb.test.tap/.src/TestHarness.class | 6 +++++ 4 files changed, 48 insertions(+), 4 deletions(-) diff --git a/comp/src/gb.test.tap/.src/Assert.class b/comp/src/gb.test.tap/.src/Assert.class index 295731371..6bd7fe7b2 100644 --- a/comp/src/gb.test.tap/.src/Assert.class +++ b/comp/src/gb.test.tap/.src/Assert.class @@ -16,6 +16,7 @@ Public Struct Subtest End Struct Property Output As Stream +Property Read Finished As Boolean Private $aActiveTests As Subtest[] Private $hCurrent As New Subtest @@ -72,7 +73,7 @@ Public Sub Finish() With $hCurrent .Printer.Finish() - .Success = .Success And .Printer.Planned > 0 And .Printer.Count = .Printer.Planned + .Success = .Success And (.Printer.SkippedAll Or (.Printer.Planned > 0 And .Printer.Count = .Printer.Planned)) End With hFinished = $hCurrent @@ -95,6 +96,12 @@ Public Sub Plan(Tests As Integer, Optional Comment As String) End +Public Sub SkipAll(Optional Comment As String) + + $hCurrent.Printer.SkipAll(Comment) + +End + Public Sub Ok(Result As Boolean, Optional Description As String) As Boolean With $hCurrent @@ -164,6 +171,12 @@ Private Sub Output_Write(Value As Stream) End +Private Function Finished_Read() As Boolean + + Return $hCurrent.Printer.Finished + +End + ' -------------------- High-level test functions -------------------- Public Sub Pass(Optional Description As String) As Boolean diff --git a/comp/src/gb.test.tap/.src/Main.module b/comp/src/gb.test.tap/.src/Main.module index db4987ff5..e7131acbc 100644 --- a/comp/src/gb.test.tap/.src/Main.module +++ b/comp/src/gb.test.tap/.src/Main.module @@ -21,7 +21,9 @@ Public Sub Main() Print String$(80, "*") Print - Print "Test";; .Name;; IIf(.Success, "PASSED", "FAILED");; "("; Format$(DateDiff(.Started, .Ended, gb.Second), "0.00s"); ")" + Print "Test";; .Name;; IIf(.Success, "PASSED", "FAILED");; + Print "("; "exit code";; .ExitCode; ",";; + Print "runtime";; Format$(DateDiff(.Started, .Ended, gb.Second), "0.00s"); ")" If .Run <> .Planned Then Print "Planned";; .Planned;; "tests but ran";; .Run If .Failed Then Dim iInd As Integer diff --git a/comp/src/gb.test.tap/.src/Tap/TapPrinter.class b/comp/src/gb.test.tap/.src/Tap/TapPrinter.class index 282a1beea..5fd678e44 100644 --- a/comp/src/gb.test.tap/.src/Tap/TapPrinter.class +++ b/comp/src/gb.test.tap/.src/Tap/TapPrinter.class @@ -13,12 +13,15 @@ Property Read Planned As Integer Property Read Count As Integer Property Read Last As Integer Property Line As String +Property Read Finished As Boolean +Property Read SkippedAll As Boolean Private $hOutput As Stream Private $iPlan As Integer Private $iTestsRun As Integer Private $iLast As Integer Private $bFinished As Boolean +Private $bSkippedAll As Boolean Private $sLine As String Public Sub _new(Optional Tests As Integer, Optional Comment As String, Optional {Output} As Stream = File.Out) @@ -34,6 +37,7 @@ End Public Sub Plan(Tests As Integer, Optional Comment As String) + If $bFinished Or $bSkippedAll Then Error.Raise(("Tests already finished")) If $iTestsRun Then Error.Raise(Subst$(("Too late to plan. Already ran &1 tests"), $iTestsRun)) ' TAP specification lists '1..0 # Skipped: WWW::Mechanize not installed' ' as a valid example. @@ -43,6 +47,13 @@ Public Sub Plan(Tests As Integer, Optional Comment As String) End +Public Sub SkipAll(Optional Comment As String) + + Plan(0, "SKIP" & IIf(Comment, " ", "") & Comment) + $bSkippedAll = True + +End + Public Sub Finish() If $bFinished Then Error.Raise(("Tests already finished")) @@ -58,7 +69,7 @@ Public Sub Test(Result As Boolean, Optional TestNr As Integer, Optional Descript Dim sDirective As String Dim sLine As String - If $bFinished Then Error.Raise(("Tests already finished")) + If $bFinished Or $bSkippedAll Then Error.Raise(("Tests already finished")) ' It is not advised to start a description with a number token because ' it will be interpreted as the (optional) test number. We issue a warning @@ -90,7 +101,7 @@ End Public Sub BailOut(Optional Comment As String) - If $bFinished Then Error.Raise(("Tests already finished")) + If $bFinished Or $bSkippedAll Then Error.Raise(("Tests already finished")) Print("Bail out!" & IIf(Comment, " " & Comment, "")) $bFinished = True @@ -159,3 +170,15 @@ Private Sub Line_Write(Value As String) $sLine = Value End + +Private Function Finished_Read() As Boolean + + Return $bFinished + +End + +Private Function SkippedAll_Read() As Boolean + + Return $bSkippedAll + +End diff --git a/comp/src/gb.test.tap/.src/TestHarness.class b/comp/src/gb.test.tap/.src/TestHarness.class index c5ac31dea..bea0f5081 100644 --- a/comp/src/gb.test.tap/.src/TestHarness.class +++ b/comp/src/gb.test.tap/.src/TestHarness.class @@ -89,6 +89,12 @@ Public Sub TapStream_Read() End +Public Sub TapStream_Error(Message As String) + + AddLine(Message) + +End + Public Sub TapStream_Kill() FinishStats()