sstephenson / bats

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

Nested test #185

Closed mvalin closed 7 years ago

mvalin commented 7 years ago

Hi everyone, I'd like to know if there a way to nest test, but using 'for', it could seem odd, but if you have a case where you have to test for a package installation, and you have a list of packages, could be easy to think the solution as follow:

pkg=openssh-server
@test "Check package $pkg installed" {
    run dpkg -l $pkg
    [[ "${lines[5]}" == "ii  $pkg"* ]]
}

It works if I use alone, but with a list of packages:

for pkg in openssh-server vim curl
do
    @test "Check package $pkg installed" {
        run dpkg -l $pkg
        [[ "${lines[5]}" == "ii  $pkg"* ]]
    }
done

The test is only one, not 3, and the output is as follow, the last package:

 ✓ Check package curl installed
1 test, 0 failures

Is there away to do this?

In other test tools as Pester for Powershell, that is possible, I know that the solution is different, but I just ask for doubt, maybe there is a way that I don't know.

Regards

ztombol commented 7 years ago

This is a duplicate of #136. See there why this doesn't work and what are the possible solutions.

For reference, #157 and #179 are other duplicates that tried to do the same "is the package installed" use case.

mvalin commented 7 years ago

It is clear, I replaced the code using helper function. I close this issue.

Thanks.