Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Parametrized example group #315

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
LukeSavefrogs opened this issue Jun 3, 2024 · 2 comments
Open

Parametrized example group #315

LukeSavefrogs opened this issue Jun 3, 2024 · 2 comments

Comments

@LukeSavefrogs
Copy link
Contributor

LukeSavefrogs commented Jun 3, 2024

Hi @ko1nksm
I wanted to repeat the same example group for multiple identical files, which would help reducing duplication...

I tried to do something like this:

Describe "Report scripts"
    Parameters:dynamic
        for file in ./src/*_report.*sh; do
            %data "#$file" "$file"
        done
    End
    Describe "File $1"
        It 'is executable'
            The path "$1" should be executable
        End
        Describe 'help text'
            It 'is present'
                When run script "$1" --help
                The output should include "NAME"
                The output should include "DESCRIPTION"
                The output should include "USAGE"
                The output should include "OPTIONS"
                The output should include "VERSION"
            End
        End
    End
End

However this doesn't work (as expected) because it is not a supported syntax.

This is also shown in this spec, where the same parameters are repeated 3 times:

Describe "shellspec_includes()"
lf=$SHELLSPEC_LF tab=$SHELLSPEC_TAB vt=$SHELLSPEC_VT cr=$SHELLSPEC_CR
Parameters
"abc" "b" success
"abc" "d" failure
"a|b|c" "|b|" success
"abc" "*" failure
"abc" "?" failure
"abc[d]" "c[d]" success
"# # #" "# # #" success
"a\"\\\$&';\`~" "a\"\\\$&';\`~" success
"< > ( ) { } ^ =" "< > ( ) { } ^ =" success
"$lf$tab$vt$cr" "$lf$tab$vt$cr" success
End
It "checks if it includes a string (target: $1, string: $2)"
When call shellspec_includes "$1" "$2"
The status should be "$3"
End
End
Describe "shellspec_includes_posix()"
Skip if "parameter expansion is not POSIX compliant" invalid_posix_parameter_expansion
lf=$SHELLSPEC_LF tab=$SHELLSPEC_TAB vt=$SHELLSPEC_VT cr=$SHELLSPEC_CR
Parameters
"abc" "b" success
"abc" "d" failure
"a|b|c" "|b|" success
"abc" "*" failure
"abc" "?" failure
"abc[d]" "c[d]" success
"# # #" "# # #" success
"a\"\\\$&';\`~" "a\"\\\$&';\`~" success
"< > ( ) { } ^ =" "< > ( ) { } ^ =" success
"$lf$tab$vt$cr" "$lf$tab$vt$cr" success
End
It "checks if it includes a string (target: $1, string: $2)"
When call shellspec_includes_posix "$1" "$2"
The status should be "$3"
End
End
Describe "shellspec_includes_fallback()"
lf=$SHELLSPEC_LF tab=$SHELLSPEC_TAB vt=$SHELLSPEC_VT cr=$SHELLSPEC_CR
Parameters
"abc" "b" success
"abc" "d" failure
"a|b|c" "|b|" success
"abc" "*" failure
"abc" "?" failure
"abc[d]" "c[d]" success
"# # #" "# # #" success
"a\"\\\$&';\`~" "a\"\\\$&';\`~" success
"< > ( ) { } ^ =" "< > ( ) { } ^ =" success
"$lf$tab$vt$cr" "$lf$tab$vt$cr" success
End
It "checks if it includes a string (target: $1, string: $2)"
When call shellspec_includes_fallback "$1" "$2"
The status should be "$3"
End
End

Is there a better way of doing this or should be a proposed feature?

@ko1nksm
Copy link
Member

ko1nksm commented Jun 4, 2024

Just a quick look, but I'm guessing it's $2, not $1.

    Describe "File $1"
        It 'is executable'
            The path "$2" should be executable
        End
        Describe 'help text'
            It 'is present'
                When run script "$2" --help
                The output should include "NAME"
                The output should include "DESCRIPTION"
                The output should include "USAGE"
                The output should include "OPTIONS"
                The output should include "VERSION"
            End
        End
    End

@LukeSavefrogs
Copy link
Contributor Author

Just a quick look, but I'm guessing it's $2, not $1.

You're right, my bad. With $2 it works correctly

Describe "Report scripts"
    Parameters:dynamic
        for file in ./src/*_report.*sh; do
            %data "#$file" "$file"
        done
    End
    Describe "File $2"
        It 'is executable'
            The path "$2" should be executable
        End
        Describe 'help text'
            It 'is present'
                When run script "$2" --help
                The output should include "NAME"
                The output should include "DESCRIPTION"
                The output should include "USAGE"
                The output should include "OPTIONS"
                The output should include "VERSION"
            End
        End
    End
End

Output:

lsalvarani@Desktop-Luca$ shellspec --format d spec/binaries_spec.sh 
Running: /usr/bin/bash [bash 5.1.4(1)-release]

Report scripts
  File
    is executable
    is executable
    help text
      is present
      is present

Finished in 0.23 seconds (user 0.14 seconds, sys 0.02 seconds)
4 examples, 0 failures

I would have expected them to be grouped together btw... Something like this:

Report scripts
  File ./src/test1_report.sh
    is executable
    help text
      is present
  File ./src/test2_report.sh
    is executable
    help text
      is present

Do you think this can be done?

As soon as I have free time I would also like to help with the documentation, the one on Parameters and Data lacks a bit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants