gambas-source-code/.src/TestRunner/MRunner.module
2016-09-20 23:49:28 +02:00

104 lines
2.4 KiB
Text

' Gambas module file
Export
Public Sub Main()
Dim res As New TestResult
RunTests(res, "GuTestIntentionalError", Null, True)
'RunTests(res)
PrintResult(res)
End
'' Show the Test Runner Form
Public Sub ShowTestRunnerForm()
Dim fm As New FmRunner
fm.Show()
End
Public Sub PrintResult(Res As TestResult)
'Dim Container As TestContainer
' Dim Suite As TestSuite
' Dim Res As New TestResult
Dim Errs As TestErrors
Dim Fails As TestErrors
Dim Err As TestError
Dim Fail As TestError
' Dim C As Class
'TS.Run(Res)
Errs = Res.Errors
Fails = Res.Failures
Print "------------------------------------------------- Test Results"
Print res.CountRunnedTests & " Test done"
Print "------------------------------------------------- "
If Errs.Count > 0 Then
For Each Err In Errs.Items
Print "Error in:";; Err.Source
Print "Error:";; Err.Description
Next
Else
Print "No Errors"
Endif
If Fails.Count > 0 Then
For Each Fail In Fails.Items
Print "Failure in:";; Fail.Source
Print "Failure:";; Fail.Description
Next
Else
Print "No Failures"
Endif
Print "------------------------------------------------- End"
End
'' Run all tests, optional limited by Container or TestCaseName. TestResult contains .
Public Sub RunTests(Result As TestResult, Optional ContainerName As String, Optional CaseName As String, Optional ShowDebug As Boolean)
Dim Container As TestContainer
Dim Suite As New TestSuite
If ContainerName = Null Then
If CaseName = Null Then
For Each ContainerName In MRunner.GetAllTestContainerNames()
Container = Object.New(ContainerName)
Suite.AddAllTestCases(Container)
Next
Endif
Else
Container = Object.New(ContainerName)
If CaseName = Null Then
Suite.AddAllTestCases(Container)
Else
Suite.AddNewTestCase(CaseName, Container)
Endif
Endif
Suite.Run(Result, ShowDebug)
End
Public Function GetAllTestContainerNames() As String[]
Dim ret As New String[]
Dim C As Class
For Each C In Classes
If Left(C.Name, 6) = "GuTest" Then
ret.add(C.Name)
Endif
Next
ret.Sort()
Return ret
End