Skip to content

Commit

Permalink
Issue #1956712 by greg.1.anderson: fix over-isolation of test environ…
Browse files Browse the repository at this point in the history
…ment when test specifies additional environment settings
  • Loading branch information
greg-1-anderson committed Mar 30, 2013
1 parent 8c21b8a commit 9f413ea
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 21 deletions.
30 changes: 10 additions & 20 deletions tests/drush_testcase.inc
Original file line number Diff line number Diff line change
Expand Up @@ -323,29 +323,19 @@ abstract class Drush_CommandTestCase extends Drush_TestCase {
* @return integer
* Exit code. Usually self::EXIT_ERROR or self::EXIT_SUCCESS.
*/
function execute($command, $expected_return = self::EXIT_SUCCESS, $env = NULL) {
function execute($command, $expected_return = self::EXIT_SUCCESS, $env = array()) {
$this->_output = FALSE;
$return = 1;
$this->log("Executing: $command", 'notice');
// If the test passed in an environment to use, then run the test
// with proc_open
if (isset($env)) {
$descriptorspec = array(
0 => array("pipe", "r"),
1 => array("pipe", "w") );
$process = proc_open($command, $descriptorspec, $pipes, NULL, $env);
if (is_resource($process)) {
fclose($pipes[0]);
$output = stream_get_contents($pipes[1]);
$this->_output = explode("\n", rtrim($output)); // one more /n than with exec
fclose($pipes[1]);
$return = proc_close($process);
}
}
// Tests that do not provide their own environment run with exec
else {
exec($command, $this->_output, $return);

// Apply the environment variables we need for our test
// to the head of the command
$prefix = '';
foreach ($env as $env_name => $env_value) {
$prefix .= $env_name . '=' . self::escapeshellarg($env_value) . ' ';
}
exec($prefix . $command, $this->_output, $return);

$this->assertEquals($expected_return, $return, 'Unexpected exit code: ' . $command);
return $return;
}
Expand All @@ -370,7 +360,7 @@ abstract class Drush_CommandTestCase extends Drush_TestCase {
* @return integer
* An exit code.
*/
function drush($command, array $args = array(), array $options = array(), $site_specification = NULL, $cd = NULL, $expected_return = self::EXIT_SUCCESS, $suffix = NULL, $env = NULL) {
function drush($command, array $args = array(), array $options = array(), $site_specification = NULL, $cd = NULL, $expected_return = self::EXIT_SUCCESS, $suffix = NULL, $env = array()) {
$global_option_list = array('simulate', 'root', 'uri', 'include', 'config', 'alias-path', 'ssh-options');
// insert "cd ... ; drush"
$cmd[] = $cd ? sprintf('cd %s &&', self::escapeshellarg($cd)) : NULL;
Expand Down
8 changes: 7 additions & 1 deletion tests/outputFormatTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,13 @@ public function testOutputFormatWithDrupal() {
);
$name = $test['name'] . ": ";
$expected = $test['expected'];
$this->drush($test['command'], $test['args'], $options + $test['options'] + array('format' => $test['format']));
// We need to specify a fixed column width so that word wrapping does
// not change our output contrary to our expectations when run in
// a narrow terminal window.
$env = array(
'COLUMNS' => '120',
);
$this->drush($test['command'], $test['args'], $options + $test['options'] + array('format' => $test['format']), NULL, NULL, self::EXIT_SUCCESS, NULL, $env);
$output = trim($this->getOutput()); // note: we consider trailing eols insignificant
// If the Drupal command we are running might produce variable output,
// we can use one or more output filters to simplify the output down
Expand Down

0 comments on commit 9f413ea

Please sign in to comment.