-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Revamped testing guide #19627
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
Revamped testing guide #19627
Conversation
test on windows you can write `#[cfg_attr(windows, ignore)]`. | ||
The second change is the `use` declaration. Because we're in an inner module, | ||
we need to bring our test function into scope. This can be annoying if you have | ||
a large module, and so this is a common use of the `glob` crate. |
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.
The glob
crate is unrelated to use foo:::*
. All you need for that is #![feature(globs)]
in the crate root.
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.
Ah! 😅
cc #19560 - don't want to lose the doc change if that PR merges first. |
## Benchmarks and the optimizer | ||
* Move setup code outside the `iter` loop; only put the part you want to measure inside | ||
* Make the code do "the same thing" on each iteration; do not accumulate or change state | ||
* Make the outer function idempotent too; the benchmark runner is likely to run |
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.
s/idempotent/independent/
?
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 was copied straight from the previous version of the text. Regardless, idempotent
is the correct word here: you don't want multiple calls to the test to have different outcomes.
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.
Oh! I didn't realize it was a word.
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.
One of my favorites! http://en.wikipedia.org/wiki/Idempotence
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.
Yeah. I saw that once I saw it was real. Good to know.
70ef7aa
to
5d8ff6a
Compare
@sfackler addressed your comments and included the fixes from your PR. |
|
||
To create test functions, add a `#[test]` attribute like this: | ||
Let's talk about how to test Rust code. What we will not be talking about the |
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.
Missing an "is" from this line.
What we will not be talking about is the ...
2bc2574
to
5b11154
Compare
5b11154
to
d4ea71d
Compare
|
||
## Benchmarks and the optimizer |
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.
FWIW, it's a little sad to lose the headings, since it's useful to link people directly to this optimisation section when they encounter a optimised-out benchmark.
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.
@huonw mind opening up a new issue with these comments? this already got merged, and I'm not going to get to them tonight, and I don't want to lose them :)
No description provided.