2019-11-15 22:33:54 +01:00
|
|
|
' Gambas class file
|
|
|
|
|
2020-06-05 10:56:37 +02:00
|
|
|
''' The TestSuite class represents a suite of different testcases to be run.
|
2019-11-15 22:33:54 +01:00
|
|
|
|
2020-02-27 20:58:27 +01:00
|
|
|
Property Read Tests As TestCase[]
|
|
|
|
Private $Tests As New TestCase[]
|
2019-11-15 22:33:54 +01:00
|
|
|
|
|
|
|
'' Runs all tests contained within the collection and collects the result in the Track parameter.
|
|
|
|
Public Sub Run()
|
|
|
|
|
2020-02-27 20:58:27 +01:00
|
|
|
Dim oTest As TestCase
|
2020-02-23 12:38:53 +01:00
|
|
|
Dim CurrentTestModule, LastTestModule As Class
|
2019-11-15 22:33:54 +01:00
|
|
|
Dim CurrentAction As String
|
|
|
|
|
|
|
|
Assert $Tests
|
|
|
|
|
2020-05-23 12:09:34 +02:00
|
|
|
$Tests.Sort()
|
|
|
|
|
2020-04-27 12:01:47 +02:00
|
|
|
Test.Plan($Tests.Count)
|
2019-11-15 22:33:54 +01:00
|
|
|
For Each oTest In $Tests
|
2020-02-23 12:38:53 +01:00
|
|
|
CurrentTestModule = oTest.TestModule
|
|
|
|
If LastTestModule Then
|
|
|
|
If LastTestModule <> CurrentTestModule Then
|
2020-05-11 22:26:08 +02:00
|
|
|
CurrentAction = LastTestModule.Name & ":TeardownTestModule"
|
2020-02-23 12:38:53 +01:00
|
|
|
StopTestModule(LastTestModule)
|
|
|
|
CurrentAction = CurrentTestModule.Name & ":SetupTestModule"
|
|
|
|
StartTestModule(CurrentTestModule)
|
2019-11-15 22:33:54 +01:00
|
|
|
Endif
|
|
|
|
Else
|
2020-04-27 12:01:47 +02:00
|
|
|
'Test.Note("-------------------- " & CurrentTestModule.Name)
|
2020-02-23 12:38:53 +01:00
|
|
|
CurrentAction = CurrentTestModule.Name & ":SetupTestModule"
|
|
|
|
StartTestModule(CurrentTestModule)
|
2019-11-15 22:33:54 +01:00
|
|
|
Endif
|
|
|
|
|
2020-05-26 20:45:18 +02:00
|
|
|
Test._Print(Null) 'better readability for humans
|
2020-05-02 18:35:48 +02:00
|
|
|
Test._Subtest(Subst$("&1:&2", oTest.TestModule.Name, oTest.Name))
|
2020-05-23 12:09:34 +02:00
|
|
|
'Debug oTest.Name
|
|
|
|
oTest.Run()
|
2020-05-02 18:35:48 +02:00
|
|
|
If Not Test._Finished Then Test._Finish()
|
2020-02-23 12:38:53 +01:00
|
|
|
LastTestModule = CurrentTestModule
|
2019-11-15 22:33:54 +01:00
|
|
|
Next
|
|
|
|
|
2020-02-23 12:38:53 +01:00
|
|
|
If LastTestModule Then
|
2020-05-11 22:26:08 +02:00
|
|
|
CurrentAction = LastTestModule.Name & ":TeardownTestModule"
|
2020-02-23 12:38:53 +01:00
|
|
|
StopTestModule(LastTestModule)
|
2019-11-15 22:33:54 +01:00
|
|
|
Endif
|
|
|
|
|
|
|
|
Catch
|
2020-04-27 12:01:47 +02:00
|
|
|
Test.BailOut("Test Stopped with error \"" & Error.Text & "\" caused by " & CurrentAction & " in " & Error.Where & ".")
|
2019-11-15 22:33:54 +01:00
|
|
|
|
|
|
|
End Sub
|
|
|
|
|
2020-02-23 12:38:53 +01:00
|
|
|
Private Sub StartTestModule(TestModule As Class)
|
2019-12-30 22:10:37 +01:00
|
|
|
|
2020-07-18 12:45:31 +02:00
|
|
|
If TestModule.Symbols.Exist("_Setup", gb.IgnoreCase) Then
|
2020-06-06 12:08:14 +02:00
|
|
|
Test._InSetup = True
|
2020-05-11 22:26:08 +02:00
|
|
|
Object.Call(TestModule, "_Setup")
|
2020-06-06 12:08:14 +02:00
|
|
|
Test._InSetup = False
|
2020-02-23 12:38:53 +01:00
|
|
|
Endif
|
2019-12-30 22:10:37 +01:00
|
|
|
|
|
|
|
End
|
|
|
|
|
2020-02-23 12:38:53 +01:00
|
|
|
Private Sub StopTestModule(TestModule As Class)
|
2019-12-30 22:10:37 +01:00
|
|
|
|
2020-07-18 12:45:31 +02:00
|
|
|
If TestModule.Symbols.Exist("_Teardown", gb.IgnoreCase) Then
|
2020-06-06 12:08:14 +02:00
|
|
|
Test._InSetup = True
|
2020-05-11 22:26:08 +02:00
|
|
|
Object.Call(TestModule, "_Teardown")
|
2020-06-06 12:08:14 +02:00
|
|
|
Test._InSetup = False
|
2020-02-23 12:38:53 +01:00
|
|
|
Endif
|
|
|
|
|
2019-12-30 22:10:37 +01:00
|
|
|
End
|
|
|
|
|
2019-11-15 22:33:54 +01:00
|
|
|
'' Create a new test case and add it to the suite.
|
2020-05-23 08:10:33 +02:00
|
|
|
Public Function AddTestCase(sName As String, TestModule As Class)
|
2019-11-15 22:33:54 +01:00
|
|
|
|
|
|
|
Dim test As TestCase
|
|
|
|
|
|
|
|
Assert sName <> Null
|
2020-02-23 12:38:53 +01:00
|
|
|
Assert TestModule
|
2019-11-15 22:33:54 +01:00
|
|
|
|
2020-02-23 12:38:53 +01:00
|
|
|
test = New TestCase(sName, TestModule)
|
2019-11-15 22:33:54 +01:00
|
|
|
Assert $Tests
|
|
|
|
|
2020-05-23 12:09:34 +02:00
|
|
|
If Not $Tests.Exist(test) Then
|
|
|
|
$Tests.Add(test)
|
|
|
|
Endif
|
2020-05-23 08:10:33 +02:00
|
|
|
|
|
|
|
End
|
|
|
|
|
2020-05-11 23:28:42 +02:00
|
|
|
Static Public Function GetTestsFromTestModule(TestModule As Class) As String[]
|
2020-02-23 12:38:53 +01:00
|
|
|
|
|
|
|
Dim sSymbol As String
|
2020-05-11 22:26:08 +02:00
|
|
|
Dim NoTestSymbols As String[] = ["_Setup", "_SetupEach", "_Teardown", "_TeardownEach", "Plan"]
|
2020-02-23 12:38:53 +01:00
|
|
|
Dim asTests As New String[]
|
|
|
|
|
|
|
|
Assert TestModule
|
|
|
|
|
|
|
|
For Each sSymbol In TestModule.Symbols
|
2020-06-02 11:04:06 +02:00
|
|
|
If Not NoTestSymbols.Exist(sSymbol, gb.IgnoreCase) And If InStr(sSymbol, "_") = 0 Then
|
2020-02-23 12:38:53 +01:00
|
|
|
asTests.Add(sSymbol)
|
|
|
|
Endif
|
|
|
|
Next
|
|
|
|
|
|
|
|
Return asTests
|
|
|
|
|
|
|
|
End
|
|
|
|
|
2020-06-05 10:56:37 +02:00
|
|
|
'' Create all test cases that are contained in the specified testmodule and add them to the suite.
|
2020-05-23 12:09:34 +02:00
|
|
|
Public Function AddAllTestCases(TestModule As Class)
|
2019-11-15 22:33:54 +01:00
|
|
|
|
2020-02-23 12:38:53 +01:00
|
|
|
Dim asTests As String[]
|
2020-05-23 12:09:34 +02:00
|
|
|
Dim i As Integer
|
2020-04-08 12:39:55 +02:00
|
|
|
Dim NameProcedure As String
|
2019-11-15 22:33:54 +01:00
|
|
|
|
2020-02-23 12:38:53 +01:00
|
|
|
Assert TestModule
|
|
|
|
|
|
|
|
asTests = GetTestsFromTestModule(TestModule)
|
|
|
|
asTests.Sort
|
|
|
|
|
2020-02-23 22:31:28 +01:00
|
|
|
'Assert asTests.Count > 0 Error "Failed: No tests in " & TestModule.Name
|
|
|
|
If asTests.Count = 0 Then
|
2020-05-23 12:09:34 +02:00
|
|
|
Assert.Todo("No tests in " & TestModule.Name)
|
2020-02-23 22:31:28 +01:00
|
|
|
Endif
|
2020-02-23 12:38:53 +01:00
|
|
|
|
|
|
|
For i = 0 To asTests.Count - 1
|
2020-04-08 12:39:55 +02:00
|
|
|
NameProcedure = CStr(asTests[i])
|
2020-05-23 12:09:34 +02:00
|
|
|
AddTestCase(NameProcedure, TestModule)
|
2020-02-23 12:38:53 +01:00
|
|
|
Next
|
2019-11-15 22:33:54 +01:00
|
|
|
|
|
|
|
End
|
|
|
|
|
2020-02-27 20:58:27 +01:00
|
|
|
Private Function Tests_Read() As TestCase[]
|
2019-11-15 22:33:54 +01:00
|
|
|
|
|
|
|
Return $Tests
|
|
|
|
|
|
|
|
End
|