-
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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)']; | ||
| 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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I had to double check, but yes I confirm that 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 commentThe 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: 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. |
||
| $env_lines[] = "export $env_var=" . escapeshellarg($env_val ?? ""); | ||
| } | ||
| $exported_environment = "\n" . implode("\n", $env_lines) . "\n"; | ||
|
|
@@ -2733,7 +2737,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} | ||
|
|
||
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 :)