-
-
Notifications
You must be signed in to change notification settings - Fork 91
add bats-assert functionality #539
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 bats-assert functionality #539
Conversation
For example, "hello world": The successful test output appearance does not change $ bats hello_world_test.sh
✓ Say Hi!
1 test, 0 failures If the exit status is non-zero: $ cat hello_world.sh
#!/usr/bin/env bash
echo "Hello, World!"
exit 2
$ bats hello_world_test.sh
✗ Say Hi!
(from function `assert_success' in file ./bats-extra.bash, line 409,
in test file hello_world_test.sh, line 10)
`assert_success' failed with status 2
-- command failed --
status : 2
output : Hello, World!
--
1 test, 1 failure
$ echo $?
1 If the output does not match what's expected: $ cat hello_world.sh
#!/usr/bin/env bash
echo "Goodbye, Mars!"
$ bats hello_world_test.sh
✗ Say Hi!
(from function `assert_output' in file ./bats-extra.bash, line 394,
in test file hello_world_test.sh, line 13)
`assert_output "Hello, World!"' failed
-- output differs --
expected : Hello, World!
actual : Goodbye, Mars!
--
1 test, 1 failure
$ echo $?
1 |
@exercism/bash Thoughts please? This will turn into a very substantial PR with every exercise being affected. For cleanliness, I'll make a commit that's just adding the new file, and another with changes to the test files. Following that, there are also changed to the bash-test-runner to make. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me, with one suggestion for the repeated "kv" use in the names to show what the placeholder might be.
@@ -1,10 +1,14 @@ | |||
#!/usr/bin/env bash | |||
source ./bats-extra.bash |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any test to fail if the file is missing or cannot be sourced?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, well if it can't be found then exercism download
would be broken. If the student accidentally deletes it, then a helpful message to re-download would be useful
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I changed source
to the bats function load
. If the file does not exist, then
$ bats hello_world_test.sh
✗ File hello_world_test.sh
bats: bats-extra.bash does not exist
(in test file hello_world_test.sh, line 9)
`load bats-extra.bash' failed
1 test, 1 failure
I can see that it is titled WIP, but "convert to draft" is probably a better solution. It can prevent premature merges. |
Phew, all tests passing. |
No longer WIP/draft |
Reviewers: coments about the commits here:
|
cool, thanks for adding this. nice idea to save users from needing to install via npm, homebrew, submodule or otherwise. and adding the extra file bats-extra.bash that In the future maybe a script iterates through all files in the test folder and updates bats-extra.bash if the plugins have an update we want to add. But no need to overengineer at present moment. definately gives more output to students 👍 |
Thanks for the inspiration. While I was working on it I was thinking I should apologize: I think I was pretty dismissive about your ideas. So, sorry. Working with the v3 website really revealed the need for better test failure feedback. |
Resolves #536. Resolves #531
The
bats-extra.bash
will be added to every exercise. The contents are thesrc
files for bats-support and bats-assert concatenated, with comment blocks removed.Each exercise's test file will be updated to use bats-assert functions.
The augmented test failure output is important particularly for the
Reviewer Resources:
Track Policies