Commit 6f4c24c3 authored by Christof Thalhofer's avatar Christof Thalhofer

gb.test test all assertions

[GB.TEST]
* NEW: Assert.IntendedFailure move to Test.IntendedFailure
* NEW: TAllAsserts tests all assertions (3 todo left)
parent c0b7e7db
# Gambas Project File 3.0
Title=gb.test
Startup=TestMe
Startup=ZzzDoSth
Icon=.hidden/gb.test.png
Version=3.14.90
VersionFile=1
......
' Gambas module file
' Playground for development ...
Public Sub Main()
' ------------------------------------------------- Interpreter Interface
' Dim testclass As Class
'
' testclass = Class.Load("TestElse")
' Test._Add(testclass, "TestElse.TestNote")
' testclass = Class.Load("TestAllAsserts")
' Test._Add(testclass, "TestAllAsserts")
' ' these are already contained, do not increase the numbers of tests!
' Test._Add(testclass, "TestAllAsserts.TestNote;TestLike")
'
' Test._Run()
End
......@@ -2,22 +2,7 @@
''' Tests all Asserts
Public Sub Assert()
Test.Plan(1)
Assert.Ok(True, "Testing True")
End
Public Sub AssertEmpty()
Test.Plan(2)
Assert.Null("", "Empty with \"\"")
Assert.Null(Null, "Empty with Null")
End
Public Sub AssertEqualsFloat()
Public Sub Approximate()
Dim f As Float
......@@ -27,17 +12,18 @@ Public Sub AssertEqualsFloat()
End
Public Sub AssertEqualsLong()
Public Sub Equals()
Test.Plan(3)
' ------------------------------------------------- Long
Dim l As Long
l = 555555555555555555
Test.Plan(1)
Assert.Equals(555555555555555555, l, "Check long")
End
Public Sub AssertEqualsDate()
' ------------------------------------------------- Date
Dim d As Date
Dim sdate As String
......@@ -46,87 +32,335 @@ Public Sub AssertEqualsDate()
d = Now()
sdate = CString(d)
d2 = CDate(sdate)
Test.Plan(1)
Assert.Equals(d, d2, "Check with equal dates")
End
Assert.Equals(d, d2, "Check with equal dates")
Public Sub AssertEqualsObject()
' ------------------------------------------------- Object
Dim s As New TestCase("1", Me)
Dim s2 As Object
s2 = s
Test.Plan(1)
Assert.Equals(s2, s, "Equal Objects")
End
Public Sub AssertEqualsString()
Public Sub Error()
Dim s1, s2 As String
Dim r As Float
s1 = "blaahhh"
s2 = "blaahhh"
Test.Plan(1)
Assert.StringEquals(s1, s2, "Equal Strings")
Try r = 2 / 0
Assert.Error("Test error")
End
Public Sub AssertNotNull()
Public Sub ErrorCode()
Test.Plan(2)
Assert.NotNull("" & Null & 1, "String is not Null")
Assert.NotNull(Me, "Object is not Null")
Dim r As Float
Test.Plan(1)
Try r = 2 / 0
Assert.ErrorCode(26, "Test error with code")
End
Public Sub AssertError()
Public Sub Fail()
Dim r As Float
Test.Plan(1)
Try r = 2 / 0
Test.IntendedFailure()
Assert.Fail()
Assert.Error("Test error")
End
Public Sub Greater()
Dim small, great As Variant
Test.Plan(4)
' ------------------------------------------------- String
small = "a"
great = "z"
Assert.Greater(great, small)
' ------------------------------------------------- Integer
small = -1
great = 0
Assert.Greater(great, small)
' ------------------------------------------------- Float
small = 0.1
great = 10000000000000000.5
Assert.Greater(great, small)
' ------------------------------------------------- Date
small = Date(Year(Now), Month(Now), Day(Now))
great = Date(Year(Now) + 1, Month(Now), Day(Now))
Assert.Greater(great, small)
End
Public Sub AssertErrorCode()
Public Sub GreaterEqual()
Dim r As Float
Test.Plan(1)
Try r = 2 / 0
Assert.ErrorCode(26, "Test error with code")
Dim small, great As Variant
Test.Plan(8)
' ------------------------------------------------- String
small = "a"
great = "z"
Assert.GreaterEqual(great, small)
Assert.GreaterEqual(great, great)
' ------------------------------------------------- Integer
small = -1
great = 0
Assert.GreaterEqual(great, small)
Assert.GreaterEqual(great, great)
' ------------------------------------------------- Float
small = 0.1
great = 10000000000000000.5
Assert.GreaterEqual(great, small)
Assert.GreaterEqual(great, great)
' ------------------------------------------------- Date
small = Date(Year(Now), Month(Now), Day(Now))
great = Date(Year(Now) + 1, Month(Now), Day(Now))
Assert.GreaterEqual(great, small)
Assert.GreaterEqual(great, great)
End
Public Sub TodoErrorCode()
Public Sub IsType()
Dim r As Float
Test.Plan(2)
Dim thing As Variant
Try r = 2 / 1
Test.Todo("See automatic diagnostics 1/2")
Assert.ErrorCode(26, "Division by zero?")
Test.Plan(7)
' ------------------------------------------------- Boolean
thing = True
Assert.IsType(thing, gb.Boolean)
' ------------------------------------------------- Integer
thing = 456548812
Assert.IsType(thing, gb.Integer)
thing = 4565488121245
Assert.IsType(thing, gb.Long)
' ------------------------------------------------- Float
thing = 456548812124513564879.123456789134698797987987
Assert.IsType(thing, gb.Float)
' ------------------------------------------------- string
thing = "i bi a sdring"
Assert.IsType(thing, gb.String)
' ------------------------------------------------- Date
thing = Now()
Assert.IsType(thing, gb.Date)
' ------------------------------------------------- Object
thing = Class.Load("TAllAsserts")
Assert.IsType(thing, gb.Object)
End
Public Sub Less()
Dim small, great As Variant
Test.Plan(4)
' ------------------------------------------------- String
small = "a"
great = "z"
Assert.Less(small, great)
' ------------------------------------------------- Integer
small = -1
great = 0
Assert.Less(small, great)
' ------------------------------------------------- Long
small = 0.1
great = 1
Assert.Less(small, great)
' ------------------------------------------------- Date
small = Date(Year(Now), Month(Now), Day(Now))
great = Date(Year(Now) + 1, Month(Now), Day(Now))
Assert.Less(small, great)
Try r = 2 / 0
Test.Todo("See automatic diagnostics 2/2")
Assert.ErrorCode(25, "Division by zero?")
End
Public Sub Note()
Public Sub LessEqual()
Dim small, great As Variant
Test.Plan(8)
' ------------------------------------------------- String
small = "a"
great = "z"
Assert.LessEqual(small, great)
Assert.GreaterEqual(great, great)
' ------------------------------------------------- Integer
small = -1
great = 0
Assert.LessEqual(small, great)
Assert.GreaterEqual(great, great)
Test.Plan(0)
Test.Note("The next note is Null and that's alright:")
Test.Note(Null)
Test.SkipAll("This doesn't actually assert anything")
' ------------------------------------------------- Float
small = 0.1
great = 10000000000000000.5
Assert.LessEqual(small, great)
Assert.GreaterEqual(great, great)
' ------------------------------------------------- Date
small = Date(Year(Now), Month(Now), Day(Now))
great = Date(Year(Now) + 1, Month(Now), Day(Now))
Assert.LessEqual(small, great)
Assert.GreaterEqual(great, great)
End
Public Sub Like()
Test.Plan(2)
Assert.Like("Gambas", "G*", "Gambas like G*")
Assert.Like("Gambas", "?[Aa]*", "Gambas Like \"?[Aa]*\"")
End
Public Sub Match()
Test.Plan(1)
Test.Todo()
Assert.Match("No idea..", "..how to test this")
End
Public Sub NotNull()
Test.Plan(2)
Assert.NotNull("" & Null & 1, "String is not Null")
Assert.NotNull(Me, "Object is not Null")
End
Public Sub NotOk()
Test.Plan(1)
Assert.NotOk(False)
End
Public Sub Notequals()
Dim small, great As Variant
Test.Plan(5)
' ------------------------------------------------- String
small = "a"
great = "z"
Assert.Notequals(great, small)
' ------------------------------------------------- Integer
small = -1
great = 0
Assert.Notequals(great, small)
' ------------------------------------------------- Float
small = 0.1
great = 10000000000000000.5
Assert.Notequals(great, small)
' ------------------------------------------------- Date
small = Date(Year(Now), Month(Now), Day(Now))
great = Date(Year(Now) + 1, Month(Now), Day(Now))
Assert.Notequals(great, small)
' ------------------------------------------------- Object
Dim s As New TestCase("1", Me)
Dim s2 As New TestCase("2", Me)
Assert.Notequals(s2, s)
End
Public Sub Noterror()
Dim x As Variant
Try x = 2 / 0
Test.Plan(1)
'btw we can test Error.Clear
Error.Clear()
Assert.Noterror()
End
Public Sub Null()
Test.Plan(2)
Assert.Null("", "Empty with \"\"")
Assert.Null(Null, "Empty with Null")
End
Public Sub Ok()
Test.Plan(1)
Assert.Ok(True, "Testing True")
End
Public Sub Pass()
Test.Plan(1)
Assert.Pass("Should report ok")
End
Public Sub RelativeApproximate()
Test.Todo
Test.Plan(1)
Assert.RelativeApproximate(0, 0, 0)
End
Public Sub StringEquals()
Dim s1, s2 As String
s1 = "blaahhh"
s2 = "blaahhh"
Test.Plan(1)
Assert.StringEquals(s1, s2, "Equal Strings")
End
' Gambas test file
' A Test with no message, should display then method name as message
Public Sub NoMessage()
'There is no message whicht
......@@ -22,6 +19,9 @@ End
Public Sub Note()
Test.Note("This\nis\na\nnote")
Test.SkipAll()
Test.Plan(0)
Test.Note("The next note is Null and that's alright:")
Test.Note(Null)
Test.SkipAll("This doesn't actually assert anything")
End
End
\ No newline at end of file
' Gambas test file
Public Sub Error()
Dim a As Long
Try a = 3 / 0
Assert.Error("Wanted error. Ok if ok.")
Try a = 3 / 0 ' Throws Error.Code 26
Assert.ErrorCode(26, "Wanted error 26. Ok if ok.")
End
......@@ -4,14 +4,14 @@
Public Sub StringFailure()
Assert.IntendedFailure()
Test.IntendedFailure()
Assert.StringEquals("Lisa", "Paul", "Intentional String failure. Ok if not ok.")
End
Public Sub LongFailure()
Assert.IntendedFailure()
Test.IntendedFailure()
Assert.Equals(2, 3, "Intentional Long failure. Ok if not ok.")
End
......@@ -20,7 +20,7 @@ Public Sub LongTypeMismatchFailure()
Dim s As String = "3.0"
Assert.IntendedFailure()
Test.IntendedFailure()
Assert.Equals(s, 3, "Intentional Long type mismatch failure. Ok if not ok.")
End
......@@ -30,18 +30,18 @@ Public Sub EqualsFailure()
Dim oOne, oTwo As Object
Test.Note("Equals failures")
Assert.IntendedFailure()
Test.IntendedFailure()
Assert.Equals(2, 3)
Assert.IntendedFailure()
Test.IntendedFailure()
Assert.Equals("3", 2.0)
Assert.IntendedFailure()
Test.IntendedFailure()
Assert.Equals("2", 2.1)
oOne = New Test
oTwo = New Test
Assert.IntendedFailure()
Test.IntendedFailure()
Assert.Equals(oOne, oTwo)
End
......@@ -51,11 +51,11 @@ Public Sub Error()
Dim a As Long
Try a = 3 / 0
Assert.IntendedFailure()
Test.IntendedFailure()
Assert.ErrorCode(5, "Wanted error 5. Ok if not ok.")
' No Error, AssertError has to report a failure
Assert.IntendedFailure()
Test.IntendedFailure()
Assert.Error("No Error but error expected. Ok if not ok.")
End
......@@ -80,9 +80,7 @@ Public Sub ReflectTest()
'count of all testmodules, if it fails we created a new one and we have to count new
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["TAllAsserts"].Count, 13, "count of all testmethods in TAllAsserts")
Assert.Equals(tests["TAllAsserts"].Count, 21, "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")
......@@ -100,7 +98,7 @@ Public Sub ReflectTestsString()
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;FindTestSuiteByName;InterpreterInterface;ParseTestCommands;ReflectTest;ReflectTestsString,TSetup.NameOfMethodDoesNotStartWithTest;TestFirst,TSummary.DoOneFailure;DoSkip;DoSomeAsserts;DoTodo,TWrongPlan.IHaveAWrongPlan"
want = "TAllAsserts.Approximate;Equals;Error;ErrorCode;Fail;Greater;GreaterEqual;IsType;Less;LessEqual;Like;Match;NotNull;NotOk;Notequals;Noterror;Null;Ok;Pass;RelativeApproximate;StringEquals,TBailout.Bailout,TCrashes.DoACrash;ErrorTwo,TElse.NoMessage;NoMessageInbetween;Note,TFailures.EqualsFailure;Error;LongFailure;LongTypeMismatchFailure;StringFailure,TInternals.CommandsToString;FindTestSuiteByName;InterpreterInterface;ParseTestCommands;ReflectTest;ReflectTestsString,TSetup.NameOfMethodDoesNotStartWithTest;TestFirst,TSkipAll.SkipAll,TSummary.DoOneFailure;DoSkip;DoSomeAsserts;DoTodo;TodoErrorCode,TWrongPlan.IHaveAWrongPlan"
got = Test.AllTests()
Assert.Equals(got, want, "All Test names as string")
......
......@@ -8,7 +8,7 @@ Private $EachSetupIsDone As Boolean
Public Sub _Setup()
$SetupIsDone = True
Test.Note("_Setup TestModule")
Test.Note("Setup TestModule")
End
......@@ -26,7 +26,7 @@ Public Sub _SetupEach()
Assert.NotOk($EachSetupIsDone, "Check if each was not setup.")
$EachSetupIsDone = True
Test.Note("_Setup Each")
Test.Note("Setup Each")
End
......
' Gambas test file
Public Sub SkipAll()
Test.Todo("SkipAll has to be finished.")
Assert.Ok(False)
'Test.SkipAll()
End
......@@ -29,6 +29,22 @@ Public Sub DoTodo()
End
Public Sub TodoErrorCode()
Dim r As Float
Test.Plan(2)
Try r = 2 / 1
Test.Todo("See automatic diagnostics 1/2")
Assert.ErrorCode(26, "Division by zero?")
Try r = 2 / 0
Test.Todo("See automatic diagnostics 2/2")
Assert.ErrorCode(25, "Division by zero?")
End
'' Will fail
Public Sub DoOneFailure()
......
' Gambas module file
''' This module extends the Assert instruction, which checks
''' that Expression is TRUE, and if the Expression is FALSE,
''' an uncatchable "Assertion failed" error is raised, the
''' that Expression is TRUE, and if the Expression is FALSE,
''' an uncatchable "Assertion failed" error is raised, the
''' PRINT or ERROR instruction is executed, and the program stops immediately.