2019-11-15 22:33:54 +01:00
|
|
|
' Gambas class file
|
|
|
|
|
|
|
|
Export
|
|
|
|
|
|
|
|
''' The static procedure Unittest.Main() starts test(s).
|
|
|
|
|
|
|
|
'' Runs all tests in all testcontainers and prints the result to the console.
|
2020-02-23 12:38:53 +01:00
|
|
|
'' With UnitTest.Main(NameTestModule) the tests can be restricted to only those of a single test module.
|
|
|
|
'' With UnitTest.Main(NameTestModule, NameProcedure) only a single test can be accomplished.
|
2019-11-15 22:33:54 +01:00
|
|
|
|
2020-02-23 12:38:53 +01:00
|
|
|
Static Public Sub Main(Optional NameTestModule As String, Optional NameProcedure As String, Optional DoSelfTest As Boolean)
|
2019-11-15 22:33:54 +01:00
|
|
|
|
|
|
|
'Track.Initialize()
|
2020-02-23 12:38:53 +01:00
|
|
|
RunTests(NameTestModule, NameProcedure, DoSelfTest)
|
2019-11-15 22:33:54 +01:00
|
|
|
PrintSummary()
|
|
|
|
|
|
|
|
End
|
|
|
|
|
|
|
|
Static Private Sub PrintSummary()
|
|
|
|
|
2019-12-31 01:47:37 +01:00
|
|
|
Dim bSuccess As Boolean = True
|
|
|
|
|
2019-11-15 22:33:54 +01:00
|
|
|
If Track.NOKs.Count > 0 Then Print "# Failed tests: " & PrintNumbers(Track.NOKs)
|
|
|
|
|
|
|
|
'Plan
|
2019-12-30 22:10:37 +01:00
|
|
|
If Track.Plan > 0 Then
|
|
|
|
Print "1.." & Track.Plan
|
2019-11-15 22:33:54 +01:00
|
|
|
Else
|
2019-12-30 22:10:37 +01:00
|
|
|
Print "0..0"
|
2019-11-15 22:33:54 +01:00
|
|
|
Endif
|
2019-12-30 22:10:37 +01:00
|
|
|
|
2019-11-15 22:33:54 +01:00
|
|
|
If Track.NOKs.Count > 0 Or If Track.Counter = 0 Then
|
2019-12-31 01:47:37 +01:00
|
|
|
bSuccess = False
|
|
|
|
Endif
|
2020-02-23 12:38:53 +01:00
|
|
|
|
2019-12-31 01:47:37 +01:00
|
|
|
If Track.Plan <> Track.Counter Then
|
|
|
|
bSuccess = False
|
2019-12-30 22:10:37 +01:00
|
|
|
Print "# Plan was " & Track.Plan & " but assertions counted was " & Track.Counter
|
2019-12-31 01:47:37 +01:00
|
|
|
Endif
|
|
|
|
|
|
|
|
If bSuccess = True Then
|
2019-12-30 22:10:37 +01:00
|
|
|
Print "# ------- Success! -------"
|
2019-12-31 01:47:37 +01:00
|
|
|
Else
|
|
|
|
Print "# ------- No success! -------"
|
2019-11-15 22:33:54 +01:00
|
|
|
Endif
|
|
|
|
|
|
|
|
Track.Reset()
|
|
|
|
|
|
|
|
End
|
|
|
|
|
|
|
|
Static Private Function PrintNumbers(Numbers As Long[]) As String
|
|
|
|
|
|
|
|
Dim Number As Long
|
|
|
|
Dim s As New String[]
|
|
|
|
|
|
|
|
For Each Number In Numbers
|
|
|
|
s.Add(Number)
|
|
|
|
Next
|
|
|
|
|
|
|
|
Return s.Join(",")
|
|
|
|
|
|
|
|
End
|
|
|
|
|
|
|
|
'
|
|
|
|
'' Run all tests, optional limited by Container or TestCaseName. Track contains .
|
|
|
|
|
2020-02-23 12:38:53 +01:00
|
|
|
Static Private Function RunTests(SingleTestModule As String, Optional NameProcedure As String, Optional DoSelfTest As Boolean)
|
2019-11-15 22:33:54 +01:00
|
|
|
|
2020-02-23 12:38:53 +01:00
|
|
|
Dim sTestModule As String
|
|
|
|
Dim TestModule As Class
|
2019-11-15 22:33:54 +01:00
|
|
|
Dim Suite As New TestSuite
|
|
|
|
|
|
|
|
'FIXME: If included as component then TestContainers can only be loaded if they contain the magic word Export
|
|
|
|
|
2020-02-23 12:38:53 +01:00
|
|
|
For Each sTestModule In GetAllTestTestModules(SingleTestModule, DoSelfTest)
|
|
|
|
TestModule = Class.Load(sTestModule)
|
|
|
|
Suite.AddAllTestCases(TestModule, NameProcedure)
|
2019-11-15 22:33:54 +01:00
|
|
|
Next
|
|
|
|
|
|
|
|
Suite.Run()
|
|
|
|
|
|
|
|
End
|
|
|
|
|
2020-02-23 12:38:53 +01:00
|
|
|
Static Function GetAllTestTestModules(Optional SingleTestModule As String, Optional DoSelfTest As Boolean) As String[]
|
2019-11-15 22:33:54 +01:00
|
|
|
|
|
|
|
Dim TestClass As Class
|
2020-02-23 12:38:53 +01:00
|
|
|
Dim TestModuleNames As New String[]
|
2019-11-15 22:33:54 +01:00
|
|
|
Dim sNames As New String[]
|
|
|
|
Dim sName As String
|
|
|
|
|
2020-02-23 12:38:53 +01:00
|
|
|
If Exist(".../.test")
|
|
|
|
sNames = Split(File.Load(".../.test"), gb.Lf, Null, True)
|
|
|
|
Endif
|
2019-11-15 22:33:54 +01:00
|
|
|
|
|
|
|
Assert sNames
|
|
|
|
|
|
|
|
sNames.Sort
|
|
|
|
For Each sName In sNames
|
2020-02-23 12:38:53 +01:00
|
|
|
GoSub AddClass
|
2019-11-15 22:33:54 +01:00
|
|
|
Next
|
|
|
|
|
|
|
|
Goto Done
|
|
|
|
|
|
|
|
AddClass:
|
|
|
|
|
2020-01-04 14:48:51 +01:00
|
|
|
TestClass = Class.Load(sName)
|
2019-11-15 22:33:54 +01:00
|
|
|
If TestClass Then
|
2020-02-23 12:38:53 +01:00
|
|
|
|
2019-11-15 22:33:54 +01:00
|
|
|
'sName = Class.Stat(sName).Name
|
2020-02-23 12:38:53 +01:00
|
|
|
|
2020-01-22 09:13:41 +01:00
|
|
|
'Atention: Class.Stat(sName).Name does not work if included as component
|
2020-01-04 14:48:51 +01:00
|
|
|
'Then this creates the error:
|
2020-02-23 12:38:53 +01:00
|
|
|
'Bail out! Error in Unittest->GetAllTestModuleNames: Unknown symbol 'Stat' in class 'Class'
|
2020-01-04 14:48:51 +01:00
|
|
|
|
2020-02-23 12:38:53 +01:00
|
|
|
If Not TestModuleNames.Exist(sName) Then
|
2019-11-15 22:33:54 +01:00
|
|
|
If testclass.Symbols.Exist("ThisIsAnUnitTestSelfTest")
|
|
|
|
If DoSelfTest = True Then
|
2020-02-23 12:38:53 +01:00
|
|
|
GoSub AddTestModule
|
2019-11-15 22:33:54 +01:00
|
|
|
Endif
|
|
|
|
Else
|
2020-02-23 12:38:53 +01:00
|
|
|
GoSub AddTestModule
|
2019-11-15 22:33:54 +01:00
|
|
|
Endif
|
|
|
|
Endif
|
|
|
|
Endif
|
|
|
|
Return
|
|
|
|
|
2020-02-23 12:38:53 +01:00
|
|
|
AddTestModule:
|
2019-11-15 22:33:54 +01:00
|
|
|
|
2020-02-23 12:38:53 +01:00
|
|
|
If SingleTestModule = Null Then
|
|
|
|
TestModuleNames.Add(sName)
|
2019-11-15 22:33:54 +01:00
|
|
|
Else
|
2020-02-23 12:38:53 +01:00
|
|
|
If Lower(sName) = Lower(SingleTestModule) Then
|
|
|
|
TestModuleNames.Add(sName)
|
2019-11-15 22:33:54 +01:00
|
|
|
Endif
|
|
|
|
Endif
|
|
|
|
|
|
|
|
Return
|
|
|
|
|
|
|
|
Done:
|
2020-02-23 12:38:53 +01:00
|
|
|
TestModuleNames.Sort
|
|
|
|
' Print "# These TestContainer will be executed:\n#\n# " & TestModuleNames.Join("\n# ") & "\n"
|
|
|
|
Return TestModuleNames
|
2019-11-15 22:33:54 +01:00
|
|
|
|
2020-01-04 14:48:51 +01:00
|
|
|
Catch
|
2020-02-23 12:38:53 +01:00
|
|
|
Print "Bail out! Error in Unittest->GetAllTestModuleNames: " & Error.Text
|
2019-12-30 22:10:37 +01:00
|
|
|
Print "# ------- No success! -------"
|
|
|
|
Quit
|
|
|
|
|
2019-11-15 22:33:54 +01:00
|
|
|
End
|
|
|
|
|
2020-02-23 12:38:53 +01:00
|
|
|
' Private Function CaseNames_Read() As String[]
|
|
|
|
'
|
|
|
|
' Return $CaseNames
|
|
|
|
'
|
|
|
|
' End
|
|
|
|
'
|
|
|
|
' '' Returns the classname of the TestContainer
|
|
|
|
' Private Function Name_Read() As String
|
|
|
|
'
|
|
|
|
' Return Object.Class(Me).Name
|
|
|
|
'
|
|
|
|
' End
|