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.
This commit is contained in:
Tobias Boege 2020-02-24 17:52:35 +01:00
parent 27cc0504ac
commit 6c82b48abc
4 changed files with 48 additions and 4 deletions

View File

@ -16,6 +16,7 @@ Public Struct Subtest
End Struct End Struct
Property Output As Stream Property Output As Stream
Property Read Finished As Boolean
Private $aActiveTests As Subtest[] Private $aActiveTests As Subtest[]
Private $hCurrent As New Subtest Private $hCurrent As New Subtest
@ -72,7 +73,7 @@ Public Sub Finish()
With $hCurrent With $hCurrent
.Printer.Finish() .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 End With
hFinished = $hCurrent hFinished = $hCurrent
@ -95,6 +96,12 @@ Public Sub Plan(Tests As Integer, Optional Comment As String)
End 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 Public Sub Ok(Result As Boolean, Optional Description As String) As Boolean
With $hCurrent With $hCurrent
@ -164,6 +171,12 @@ Private Sub Output_Write(Value As Stream)
End End
Private Function Finished_Read() As Boolean
Return $hCurrent.Printer.Finished
End
' -------------------- High-level test functions -------------------- ' -------------------- High-level test functions --------------------
Public Sub Pass(Optional Description As String) As Boolean Public Sub Pass(Optional Description As String) As Boolean

View File

@ -21,7 +21,9 @@ Public Sub Main()
Print String$(80, "*") Print String$(80, "*")
Print 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 .Run <> .Planned Then Print "Planned";; .Planned;; "tests but ran";; .Run
If .Failed Then If .Failed Then
Dim iInd As Integer Dim iInd As Integer

View File

@ -13,12 +13,15 @@ Property Read Planned As Integer
Property Read Count As Integer Property Read Count As Integer
Property Read Last As Integer Property Read Last As Integer
Property Line As String Property Line As String
Property Read Finished As Boolean
Property Read SkippedAll As Boolean
Private $hOutput As Stream Private $hOutput As Stream
Private $iPlan As Integer Private $iPlan As Integer
Private $iTestsRun As Integer Private $iTestsRun As Integer
Private $iLast As Integer Private $iLast As Integer
Private $bFinished As Boolean Private $bFinished As Boolean
Private $bSkippedAll As Boolean
Private $sLine As String Private $sLine As String
Public Sub _new(Optional Tests As Integer, Optional Comment As String, Optional {Output} As Stream = File.Out) 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) 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)) 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' ' TAP specification lists '1..0 # Skipped: WWW::Mechanize not installed'
' as a valid example. ' as a valid example.
@ -43,6 +47,13 @@ Public Sub Plan(Tests As Integer, Optional Comment As String)
End End
Public Sub SkipAll(Optional Comment As String)
Plan(0, "SKIP" & IIf(Comment, " ", "") & Comment)
$bSkippedAll = True
End
Public Sub Finish() Public Sub Finish()
If $bFinished Then Error.Raise(("Tests already finished")) 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 sDirective As String
Dim sLine 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 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 ' 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) 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, "")) Print("Bail out!" & IIf(Comment, " " & Comment, ""))
$bFinished = True $bFinished = True
@ -159,3 +170,15 @@ Private Sub Line_Write(Value As String)
$sLine = Value $sLine = Value
End End
Private Function Finished_Read() As Boolean
Return $bFinished
End
Private Function SkippedAll_Read() As Boolean
Return $bSkippedAll
End

View File

@ -89,6 +89,12 @@ Public Sub TapStream_Read()
End End
Public Sub TapStream_Error(Message As String)
AddLine(Message)
End
Public Sub TapStream_Kill() Public Sub TapStream_Kill()
FinishStats() FinishStats()