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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

arnaud-lb
Copy link
Member

@arnaud-lb arnaud-lb commented Apr 11, 2025

run-tests.php conveniently generates a .sh file for each failed test.

The file starts by setting environment variables to the value they had during the test run.

Unfortunately, sometimes extra env vars will sneak in and prevent reproduction:

  • Variables are inherited from the process that executes the .sh file
  • The .sh file exports empty variables, but proc_open() does not
  • When running under gdb, the variables LINES and COLUMNS are set

Here I ensure that these variables do not sneak in anymore in these cases when using the .sh file.

@@ -2723,8 +2723,12 @@ function run_test(string $php, $file, array $env): string
if (!$passed || $leaked) {
// write .sh
if (strpos($log_format, 'S') !== false) {
$env_lines = [];
$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 :)

Comment on lines +2728 to +2731
if (strval($env_val) === '') {
// proc_open does not pass empty env vars
continue;
}
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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants