I am facing some problems with a bash exercise

I am currently stuck on “Bash/Two Fer” problem. I am trying to write the answer but am getting this output-
"An error occurred while running your tests. This might mean that there was an issue in our infrastructure, or it might mean that you have something in your code that’s causing our systems to break.

Please check your code, and if nothing seems to be wrong, try running the tests again."

My code is-

#!/usr/bin/env bash
read -r name
if [ -z “$name” ]
then
echo “One for you, one for me.”
else
echo “One for $1, one for me”
fi

The issue is the read line. It waits for input from STDIN. The tests do not provide any input on STDIN.

Can then you tell me the correct way to do it?

The stub calls main using $@, which is the list of arguments the program is called with. That’s similar to, say, how you would pass arguments to echo. You may want to read up on positional parameters. BashGuide/Parameters - Greg's Wiki

#!/usr/bin/env bash

if [ -z “$1” ]
then
echo “One for you, one for me.”
else
echo “One for $1, one for me”
fi

The above is the solution that I submitted by I am still getting the error message. When I searched for others solution for this problem they have written the solution similar to mine. Why I am facing the problem of it not running.

That code has a different bug.

Can you copy/paste (no screenshots) the exact code you are using the the exact error you see when you run it? Make sure to click on “TEST FAILURES” to expand them for details!

Right now I am trying to do the “Error Handling” exercise of bash and am still facing the same problem. The editor doesn’t show me any specific error and just tells “An Error Occured”. Nor am I able to find the “TEST FAILURES” option to expand for detail. Here is the screenshot of the problem I am facing.

Yeah… It looks like the test runner isn’t reporting test failures but is instead failing. @glennj Would you be able to take a look?

@Aadillore You may want to try working locally. That should be more reliable. For the Two-fer exercise,

» cat > two_fer.sh <<END
#!/usr/bin/env bash

if [ -z “$1” ]
then
echo “One for you, one for me.”
else
echo “One for $1, one for me”
fi

END

» BATS_RUN_SKIPPED=true bats *bats
 ✗ no name given
   (from function `assert_output' in file bats-extra.bash, line 394,
    in test file two_fer.bats, line 24)
     `assert_output "One for you, one for me."' failed

   -- output differs --
   expected : One for you, one for me.
   actual   : “One for , one for me”
   --

 ✗ a name given
   (from function `assert_output' in file bats-extra.bash, line 394,
    in test file two_fer.bats, line 31)
     `assert_output "One for Alice, one for me."' failed

   -- output differs --
   expected : One for Alice, one for me.
   actual   : “One for Alice, one for me”
   --

 ✗ another name given
   (from function `assert_output' in file bats-extra.bash, line 394,
    in test file two_fer.bats, line 38)
     `assert_output "One for Bob, one for me."' failed

   -- output differs --
   expected : One for Bob, one for me.
   actual   : “One for Bob, one for me”
   --

 ✗ handle arg with spaces
   (from function `assert_output' in file bats-extra.bash, line 394,
    in test file two_fer.bats, line 49)
     `assert_output "One for John Smith, one for me."' failed

   -- output differs --
   expected (1 lines):
     One for John Smith, one for me.
   actual (2 lines):
     two_fer.sh: line 3: [: “John: binary operator expected
     “One for John Smith, one for me”
   --

 ✗ handle arg with glob char
   (from function `assert_output' in file bats-extra.bash, line 394,
    in test file two_fer.bats, line 56)
     `assert_output "One for * , one for me."' failed

   -- output differs --
   expected (1 lines):
     One for * , one for me.
   actual (2 lines):
     two_fer.sh: line 3: [: “*: binary operator expected
     “One for a b bats-extra.bash HELP.md README.md two_fer.bats two_fer.sh two_fer_test.sh , one for me”
   --


5 tests, 5 failures

I can reproduce it. I’ll dig into the test runner for this exercise.

2 Likes

@ErikSchierboom can you please have a look at https://github.com/exercism/bash-test-runner/pull/70 – the bash test runner is erroring instead of reporting test failures.

This commit (https://github.com/exercism/bash-test-runner/commit/bbf0d918b43565a45856656b3d8ef74fb3925da6) is the likely culprit,

Found it: https://github.com/exercism/bash-test-runner/pull/71

@ErikSchierboom a review please.

1 Like

I’ve approved.

1 Like

@Aadillore it’s fixed now. Please try again.