2019-11-15 22:33:54 +01:00
|
|
|
' Gambas class file
|
|
|
|
|
|
|
|
Export
|
|
|
|
|
2020-02-24 17:59:14 +01:00
|
|
|
Create Static
|
|
|
|
|
|
|
|
Private $hHarness As New TestHarness
|
|
|
|
Private $bVerbose As Boolean
|
|
|
|
|
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-08 00:46:09 +02:00
|
|
|
Public Sub Main(Optional Tests As String, Optional Sparse As Boolean, Optional NoSummary As Boolean)
|
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-08 00:46:09 +02:00
|
|
|
$bVerbose = Not Sparse
|
|
|
|
RunTests(Tests, Sparse)
|
|
|
|
If Not NoSummary Then PrintSummary()
|
2019-11-15 22:33:54 +01:00
|
|
|
|
|
|
|
End
|
|
|
|
|
2020-02-24 17:59:14 +01:00
|
|
|
Private Sub PrintSummary()
|
|
|
|
|
|
|
|
With $hHarness.Current
|
2020-04-10 13:52:56 +02:00
|
|
|
|
2020-02-24 17:59:14 +01:00
|
|
|
If $bVerbose Then
|
|
|
|
Dim sLine As String
|
2020-04-10 11:15:17 +02:00
|
|
|
Print "# Transcript of the TAP stream:"
|
2020-02-24 17:59:14 +01:00
|
|
|
Print
|
|
|
|
For Each sLine In .Lines
|
|
|
|
Print sLine
|
|
|
|
Next
|
|
|
|
Print
|
|
|
|
Print String$(80, "*")
|
|
|
|
Print
|
|
|
|
Endif
|
2019-12-31 01:47:37 +01:00
|
|
|
|
2020-02-24 17:59:14 +01:00
|
|
|
Print .Name;; IIf(.Success, "PASSED", "FAILED");;
|
|
|
|
Print "("; "exit code";; .ExitCode; ",";;
|
|
|
|
Print "runtime";; Format$(DateDiff(.Started, .Ended, gb.Second), "0.00s"); ")"
|
2019-11-15 22:33:54 +01:00
|
|
|
|
2020-02-24 17:59:14 +01:00
|
|
|
If .Run <> .Planned Then
|
|
|
|
Print "Planned";; .Planned;; "tests but ran";; .Run
|
|
|
|
Endif
|
2019-11-15 22:33:54 +01:00
|
|
|
|
2020-02-24 17:59:14 +01:00
|
|
|
If .Failed > 0 Then
|
|
|
|
Dim iInd As Integer
|
|
|
|
Print "Failed";; .Failed;; "out of";; .Run;; "tests:";;
|
|
|
|
For iInd = 0 To .Failures.Max
|
|
|
|
Print .Failures[iInd];
|
|
|
|
If iInd < .Failures.Max Then Print ",";;
|
|
|
|
Next
|
|
|
|
Print
|
|
|
|
Endif
|
2019-11-15 22:33:54 +01:00
|
|
|
|
2020-02-24 17:59:14 +01:00
|
|
|
If .Bonus Then
|
|
|
|
Print "Passed";; .Bonus;; "additional tests marked as TODO"
|
|
|
|
Endif
|
2019-11-15 22:33:54 +01:00
|
|
|
|
2020-02-24 17:59:14 +01:00
|
|
|
If .BailedOut Then
|
|
|
|
Print "Bailed out with message";; .BailMessage
|
|
|
|
Endif
|
2019-11-15 22:33:54 +01:00
|
|
|
|
2020-02-24 17:59:14 +01:00
|
|
|
Print
|
2020-04-10 13:52:56 +02:00
|
|
|
Print "# " & String$(80, "*")
|
2020-02-24 17:59:14 +01:00
|
|
|
Print
|
2019-11-15 22:33:54 +01:00
|
|
|
|
2020-02-24 17:59:14 +01:00
|
|
|
End With
|
2019-11-15 22:33:54 +01:00
|
|
|
|
|
|
|
End
|
|
|
|
|
|
|
|
'
|
|
|
|
'' Run all tests, optional limited by Container or TestCaseName. Track contains .
|
|
|
|
|
2020-04-08 00:46:09 +02:00
|
|
|
Private Function RunTests(Tests As String, Optional Sparse As Boolean)
|
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-02-24 17:59:14 +01:00
|
|
|
Dim hTapStream As Stream, sTap As String
|
2019-11-15 22:33:54 +01:00
|
|
|
|
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-08 12:39:55 +02:00
|
|
|
' FIXME: This as hack that allows to see the TAP as it is produced. Sparse = true switches that off
|
2020-02-27 20:28:49 +01:00
|
|
|
' 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.
|
2020-04-10 13:52:56 +02:00
|
|
|
|
2020-04-08 00:46:09 +02:00
|
|
|
If Sparse = False Then
|
2020-02-27 20:28:49 +01:00
|
|
|
' The TAP stream is produced in this process. We have to get it into the
|
|
|
|
' harness somehow. Since we don't start a new process, it is going to be
|
|
|
|
' done by a buffer.
|
|
|
|
hTapStream = Open String For Write
|
|
|
|
Assert.Output = hTapStream
|
2020-04-10 13:52:56 +02:00
|
|
|
Suite.Run()
|
2020-02-27 20:28:49 +01:00
|
|
|
sTap = Close #hTapStream
|
|
|
|
hTapStream = Open String sTap For Read
|
2020-04-10 13:52:56 +02:00
|
|
|
|
|
|
|
'FIXME: SingleTestModule, NameProcedure do not exist any more
|
2020-02-27 20:28:49 +01:00
|
|
|
$hHarness.Read(hTapStream, Subst$("&1:&2", SingleTestModule, IIf(NameProcedure, NameProcedure, "*")))
|
|
|
|
Close #hTapStream
|
|
|
|
Else
|
2020-02-24 17:59:14 +01:00
|
|
|
Suite.Run()
|
2020-02-27 20:28:49 +01:00
|
|
|
Endif
|
|
|
|
|
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
|