gb.test: Add test for subtest printing

[GB.TEST]
* NEW: Add test for subtest printing
* OPT: Prefix test classes run by self-tests with an underscore so that they don't interfere with class and struct names
This commit is contained in:
Tobias Boege 2018-06-09 23:50:53 +02:00
parent 7e1a24bc81
commit eaad6a640f
4 changed files with 67 additions and 4 deletions

View File

@ -3,9 +3,9 @@
Private Const EXPECTED As String = ""
"1..1\n"
"# This is intended to fail\n"
"# Crash.Main.7: Like this Debug statement, the division by zero error should be captured and converted to a diagnostic\n"
"# Crash.Main.9: #26: Division by zero\n"
"# Crash.Main.9 \n"
"# _Crash.Main.7: Like this Debug statement, the division by zero error should be captured and converted to a diagnostic\n"
"# _Crash.Main.9: #26: Division by zero\n"
"# _Crash.Main.9 \n"
"# "
Public Sub Main()
@ -13,7 +13,7 @@ Public Sub Main()
Dim hHarness As New TestHarness
Assert.Setup(6)
hHarness.Run(Application.Path, "Crash")
hHarness.Run(Application.Path, "_Crash")
With hHarness.Current
Assert.Equals(.ExitCode, 1, "exit code")
Assert.Equals(.Planned, 1, "planned 1 test")

View File

@ -0,0 +1,26 @@
' Gambas module file
Private Const EXPECTED As String = ""
"1..2\n"
"\t1..3\n"
"\tok 1 - Now is around Now\n"
"\tok 2 - Now is a date\n"
"\tok 3 - It is past 1970\n"
"ok 1 - TestMethod1\n"
"\t1..2\n"
"\t\t1..2\n"
"\t\tok 1 - 2 > -1\n"
"\t\tok 2 - 2 is around -1\n"
"\tok 1 - a subtest\n"
"\tok 2 - True\n"
"ok 2 - TestMethod2\n"
Public Sub Main()
Dim sOut As String
Assert.Plan(1)
Exec ["gbx3", "-s", "_Subtest", Application.Path] To sOut
Assert.StringEquals(sOut, EXPECTED, "Subtest printer")
End

View File

@ -0,0 +1,37 @@
' Gambas module file
Public Sub Main()
' TODO: This is a template for how the TestHarness should call test methods!
Assert.Plan(2)
Assert.Subtest("TestMethod1")
TestMethod1()
Assert.Finish()
Assert.Subtest("TestMethod2")
TestMethod2()
Assert.Finish()
End
Public Sub TestMethod1()
Assert.Plan(3)
Assert.Approximate(Now, Now, 1e-1, "Now is around Now")
Assert.IsType(Now, gb.Date, "Now is a date")
Assert.GreaterEqual(Now, Date(1970), "It is past 1970")
End
Public Sub TestMethod2()
Assert.Plan(2)
Assert.Subtest("a subtest", 2)
Assert.Greater(2, -1, "2 > -1")
Assert.Approximate(2, -1, 10, "2 is around -1")
Assert.Finish()
Assert.Ok(True, "True")
End