TestCommand parsing done, but system still buggy

Without "Debug oTest.Name" in TestSuite.class:39 it would silently crash anywhere
after TestNoMessage is done without printing any single character. Reason is
"Assert.BailOut" in TestSuite:51 which miraculously does nothing.

If the testsystem itself crashes, ist must print "BailOut ..."

But here also can be seen, why the system has to print every assertion immediately.
Any bufferíng is bad because if the testsystem crashes the buffered results are gone.

So we must get rid of the buffered stream thing and go back to Print scattered all over ;-)
This commit is contained in:
Christof Thalhofer 2020-04-08 12:39:55 +02:00
parent ce56c1ddb4
commit 815a1ddcf2
5 changed files with 139 additions and 54 deletions

View file

@ -5,11 +5,12 @@ Public Sub Main()
' These must succeed:
'Test
'Test.Main()
Test.Main("TestInternals")
Test.Main()
'Test.Main("TestInternals, TestAllAsserts.TestAssert")
'
'Test.Main("TestAllAsserts.TestAssert,TestAllAsserts.TestAssertEmpty,TestElse")
' Test.Main("TestAllAsserts", Null)
'Test.Main("TestAllAsserts", True)
' Test.Main("TestSetup", Null)
' Test.Main("TestElse", Null)
' Test.Main("TestError", Null)

View file

@ -6,33 +6,56 @@
Public Sub ParseTestCommands()
Dim sCommand As String
Dim Commands As TestCommand[]
Dim Got As String
Dim sGot As String
Dim iGot As Integer
'Three TestModules
sCommand = "Bing, Bong, Bung"
Commands = TestCommand.ParseCommands(sCommand)
Got = Commands[0].ModuleName & Commands[1].ModuleName & Commands[2].ModuleName
sGot = Commands[0].ModuleName & Commands[1].ModuleName & Commands[2].ModuleName
Assert.Equals(Got, "BingBongBung", "ParseCommands: Three TestModules")
Assert.Equals(sGot, "BingBongBung", "ParseCommands: Three testmodules")
'Test testmodules sort
sCommand = "Bing,Bung,Bong"
Commands = TestCommand.ParseCommands(sCommand)
Got = Commands[0].ModuleName & Commands[1].ModuleName & Commands[2].ModuleName
sGot = Commands[0].ModuleName & Commands[1].ModuleName & Commands[2].ModuleName
Assert.Equals(Got, "BingBongBung", "ParseCommands: Test testmodules sort")
Assert.Equals(sGot, "BingBongBung", "ParseCommands: Testmodules have to be sorted")
'Three testmodules, one with methods
sCommand = "Bing, Bong.A, Bung, Bong.B, Bong.C"
'Three testmodules, one with three methods
sCommand = "Bong.B, Bing, Bong.A, Bung, Bong.C"
Commands = TestCommand.ParseCommands(sCommand)
Got = Commands[0].ModuleName & Commands[1].ModuleName & Commands[2].ModuleName
Assert.Equals(Got, "BingBongBung", "ParseCommands: Three testmodules, one with methods")
sGot = Commands[0].ModuleName & Commands[1].ModuleName & Commands[2].ModuleName
Assert.Equals(sGot, "BingBongBung", "ParseCommands: Three testmodules, one with three methods")
'Methods name sort
Got = Commands[1].Methods.Join()
Assert.Equals(Got, "A,B,C", "ParseCommands: Methods name sort")
sGot = Commands[1].Methods.Join()
Assert.Equals(sGot, "A,B,C", "ParseCommands: Methods name sort")
'Three testmodules, one with methods, but Bong also wanted all, the more greedy one has to get it
sCommand = "Bong, Bing, Bong.A, Bung, Bong.B, Bong.C"
Commands = TestCommand.ParseCommands(sCommand)
'Methods name sort
iGot = Commands[1].Methods.Count
Assert.Equals(iGot, 0, "ParseCommands: Greedy testmodule Bong")
'Programmer was a little tipsy but got it all except Bung which only wants testmethod U
sCommand = "Bong, Bong.A, Bing, Bing, Bing, Bing, Bing, Bing, Bong.A, Bung.U, Bong.B, Bong.C, Bing, Bing, Bing, Bong, Bong"
Commands = TestCommand.ParseCommands(sCommand)
'Methods name sort
iGot = Commands[0].Methods.Count
Assert.Equals(iGot, 0, "ParseCommands: Tipsy programmer 1")
iGot = Commands[1].Methods.Count
Assert.Equals(iGot, 0, "ParseCommands: Tipsy programmer 2")
iGot = Commands[2].Methods.Count
Assert.Equals(iGot, 1, "ParseCommands: Tipsy programmer 3")
sGot = Commands[2].Methods[0]
Assert.Equals(sGot, "U", "ParseCommands: Tipsy programmer 4")
End

