Commit 024417bc authored by Christof Thalhofer's avatar Christof Thalhofer

gb.test: Run test suite by name

[GB.TEST]
* new: Run test suite by name
parent e447aa17
......@@ -87,21 +87,20 @@ Public Sub ReflectTest()
Assert.Equals(tests["TCrashes"].Count, 2, "count of all testmethods in TCrashes")
Assert.Equals(tests["TElse"].Count, 3, "count of all testmethods in TElse")
Assert.Equals(tests["TEmpty"].Count, 0, "count of all testmethods in TEmpty")
Assert.Equals(tests["TInternals"].Count, 5, "count of all testmethods in TInternals")
Assert.Equals(tests["TInternals"].Count, 6, "count of all testmethods in TInternals")
End
'' test the ability to create a testsuite string with my own tests
Public Sub ReflectTestsString()
Dim easy As String = Test.AllTests()
Dim got, want As String
' These have to be adjusted when tests change
' If tests are updated, get them with
Dim cheese As String = Test.AllTests()
' Dim easy As String = Test.AllTests()
Dim got, want As String
want = "TAllAsserts.Assert;AssertEmpty;AssertEqualsDate;AssertEqualsFloat;AssertEqualsLong;AssertEqualsObject;AssertEqualsString;AssertError;AssertErrorCode;AssertNotNull;Like;Note;TodoErrorCode,TBailout.Bailout,TCrashes.DoACrash;ErrorTwo,TElse.NoMessage;NoMessageInbetween;Note,TError.Error,TFailures.EqualsFailure;Error;LongFailure;LongTypeMismatchFailure;StringFailure,TInternals.CommandsToString;InterpreterInterface;ParseTestCommands;ReflectTest;ReflectTestsString,TSetup.NameOfMethodDoesNotStartWithTest;TestFirst,TSummary.DoOneFailure;DoSkip;DoSomeAsserts;DoTodo,TWrongPlan.IHaveAWrongPlan"
want = "TAllAsserts.Assert;AssertEmpty;AssertEqualsDate;AssertEqualsFloat;AssertEqualsLong;AssertEqualsObject;AssertEqualsString;AssertError;AssertErrorCode;AssertNotNull;Like;Note;TodoErrorCode,TBailout.Bailout,TCrashes.DoACrash;ErrorTwo,TElse.NoMessage;NoMessageInbetween;Note,TError.Error,TFailures.EqualsFailure;Error;LongFailure;LongTypeMismatchFailure;StringFailure,TInternals.CommandsToString;FindTestSuiteByName;InterpreterInterface;ParseTestCommands;ReflectTest;ReflectTestsString,TSetup.NameOfMethodDoesNotStartWithTest;TestFirst,TSummary.DoOneFailure;DoSkip;DoSomeAsserts;DoTodo,TWrongPlan.IHaveAWrongPlan"
got = Test.AllTests()
Assert.Equals(got, want, "All Test names as string")
......@@ -129,3 +128,13 @@ Public Sub InterpreterInterface()
Assert.Equals(TestCommand.ToString(Commands), Tests, "commands as string defining a testsuite")
End
Public Sub FindTestSuiteByName()
Dim sName As String = "Keep this test suite, it is necessary for testing gb.test."
Assert.Equals(MTest.GetTestSuiteByName(sName), "TInternals.FindTestSuiteByName")
End
' Gambas module file
''' Helper functions for Test class (that need to be tested but should not be exported)
'' fiddle out testsuite's tests out of .test file
Public Function GetTestSuiteByName(Name As String) As String
Dim sTests As String
Dim asLines As String[]
Dim bFoundName As Boolean
Dim sLine As String
If Name Begins "@" Then
Name = Right(Name, String.Len(Name) - 1)
Endif
sTests = File.Load(Application.Path &/ ".test")
asLines = Split(sTests, gb.lf)
For Each sLine In asLines
If bFoundName = True Then
'sLine starts with 'Tests="'
Return String.Mid(sLine, 8, String.Len(sLine) - 8)
Endif
If InStr(sLine, "\"" & Name & "\"") Then
bFoundName = True
Endif
Next
If bFoundName = False Then
Error.Raise(Subst(("Could not find a test suite with name &1."), Name))
Endif
End
......@@ -19,7 +19,6 @@ Private $Suite As TestSuite
'' Used to trigger Test.Main to print all tests as comma separated string.
Public Const _TRIGGER_GET_ALLTESTS As String = "#GetAllTests"
'' The static procedure Test.Main() starts tests. By default it runs all testmethods in all
'' testmodules ordered by name and prints the result to the console.
''
......@@ -43,6 +42,8 @@ Public Const _TRIGGER_GET_ALLTESTS As String = "#GetAllTests"
Public Sub Main(Optional Tests As String)
Dim sTestsuite As String
If Not Tests Then
'prints the names of all testmodules
PrintAllTestModules()
......@@ -53,21 +54,38 @@ Public Sub Main(Optional Tests As String)
Print AllTests()
Return
Endif
If Tests = "*" Then
'triggers all tests
Tests = ""
Endif
If Tests Begins "@" Then
'a test suite was called by name
sTestsuite = Tests
Tests = MTest.GetTestSuiteByName(Tests)
Endif
' run tests
Test._Reset() ' only if you run this Main multiple times per process, which you shouldn't
If Tests Then
FromString(Tests)
Endif
RunTests()
$hPrinter.Session.Summary.Description = TestCommand.ToString(TestCommand.FromString(Tests))
If sTestsuite Then
sTestsuite = Replace(sTestsuite, "@", "Testsuite: ")
$hPrinter.Session.Summary.Description = sTestsuite
Else
$hPrinter.Session.Summary.Description = TestCommand.ToString(TestCommand.FromString(Tests))
Endif
PrintSummary()
Quit ExitCode()
TheEnd:
Catch
Test.BailOut(Error.Text)
End
......@@ -75,9 +93,9 @@ Private Sub PrintSummary()
With $hPrinter.Session
Test._Print(Null) ' better readability for humans
' even if the tests came in unsorted, print it sorted
Test.Note(Subst$(("Ran: '&1' "), TestCommand.ToString(TestCommand.FromString(.Summary.Description))))
Test.Note(Subst$(("Ran '&1' "), TestCommand.ToString(TestCommand.FromString(.Summary.Description))))
If .TestsRun <> .Plan Then Test.Note(Subst$(("Planned &1 tests but ran &2"), .Plan, .TestsRun))
Test.Note(gb.Lf)
......@@ -180,7 +198,6 @@ End
Private Function RunTests()
Dim Testmodule As Class
Dim sTestModule As String
If Not $Suite Then
' create as Suite with all tests
......@@ -233,8 +250,6 @@ End
Public Function AllTestsCollection() As Collection
Dim aoTestModules As Class[]
Dim sModule As String
Dim TestModule As Class
Dim cAlltests As New Collection
Dim oTestModule As Class
......@@ -373,7 +388,7 @@ Private Sub PrintAllTestModules()
hStat = Class.Stat("..." &/ sName)
If hStat.Test Then aTest.Add(hStat.Name)
Next
Print aTest.Join();
End
......@@ -387,7 +402,7 @@ Private Sub FromString(Tests As String)
Dim sName As String
Commands = TestCommand.FromString(Tests)
$Suite = New TestSuite
For Each Command In Commands
......
......@@ -29,7 +29,6 @@ Static Public Function ToString(Commands As TestCommand[]) As String
Dim Command As TestCommand
Dim asBuf As New String[]
Dim sMethod As String
Commands.Sort()
For Each Command In Commands
......
[TestSuites]
Count=4
Count=5
TestWith=4
Default="TestAllAsserts,TestFailures.TestEqualsFailure;TestLongFailure;TestLongTypeMismatchFailure;TestStringFailure,TestInternals.CommandsToString;InterpreterInterface;ParseTestCommands;ReflectTest;ReflectTestsString"
......@@ -19,32 +19,7 @@ Tests="TWrongPlan.IHaveAWrongPlan"
Name="All good"
Tests="TAllAsserts.Assert;AssertEmpty;AssertEqualsDate;AssertEqualsFloat;AssertEqualsLong;AssertEqualsObject;AssertEqualsString;AssertError;AssertErrorCode;AssertNotNull;Like;Note;TodoErrorCode,TElse.NoMessage;NoMessageInbetween;Note,TEmpty,TError.Error,TFailures.EqualsFailure;Error;LongFailure;LongTypeMismatchFailure;StringFailure,TInternals.CommandsToString;InterpreterInterface;ParseTestCommands;ReflectTest;ReflectTestsString,TSetup.NameOfMethodDoesNotStartWithTest;TestFirst,TSummary.DoSkip;DoSomeAsserts;DoTodo"
[TestSuites/Suite1]
Name="Série de tests n°1"
[TestSuites/Suite2]
Name="Série de tests n°2"
Tests="TestElse"
[TestSuites/Suite3]
Name="Série de tests n°3"
Tests="TestError"
[TestSuites/Suite4]
Name="Série de tests n°6"
[TestSuites/Suite5]
Name="Série de tests n°7"
Tests="TestElse.TestNoMessage;TestNote"
[TestSuites/Suite6]
Name="Série de tests n°8"
Tests="TestCrashes"
[TestSuites/Suite7]
Name="Test suite #1"
Tests="TestAllAsserts,TestBailout,TestCrashes"
[TestSuites/Suite8]
Name="Série de tests n°7"
[TestSuites/5]
Name="Keep this test suite, it is necessary for testing gb.test."
Tests="TInternals.FindTestSuiteByName"
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment