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

chore: add fail() function #249

Merged
merged 3 commits into from
Apr 25, 2024
Merged

chore: add fail() function #249

merged 3 commits into from
Apr 25, 2024

Conversation

ceejatec
Copy link
Contributor

@ceejatec ceejatec commented Apr 24, 2024

📚 Description

Adds new fail() function for general purpose test failures not covered by the various assert_* functions.

🔖 Changes

  • Added fail() function in assert.sh
  • Added console_results::print_failure_message() function in console_results.sh
  • Added test case

✅ To-do list

  • I updated the CHANGELOG.md to reflect the new feature or fix
  • I updated the documentation to reflect the changes

Copy link
Member

@Chemaclass Chemaclass left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How interesting. Is this something you have seen in other libraries, @ceejatec?

Copy link
Member

@antonio-gg-dev antonio-gg-dev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you very much for your contribution and for treating bashunit with the same care as we do, I love your idea.

Comment on lines 871 to 873
function test_failure() {
[ $(date +%-H) -lt 6 ] || fail "It's late, go to bed"
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The example you set for test_failure doesn't always fail because it depends on the time of execution. The idea is to have one of the examples always succeed and the other always fail. Could you change it?

I think it would also help to use the if syntax instead of the || operator in both examples, as it's more familiar to a greater number of programmers.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've modified them as requested. I had trouble coming up with an example that could seem useful in only a line or two, but I think this gets the job done.

@ceejatec
Copy link
Contributor Author

@Chemaclass Indeed, it's a pretty common function, going right back to JUnit. IME, frequently the various assert() methods are internally implemented in terms of the basic fail(message) function too.

Copy link
Member

@antonio-gg-dev antonio-gg-dev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@Chemaclass Chemaclass merged commit 8021b2f into TypedDevs:main Apr 25, 2024
7 checks passed
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.

3 participants