Commit ac91967c authored by Benoît Minisini's avatar Benoît Minisini

Merge branch 'master' of gitlab.com:gambas/gambas

parents f91f8dc1 56ea4ae6
......@@ -452,3 +452,9 @@ Public Sub Form_KeyPress()
End Select
End
Public Sub lvwSuite_DblClick()
Try lvwSuite.Current.Rename()
End
' Gambas module file
Public Sub Main()
Dim asGood As New String[]
Dim Tests As String
With asGood
.Add("TestAllAsserts")
.Add("TestElse")
.Add("TestError")
.Add("TestInternals")
.Add("TestFailures")
.Add("TestSetup")
.Add("TestSummary.DoSomeAsserts")
.Add("TestSummary.DoTodo")
.Add("TestSummary.DoSkip")
End With
' ------------------------------------------------- These must succeed
Tests = asGood.Join(",")
Test.Main(Tests)
' ------------------------------------------------- This must not succeed
'Tests = "TestCrashes"
'Tests = "TestSummary"
' Playground for development ...
' ------------------------------------------------- These must bailout
'Tests = "TestBailout"
'Tests = ""
'Tests = "TestAllAsserts, Wurstsupp"
' ------------------------------------------------- Playing field
'Tests = "TestAllAsserts, Wurstsupp"
'Debug TestCommand.ToString(TestRunner.List("~/programming/gambas/gambas/comp/src/gb.test"))
'Tests = "TestInternals.InterpreterInterface"
'Test.Main(Tests)
Public Sub Main()
' ------------------------------------------------- Interpreter Interface
' Dim testclass As Class
......
......@@ -2,14 +2,14 @@
''' Tests all Asserts
Public Sub TestAssert()
Public Sub Assert()
Test.Plan(1)
Assert.Ok(True, "Testing True")
End
Public Sub TestAssertEmpty()
Public Sub AssertEmpty()
Test.Plan(2)
Assert.Null("", "Empty with \"\"")
......@@ -17,7 +17,7 @@ Public Sub TestAssertEmpty()
End
Public Sub TestAssertEqualsFloat()
Public Sub AssertEqualsFloat()
Dim f As Float
......@@ -27,7 +27,7 @@ Public Sub TestAssertEqualsFloat()
End
Public Sub TestAssertEqualsLong()
Public Sub AssertEqualsLong()
Dim l As Long
......@@ -37,7 +37,7 @@ Public Sub TestAssertEqualsLong()
End
Public Sub TestAssertEqualsDate()
Public Sub AssertEqualsDate()
Dim d As Date
Dim sdate As String
......@@ -51,7 +51,7 @@ Public Sub TestAssertEqualsDate()
End
Public Sub TestAssertEqualsObject()
Public Sub AssertEqualsObject()
Dim s As New TestCase("1", Me)
Dim s2 As Object
......@@ -62,7 +62,7 @@ Public Sub TestAssertEqualsObject()
End
Public Sub TestAssertEqualsString()
Public Sub AssertEqualsString()
Dim s1, s2 As String
......@@ -73,7 +73,7 @@ Public Sub TestAssertEqualsString()
End
Public Sub TestAssertNotNull()
Public Sub AssertNotNull()
Test.Plan(2)
Assert.NotNull("" & Null & 1, "String is not Null")
......@@ -81,7 +81,7 @@ Public Sub TestAssertNotNull()
End
Public Sub TestAssertError()
Public Sub AssertError()
Dim r As Float
Test.Plan(1)
......@@ -91,7 +91,7 @@ Public Sub TestAssertError()
End
Public Sub TestAssertErrorCode()
Public Sub AssertErrorCode()
Dim r As Float
Test.Plan(1)
......@@ -100,7 +100,7 @@ Public Sub TestAssertErrorCode()
End
Public Sub TestTodoErrorCode()
Public Sub TodoErrorCode()
Dim r As Float
Test.Plan(2)
......@@ -115,7 +115,7 @@ Public Sub TestTodoErrorCode()
End
Public Sub TestNote()
Public Sub Note()
Test.Plan(0)
Test.Note("The next note is Null and that's alright:")
......@@ -124,7 +124,7 @@ Public Sub TestNote()
End
Public Sub TestLike()
Public Sub Like()
Test.Plan(2)
Assert.Like("Gambas", "G*", "Gambas like G*")
Assert.Like("Gambas", "?[Aa]*", "Gambas Like \"?[Aa]*\"")
......
' Gambas test file
Public Sub TestBailout()
Public Sub Bailout()
Test.Note("This will stop all testing immediately")
Test.BailOut("Bo-Test")
......
......@@ -6,17 +6,17 @@
''' But the test system has to report it
''' and shall not crash itself
Public Sub TestErrorTwo()
Public Sub ErrorTwo()
Error.Raise("I shot the sheriff.")
End
Public Sub TestDoACrash()
Public Sub DoACrash()
Dim a As Long
'This is a crash
a = 3 / 0
End
\ No newline at end of file
End
......@@ -3,14 +3,14 @@
' A Test with no message, should display then method name as message
Public Sub TestNoMessage()
Public Sub NoMessage()
'There is no message whicht
Assert.Ok(True)
End
Public Sub TestNoMessageInbetween()
Public Sub NoMessageInbetween()
Assert.Ok(True, "TestNoMessageInbetween Assert 1 description defined")
Assert.Ok(True)
......@@ -19,7 +19,7 @@ Public Sub TestNoMessageInbetween()
End
Public Sub TestNote()
Public Sub Note()
Test.Note("This\nis\na\nnote")
Test.SkipAll()
......
......@@ -2,21 +2,21 @@
''' Every test in this class failes, but is reverted to be reported as good
Public Sub TestStringFailure()
Public Sub StringFailure()
Assert.IntendedFailure()
Assert.StringEquals("Lisa", "Paul", "Intentional String failure. Ok if not ok.")
End
Public Sub TestLongFailure()
Public Sub LongFailure()
Assert.IntendedFailure()
Assert.Equals(2, 3, "Intentional Long failure. Ok if not ok.")
End
Public Sub TestLongTypeMismatchFailure()
Public Sub LongTypeMismatchFailure()
Dim s As String = "3.0"
......@@ -25,7 +25,7 @@ Public Sub TestLongTypeMismatchFailure()
End
Public Sub TestEqualsFailure()
Public Sub EqualsFailure()
Dim oOne, oTwo As Object
......@@ -46,7 +46,7 @@ Public Sub TestEqualsFailure()
End
Public Sub TestError()
Public Sub Error()
Dim a As Long
......
' Gambas test file
'' P
Public Sub ParseTestCommands()
Dim sCommand As String
......@@ -84,12 +82,12 @@ Public Sub ReflectTest()
Assert.Equals(tests.Count, 11, "number of all testmodules")
'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")
Assert.Equals(tests["TestInternals"].Count, 5, "count of all testmethods in TestInternals")
Assert.Equals(tests["TAllAsserts"].Count, 13, "count of all testmethods in TAllAsserts")
Assert.Equals(tests["TBailout"].Count, 1, "count of all testmethods in TBailout")
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")
End
......@@ -101,9 +99,9 @@ Public Sub ReflectTestsString()
' These have to be adjusted when tests change
' If tests are updated, get them with
' Dim cheese As String = Test.AllTests()
Dim cheese As String = Test.AllTests()
want = "TestAllAsserts.TestAssert;TestAssertEmpty;TestAssertEqualsDate;TestAssertEqualsFloat;TestAssertEqualsLong;TestAssertEqualsObject;TestAssertEqualsString;TestAssertError;TestAssertErrorCode;TestAssertNotNull;TestLike;TestNote;TestTodoErrorCode,TestBailout.TestBailout,TestCrashes.TestDoACrash;TestErrorTwo,TestElse.TestNoMessage;TestNoMessageInbetween;TestNote,TestError.TestError,TestFailures.TestEqualsFailure;TestError;TestLongFailure;TestLongTypeMismatchFailure;TestStringFailure,TestInternals.CommandsToString;InterpreterInterface;ParseTestCommands;ReflectTest;ReflectTestsString,TestSetup.NameOfMethodDoesNotStartWithTest;TestFirst,TestSummary.DoOneFailure;DoSkip;DoSomeAsserts;DoTodo,TestWrongPlan.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;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")
......
......@@ -16,6 +16,9 @@ Private $hNext As TestAssertion
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.
......@@ -41,10 +44,16 @@ Private $Suite As TestSuite
Public Sub Main(Optional Tests As String)
If Not Tests Then
PrintAllTests()
'prints the names of all testmodules
PrintAllTestModules()
Return
Endif
If Tests = _TRIGGER_GET_ALLTESTS Then
Print AllTests()
Return
Endif
If Tests = "*" Then
'triggers all tests
Tests = ""
......@@ -65,7 +74,7 @@ End
Private Sub PrintSummary()
With $hPrinter.Session
Test._Print(gb.Lf) ' better readability for humans
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))))
......@@ -176,8 +185,7 @@ Private Function RunTests()
If Not $Suite Then
' create as Suite with all tests
$Suite = New TestSuite
For Each sTestModule In GetAllTestModules()
TestModule = __Test.Load(sTestModule)
For Each TestModule In GetAllTestModules()
$Suite.AddAllTestCases(TestModule)
Next
Endif
......@@ -187,10 +195,10 @@ Private Function RunTests()
End
Private Function GetAllTestModules() As String[]
Private Function GetAllTestModules() As Class[]
Dim TestClass As Class
Dim TestModuleNames As New String[]
Dim TestModules As New Class[]
Dim sNames As New String[]
Dim sName As String
Dim hStat As ClassStat
......@@ -209,12 +217,10 @@ Private Function GetAllTestModules() As String[]
For Each sName In sNames
TestClass = __Test.Load(sName)
If Not TestClass Then Error.Raise(Subst$(("Could not load test module '&1'"), sName))
If TestModuleNames.Exist(sName) Then Continue
TestModuleNames.Add(sName)
TestModules.Add(TestClass)
Next
TestModuleNames.Sort
Return TestModuleNames
Return TestModules
Catch
Test.BailOut("Error in " & Error.Where & ": " & Error.Text)
......@@ -226,16 +232,16 @@ End
Public Function AllTestsCollection() As Collection
Dim sModules As String[]
Dim aoTestModules As Class[]
Dim sModule As String
Dim TestModule As Class
Dim cAlltests As New Collection
Dim oTestModule As Class
sModules = GetAllTestModules()
aoTestModules = GetAllTestModules()
For Each sModule In sModules
TestModule = __Test.Load(sModule)
cAlltests.Add(TestSuite.GetTestsFromTestModule(Testmodule), TestModule.Name)
For Each oTestModule In aoTestModules
cAlltests.Add(TestSuite.GetTestsFromTestModule(oTestModule), oTestModule.Name)
Next
Return cAlltests
......@@ -355,7 +361,7 @@ Public Sub _Finish()
End
Private Sub PrintAllTests()
Private Sub PrintAllTestModules()
Dim sName As String
Dim hStat As ClassStat
......@@ -371,6 +377,8 @@ Private Sub PrintAllTests()
Print aTest.Join();
End
'Fill suite from String
Private Sub FromString(Tests As String)
Dim Commands As TestCommand[]
......
......@@ -36,7 +36,7 @@ Public Sub Run()
StartTestModule(CurrentTestModule)
Endif
Test._Print(gb.Lf) 'better readability for humans
Test._Print(Null) 'better readability for humans
Test._Print(Subst$(("Test &1:&2"), oTest.TestModule.Name, oTest.Name))
Test._Subtest(Subst$("&1:&2", oTest.TestModule.Name, oTest.Name))
'Debug oTest.Name
......
......@@ -5,19 +5,19 @@ Default="TestAllAsserts,TestFailures.TestEqualsFailure;TestLongFailure;TestLongT
[TestSuites/1]
Name="! Must Bail out!"
Tests="TestBailout.TestBailout"
Tests="TBailout.Bailout"
[TestSuites/2]
Name="! Must fail (a couple of crashes)"
Tests="TestCrashes.TestDoACrash;TestErrorTwo"
Tests="TCrashes.DoACrash;ErrorTwo"
[TestSuites/3]
Name="! Must fail (wrong plan)"
Tests="TestWrongPlan.IHaveAWrongPlan"
Tests="TWrongPlan.IHaveAWrongPlan"
[TestSuites/4]
Name="All good"
Tests="TestAllAsserts.TestAssert;TestAssertEmpty;TestAssertEqualsDate;TestAssertEqualsFloat;TestAssertEqualsLong;TestAssertEqualsObject;TestAssertEqualsString;TestAssertError;TestAssertErrorCode;TestAssertNotNull;TestLike;TestNote;TestTodoErrorCode,TestElse.TestNoMessage;TestNoMessageInbetween;TestNote,TestEmpty,TestError.TestError,TestFailures.TestEqualsFailure;TestError;TestLongFailure;TestLongTypeMismatchFailure;TestStringFailure,TestInternals.CommandsToString;InterpreterInterface;ParseTestCommands;ReflectTest;ReflectTestsString,TestSetup.NameOfMethodDoesNotStartWithTest;TestFirst,TestSummary.DoSkip;DoSomeAsserts;DoTodo"
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"
......
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