testly.bi

Summary
testly.bi
LicenseCopyright © 2006-2008 Luis Lavena, Multimedia systems
ext.Testly
Types
test_func_tFunction prototype for testcases.
Enumerations
HookUsed with addSuiteHook to run a procedure on certain events.
Functions
customAssertionUsed by the helper macros below.
addSuiteAdd a test Suite.
addSuiteHookAssign a function to run at certain points in the suite.
addTestAdds a testcase to the testsuite.
runTestsRuns the testcases for all registered Suites.
Macros
testly_assert_true
testly_assert_true_error
testly_assert_false
testly_assert_false_error
testly_assert_equal
testly_assert_equal_error
testly_assert_not_equal
testly_assert_not_equal_error
testly_assert_string_equal
testly_assert_string_equal_error
testly_assert_string_not_equal
testly_assert_string_not_equal_error
testly_assert_pass
testly_assert_fail
testly_assert_error

License

Copyright © 2006-2008 Luis Lavena, Multimedia systems

Copyright © 2007-2011, FreeBASIC Extended Library Development Group

Distributed under the FreeBASIC Extended Library Group license.  See accompanying file LICENSE.txt or copy at http://code.google.com/p/fb-extended-lib/wiki/License

Types

test_func_t

type test_func_t as sub()

Function prototype for testcases.

Enumerations

Hook

Used with addSuiteHook to run a procedure on certain events.

before_allruns this procedure before running any testcases.
before_eachruns this procedure before running each testcase.
after_allruns this procedure after running all testcases.
after_eachruns this procedure after each testcase.

Functions

customAssertion

declare function customAssertion(byval as ext.bool,  
byref as string,  
byval as uinteger,  
byref as string,  
byval as ext.bool =  false) as ext.bool

Used by the helper macros below.  Generally not needed to call directly.

Parameters

testboolean value indicating whether assertion was sucessful.
filestring containing the file the testcase is in.
lineuinteger containing the line number of the assertion.
msgstring containing the message to be passed to the user if assertion fails.
errorboolean value indicating true if there is an error and the suite should stop. defaults to false.

Returns

boolean value indicating false if there is a fatal error.  Usually ignored.

addSuite

declare function addSuite(byref as string) as ext.bool

Add a test Suite.

Parameters

namestring containing the name of the test suite to add, used in error reporting.

Returns

True if sucessful.

addSuiteHook

declare function addSuiteHook(byval as Hook,
byref as sub()) as ext.bool

Assign a function to run at certain points in the suite.

Parameters

hooktypesee Hook
procfunction to run at specified time.

Returns

True if procedure is added.

addTest

declare function addTest(byref as string,
byref as test_func_t) as ext.bool

Adds a testcase to the testsuite.

Parameters

namestring containing the name of the testcase.
procprocedure containing the testcase.

Returns

True if testcase is added.

runTests

declare function runTests() as ext.bool

Runs the testcases for all registered Suites.

Returns

True on success.

Macros

testly_assert_true

