Skip to content

Test suite fails on Windows and whenever STDOUT is not ANSI capable #43

Description

@HafizMMoaz

vendor/bin/phpunit on Windows with piped output gives 8 failures out of 75 tests (PHP 8.4.19, main 2c0159f):

1) CLITest::testWrite            5) CLITest::testStyle
2) CLITest::testLiveLine         6) CLITest::testStyleWithInvalidColor
3) CLITest::testIsWindows        7) CLITest::testStyleWithInvalidBackground
4) CLITest::testClear            8) CLITest::testStyleWithInvalidFormat

Setting WT_SESSION=1 (which makes supportsAnsi() return true) brings it down to 2 failures, which isolates the causes:

  • Six of them assume ANSI is always on. CLI::style() returns the text unchanged when supportsAnsi() is false, so both the escape sequence assertions and the three ValueError assertions fail. Tests should force a known state with CLI::setAnsi(true) in setUp() rather than inherit the terminal's.
  • testIsWindows() asserts assertFalse(CLI::isWindows()), which can only pass on non Windows. It should assert against DIRECTORY_SEPARATOR instead.
  • getTerminalWidth() shells out to tput cols, which does not exist on Windows.
  • testWrite and others hardcode \n where the code writes PHP_EOL, so they fail on CRLF platforms.

CI only runs ubuntu, where supportsAnsi() returns true unconditionally, which is why this is green there and red for anyone developing on Windows.

Unrelated but in the same area: tests/ExitCodeTest.php:1-19 has the license header duplicated, with declare(strict_types=1); sandwiched between the two copies.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions