Skip to content

Commit dcd6e87

Browse files
committed
Make run-tests GitHub Actions aware
1 parent 3331832 commit dcd6e87

File tree

2 files changed

+67
-16
lines changed

2 files changed

+67
-16
lines changed

ext/random/tests/03_randomizer/pick_array_keys_error.phpt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,7 @@ var_dump((new \Random\Randomizer())->pickArrayKeys(range(1, 3), 2));
3333
?>
3434
--EXPECTF--
3535
Random\Randomizer::pickArrayKeys(): Argument #1 ($array) cannot be empty
36-
Random\Randomizer::pickArrayKeys(): Argument #2 ($num) must be between 1 and the number of elements in argument #1 ($array)
37-
Random\Randomizer::pickArrayKeys(): Argument #2 ($num) must be between 1 and the number of elements in argument #1 ($array)
36+
Random\Randomizer::piyKeys(): Argument #2 ($num) must be between 1 and the number of elements in argument #1 ($array)
3837
Random\Randomizer::pickArrayKeys(): Argument #2 ($num) must be between 1 and the number of elements in argument #1 ($array)
3938
array(3) {
4039
[0]=>

run-tests.php

Lines changed: 66 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ function main(): void
151151
global $DETAILED, $PHP_FAILED_TESTS, $SHOW_ONLY_GROUPS, $argc, $argv, $cfg,
152152
$cfgfiles, $cfgtypes, $conf_passed, $end_time, $environment,
153153
$exts_skipped, $exts_tested, $exts_to_test, $failed_tests_file,
154-
$ignored_by_ext, $ini_overwrites, $is_switch, $colorize,
154+
$ignored_by_ext, $ini_overwrites, $is_switch, $colorize, $github_actions,
155155
$log_format, $matches, $no_clean, $no_file_cache,
156156
$optionals, $pass_option_n, $pass_options,
157157
$pattern_match, $php, $php_cgi, $phpdbg, $preload, $redir_tests,
@@ -351,6 +351,10 @@ function main(): void
351351
if (array_key_exists('NO_COLOR', $environment)) {
352352
$colorize = false;
353353
}
354+
$github_actions = false;
355+
if (array_key_exists('CI', $environment) && array_key_exists('GITHUB_ACTIONS', $environment)) {
356+
$github_actions = true;
357+
}
354358
$selected_tests = false;
355359
$slow_min_ms = INF;
356360
$preload = false;
@@ -2117,9 +2121,9 @@ function run_test(string $php, $file, array $env): string
21172121

21182122
if (!strncasecmp('skip', $output, 4)) {
21192123
if (preg_match('/^skip\s*(.+)/i', $output, $m)) {
2120-
show_result('SKIP', $tested, $tested_file, "reason: $m[1]", $temp_filenames);
2124+
show_result('SKIP', $tested, $tested_file, "reason: $m[1]");
21212125
} else {
2122-
show_result('SKIP', $tested, $tested_file, '', $temp_filenames);
2126+
show_result('SKIP', $tested, $tested_file, '');
21232127
}
21242128

21252129
$message = !empty($m[1]) ? $m[1] : '';
@@ -2137,7 +2141,7 @@ function run_test(string $php, $file, array $env): string
21372141
// Pretend we have an XFAIL section
21382142
$test->setSection('XFAIL', ltrim(substr($output, 5)));
21392143
} elseif ($output !== '') {
2140-
show_result("BORK", $output, $tested_file, 'reason: invalid output from SKIPIF', $temp_filenames);
2144+
show_result("BORK", $output, $tested_file, 'reason: invalid output from SKIPIF');
21412145
$PHP_FAILED_TESTS['BORKED'][] = [
21422146
'name' => $file,
21432147
'test_name' => '',
@@ -2153,7 +2157,7 @@ function run_test(string $php, $file, array $env): string
21532157

21542158
if (!extension_loaded("zlib") && $test->hasAnySections("GZIP_POST", "DEFLATE_POST")) {
21552159
$message = "ext/zlib required";
2156-
show_result('SKIP', $tested, $tested_file, "reason: $message", $temp_filenames);
2160+
show_result('SKIP', $tested, $tested_file, "reason: $message");
21572161
$junit->markTestAs('SKIP', $shortname, $tested, null, $message);
21582162
return 'SKIPPED';
21592163
}
@@ -2200,7 +2204,7 @@ function run_test(string $php, $file, array $env): string
22002204
}
22012205

22022206
$bork_info = "Redirect info must contain exactly one TEST string to be used as redirect directory.";
2203-
show_result("BORK", $bork_info, '', '', $temp_filenames);
2207+
show_result("BORK", $bork_info, '', '');
22042208
$PHP_FAILED_TESTS['BORKED'][] = [
22052209
'name' => $file,
22062210
'test_name' => '',
@@ -2216,7 +2220,7 @@ function run_test(string $php, $file, array $env): string
22162220
}
22172221

22182222
$bork_info = "Redirected test did not contain redirection info";
2219-
show_result("BORK", $bork_info, '', '', $temp_filenames);
2223+
show_result("BORK", $bork_info, '', '');
22202224
$PHP_FAILED_TESTS['BORKED'][] = [
22212225
'name' => $file,
22222226
'test_name' => '',
@@ -2612,7 +2616,7 @@ function run_test(string $php, $file, array $env): string
26122616
if (!$leaked && !$failed_headers) {
26132617
// If the test passed and CLEAN produced output, report test as borked.
26142618
if ($clean_output) {
2615-
show_result("BORK", $output, $tested_file, 'reason: invalid output from CLEAN', $temp_filenames);
2619+
show_result("BORK", $output, $tested_file, 'reason: invalid output from CLEAN');
26162620
$PHP_FAILED_TESTS['BORKED'][] = [
26172621
'name' => $file,
26182622
'test_name' => '',
@@ -2632,7 +2636,7 @@ function run_test(string $php, $file, array $env): string
26322636
$warn = true;
26332637
$info = " (warn: XLEAK section but test passes)";
26342638
} else {
2635-
show_result("PASS", $tested, $tested_file, '', $temp_filenames);
2639+
show_result("PASS", $tested, $tested_file, '');
26362640
$junit->markTestAs('PASS', $shortname, $tested);
26372641
return 'PASSED';
26382642
}
@@ -2750,7 +2754,9 @@ function run_test(string $php, $file, array $env): string
27502754
show_file_block('mem', file_get_contents($memcheck_filename));
27512755
}
27522756

2753-
show_result(implode('&', $restype), $tested, $tested_file, $info, $temp_filenames);
2757+
$diff = empty($diff) ? '' : preg_replace('/\e/', '<esc>', $diff);
2758+
2759+
show_result(implode('&', $restype), $tested, $tested_file, $info, $diff);
27542760

27552761
foreach ($restype as $type) {
27562762
$PHP_FAILED_TESTS[$type . 'ED'][] = [
@@ -2762,8 +2768,6 @@ function run_test(string $php, $file, array $env): string
27622768
];
27632769
}
27642770

2765-
$diff = empty($diff) ? '' : preg_replace('/\e/', '<esc>', $diff);
2766-
27672771
$junit->markTestAs($restype, $shortname, $tested, null, $info, $diff);
27682772

27692773
return $restype[0] . 'ED';
@@ -3278,9 +3282,9 @@ function show_result(
32783282
string $tested,
32793283
string $tested_file,
32803284
string $extra = '',
3281-
?array $temp_filenames = null
3285+
string $diff = ''
32823286
): void {
3283-
global $SHOW_ONLY_GROUPS, $colorize;
3287+
global $SHOW_ONLY_GROUPS, $colorize, $github_actions;
32843288

32853289
if (!$SHOW_ONLY_GROUPS || in_array($result, $SHOW_ONLY_GROUPS)) {
32863290
if ($colorize) {
@@ -3302,6 +3306,54 @@ function show_result(
33023306
} else {
33033307
echo "$result $tested [$tested_file] $extra\n";
33043308
}
3309+
3310+
if ($github_actions) {
3311+
$title = $tested;
3312+
$message = '';
3313+
3314+
$type = null;
3315+
switch ( $result ) {
3316+
case 'FAIL':
3317+
$type = 'error';
3318+
$message = "Test failed" . ($extra ? " - {$extra}" : '');
3319+
break;
3320+
case 'BORK':
3321+
$type = 'error';
3322+
$message = "Test borked" . ($extra ? " - {$extra}" : '');
3323+
break;
3324+
case 'LEAK':
3325+
$type = 'error';
3326+
$message = "Test leaked" . ($extra ? " - {$extra}" : '');
3327+
break;
3328+
case 'LEAK&FAIL':
3329+
$type = 'error';
3330+
$message = "Test failed and leaked" . ($extra ? " - {$extra}" : '');
3331+
break;
3332+
case 'WARN':
3333+
$type = 'warning';
3334+
$message = "Test warned" . ($extra ? " - {$extra}" : '');
3335+
break;
3336+
}
3337+
3338+
$message .= "\n\n{$diff}";
3339+
3340+
if ($type !== null) {
3341+
$title = strtr($title, [
3342+
"%" => '%25',
3343+
"\r" => '%0D',
3344+
"\n" => '%0A',
3345+
":" => '%3A',
3346+
"," => '%2C',
3347+
]);
3348+
$message = strtr($message, [
3349+
"%" => '%25',
3350+
"\r" => '%0D',
3351+
"\n" => '%0A',
3352+
]);
3353+
3354+
echo "::{$type} file={$tested_file},title={$title}::{$message}\n";
3355+
}
3356+
}
33053357
} elseif (!$SHOW_ONLY_GROUPS) {
33063358
clear_show_test();
33073359
}

0 commit comments

Comments
 (0)