sstephenson / bats

Bash Automated Testing System
MIT License
7.13k stars 517 forks source link

Infinite loop with "Begin 1 ... 100/2" then 101/2 and so on for 2 tests #235

Closed NBardelot closed 7 years ago

NBardelot commented 7 years ago
> bats -v
Bats 0.4.0

Here are the files I load in my tests (those are purposefully "dumb" as I'm testing bats and want to see how it behaves) :

> cat common_tests.bash

test_whoami() {
    /bin/whoami
}

export -f test_whoami
> cat root_tests.bash
test_port_8779() {
    iptables -C noee_services -p tcp --destination-port 8779 -j ACCEPT
}

export -f test_port_8779

and here is the bats file with two tests:

> cat test_as_root.bats
#!/usr/bin/env bats

load common_tests
load root_tests

@test "whoami" {
   run test_whoami
   [ "$output" = "root" ]
}

@test "iptables port 8779" {
   run test_port_8779
   [ $status -eq 0 ]
}

And the output (there is a "2" on the last line after Ctrl+C) :

> bats test_as_root.bats
begin 1 whoami  100/
begin 1 whoami  101/
begin 1 whoami  102/
begin 1 whoami  103/
begin 1 whoami
2

And please note that:

NBardelot commented 7 years ago

OK found the issue... My function name "test_whoami" is colliding with the tool's choice of names when it generates some internal functions/files/whatever.

You might consider to change the internal "test_" for something that the user would not* use as a test function name (like prefixing with a random string from /dev/urandom or something).