Fix PHP test suite error reporting

check::fail() and check::warn() now fully support a printf-format
with arguments.
This commit is contained in:
Olly Betts 2023-06-12 15:05:38 +12:00
parent 2e6e71e5ca
commit da4a6062bb
1 changed files with 7 additions and 10 deletions

View File

@ -188,25 +188,22 @@ class check {
return check::equal($a,NULL,$message);
}
private static function fail_($message, $pattern) {
private static function fail_($message, $pattern, ...$args) {
$bt = debug_backtrace(0);
$bt = $bt[array_key_last($bt)-1];
print("{$bt['file']}:{$bt['line']}: Failed on: ");
if ($message !== NULL) print("$message: ");
$args=func_get_args();
array_shift($args);
print(call_user_func_array("sprintf",$args)."\n");
print(sprintf($pattern, ...$args) . "\n");
exit(1);
}
static function fail($pattern) {
check::fail_(null, $pattern);
static function fail(...$args) {
check::fail_(null, ...$args);
}
static function warn($pattern) {
$args=func_get_args();
if (self::$_werror) self::fail($pattern);
print("Warning on: ".call_user_func_array("sprintf",$args)."\n");
static function warn($pattern, ...$args) {
if (self::$_werror) self::fail($pattern, ...$args);
print("Warning on: " . sprintf($pattern, ...$args) . "\n");
return FALSE;
}