summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorUrban Müller2023-08-16 15:38:10 +0200
committerUrban Müller2023-08-16 15:40:38 +0200
commitbd4392574a36a01a464ed8a12b5c955883d536ee (patch)
treee85270ed3e6e0f02120eb9a882e72481adb132f5 /test
parent9779bf01e4fb5383e873465b5b3dcadd613aac56 (diff)
downloaditools-bd4392574a36a01a464ed8a12b5c955883d536ee.tar.gz
itools-bd4392574a36a01a464ed8a12b5c955883d536ee.tar.bz2
itools-bd4392574a36a01a464ed8a12b5c955883d536ee.zip
recursive test script for it::error stackdumps
Diffstat (limited to 'test')
-rwxr-xr-xtest/it_error.t51
1 files changed, 51 insertions, 0 deletions
diff --git a/test/it_error.t b/test/it_error.t
new file mode 100755
index 0000000..522d253
--- /dev/null
+++ b/test/it_error.t
@@ -0,0 +1,51 @@
+#!/www/server/bin/php
+<?php
+# TESTFLAGS SLOW
+
+it::$error_context = fn() => ['blockmail' => 0, 'to' => "mueller", 'toscreen' => 1];
+$GLOBALS['debug_verboseerrors'] = 1;
+
+if ($argv[1])
+ foo($argv[1]);
+else {
+ foreach (range(1, 10) as $testnum) {
+ $errlines = explode("\n", it::exec('{cmd} {testnum} |& cat', ['cmd' => $argv[0], 'testnum' => $testnum]));
+ $expect = $expect = it::match('Expect: (.*)', $errlines[0]);
+ $errbody = join("\n", array_slice($errlines, 1));
+ $trace = $trace = it::match('Trace: *(\S*)', $errbody);
+ $stack = $stack = it::match('Stack:\n\s*(\S*)', $errbody);
+ if ($trace)
+ is($trace, $expect, "testcase $testnum: correct single line trace on $expect");
+ if ($stack)
+ is($stack, $expect, "testcase $testnum: correct multi line trace on $expect");
+
+ }
+}
+
+
+function expect()
+{
+ $frames = debug_backtrace();
+ echo "Expect: " . basename($frames[0]['file']) . ":" . $frames[0]['line'] . "\n";
+}
+
+function foo($testno)
+{
+ $a = "hi";
+
+ switch ($testno) {
+ case 1: expect(); echo "Trace: " . it_debug::backtrace() . "\n\n"; exit;
+ case 2: expect(); echo "Stack:\n" . it_debug::backtrace(['format' => "medium"]); exit;
+
+ case 3: expect(); it::error(['title' => "bad"]); exit;
+ case 4: expect(); it::fatal(['title' => "bad"]); exit;
+
+ case 5: expect(); array_keys($testno); exit; # exception
+ case 6: expect(); intval(); exit; # exception
+ case 7: expect(); $b = "hi" + 2; exit; # exception
+ case 8: expect(); $b = 1 / 0; exit; # exception
+ case 9: expect(); $a["bbb"] = 5; exit; # exception
+ case 10: expect(); filemtime("/foobar"); exit; # error
+ case 11: expect(); $b = $a["13th"]; exit; # error
+ }
+}