Skip to content

run-tests.php: Remove extra env vars in the generated .sh file #18306

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 29, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions run-tests.php
Original file line number Diff line number Diff line change
Expand Up @@ -2723,8 +2723,14 @@ function run_test(string $php, $file, array $env): string
if (!$passed || $leaked) {
// write .sh
if (strpos($log_format, 'S') !== false) {
$env_lines = [];
// Unset all environment variables so that we don't inherit extra
// ones from the parent process.
$env_lines = ['unset $(env | cut -d= -f1)'];
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This removes any additional variable that may have been inherited from the parent process.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe your github.com comment should be a comment in the source for this magic sauce :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed :)

foreach ($env as $env_var => $env_val) {
if (strval($env_val) === '') {
// proc_open does not pass empty env vars
continue;
}
Comment on lines +2730 to +2733
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

proc_open does not pass empty env vars, so if we export empty env vars here, the test will see these vars when running with the .sh file, but not when running it via run-tests.php.

$env_lines[] = "export $env_var=" . escapeshellarg($env_val ?? "");
}
$exported_environment = "\n" . implode("\n", $env_lines) . "\n";
Expand All @@ -2733,7 +2739,7 @@ function run_test(string $php, $file, array $env): string
{$exported_environment}
case "$1" in
"gdb")
gdb --args {$orig_cmd}
gdb -ex 'unset environment LINES' -ex 'unset environment COLUMNS' --args {$orig_cmd}
;;
"lldb")
lldb -- {$orig_cmd}
Expand Down
Loading