summaryrefslogtreecommitdiff
path: root/tests/quicktester.inc
blob: 08e3c0a40f05dc72e615013885bf3ab3208c90a6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
<?php
 /*
  Helper for simple tests to check return-value. Usage:

  $tests = <<<TESTS
   expected_return_value === expression
   2                     === 1+1
   4                     === 2*2
   FALSE                 === @ fopen('non_existent_file')
TESTS;
  include( '../../../(../)tests/quicktester.inc' );

  Expect: OK

  Remember to NOT put a trailing ; after a line!

 */
 error_reporting(E_ALL);  
 $tests = explode("\n",$tests);
 $success = TRUE;
 foreach ($tests as $test)
 {
	 $res = eval("return ($test);");
	 $success = $success && $res;
	 if (!$res)
	 {
		 echo "\nAssert failed:\n";
		 echo "$test\n";
		 list($left,$right) = explode('===',$test);
		 echo "Left:  ";var_dump(eval("return ($left );"));
		 echo "Right: ";var_dump(eval("return ($right);"));
	 }
 }
 if ($success) echo "OK";