Skip to content
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

Trailing empty lines are ignored by design? #269

Open
kai2nenobu opened this issue May 27, 2022 · 1 comment
Open

Trailing empty lines are ignored by design? #269

kai2nenobu opened this issue May 27, 2022 · 1 comment

Comments

@kai2nenobu
Copy link

I wrote following examples to test a trailing empty line.

Describe "Demo"
  trailing_empty_line() {
    printf "1\n2\n\n"
  }

  It "Last empty line is not counted"
    When call trailing_empty_line
    The lines of output should eq 3
  End
  It "Last empty line is not set"
    When call trailing_empty_line
    The 3rd line of output should eq ""
  End
End

However, these examples failed as below.

$ shellspec --format tap
1..2
not ok 1 - Demo Last empty line is not counted # FAILED
# (in specfile spec/sample_spec.sh, line 8)
# When call trailing_empty_line
# The lines of output should eq 3
# 
#   expected: 3
#        got: 2
# 
not ok 2 - Demo Last empty line is not set # FAILED
# (in specfile spec/sample_spec.sh, line 12)
# When call trailing_empty_line
# The 3rd line of output should eq 
# 
#   expected: ""
#        got: <unset>
# 

This shellspec behavior is intended one? Can I test trailing empty lines by shellspec?

@LukeSavefrogs
Copy link
Contributor

Strange...

Seems like testing the output instead works as expected:

#shellcheck shell=sh

Describe "Demo"
  trailing_empty_line() {
    printf "1\n2\n\n"
  }

  It "Last empty line is not counted"
    When call trailing_empty_line
    The lines of output should eq 3
  End

  It "Last empty line is not counted"
    When call trailing_empty_line
    The output should eq "$(trailing_empty_line)"
  End
  
  It "Last empty line is not set"
    When call trailing_empty_line
    The 3rd line of output should eq ""
  End
End

Output

$ shellspec ./test.test.sh
Running: /usr/bin/bash [bash 4.4.12(3)-release] {--jobs 3}
F.F

Examples:
  1) Demo Last empty line is not counted
     When call trailing_empty_line

     1.1) The lines of output should eq 3

            expected: 3
                 got: 2

          # ./test.test.sh:10

  2) Demo Last empty line is not set
     When call trailing_empty_line

     2.1) The 3rd line of output should eq

            expected: ""
                 got: <unset>

          # ./test.test.sh:20

Finished in 1,48 seconds (user 0,64 seconds, sys 1,03 seconds)
3 examples, 2 failures


Failure examples / Errors: (Listed here affect your suite's status)

shellspec ./test.test.sh:8 # 1) Demo Last empty line is not counted FAILED
shellspec ./test.test.sh:18 # 2) Demo Last empty line is not set FAILED

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