#define testly_assert_true(
   __value__
) ext.Testly.customAssertion((__value__) = (true), __FILE__, __LINE__, ("{" #__value__ "} is not true."))

testly_assert_true_error

#define testly_assert_true_error(
   __value__
) if (ext.Testly.customAssertion((__value__) = (true), __FILE__, __LINE__, ("{" #__value__ "} is not true."), true) = false) then exit sub

testly_assert_false

#define testly_assert_false(
   __value__
) ext.Testly.customAssertion((__value__) = (false), __FILE__, __LINE__, ("{" #__value__ "} is not false."))

testly_assert_false_error

#define testly_assert_false_error(
   __value__
) if (ext.Testly.customAssertion((__value__) = (false), __FILE__, __LINE__, ("{" #__value__ "} is not false."), true) = false) then exit sub

testly_assert_equal

#define testly_assert_equal(
   __expected__,
   __actual__
) ext.Testly.customAssertion((__actual__) = (__expected__), __FILE__, __LINE__, ("expected {" #__expected__ "} but was {" #__actual__ "}"))

testly_assert_equal_error

#define testly_assert_equal_error(
   __expected__,
   __actual__
) if (ext.Testly.customAssertion((__actual__) = (__expected__), __FILE__, __LINE__, ("expected {" #__expected__ "} but was {" #__actual__ "}"), true) = false) then exit sub

testly_assert_not_equal

#define testly_assert_not_equal(
   __expected__,
   __actual__
) ext.Testly.customAssertion((__actual__) <> (__expected__), __FILE__, __LINE__, ("{" #__actual__ "} expected to be != to {" #__expected__ "}"))

testly_assert_not_equal_error

#define testly_assert_not_equal_error(
   __expected__,
   __actual__
) if (ext.Testly.customAssertion((__actual__) <> (__expected__), __FILE__, __LINE__, ("{" #__actual__ "} expected to be != to {" #__expected__ "}"), true) = false) then exit sub

testly_assert_string_equal

#define testly_assert_string_equal(
   __expected__,
   __actual__
) ext.Testly.customAssertion((str(__actual__) = str(__expected__)), __FILE__, __LINE__, ("expected {" #__expected__ "} but was {" #__actual__ "}"))

testly_assert_string_equal_error

#define testly_assert_string_equal_error(
   __expected__,
   __actual__
) if (ext.Testly.customAssertion((str(__actual__) = str(__expected__)), __FILE__, __LINE__, ("expected {" #__expected__ "} but was {" #__actual__ "}"), true) = false) then exit sub

testly_assert_string_not_equal

#define testly_assert_string_not_equal(
   __expected__,
   __actual__
) ext.Testly.customAssertion((str(__actual__) <> str(__expected__)), __FILE__, __LINE__, ("{" #__actual__ "} expected to be != to {" #__expected__ "}"))

testly_assert_string_not_equal_error

#define testly_assert_string_not_equal_error(
   __expected__,
   __actual__
) if (ext.Testly.customAssertion((str(__actual__) <> str(__expected__)), __FILE__, __LINE__, ("{" #__actual__ "} expected to be != to {" #__expected__ "}"), true) = false) then exit sub

testly_assert_pass

#define testly_assert_pass(
   __message__
) ext.Testly.customAssertion((true), __FILE__, __LINE__, __message__)

testly_assert_fail

#define testly_assert_fail(
   __message__
) ext.Testly.customAssertion((false), __FILE__, __LINE__, __message__)

testly_assert_error

#define testly_assert_error(
   __message__
) if (ext.Testly.customAssertion((false), __FILE__, __LINE__, __message__, true) = false) then exit sub
type test_func_t as sub()
Function prototype for testcases.
declare function customAssertion(byval as ext.bool,  
byref as string,  
byval as uinteger,  
byref as string,  
byval as ext.bool =  false) as ext.bool
Used by the helper macros below.
declare function addSuite(byref as string) as ext.bool
Add a test Suite.
declare function addSuiteHook(byval as Hook,
byref as sub()) as ext.bool
Assign a function to run at certain points in the suite.
declare function addTest(byref as string,
byref as test_func_t) as ext.bool
Adds a testcase to the testsuite.
declare function runTests() as ext.bool
Runs the testcases for all registered Suites.
#define testly_assert_true(
   __value__
) ext.Testly.customAssertion((__value__) = (true), __FILE__, __LINE__, ("{" #__value__ "} is not true."))
#define testly_assert_true_error(
   __value__
) if (ext.Testly.customAssertion((__value__) = (true), __FILE__, __LINE__, ("{" #__value__ "} is not true."), true) = false) then exit sub
#define testly_assert_false(
   __value__
) ext.Testly.customAssertion((__value__) = (false), __FILE__, __LINE__, ("{" #__value__ "} is not false."))
#define testly_assert_false_error(
   __value__
) if (ext.Testly.customAssertion((__value__) = (false), __FILE__, __LINE__, ("{" #__value__ "} is not false."), true) = false) then exit sub
#define testly_assert_equal(
   __expected__,
   __actual__
) ext.Testly.customAssertion((__actual__) = (__expected__), __FILE__, __LINE__, ("expected {" #__expected__ "} but was {" #__actual__ "}"))
#define testly_assert_equal_error(
   __expected__,
   __actual__
) if (ext.Testly.customAssertion((__actual__) = (__expected__), __FILE__, __LINE__, ("expected {" #__expected__ "} but was {" #__actual__ "}"), true) = false) then exit sub
#define testly_assert_not_equal(
   __expected__,
   __actual__
) ext.Testly.customAssertion((__actual__) <> (__expected__), __FILE__, __LINE__, ("{" #__actual__ "} expected to be != to {" #__expected__ "}"))
#define testly_assert_not_equal_error(
   __expected__,
   __actual__
) if (ext.Testly.customAssertion((__actual__) <> (__expected__), __FILE__, __LINE__, ("{" #__actual__ "} expected to be != to {" #__expected__ "}"), true) = false) then exit sub
#define testly_assert_string_equal(
   __expected__,
   __actual__
) ext.Testly.customAssertion((str(__actual__) = str(__expected__)), __FILE__, __LINE__, ("expected {" #__expected__ "} but was {" #__actual__ "}"))
#define testly_assert_string_equal_error(
   __expected__,
   __actual__
) if (ext.Testly.customAssertion((str(__actual__) = str(__expected__)), __FILE__, __LINE__, ("expected {" #__expected__ "} but was {" #__actual__ "}"), true) = false) then exit sub
#define testly_assert_string_not_equal(
   __expected__,
   __actual__
) ext.Testly.customAssertion((str(__actual__) <> str(__expected__)), __FILE__, __LINE__, ("{" #__actual__ "} expected to be != to {" #__expected__ "}"))
#define testly_assert_string_not_equal_error(
   __expected__,
   __actual__
) if (ext.Testly.customAssertion((str(__actual__) <> str(__expected__)), __FILE__, __LINE__, ("{" #__actual__ "} expected to be != to {" #__expected__ "}"), true) = false) then exit sub
#define testly_assert_pass(
   __message__
) ext.Testly.customAssertion((true), __FILE__, __LINE__, __message__)
#define testly_assert_fail(
   __message__
) ext.Testly.customAssertion((false), __FILE__, __LINE__, __message__)
#define testly_assert_error(
   __message__
) if (ext.Testly.customAssertion((false), __FILE__, __LINE__, __message__, true) = false) then exit sub
Used with addSuiteHook to run a procedure on certain events.