View file

@ -23,7 +23,6 @@ Public Sub Main(Optional Tests As String, Optional Sparse As Boolean, Optional N
End
Private Sub PrintSummary()
With $hHarness.Current
@ -78,19 +77,22 @@ End
Private Function RunTests(Tests As String, Optional Sparse As Boolean)
Dim aTestCommands As TestCommand[]
Dim sTestModule As String
Dim TestModule As Class
Dim Suite As New TestSuite
Dim hTapStream As Stream, sTap As String
aTestCommands = TestCommand.ParseCommands(Tests)
Dim NameProcedure, SingleTestModule As String
For Each sTestModule In GetAllTestModules(Tests)
For Each sTestModule In GetAllTestModules(aTestCommands)
TestModule = Class.Load(sTestModule)
Suite.AddAllTestCases(TestModule, NameProcedure)
Suite.AddAllTestCases(TestModule, aTestCommands)
Next
' FIXME: RawTap is hack that allows to see the TAP as it is produced.
' FIXME: This as hack that allows to see the TAP as it is produced. Sparse = true switches that off
' This is for tests which fail with an error and test gb.test's BailOut.
' Such tests are buffered to a string stream but before they can be echoed,
' the process dies.
@ -112,12 +114,15 @@ Private Function RunTests(Tests As String, Optional Sparse As Boolean)
End
Function GetAllTestModules(Optional SingleTestModule As String) As String[]
''
Function GetAllTestModules(Commands As TestCommand[]) As String[]
Dim TestClass As Class
Dim TestModuleNames As New String[]
Dim sNames As New String[]
Dim sName As String
Dim Command As TestCommand
If Exist(".../.test")
sNames = Split(File.Load(".../.test"), gb.Lf, Null, True)
@ -137,12 +142,19 @@ Function GetAllTestModules(Optional SingleTestModule As String) As String[]
'Bail out! Error in Test->GetAllTestModuleNames: Unknown symbol 'Stat' in class 'Class'
If TestModuleNames.Exist(sName) Then Continue
If SingleTestModule = Null Then
If Commands.Count = 0 Then
'Add every Testmodule
TestModuleNames.Add(sName)
Else
If Lower(sName) = Lower(SingleTestModule) Then
TestModuleNames.Add(sName)
Endif
' Add only testmodules whose names exist in Commands
For Each Command In Commands
If Lower(Command.ModuleName) = Lower(sName) Then
TestModuleNames.Add(sName)
Endif
Next
' If Lower(sName) = Lower(SingleTestModule) Then
' TestModuleNames.Add(sName)
' Endif
Endif
Next
@ -151,7 +163,7 @@ Function GetAllTestModules(Optional SingleTestModule As String) As String[]
Return TestModuleNames
Catch
Assert.BailOut("Error in Test->GetAllTestModuleNames: " & Error.Text)
Assert.BailOut("Error in " & Error.Where & ": " & Error.Text)
Quit 1
End

View file

@ -1,33 +1,65 @@
' Gambas class file
''' Helper class to split string Tests in Test.Main(Tests) into names of testmodules and testmethods
''' Helper class to split a string containing names of testmodules and testmethods into TestCommands.
''' Does not check validity of symbols or if the symbols exist.
Create Static
'' Name of the testmodule to be called
Public ModuleName As String
'' Name of testmethods in a testmodule to be called. If empty, all will be called.
Public Methods As New String[]
'' Finds the Command for the TestModule with name TestModuleName
Static Public Function Find(Commands As TestCommand[], TestModuleName As String) As TestCommand
Dim Command As TestCommand
For Each Command In Commands
If Lower(Command.ModuleName) = Lower(TestModuleName) Then
Return Command
Endif
Next
End
'' Parses a string with comma separated tests and creates an array of TestCommands.
Public Function ParseCommands(Tests As String) As TestCommand[]
Dim asAll As String[]
Dim sCommand, sModulename, sMethodname As String
Dim Command As TestCommand
Dim Commands As TestCommand[]
Dim Commands As New TestCommand[]
Dim i As Integer
If Tests <> Null Then
Commands = New TestCommand[]
'Commands = New TestCommand[]
asAll = Split(Tests, ",", Null, True)
For i = 0 To asAll.Count - 1
asAll[i] = Trim(asAll[i])
Next
asAll.Sort
For Each sCommand In asAll
'just to be sure
sModulename = Null
sMethodname = Null
i = 0
Command = New TestCommand
With Command
If InStr(sCommand, ".") > 0 Then
sModulename = Trim(Left(sCommand, InStr(sCommand, ".") - 1))
sMethodname = Trim(Right(sCommand, Len(sCommand) - InStr(sCommand, ".")))
sModulename = Trim(Left(sCommand, InStr(sCommand, ".") - 1))
sMethodname = Trim(Right(sCommand, Len(sCommand) - InStr(sCommand, ".")))
.ModuleName = sModulename
.Methods.Add(sMethodname)
Else
@ -38,29 +70,35 @@ Public Function ParseCommands(Tests As String) As TestCommand[]
'If InStr(Command, ".") > 0 Then
If Not Commands.Exist(Command) Then
Commands.Add(Command)
Else
i = 0
For Each Commands
If Commands[i].ModuleName = sModulename Then
Endif
For Each Commands
If Commands[i].ModuleName = sModulename And If Commands[i].Methods.Count > 0 Then
If Not Commands[i].Methods.Exist(sMethodname) Then
Commands[i].Methods.Add(sMethodname)
Endif
Inc i
Next
Endif
Endif
Inc i
Next
Next
For Each Command In Commands
Command.Methods = Command.Methods.Sort()
Next
Return Commands.Sort()
Commands = Commands.Sort()
Endif
Return Commands
End
Public Function _compare(TC As TestCommand) As Integer
Dim ret As Integer
ret = Comp(ModuleName, TC.ModuleName, gb.Binary)
Return ret
End
End

View file

@ -36,6 +36,7 @@ Public Sub Run()
Assert.Note(Subst$(("Entering subtest &1:&2"), oTest.TestModule.Name, oTest.Name))
Assert.Subtest(Subst$("&1:&2", oTest.TestModule.Name, oTest.Name))
Debug oTest.Name
oTest.Run()
If Not Assert.Finished Then Assert.Finish()
LastTestModule = CurrentTestModule
@ -111,35 +112,45 @@ Private Function GetTestsFromTestModule(TestModule As Class) As String[]
End
'' Create all test cases that are contained in the specified TestModule and add them to the suite.
Public Function AddAllTestCases(TestModule As Class, Optional NameProcedure As String)
Public Function AddAllTestCases(TestModule As Class, Commands As TestCommand[])
Dim asTests As String[]
Dim i As Integer
Dim i, Plan, MethodCounts As Integer
Dim Command As TestCommand
Dim NameProcedure As String
Assert TestModule
asTests = GetTestsFromTestModule(TestModule)
asTests.Sort
' Tests must not be empty
Command = TestCommand.Find(Commands, TestModule.Name)
'If there was no Command then Command is Null
Try MethodCounts = Command.Methods.Count
'Assert asTests.Count > 0 Error "Failed: No tests in " & TestModule.Name
If asTests.Count = 0 Then
Assert.BailOut("Error: No tests in " & TestModule.Name)
Assert.Todo("No tests in " & TestModule.Name)
Endif
For i = 0 To asTests.Count - 1
If NameProcedure = Null Then
AddNewTestCase(CStr(asTests[i]), TestModule)
NameProcedure = CStr(asTests[i])
If MethodCounts = 0 Then
'add every testmethod
AddNewTestCase(NameProcedure, TestModule)
Else
' just one TestMethod was called, change plan, if plan exists in TestModule
' just certain TestMethods will be added, increase plan, if plan exists in TestModule
If TestModule.Symbols.Exist("Plan", gb.IgnoreCase) Then
Object.SetProperty(TestModule, "Plan", 1)
Plan = Object.GetProperty(TestModule, "Plan")
Inc Plan
Object.SetProperty(TestModule, "Plan", Plan)
Endif
If asTests[i] = NameProcedure Then
AddNewTestCase(CStr(asTests[i]), TestModule)
If Command.Methods.Exist(NameProcedure) Then
AddNewTestCase(NameProcedure, TestModule)
Endif
Endif
Next
End