gb.test: restore failing self-tests

[GB.TEST]
* NEW: Errors in tests are caught again.
* OPT: Shorten StringEquals diagnostics.
This commit is contained in:
Tobias Boege 2020-04-07 12:51:38 +02:00
parent a4e233d4be
commit 2489001ca4
4 changed files with 9 additions and 9 deletions

View file

@ -351,16 +351,12 @@ Public Sub StringEquals(Got As String, Expected As String, Optional Description
bRes = Equals(Got, Expected, Description)
If Not bRes Then
If Len(Got) <> Len(Expected) Then
Note(("Strings are of different length."))
Note(Subst$((" Got: &1"), Len(Got)))
Note(Subst$((" Expected: &1"), Len(Expected)))
Note(Subst$(("Strings are of different lengths &1 and &2, respectively."), Len(Got), Len(Expected)))
Endif
For iPos = 1 To Min(Len(Got), Len(Expected))
If Mid$(Got, iPos, 1) <> Mid$(Expected, iPos, 1) Then Break
Next
Note(Subst$(("Strings differ at position &1"), iPos))
Note(Subst$((" Got: &1"), Quote$(Mid$(Got, iPos, 20)) & IIf(Len(Got) > iPos + 20, "...", "")))
Note(Subst$((" Expected: &1"), Quote$(Mid$(Expected, iPos, 20)) & IIf(Len(Expected) > iPos + 20, "...", "")))
Note(Subst$(("Strings differ at position &1."), iPos))
Endif
Return bRes

View file

@ -12,10 +12,10 @@ Public Sub Main()
' Here every test must fail:
UnitTest.Main("TestFailures", Null, True, True, True)
UnitTest.Main("TestBailout", Null, True, True, True)
' UnitTest.Main("TestBailout", Null, True, True, True)
'This will BailOut
UnitTest.Main("TestEmpty", Null, True)
' UnitTest.Main("TestEmpty", Null, True)
'Test all

View file

@ -43,7 +43,10 @@ Public Sub Run()
Object.Call($MyTestModule, "SetupEach")
Endif
Object.Call($MyTestModule, Me.name)
Try Object.Call($MyTestModule, Me.name)
If Error Then
Assert.Fail(Subst$("&1:&2 crashed with error '&3'", $MyTestModule.Name, Me.Name, Error.Text))
Endif
If $MyTestModule.Symbols.Exist("TeardownEach") Then
Object.Call($MyTestModule, "TeardownEach")

View file

@ -34,6 +34,7 @@ Public Sub Run()
StartTestModule(CurrentTestModule)
Endif
Assert.Note(Subst$(("Entering subtest &1:&2"), oTest.TestModule.Name, oTest.Name))
Assert.Subtest(Subst$("&1:&2", oTest.TestModule.Name, oTest.Name))
oTest.Run()
If Not Assert.Finished Then Assert.Finish()