diff --git a/run-tests.php b/run-tests.php index 0b74873d..e9b7cb0b 100755 --- a/run-tests.php +++ b/run-tests.php @@ -2444,7 +2444,40 @@ TEST $file global $no_aot; if (!$no_aot) { - $bin_file = compile_php_file($test_file); + try { + $bin_file = compile_php_file($test_file); + } catch (Throwable $e) { + $compileOutput = trim($e instanceof CompilationFailureException ? $e->getCompilerOutput() : ''); + $message = $e->getMessage(); + $compileInfo = ' (compilation failed: ' . $message . ')'; + + if (strpos($log_format, 'O') !== false && file_put_contents($output_filename, $compileOutput !== '' ? $compileOutput : $message) === false) { + error("Cannot create test output - $output_filename"); + } + if (strpos($log_format, 'D') !== false && file_put_contents($diff_filename, $compileInfo . PHP_EOL) === false) { + error("Cannot create test diff - $diff_filename"); + } + if (strpos($log_format, 'L') !== false && file_put_contents($log_filename, " +---- AOT COMPILATION FAILED +$message +---- COMPILER OUTPUT +" . ($compileOutput !== '' ? $compileOutput : '(no compiler output)') . " +---- FAILED +") === false) { + error("Cannot create test log - $log_filename"); + } + + show_result('FAIL', $tested, $tested_file, 'reason: ' . $message); + $PHP_FAILED_TESTS['FAILED'][] = [ + 'name' => $file, + 'test_name' => (is_array($IN_REDIRECT) ? $IN_REDIRECT['via'] : '') . $tested . " [$tested_file]", + 'output' => $output_filename, + 'diff' => $diff_filename, + 'info' => $compileInfo, + ]; + $junit->markTestAs('FAIL', $shortname, $tested, null, $message, $compileOutput); + return 'FAILED'; + } $args = substr($args, strlen(' -- ')); $cmd = './' . $bin_file . ' ' . $args . $cmdRedirect; } else { @@ -3303,6 +3336,19 @@ class BorkageException extends Exception { } +class CompilationFailureException extends RuntimeException +{ + public function __construct(string $message, private string $compilerOutput = '') + { + parent::__construct($message); + } + + public function getCompilerOutput(): string + { + return $this->compilerOutput; + } +} + class JUnit { private bool $enabled = true; @@ -4218,16 +4264,28 @@ function compile_php_file(string $file): string $data = trim(file_get_contents($file)); if (!str_starts_with($data, '')) { - throw new Exception('Invalid PHP file'); + throw new CompilationFailureException('Invalid PHP file'); } + $binary_file = str_replace('-', '_', basename($file, '.php')); + if (!str_contains($data, 'function main()')) { file_put_contents($file, "&1', $output, $exitCode); + clearstatcache(true, $binary_file); + + if ($exitCode !== 0 || !file_exists($binary_file)) { + throw new CompilationFailureException('Compilation failed', implode(PHP_EOL, $output)); } + return $binary_file; }