Skip to content
This repository has been archived by the owner on Apr 29, 2021. It is now read-only.

Nested test #185

Closed
mvalin opened this issue Oct 11, 2016 · 2 comments
Closed

Nested test #185

mvalin opened this issue Oct 11, 2016 · 2 comments

Comments

@mvalin
Copy link

mvalin commented Oct 11, 2016

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
Copy link

ztombol commented Oct 11, 2016

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
Copy link
Author

mvalin commented Oct 13, 2016

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

Thanks.

@mvalin mvalin closed this as completed Oct 13, 2016
@ztombol ztombol mentioned this issue Dec 13, 2016
18 tasks
yarikoptic pushed a commit to neurodebian/bats that referenced this issue Aug 6, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants