Skip to content

Commit 1e227ab

Browse files
committed
Use env vars instead of test args.
1 parent 65b93d0 commit 1e227ab

2 files changed

Lines changed: 21 additions & 9 deletions

File tree

lib/cli/Shell.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,18 @@ class Shell {
2121
/**
2222
* Returns the number of columns the current shell has for display.
2323
*
24-
* @param mixed $test For testing only.
25-
*
2624
* @return int The number of columns.
2725
* @todo Test on more systems.
2826
*/
29-
static public function columns( $test = null ) {
27+
static public function columns() {
3028
static $columns;
3129

32-
if ( null !== $test ) {
30+
if ( false !== ( $env_reset = getenv( 'WP_CLI_TEST_SHELL_COLUMNS_RESET' ) ) && $env_reset ) {
3331
$columns = null;
3432
}
3533
if ( null === $columns ) {
3634
if ( function_exists( 'exec' ) ) {
37-
if ( self::is_windows( 'WIN' === $test ) ) {
35+
if ( self::is_windows() ) {
3836
// Cater for shells such as Cygwin and Git bash where `mode CON` returns an incorrect value for columns.
3937
if ( ( $shell = getenv( 'SHELL' ) ) && preg_match( '/(?:bash|zsh)(?:.exe)?$/', $shell ) && getenv( 'TERM' ) ) {
4038
$columns = (int) exec( 'tput cols' );

tests/test-shell.php

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,26 +14,40 @@ function testColumns() {
1414
// Save.
1515
$env_term = getenv( 'TERM' );
1616
$env_columns = getenv( 'COLUMNS' );
17+
$env_is_windows = getenv( 'WP_CLI_TEST_IS_WINDOWS' );
18+
$env_shell_columns_reset = getenv( 'WP_CLI_TEST_SHELL_COLUMNS_RESET' );
19+
20+
putenv( 'WP_CLI_TEST_SHELL_COLUMNS_RESET=1' );
1721

1822
// No TERM should result in default 80.
1923

2024
putenv( 'TERM' );
21-
$columns = cli\Shell::columns( true /*test*/ );
25+
26+
putenv( 'WP_CLI_TEST_IS_WINDOWS=0' );
27+
$columns = cli\Shell::columns();
2228
$this->assertSame( 80, $columns );
23-
$columns = cli\Shell::columns( 'WIN' /*test*/ );
29+
30+
putenv( 'WP_CLI_TEST_IS_WINDOWS=1' );
31+
$columns = cli\Shell::columns();
2432
$this->assertSame( 80, $columns );
2533

2634
// TERM and COLUMNS should result in whatever COLUMNS is.
2735

2836
putenv( 'TERM=vt100' );
2937
putenv( 'COLUMNS=100' );
30-
$columns = cli\Shell::columns( true /*test*/ );
38+
39+
putenv( 'WP_CLI_TEST_IS_WINDOWS=0' );
40+
$columns = cli\Shell::columns();
3141
$this->assertSame( 100, $columns );
32-
$columns = cli\Shell::columns( 'WIN' /*test*/ );
42+
43+
putenv( 'WP_CLI_TEST_IS_WINDOWS=1' );
44+
$columns = cli\Shell::columns();
3345
$this->assertSame( 100, $columns );
3446

3547
// Restore.
3648
putenv( false === $env_term ? 'TERM' : "TERM=$env_term" );
3749
putenv( false === $env_columns ? 'COLUMNS' : "COLUMNS=$env_columns" );
50+
putenv( false === $env_is_windows ? 'WP_CLI_TEST_IS_WINDOWS' : "WP_CLI_TEST_IS_WINDOWS=$env_is_windows" );
51+
putenv( false === $env_shell_columns_reset ? 'WP_CLI_TEST_SHELL_COLUMNS_RESET' : "WP_CLI_TEST_SHELL_COLUMNS_RESET=$env_shell_columns_reset" );
3852
}
3953
}

0 commit comments

Comments
 (0)