-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Be more consistent about tests vs. main #2644
Conversation
The content slides all use `fn main`, with the exception of the testing segment. But with this change, where it makes sense exercises use tests instead, and not both tests and `fn main`. A small change in `book.js` supports running tests when a code sample does not have `fn main` but does have `#[test]`, so these work naturally. Note, however, that this doesn't work for non-editable `rust` text, as Highlightjs is responsible for running the playground in that case. This means the exercises produce `No output.` when run, but the solutions (which are editable) show the test results.
// ANCHOR_END: solution | ||
|
||
#[test] | ||
fn test_collatz_length() { | ||
assert_eq!(collatz_length(11), 15); | ||
} |
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.
This is excluding the test from the starting code and solution, was that intended? I thought the goal was to normalize tests on using tests instead of main
.
OK, I've reviewed all of the exercises, and made a few changes. I've also added a section in CONTRIBUTING.md regarding the choice of main or tests. Here's the summary:
|
The content slides all use
fn main
, with the exception of the testing segment. But with this change, where it makes sense exercises use tests instead, and not both tests andfn main
.A small change in
book.js
supports running tests when a code sample does not havefn main
but does have#[test]
, so these work naturally.Fixes #1581.