sstephenson / bats

Bash Automated Testing System
MIT License
7.12k stars 519 forks source link

Weird output captured from `docker run --interactive -tty` command #176

Closed ahmetb closed 8 years ago

ahmetb commented 8 years ago

When I do a run a command with docker run ... $@ vs eval $@ , I see that the output from docker one gets weird.

Here is a minimal repro

Code


IMAGE=alpine

setup(){
    # pull docker image if missing
    docker inspect $IMAGE 2>&1 1>/dev/null || docker pull $IMAGE 1>&2
}

run_normally() {
    eval $@
}

run_in_container(){
    docker run -i -t --rm $IMAGE $@
}

@test "normal" {
    run run_normally /bin/echo "Hello, world"
    echo "Output: >>>$output<<<"
    echo "Status: $status"
    [ "$status" -eq 0 ]
    [ "$output" = "Hello, world" ]
}

@test "in container" {
    run run_in_container /bin/echo "Hello, world"
    echo "Output: >>>$output<<<"
    echo "Status: $status"
    [ "$status" -eq 0 ]
    [ "$output" = "Hello, world" ]
}

Output

See that the line printing output is: <<<Output: >>>Hello, world and not Output: >>>Hello, world<<<.

$ bats integration-test/test
 ✓ normal
 ✗ in container
   (in test file integration-test/test/basic.bats, line 45)
     `[ "$output" = "Hello, world" ]' failed
<<<Output: >>>Hello, world
   Status: 0

2 tests, 1 failure

Any ideas what's going on here?

ahmetb commented 8 years ago

I must add that the problem goes away when I remove -t (--tty) from docker run command.

RomanSaveljev commented 8 years ago

I think tools like expect may handle better output of a program, which is forced to interactive mode

ahmetb commented 8 years ago

@RomanSaveljev in this case, the interesting thing is program is not interactive but the output comes in a weird shape that the >>> <<< chars I put around it gets reversed.

ahmetb commented 8 years ago

I guess not a bats issue, so closing.

RomanSaveljev commented 8 years ago

Yeah, that definitely looks intriguing to me as to why it would do that..