Testing check functions

The purpose of this is to deliberately exercise the check functions.

Lots of FAILs are expected. These should be at the 'F' labels.
You will need to look at the source code for this to make sense.

Total tests: 38 Total failures: 1723:54:03 Sun 28 Apr 2024
Basic pass/fail
ok
ok
P1.e ok
P1.f 1
F1.a FAIL(Act) Expected:Exp
F1.b FAIL
F1.c FAIL(Act) Expected:Exp
Basic pass/fail Check summary: Pass:6 Fail:3
Type checking
P2.a cat
F2.b FAIL(456) Expecting:string
F2.c FAIL(
foo ()Empty array
)
Expecting:string
P3.a
0cat
1dog
2weasle

P3.b Empty array
F3.c FAIL(cat) Expecting:array
F3.d FAIL(NULL) Expecting:array
P4.a TRUE
P4.b FALSE
F4.c FAIL(Null string) Expecting:boolean
F4.d FAIL(NULL) Expecting:boolean
P5.a 123
P5.b 123
P5.c FAIL(TRUE) Expecting:numeric
P6.a NULL
F6.a FAIL(Null string) Expecting:null
F6.b FAIL(0) Expecting:null
P9.a foo
F9.b FAIL(
foo ()Empty array
)
Expecting:foox
Type checking Check summary: Pass:9 Fail:10
Exceptions
P7.a BareFailOnNegative
P7.b BareFailOnNegative
P7.c BareFailOnNegative
F7.d FAIL(BareFailOnNegative WRONG EXCEPTION: Negative not allowed)
F7.e FAIL(BareFailOnNegative NO EXCEPTION:Neg)
P8.a FailOnNegative
P8.b FailOnNegative
P8.c FailOnNegative
F8.d FAIL(FailOnNegative WRONG EXCEPTION: Negative not allowed)
F8.e FAIL(FailOnNegative NO EXCEPTION:Neg)
Exceptions Check summary: Pass:6 Fail:4
Total tests: 38 Total failures: 1723:54:03 Sun 28 Apr 2024

Key methods
  • check::Test(label,expected,actual)→bool Simple 'do we get the expected result'
    • check::TestNot() is the negative truth of Test()
  • check::Is(label,type,variable)→bool type can be
    • 'string','null','array','boolean'
    • 'numeric' ie. is numeric or convertable to a number
    • A class name (case sensitive)
  • check::Trap(label,message,function name,Object,Arguments)→bool Testing for exception handling
    • label is test identifier
    • message
      • If there shouldn't be an exception then an empty string
      • Otherwise some text fragment found in exception message
      • Note this works exclusively on exception message not exception 'type'(sub-class)
    • function name is a string being the name of the function or method to be executed
    • Object will be null if this is working on a plain function
    • Arguments is missing, a scalar (if only one argument) or an array of arguments
    • Examples
      • ('Zdiv','zero','Divide',$myObject,array(5,0)) // expects to trigger divide by zero
      • ('Feline.a','','AddToList',null,'cat') // this shouldn't be an exception
      • ('Feline.b','not a cat','AddToList',null,array('dolphin')) // triggers exception
  • check::Finish([fileName]) Prints full totals and timestamp. Optionally send output to file instead. The following tokens can be embedded. #n : Basename of test script. #d : DDYYMM #t : HHMMSS #f : Fail count. eg check::Finish('#nResults.htm');
Other test methods
  • check::Show(label,variable) Dump of variable.
  • check::TestNot(label,expected,actual)→bool
    Inverse truth of Test(). Used where you know of a result you don't want.
  • check::Label(label,[NewLineAfter=false])
    Writes just a label to the results. Optionally followed by new line.
Blocks of tests
The normal structure is repeating StartBlock()...tests ...EndBlock() followed by a final Finish() It is recommended to follow this pattern. Flush() shouldn't normally be required.
  • check::StartBlock(text,[buffering=true])
    • Text heading at the start of a block of tests.
    • Buffering defaults to true but may be set false if you want immediate reporting.
    • Note This doesn't reset counters
  • check::EndBlock()
    • Block summary
    • This resets counters
    • See check::ShowOkBlockDetails() below
  • check::AnyFailures() Boolean true if any failures in this block ie. since start or last Summary()
  • check::ShowOkBlockDetails(Show_flag) Call with false to suppress display of individual tests if a block has no failures. Default is true.
Verbosity adjustment
  • check::PassNone() Test functions still return truth values
  • check::PassDot() Dot with no new line
  • check::PassOk() 'ok' and new line
  • check::PassShort() label, ok and new line
  • check::PassLong() label, variable, new line
  • check::FailTiny() label and FAIL and new line
  • check::FailShort() label, FAIL, variable dumped and new line
  • check::FailLong() label, FAIL, variable dumped, message and new line
Miscellaneous
  • You need require_once('check.php'); at the top of your code.
  • dump.php needs to be in yor include path
  • check::Help() displays this information
  • Version as file date.
  • Contact the author at author@vulpeculox.net
  • Website vulpeculox.net
Example function FailOnNegative($Arg){ if($Arg<0){ throw new Exception('Negative not allowed'); } } check::PassLong(); check::StartBlock('Checking examples'); check::Is('E1.a','numeric',Time()); check::Test('E2.a','2011',Date('Y')); check::Trap('E3.a','Negative','FailOnNegative','',-5); check::EndBlock(); // more StartBlock()...tests...EndBlock() blocks might go here check::Finish();