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

Shellspec Reporting Failure when all test passed- script uses dynamic parameter as input #259

Open
billmallard opened this issue Mar 31, 2022 · 3 comments

Comments

@billmallard
Copy link

billmallard commented Mar 31, 2022

The script is reading in a text file as a dynamic parameter:

#Names the test for the report
Describe 'URL Validation Test -'

# Read in the input test file, build the data for use by shellspec framework convention
# Parameter #5 is the URL in the text file line data
  Parameters:dynamic
    cat ./input_$envName.txt | while read line
          do
                %data `echo $line`
          done
  End #Parameters

#Data driven test will iterate each URL in the formatted text file
  It "URL  $1 $2 $3 $4 $5"
    When call wget --server-response  -nv --spider --timeout=10 --tries=4 --retry-connrefused  --wait=5 --no-check-certificate $5 #5th param url
    The stderr should include 'HTTP/1.1 200' #wget returns body text to stderr - look for the 200 response and confirm
  End #It

End #Describe

This is the output from Execution. All 59 tests passed but it's reporting a fail

+ shellspec --env envName=PROD --output junit --reportdir report
Running: /bin/sh [bash 4.2.46(2)-release]
...........................................................

Finished in 22.16 seconds (user 1.13 seconds, sys 0.45 seconds)
59 examples, 0 failures, -59 examples did not run (unexpected exit?)


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

shellspec spec/bin/URL_Validation_spec.sh # expected 0 examples, but only ran 59 examples

Build step 'Execute shell' marked build as failure
Archiving artifacts
Recording test results
Finished: FAILURE

@billmallard
Copy link
Author

I know it says " -59 examples did not run (unexpected exit?)" but they did run and the JUNIT report produced is correct.

@billmallard
Copy link
Author

Solved this. Seems like only for loops are supported. Was a bit frustrating.

Has to change the IFS setting to get it to split with cat on the newline character.

ExampleGroup 'URLValidation Test -'

# Read in the input test file, build the data for use by shellspec framework convention
Describe 'Dynamic'

 Parameters:dynamic
  IFS='
  '
  for i in `cat ./input_$envName.txt`
      do
        %data $(echo $i | awk -F" " '{print $NF}')
      done
  End

#Data driven test will iterate each URL in the formatted text file
  It "$1"

     #When call wget --server-response  -nv --spider --timeout=10 --tries=4 --retry-connrefused  --wait=5 --no-check-certificate $(echo $1 | awk -F" " '{print $NF}')
     When call wget --server-response  -nv --spider --timeout=10 --tries=4 --retry-connrefused  --wait=5 --no-check-certificate ${1} 
     The stderr should include 'HTTP/1.1 200' #wget returns body text to stderr - look for the 200 response and confirm

  End #It

  End #dynamic kgen

End #Validation Test

@coiby
Copy link

coiby commented Nov 5, 2023

Here is another example that could reproduce the error "expected 0 examples, but only ran XXX examples",

#!/bin/bash
Describe 'hello'
	seq_limit=3
	Parameters:dynamic
		for key in $(seq 0 $seq_limit); do
			%data $key
		done
	End
	hello() {
		echo -n $1
	}

	It 'should return the same thing as input'
		When call hello $1
		The output should equal $1
	End
End
$ shellspec spec/hello_spec.sh
~/.local/lib/shellspec/lib/libexec/translator.sh: line 428: seq_limit: unbound variable

Unexpected error occurred (syntax error?)
Running: /bin/sh [bash 5.2.15(1)-release]
....

Finished in 0.25 seconds (user 0.18 seconds, sys 0.05 seconds)
4 examples, 0 failures, -4 examples did not run (unexpected exit?)


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

shellspec spec/hello_spec.sh # expected 0 examples, but only ran 4 examples

Aborted with status code [executor: 0] [reporter: 101] [error handler: 102]

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