From 625f9899e6eecfc6098c5f0458b5ce9a298d285e Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Sun, 29 Mar 2026 12:06:31 +0200 Subject: [PATCH 01/10] Normalize line endings in `assertOutFileEqualsWith` --- tests/Test_Table_Ascii.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/Test_Table_Ascii.php b/tests/Test_Table_Ascii.php index 3e683b8..39cc99f 100644 --- a/tests/Test_Table_Ascii.php +++ b/tests/Test_Table_Ascii.php @@ -386,6 +386,9 @@ private function assertInOutEquals(array $input, $output) { * @param mixed $expected Expected output */ private function assertOutFileEqualsWith($expected) { - $this->assertEquals($expected, file_get_contents($this->_mockFile)); + $actual = file_get_contents($this->_mockFile); + $actual = str_replace("\r\n", "\n", $actual); + $expected = str_replace("\r\n", "\n", $expected); + $this->assertEquals($expected, $actual); } } From a4e18af4cba3b81b736f39643911ca76b9181042 Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Sun, 29 Mar 2026 12:09:22 +0200 Subject: [PATCH 02/10] Check `COLUMNS` early and on all platforms --- lib/cli/Shell.php | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/lib/cli/Shell.php b/lib/cli/Shell.php index b9ae380..dbf906c 100755 --- a/lib/cli/Shell.php +++ b/lib/cli/Shell.php @@ -31,7 +31,7 @@ static public function columns() { $columns = null; } if ( null === $columns ) { - if ( function_exists( 'exec' ) ) { + if ( ! ( $columns = (int) getenv( 'COLUMNS' ) ) && function_exists( 'exec' ) ) { if ( self::is_windows() ) { // Cater for shells such as Cygwin and Git bash where `mode CON` returns an incorrect value for columns. if ( ( $shell = getenv( 'SHELL' ) ) && preg_match( '/(?:bash|zsh)(?:\.exe)?$/', $shell ) && getenv( 'TERM' ) ) { @@ -49,15 +49,13 @@ static public function columns() { } } } else { - if ( ! ( $columns = (int) getenv( 'COLUMNS' ) ) ) { - $size = exec( '/usr/bin/env stty size 2>/dev/null' ); - if ( '' !== $size && preg_match( '/[0-9]+ ([0-9]+)/', $size, $matches ) ) { - $columns = (int) $matches[1]; - } - if ( ! $columns ) { - if ( getenv( 'TERM' ) ) { - $columns = (int) exec( '/usr/bin/env tput cols 2>/dev/null' ); - } + $size = exec( '/usr/bin/env stty size 2>/dev/null' ); + if ( '' !== $size && preg_match( '/[0-9]+ ([0-9]+)/', $size, $matches ) ) { + $columns = (int) $matches[1]; + } + if ( ! $columns ) { + if ( getenv( 'TERM' ) ) { + $columns = (int) exec( '/usr/bin/env tput cols 2>/dev/null' ); } } } From a1efaef262563303ee73612d748435851b0d7563 Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Sun, 29 Mar 2026 12:09:39 +0200 Subject: [PATCH 03/10] Improve tests cleanup --- tests/Test_Shell.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/tests/Test_Shell.php b/tests/Test_Shell.php index d2bc71e..f793027 100644 --- a/tests/Test_Shell.php +++ b/tests/Test_Shell.php @@ -49,7 +49,15 @@ function testColumns() { // Restore. putenv( false === $env_term ? 'TERM' : "TERM=$env_term" ); putenv( false === $env_columns ? 'COLUMNS' : "COLUMNS=$env_columns" ); - putenv( false === $env_is_windows ? 'WP_CLI_TEST_IS_WINDOWS' : "WP_CLI_TEST_IS_WINDOWS=$env_is_windows" ); + if ( false === $env_is_windows ) { + if ( strtoupper( substr( PHP_OS, 0, 3 ) ) === 'WIN' ) { + putenv( 'WP_CLI_TEST_IS_WINDOWS=' ); + } else { + putenv( 'WP_CLI_TEST_IS_WINDOWS' ); + } + } else { + putenv( "WP_CLI_TEST_IS_WINDOWS=$env_is_windows" ); + } putenv( false === $env_shell_columns_reset ? 'PHP_CLI_TOOLS_TEST_SHELL_COLUMNS_RESET' : "PHP_CLI_TOOLS_TEST_SHELL_COLUMNS_RESET=$env_shell_columns_reset" ); } } From 4e8771ae09f444f13eb24b1dfda6e9ac365640ce Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Sun, 29 Mar 2026 12:24:32 +0200 Subject: [PATCH 04/10] Add Windows specific assertion --- tests/Test_Table.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tests/Test_Table.php b/tests/Test_Table.php index ca03f71..948d16f 100644 --- a/tests/Test_Table.php +++ b/tests/Test_Table.php @@ -3,6 +3,7 @@ use cli\Colors; use cli\Table; use cli\Table\Ascii; +use cli\Shell; use WP_CLI\Tests\TestCase; /** @@ -96,7 +97,11 @@ public function test_column_odd_single_width_with_double_width() { $result = $strip_borders( explode( "\n", $out ) ); $this->assertSame( 3, count( $result ) ); - $this->assertSame( '1あいうえ ', $result[0] ); // 1 single width, 4 double-width, space = 10. + if ( Shell::is_windows() ) { + $this->assertSame( '1あいうえ ', $result[0] ); + } else { + $this->assertSame( '1あいうえ ', $result[0] ); // 1 single-width, 4 double-width, space = 10. + } $this->assertSame( 'おか2きくカ', $result[1] ); // 2 double-width, 1 single-width, 2 double-width, 1 half-width = 10. $this->assertSame( 'けこ ', $result[2] ); // 2 double-width, 8 spaces = 10. From 34178c65d2ff2ba2c5be0ee317863ea231616f65 Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Sun, 29 Mar 2026 12:40:33 +0200 Subject: [PATCH 05/10] try fix --- lib/cli/Shell.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/cli/Shell.php b/lib/cli/Shell.php index dbf906c..9afb257 100755 --- a/lib/cli/Shell.php +++ b/lib/cli/Shell.php @@ -112,7 +112,7 @@ static public function hide($hidden = true) { */ static public function is_windows() { $test_is_windows = getenv( 'WP_CLI_TEST_IS_WINDOWS' ); - if ( false !== $test_is_windows ) { + if ( false !== $test_is_windows && '' !== $test_is_windows ) { return (bool) $test_is_windows; } return strtoupper( substr( PHP_OS, 0, 3 ) ) === 'WIN'; From e53d0a1c854837f11bac4ac9ba66325fc9ce732b Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Sun, 29 Mar 2026 12:45:11 +0200 Subject: [PATCH 06/10] another one --- tests/Test_Table.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tests/Test_Table.php b/tests/Test_Table.php index 948d16f..548a773 100644 --- a/tests/Test_Table.php +++ b/tests/Test_Table.php @@ -102,7 +102,11 @@ public function test_column_odd_single_width_with_double_width() { } else { $this->assertSame( '1あいうえ ', $result[0] ); // 1 single-width, 4 double-width, space = 10. } - $this->assertSame( 'おか2きくカ', $result[1] ); // 2 double-width, 1 single-width, 2 double-width, 1 half-width = 10. + if ( Shell::is_windows() ) { + $this->assertSame( 'おか2きくカ ', $result[1] ); + } else { + $this->assertSame( 'おか2きくカ', $result[1] ); // 2 double-width, 1 single-width, 2 double-width, 1 half-width = 10. + } $this->assertSame( 'けこ ', $result[2] ); // 2 double-width, 8 spaces = 10. // Minimum width 1. From aee09442e1f48ed9da82254559d9a2ed06922ca2 Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Sun, 29 Mar 2026 12:54:11 +0200 Subject: [PATCH 07/10] another one --- tests/Test_Table.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tests/Test_Table.php b/tests/Test_Table.php index 548a773..e433cd1 100644 --- a/tests/Test_Table.php +++ b/tests/Test_Table.php @@ -118,7 +118,11 @@ public function test_column_odd_single_width_with_double_width() { $this->assertSame( 13, count( $result ) ); // Uneven rows. - $this->assertSame( '1', $result[0] ); + if ( Shell::is_windows() ) { + $this->assertSame( '1 ', $result[0] ); + } else { + $this->assertSame( '1', $result[0] ); + } $this->assertSame( 'あ', $result[1] ); // Zero width does no wrapping. From de381afda46bd80ff4456f271102a136a4df2e63 Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Sun, 29 Mar 2026 12:57:04 +0200 Subject: [PATCH 08/10] another one --- tests/Test_Table.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tests/Test_Table.php b/tests/Test_Table.php index e433cd1..edb95ee 100644 --- a/tests/Test_Table.php +++ b/tests/Test_Table.php @@ -123,7 +123,11 @@ public function test_column_odd_single_width_with_double_width() { } else { $this->assertSame( '1', $result[0] ); } - $this->assertSame( 'あ', $result[1] ); + if ( Shell::is_windows() ) { + $this->assertSame( 'あ ', $result[1] ); + } else { + $this->assertSame( 'あ', $result[1] ); + } // Zero width does no wrapping. From c9ccc1a7b444f72eff910590b75e43a644c41094 Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Sun, 29 Mar 2026 13:07:51 +0200 Subject: [PATCH 09/10] merge conditions --- tests/Test_Table.php | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/tests/Test_Table.php b/tests/Test_Table.php index edb95ee..4847610 100644 --- a/tests/Test_Table.php +++ b/tests/Test_Table.php @@ -99,12 +99,9 @@ public function test_column_odd_single_width_with_double_width() { $this->assertSame( 3, count( $result ) ); if ( Shell::is_windows() ) { $this->assertSame( '1あいうえ ', $result[0] ); - } else { - $this->assertSame( '1あいうえ ', $result[0] ); // 1 single-width, 4 double-width, space = 10. - } - if ( Shell::is_windows() ) { $this->assertSame( 'おか2きくカ ', $result[1] ); } else { + $this->assertSame( '1あいうえ ', $result[0] ); // 1 single-width, 4 double-width, space = 10. $this->assertSame( 'おか2きくカ', $result[1] ); // 2 double-width, 1 single-width, 2 double-width, 1 half-width = 10. } $this->assertSame( 'けこ ', $result[2] ); // 2 double-width, 8 spaces = 10. @@ -120,12 +117,9 @@ public function test_column_odd_single_width_with_double_width() { // Uneven rows. if ( Shell::is_windows() ) { $this->assertSame( '1 ', $result[0] ); - } else { - $this->assertSame( '1', $result[0] ); - } - if ( Shell::is_windows() ) { $this->assertSame( 'あ ', $result[1] ); } else { + $this->assertSame( '1', $result[0] ); $this->assertSame( 'あ', $result[1] ); } From a0cd69a35d1f9e17336d1b4c059375492e04e977 Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Sun, 29 Mar 2026 13:10:37 +0200 Subject: [PATCH 10/10] fix \r --- tests/Test_Table.php | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) diff --git a/tests/Test_Table.php b/tests/Test_Table.php index 4847610..eb6a2eb 100644 --- a/tests/Test_Table.php +++ b/tests/Test_Table.php @@ -86,7 +86,7 @@ public function test_column_odd_single_width_with_double_width() { $strip_borders = function ( $a ) { return array_map( function ( $v ) { - return substr( $v, 2, -2 ); + return substr( rtrim( $v, "\r" ), 2, -2 ); }, $a ); }; @@ -97,13 +97,8 @@ public function test_column_odd_single_width_with_double_width() { $result = $strip_borders( explode( "\n", $out ) ); $this->assertSame( 3, count( $result ) ); - if ( Shell::is_windows() ) { - $this->assertSame( '1あいうえ ', $result[0] ); - $this->assertSame( 'おか2きくカ ', $result[1] ); - } else { - $this->assertSame( '1あいうえ ', $result[0] ); // 1 single-width, 4 double-width, space = 10. - $this->assertSame( 'おか2きくカ', $result[1] ); // 2 double-width, 1 single-width, 2 double-width, 1 half-width = 10. - } + $this->assertSame( '1あいうえ ', $result[0] ); // 1 single-width, 4 double-width, space = 10. + $this->assertSame( 'おか2きくカ', $result[1] ); // 2 double-width, 1 single-width, 2 double-width, 1 half-width = 10. $this->assertSame( 'けこ ', $result[2] ); // 2 double-width, 8 spaces = 10. // Minimum width 1. @@ -115,13 +110,8 @@ public function test_column_odd_single_width_with_double_width() { $this->assertSame( 13, count( $result ) ); // Uneven rows. - if ( Shell::is_windows() ) { - $this->assertSame( '1 ', $result[0] ); - $this->assertSame( 'あ ', $result[1] ); - } else { - $this->assertSame( '1', $result[0] ); - $this->assertSame( 'あ', $result[1] ); - } + $this->assertSame( '1', $result[0] ); + $this->assertSame( 'あ', $result[1] ); // Zero width does no wrapping.