Skip to content

Commit d7d6794

Browse files
committed
Use external diff tool if TEST_PHP_DIFF_CMD env var is set
1 parent 7496a40 commit d7d6794

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

run-tests.php

+13-1
Original file line numberDiff line numberDiff line change
@@ -2696,7 +2696,12 @@ function run_test(string $php, $file, array $env): string
26962696
}
26972697

26982698
// write .diff
2699-
$diff = generate_diff($wanted, $wanted_re, $output);
2699+
if (!empty($environment['TEST_PHP_DIFF_CMD'])) {
2700+
$diff = generate_diff_external($environment['TEST_PHP_DIFF_CMD'], $exp_filename, $output_filename);
2701+
} else {
2702+
$diff = generate_diff($wanted, $wanted_re, $output);
2703+
}
2704+
27002705
if (is_array($IN_REDIRECT)) {
27012706
$orig_shortname = str_replace(TEST_PHP_SRCDIR . '/', '', $file);
27022707
$diff = "# original source file: $orig_shortname\n" . $diff;
@@ -2959,6 +2964,13 @@ function generate_array_diff(array $ar1, array $ar2, bool $is_reg, array $w): ar
29592964
return $diff;
29602965
}
29612966

2967+
function generate_diff_external(string $diff_cmd, string $exp_file, string $output_file): string
2968+
{
2969+
$retval = shell_exec("{$diff_cmd} {$exp_file} {$output_file}");
2970+
2971+
return is_string($retval) ? $retval : 'Could not run external diff tool set through PHP_TEST_DIFF_CMD environment variable';
2972+
}
2973+
29622974
function generate_diff(string $wanted, ?string $wanted_re, string $output): string
29632975
{
29642976
$w = explode("\n", $wanted);

0 commit comments

Comments
 (0)