Skip to content

Line endings in ${lines[@]} not sanitized #249

@thorstenkampe

Description

@thorstenkampe

Default line endings on different platforms are not stripped - making it hard to interact with native applications on Cygwin.

Consider the following test suite

@test 'Cygwin Python' {
    run python3.8 -m this
    [[ ${lines[0]} == 'The Zen of Python, by Tim Peters' ]]
}

@test 'Windows Python' {
    run python -m this
    [[ ${lines[0]} == 'The Zen of Python, by Tim Peters' ]]
}

Result:

 ✓ Cygwin Python
 ✗ Windows Python
   (in test file test.bats, line 8)
     `[[ ${lines[0]} == 'The Zen of Python, by Tim Peters' ]]' failed

2 tests, 1 failure

By the way: unless you already know what the issue is, bats gives you no aide for debugging. I suspected \r\n line endings from Windows Python. Let's sanitize explicitly

@test 'Windows Python' {
    run python -m this
    [[ ${lines[0]%[[:cntrl:]]} == 'The Zen of Python, by Tim Peters' ]]
}

...works...

 ✓ Cygwin Python
 ✓ Windows Python

2 tests, 0 failures

Metadata

Metadata

Assignees

No one assigned

    Labels

    Component: Bash CodeEverything regarding the bash codePriority: HighBroken behavior in specific environments like in parallel mode or only on some operating systemsStatus: WontfixType: Bug

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions