2020-04-08 00:40:14 +02:00
' Gambas test file
'' P
Public Sub ParseTestCommands()
Dim sCommand As String
Dim Commands As TestCommand[]
2020-04-08 12:39:55 +02:00
Dim sGot As String
Dim iGot As Integer
2020-05-11 23:28:42 +02:00
2020-05-12 00:49:33 +02:00
Test.Plan(9)
2020-04-08 00:40:14 +02:00
'Three TestModules
sCommand = "Bing, Bong, Bung"
2020-05-14 13:08:03 +02:00
Commands = TestCommand.FromString(sCommand)
2020-04-08 12:39:55 +02:00
sGot = Commands[0].ModuleName & Commands[1].ModuleName & Commands[2].ModuleName
2020-05-11 23:28:42 +02:00
2020-05-14 13:08:03 +02:00
Assert.Equals(sGot, "BingBongBung", "FromString: Three testmodules")
2020-05-11 23:28:42 +02:00
2020-04-08 00:40:14 +02:00
'Test testmodules sort
sCommand = "Bing,Bung,Bong"
2020-05-14 13:08:03 +02:00
Commands = TestCommand.FromString(sCommand)
2020-04-08 12:39:55 +02:00
sGot = Commands[0].ModuleName & Commands[1].ModuleName & Commands[2].ModuleName
2020-05-11 23:28:42 +02:00
2020-05-14 13:08:03 +02:00
Assert.Equals(sGot, "BingBongBung", "FromString: Testmodules have to be sorted")
2020-04-08 00:40:14 +02:00
2020-04-08 12:39:55 +02:00
'Three testmodules, one with three methods
sCommand = "Bong.B, Bing, Bong.A, Bung, Bong.C"
2020-05-14 13:08:03 +02:00
Commands = TestCommand.FromString(sCommand)
2020-04-08 12:39:55 +02:00
sGot = Commands[0].ModuleName & Commands[1].ModuleName & Commands[2].ModuleName
2020-05-14 13:08:03 +02:00
Assert.Equals(sGot, "BingBongBung", "FromString: Three testmodules, one with three methods")
2020-05-11 23:28:42 +02:00
2020-04-08 00:40:14 +02:00
'Methods name sort
2020-04-08 12:39:55 +02:00
sGot = Commands[1].Methods.Join()
2020-05-14 13:08:03 +02:00
Assert.Equals(sGot, "A,B,C", "FromString: Methods name sort")
2020-04-08 12:39:55 +02:00
'Three testmodules, one with methods, but Bong also wanted all, the more greedy one has to get it
sCommand = "Bong, Bing, Bong.A, Bung, Bong.B, Bong.C"
2020-05-14 13:08:03 +02:00
Commands = TestCommand.FromString(sCommand)
2020-04-08 12:39:55 +02:00
'Methods name sort
iGot = Commands[1].Methods.Count
2020-05-14 13:08:03 +02:00
Assert.Equals(iGot, 0, "FromString: Greedy testmodule Bong")
2020-04-08 12:39:55 +02:00
'Programmer was a little tipsy but got it all except Bung which only wants testmethod U
sCommand = "Bong, Bong.A, Bing, Bing, Bing, Bing, Bing, Bing, Bong.A, Bung.U, Bong.B, Bong.C, Bing, Bing, Bing, Bong, Bong"
2020-05-14 13:08:03 +02:00
Commands = TestCommand.FromString(sCommand)
2020-04-08 12:39:55 +02:00
'Methods name sort
iGot = Commands[0].Methods.Count
2020-05-14 13:08:03 +02:00
Assert.Equals(iGot, 0, "FromString: Tipsy programmer 1")
2020-04-08 12:39:55 +02:00
iGot = Commands[1].Methods.Count
2020-05-14 13:08:03 +02:00
Assert.Equals(iGot, 0, "FromString: Tipsy programmer 2")
2020-04-08 12:39:55 +02:00
iGot = Commands[2].Methods.Count
2020-05-14 13:08:03 +02:00
Assert.Equals(iGot, 1, "FromString: Tipsy programmer 3")
2020-04-08 12:39:55 +02:00
sGot = Commands[2].Methods[0]
2020-05-14 13:08:03 +02:00
Assert.Equals(sGot, "U", "FromString: Tipsy programmer 4")
End
Public Sub CommandsToString()
Dim Commands As TestCommand[]
Commands = TestCommand.FromString("Bong, Bong.A, Bing, Bing, Bing, Bing, Bing, Bing, Bong.A, Bung.U, Bong.B, Bong.C, Bing, Bing, Bing, Bong, Bong")
Assert.Equals(TestCommand.ToString(Commands), "Bing, Bong, Bung.U")
2020-04-08 00:40:14 +02:00
End
2020-05-11 23:28:42 +02:00
'' Tests the ability to return all tests
'' in the project as a collection
Public Sub ReflectTest()
Dim tests As Collection
2020-05-13 11:14:19 +02:00
Test.Plan(7)
tests = Test.AllTestsCollection()
2020-05-11 23:28:42 +02:00
'count of all testmodules, if it fails we created a new one and we have to count new
Assert.Equals(tests.Count, 10, "number of all testmodules")
2020-05-13 11:14:19 +02:00
2020-05-11 23:28:42 +02:00
'count of all testmethods, if it fails we created a new one and we have to count new
Assert.Equals(tests["TestAllAsserts"].Count, 13, "count of all testmethods in TestAllAsserts")
Assert.Equals(tests["TestBailout"].Count, 1, "count of all testmethods in TestBailout")
Assert.Equals(tests["TestCrashes"].Count, 2, "count of all testmethods in TestCrashes")
Assert.Equals(tests["TestElse"].Count, 3, "count of all testmethods in TestElse")
Assert.Equals(tests["TestEmpty"].Count, 0, "count of all testmethods in TestEmpty")
2020-05-14 13:08:03 +02:00
Assert.Equals(tests["TestInternals"].Count, 4, "count of all testmethods in TestInternals")
2020-05-11 23:28:42 +02:00
2020-05-12 00:49:33 +02:00
End
2020-05-13 11:14:19 +02:00
'' test the ability to create a json string with my own tests
2020-05-14 13:08:03 +02:00
Public Sub ReflectTestsString()
'dim kass as string = Test.AllTests()
2020-05-13 11:14:19 +02:00
' These have to be adjusted when tests change
2020-05-14 13:08:03 +02:00
Dim tests As String = "TestAllAsserts.TestAssert,TestAllAsserts.TestAssertEmpty,TestAllAsserts.TestAssertEqualsDate,TestAllAsserts.TestAssertEqualsFloat,TestAllAsserts.TestAssertEqualsLong,TestAllAsserts.TestAssertEqualsObject,TestAllAsserts.TestAssertEqualsString,TestAllAsserts.TestAssertError,TestAllAsserts.TestAssertErrorCode,TestAllAsserts.TestAssertNotNull,TestAllAsserts.TestLike,TestAllAsserts.TestNote,TestAllAsserts.TestTodoErrorCode,TestBailout.TestBailout,TestCrashes.TestDoACrash,TestCrashes.TestErrorTwo,TestElse.TestNoMessage,TestElse.TestNoMessageInbetween,TestElse.TestNote,TestError.TestError,TestFailures.TestEqualsFailure,TestFailures.TestError,TestFailures.TestLongFailure,TestFailures.TestLongTypeMismatchFailure,TestFailures.TestStringFailure,TestInternals.CommandsToString,TestInternals.ParseTestCommands,TestInternals.ReflectTest,TestInternals.ReflectTestsString,TestSetup.NameOfMethodDoesNotStartWithTest,TestSetup.TestFirst,TestSummary.DoOneFailure,TestSummary.DoSkip,TestSummary.DoSomeAsserts,TestSummary.DoTodo"
2020-05-13 11:14:19 +02:00
2020-05-14 13:08:03 +02:00
Assert.Equals(Test.AllTests(), tests, "All Test names as string")
2020-05-13 11:14:19 +02:00
2020-05-14 13:08:03 +02:00
End