-
Notifications
You must be signed in to change notification settings - Fork 8k
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
Conversation
| // write .sh | ||
| if (strpos($log_format, 'S') !== false) { | ||
| $env_lines = []; | ||
| $env_lines = ['unset $(env | cut -d= -f1)']; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed :)
| if (strval($env_val) === '') { | ||
| // proc_open does not pass empty env vars | ||
| continue; | ||
| } |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@arnaud-lb: is that really proc_open()? for me proc_open() does empty vars fine. My guess is that 'unset $(env | cut -d= -f1)' does the actual trick here. Otherwise this would pretty much constitute a bug if not ... .
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had to double check, but yes I confirm that proc_open does not pass variables whose value is empty string: https://github.com/arnaud-lb/php-src/blob/484d528b40645f823047b53bcb5ba4228fb612c0/ext/standard/proc_open.c#L178
proc_open(
[PHP_BINARY, '-n', '-r', 'var_dump(getenv());'],
[],
$pipes,
env_vars: ['foo' => 'bar', 'not-passed' => ''],
);
// Output:
array(1) {
["foo"]=>
string(3) "bar"
}proc_open(
'printenv',
[],
$pipes,
env_vars: ['foo' => 'bar', 'not-passed' => ''],
);
// Output:
PWD=...
foo=bar
SHLVL=0
_=/usr/bin/printenvThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, that's the spot, here is how I did it working, should have probably posted that earlier, sigh:
$descriptor_spec = [];
$env = ['TRUTH='];
$pipes = [];
$proc = proc_open(['env'], $descriptor_spec, $pipes, null, $env);
$exit = proc_close($proc);output:
TRUTH=
Thanks for double checking @arnaud-lb, this clarifies the comment in the run-tests.php script for me, it depends on passing the $env_vars as list or associative.
run-tests.phpconveniently generates a.shfile 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:
.shfile.shfile exports empty variables, butproc_open()does notgdb, the variablesLINESandCOLUMNSare setHere I ensure that these variables do not sneak in anymore in these cases when using the
.shfile.