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

Do I have to specify the path to Bash when I run a test for a Bash script? #256

Open
shinokada opened this issue Jan 4, 2022 · 3 comments

Comments

@shinokada
Copy link

shinokada commented Jan 4, 2022

The doc says:

    -s, --shell SHELL    Specify a path of shell [default: "auto" (the shell running shellspec)]

How to find the shell running shellspec?
I have a bash file to test.

#!/usr/bin/env bash
...

But when I run shellspec spec/bash_helpers_spec.sh, I get errors.
But when I run shellspec spec/bash_helpers_spec.sh -s "/usr/bin/env bash", it passes.

When I test a bash file, do I have to specify the path to Bash?

@shinokada shinokada changed the title How to find the shell running shellspec? Do I have to specify the path to Bash when I run a test for a Bash script? Jan 4, 2022
@ikkextoch
Copy link

I have never used this tool (looking into it for the first time), but I suspect that -s "auto" detects which shell you are using, probably by looking at the environment variable SHELL.

I think the explicit usage would look like this:
shellspec spec/bash_helpers_spec.sh -s "/usr/bin/bash"
or
shellspec spec/bash_helpers_spec.sh -s "/bin/bash"

@lutzmad
Copy link

lutzmad commented Feb 9, 2022

Hello Shinichi Okada,
what OS do you use? What are you doing in spec/bash_helpers_spec.sh?

In a Linux environment I get the following output

> shellspec spec/bash_spec.sh
Running: /bin/sh [bash 4.3.48(1)-release]
.

Finished in 0.15 seconds (user 0.09 seconds, sys 0.01 seconds)
1 example, 0 failures

My simple script does not fail and find the given bash shell via "/usr/bin/env bash" and SHELLSPEC is using the bash itself.

With regards,
Lutz

@ReedClanton
Copy link

Having the same issue as @shinokada.

Description

When running tests of script files that start with #!/usr/bin/env sh they fail. However, they succeed when I remove --sandbox from .shellspec. Also, some of the output tells me that the failure is caused by the script not being able to access /usr/bin/env.

The -s option values I've tried have made no difference, but just in case, they're listed bellow:

  • /usr/bin/env bash
  • /usr/bin/env sh
  • /usr/bin/bash
  • /bin/bash

Note: Running Fedora Linux 37 (Workstation Edition), I have nothing in spec/bash_helpers_spec.sh, and both #!/usr/bin/env sh and #! /usr/bin/env sh behave the same when at the top of the tested code.

Test

It "Passes when .shellspec doesn't contain --sandbox"
	When call ./specTesting.sh
	The status should be success
End

Code Under Test (COT)

#!/usr/bin/env sh
exit 0

Results

No --sandbox

Running: /bin/sh [bash 5.2.15(1)-release]
.

Finished in 0.14 seconds (user 0.11 seconds, sys 0.04 seconds)
1 example, 0 failures

With --sandbox

Running: /bin/sh [bash 5.2.15(1)-release]
F

Examples:
  1) Passes when .shellspec doesn't contain --sandbox
     When call ./specTesting.sh

     1.1) The status should be success

            expected: success (zero)
                 got: failure (non-zero) [status: 127]

          # tests/spec/learning_spec.sh:3

     1.2) WARNING: There was output to stderr but not found expectation

            stderr: /usr/bin/env: ‘sh’: No such file or directory

          # tests/spec/learning_spec.sh:1-4

Finished in 0.15 seconds (user 0.13 seconds, sys 0.03 seconds)
1 example, 1 failure


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

shellspec tests/spec/learning_spec.sh:1 # 1) Passes when .shellspec doesn't contain --sandbox 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

4 participants