2019-11-15 22:33:54 +01:00
|
|
|
' Gambas class file
|
|
|
|
|
|
|
|
Export
|
|
|
|
|
2020-02-24 17:59:14 +01:00
|
|
|
Create Static
|
|
|
|
|
2020-04-07 16:48:46 +02:00
|
|
|
''' The static procedure Test.Main() starts test(s).
|
2019-11-15 22:33:54 +01:00
|
|
|
|
|
|
|
'' Runs all tests in all testcontainers and prints the result to the console.
|
2020-04-07 16:48:46 +02:00
|
|
|
'' With Test.Main(NameTestModule) the tests can be restricted to only those of a single test module.
|
|
|
|
'' With Test.Main(NameTestModule, NameProcedure) only a single test can be accomplished.
|
2019-11-15 22:33:54 +01:00
|
|
|
|
2020-04-25 05:22:10 +02:00
|
|
|
Public Sub Main(Optional Tests As String)
|
2019-11-15 22:33:54 +01:00
|
|
|
|
2020-02-24 17:59:14 +01:00
|
|
|
Assert.Reset() ' only if you run this Main multiple times per process, which you shouldn't
|
2020-04-25 05:22:10 +02:00
|
|
|
RunTests(Tests)
|
|
|
|
PrintSummary()
|
2019-11-15 22:33:54 +01:00
|
|
|
|
|
|
|
End
|
|
|
|
|
2020-02-24 17:59:14 +01:00
|
|
|
Private Sub PrintSummary()
|
|
|
|
|
2020-04-25 05:22:10 +02:00
|
|
|
With Assert.Session
|
|
|
|
Assert.Note(Subst$(("Test run '&1' &2"), .Summary.Description, IIf(.Summary.Success, "PASSED", "FAILED")))
|
|
|
|
If .TestsRun <> .Plan Then Assert.Note(Subst$(("Planned &1 tests but ran &2"), .Plan, .TestsRun))
|
|
|
|
If Not .Summary.Success Then ShowFailures(.Summary.Subtests, "")
|
2020-02-24 17:59:14 +01:00
|
|
|
End With
|
2019-11-15 22:33:54 +01:00
|
|
|
|
|
|
|
End
|
|
|
|
|
2020-04-25 05:22:10 +02:00
|
|
|
Private Sub ShowFailures(Tests As TestAssertion[], Prefix As String)
|
|
|
|
|
|
|
|
Dim hTest As TestAssertion
|
|
|
|
Dim sName As String
|
|
|
|
|
|
|
|
For Each hTest In Tests
|
|
|
|
sName = Prefix &/ hTest.Description
|
|
|
|
' Only show the deepest subtests that caused failures.
|
|
|
|
If Not hTest.Success And If Not hTest.Subtests.Count Then Assert.Note(Subst$(("FAILED &1"), sName))
|
|
|
|
ShowFailures(hTest.Subtests, sName)
|
|
|
|
Next
|
|
|
|
|
|
|
|
End
|
|
|
|
|
2019-11-15 22:33:54 +01:00
|
|
|
'
|
|
|
|
'' Run all tests, optional limited by Container or TestCaseName. Track contains .
|
|
|
|
|
2020-04-25 05:22:10 +02:00
|
|
|
Private Function RunTests(Tests As String)
|
2019-11-15 22:33:54 +01:00
|
|
|
|
2020-04-08 12:39:55 +02:00
|
|
|
Dim aTestCommands As TestCommand[]
|
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
|
|
|
|
|
2020-04-08 12:39:55 +02:00
|
|
|
aTestCommands = TestCommand.ParseCommands(Tests)
|
|
|
|
|
2020-04-10 13:52:56 +02:00
|
|
|
'FIXME: SingleTestModule, NameProcedure do not exist any more, they are replaced by aTestCommands
|
2020-04-08 00:46:09 +02:00
|
|
|
Dim NameProcedure, SingleTestModule As String
|
2019-11-15 22:33:54 +01:00
|
|
|
|
2020-04-08 12:39:55 +02:00
|
|
|
For Each sTestModule In GetAllTestModules(aTestCommands)
|
2020-02-23 12:38:53 +01:00
|
|
|
TestModule = Class.Load(sTestModule)
|
2020-04-08 12:39:55 +02:00
|
|
|
Suite.AddAllTestCases(TestModule, aTestCommands)
|
2019-11-15 22:33:54 +01:00
|
|
|
Next
|
|
|
|
|
2020-04-25 05:22:10 +02:00
|
|
|
Assert.Session.Summary.Description = Tests
|
|
|
|
Suite.Run()
|
|
|
|
If Not Assert.Finished Then Assert.Finish()
|
2020-02-27 20:28:49 +01:00
|
|
|
|
2019-11-15 22:33:54 +01:00
|
|
|
End
|
|
|
|
|
2020-04-10 13:52:56 +02:00
|
|
|
''
|
2020-04-08 12:39:55 +02:00
|
|
|
|
|
|
|
Function GetAllTestModules(Commands As TestCommand[]) 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-04-08 12:39:55 +02:00
|
|
|
Dim Command As TestCommand
|
2019-11-15 22:33:54 +01:00
|
|
|
|
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-04-07 15:03:13 +02:00
|
|
|
TestClass = Class.Load(sName)
|
|
|
|
If Not TestClass Then Error.Raise(Subst$(("Could not load test module '&1'"), sName))
|
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-04-07 16:48:46 +02:00
|
|
|
'Bail out! Error in Test->GetAllTestModuleNames: Unknown symbol 'Stat' in class 'Class'
|
2020-01-04 14:48:51 +01:00
|
|
|
|
2020-04-07 15:03:13 +02:00
|
|
|
If TestModuleNames.Exist(sName) Then Continue
|
2020-04-08 12:39:55 +02:00
|
|
|
If Commands.Count = 0 Then
|
|
|
|
'Add every Testmodule
|
2020-02-23 12:38:53 +01:00
|
|
|
TestModuleNames.Add(sName)
|
2020-04-07 15:03:13 +02:00
|
|
|
Else
|
2020-04-08 12:39:55 +02:00
|
|
|
' 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
|
2019-11-15 22:33:54 +01:00
|
|
|
Endif
|
2020-04-07 15:03:13 +02:00
|
|
|
Next
|
2019-11-15 22:33:54 +01:00
|
|
|
|
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-04-08 12:39:55 +02:00
|
|
|
Assert.BailOut("Error in " & Error.Where & ": " & Error.Text)
|
2020-02-27 20:28:49 +01:00
|
|
|
Quit 1
|
2019-12-30 22:10:37 +01:00
|
|
|
|
2019-11-15 22:33:54 +01:00
|
|
|
End
|