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

add "&&" to ensure "status" is included in test pass/fail #445

Closed
wants to merge 1 commit into from
Closed

add "&&" to ensure "status" is included in test pass/fail #445

wants to merge 1 commit into from

Conversation

MichaelDimmitt
Copy link

Summary:

Core excercise number 3: "Error Handling"

Submitting the solution with all tests giving a result of "status code 0"

Two tests should have failed for this excercise:

@test "incorrect arguments" 
@test "print usage banner with no value given" 

With the addition of "&&" the test suite is correctly failing.

Happy to make alternative changes if preferred.

Additionally,
let me know if you want me to add this to all of the test suites for the bash track.

Below are images where the mentor spotted the excercise should have had a failing test suite.
Cheers, Michael Dimmitt

exercise-example

explanation


Reviewer Resources:

Track Policies

@IsaacG
Copy link
Member

IsaacG commented Sep 22, 2020

Assuming you're running bats from https://github.com/sstephenson/bats then test suite should be setting set -e which should cause any failed line to trigger a test failure.

Using your first solution,

» BATS_RUN_SKIPPED=true bats *test*
 ✓ correct arguments
 ✓ one long argument
 ✗ incorrect arguments
   (in test file error_handling_test.sh, line 25)
     `(( status == 1 ))' failed
 ✗ print usage banner with no value given
   (in test file error_handling_test.sh, line 33)
     `(( status == 1 ))' failed
 ✓ empty argument

@MichaelDimmitt
Copy link
Author

MichaelDimmitt commented Sep 23, 2020

> BATS_RUN_SKIPPED=true bats error_handling_test.sh

> bats error_handling_test.sh 

> bash --version
GNU bash, version 3.2.57(1)-release (x86_64-apple-darwin19)
Copyright (C) 2007 Free Software Foundation, Inc.

> bats -v
Bats 0.4.0

Environment: mac os, catalina.

@MichaelDimmitt
Copy link
Author

MichaelDimmitt commented Sep 23, 2020

Even if I add set -e to error_handling_test.sh
the tests are not failing on the incorrect status code.

Screen Shot 2020-09-22 at 8 11 45 PM

Screen Shot 2020-09-22 at 8 13 35 PM

Screen Shot 2020-09-22 at 8 14 34 PM

@IsaacG
Copy link
Member

IsaacG commented Sep 23, 2020

Let's go for a minimal reproduction of the issue.

» tmp=$(mktemp) ; cat << EOF > "$tmp"
@test a {
 false
 true
}
@test b {
 false
}
@test c {
 true
}
EOF

» bats "$tmp"; rm "$tmp"
 ✗ a
   (in test file /tmp/tmp.KI12EzFTeK, line 2)
     `false' failed
 ✗ b
   (in test file /tmp/tmp.KI12EzFTeK, line 6)
     `false' failed
 ✓ c

3 tests, 2 failures

If you get different results than I get, that should be filed as a bats bug.

@MichaelDimmitt
Copy link
Author

MichaelDimmitt commented Sep 23, 2020

@IsaacG , same results

Please let me know what else I can do.
Happy to make changes.

And if decided to close the pr thats fine too.

inline-example

@IsaacG
Copy link
Member

IsaacG commented Sep 23, 2020

You can try and slowly morph test a to match the exercism test, line by line, to figure out which line causes the issue. Start by adding a run false the run script. Start with a script that just runs false and add line by line until one line triggers the issue.

@glennj
Copy link
Contributor

glennj commented Sep 23, 2020

@MichaelDimmitt looks like you're using the unsupported https://github.com/sstephenson/bats -- this repo is known to be buggy and appears to be abandoned.

The recommended bats package is https://github.com/bats-core/bats-core as documented in https://exercism.io/tracks/bash/tests

I would vote to close this PR: having the tests's check separate allows the more specific error to be shown, instead of "the test failed due to either the status or the output"

@MichaelDimmitt
Copy link
Author

MichaelDimmitt commented Sep 24, 2020

ok, I think I was using brew install bats but I will see if there is an alternate install available.

thanks for the input.

I will uninstall and try with bats-core 👍

@bkhl
Copy link
Contributor

bkhl commented Sep 24, 2020

ok, I think I was using brew install bats but I will see if there is an alternate install available.

Probably would be worthwhile submitting an update/switch to bats-core in Homebrew, so that we don't get students running into this.

I don't use it myself, but maybe someone here can try to submit a change to https://github.com/Homebrew/homebrew-core/blob/master/Formula/bats.rb ?

@bkhl bkhl closed this Sep 24, 2020
@MichaelDimmitt
Copy link
Author

@glennj , your suggestion did the trick.

Gaving bats installed instead of bats-core was causing the issue.

Thanks @glennj , and @IsaacG

@MichaelDimmitt
Copy link
Author

MichaelDimmitt commented Sep 24, 2020

@bkhl, Thanks for the suggestion.

I am going to try submitting the suggested pr to homebrew.

Will post a link to the pr shortly.

@MichaelDimmitt
Copy link
Author

MichaelDimmitt commented Sep 24, 2020

@bkhl ,

Homebrew/homebrew-core#27796

It looks like homebrew does not want to update this package because bats has
6.6k stars and bats-core has 1.9k stars.

also I think they need to manually create an alias.
I attempted to create an alias and was not able to test locally using
brew install --build-from-source bats
Homebrew/brew#469 (comment)

I tried to rewrite the ruby formula to do the following

class Bats < BatsCore
end

However it errors out with the following,
Error: bats: uninitialized constant Formulary::FormulaNamespace

I believe this is because homebrew requires all formulas to extend formula
class Bats < Formula

therefore not submitting a pr.

@MichaelDimmitt MichaelDimmitt deleted the tests-should-assert-exit-code-and-output branch September 24, 2020 21:09
@bkhl
Copy link
Contributor

bkhl commented Sep 25, 2020

The project was handed over from the old maintainer to bats-core in this ticket: sstephenson/bats#150 (comment) , so you can refer them to the discussion there.

@MichaelDimmitt
Copy link
Author

Created a discussion on homebrew with the information discussed.
Homebrew/discussions#24

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

Successfully merging this pull request may close these issues.

4 participants