-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Guide testing #15992
Guide testing #15992
Conversation
Aaaaand as I mention this, @o11c mentions that it's because main.rs isn't a library crate. Duh. So I can make more progress here. |
$ cd ~/projects | ||
$ mkdir testing | ||
$ cd testing | ||
$ mkdir test |
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 could become cargo new --bin
now (the new command is pretty recent)
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.
Filed as #16078, there's other places where we need to do this, and I'd like to tackle that all at once.
Perhaps note that you can place tests in a submodule to allow the use of extra libraries. https://github.com/rust-lang/rust-guidelines/blob/master/testing/unit.md |
## Attributes | ||
|
||
Rust's testing system uses **attribute**s to mark which functions are tests. | ||
Attributes can be placed on any Rust **item**. Remember how most things in |
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.
It seems that using bold markers for parts of words don't work in Markdown (at least on Github). **item**s
will be rendered incorrectly (the second **
are seen as part of the word) and should probably just be **items**
.
Test:
- items works
- items doesn't work
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.
It does work with Rustdoc, so this is not a real problem.
We're getting there. First things first. |
} | ||
``` | ||
|
||
By just brining the module into scope, we can keep one level of namespacing. |
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/brining/bringing/
?
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 fixed in the upstream branch.
Okay! This is now in a reasonable state. I've addressed what's come up so far. One last question, @alexcrichton : why does it now have three testing blocks in the output? Is that because of the sub-module? |
It looks like you've got one for |
Ahh, that makes sense. I guess I should call that out specifically, huh? I thought it was only ever two, not one per file. |
It's more of one per target, which in this case you have a library target, a binary target, and an integration test target. (at least from cargo's perspective) |
Updated to include this information :) |
Rebased to one commit now that the other PR was merged. |
The start of a testing guide. This PR relies on the crates and modules one because I shuffled some stuff around, so sorry about that. I got stuck with how to import this name with cargo. @wycats and @alexcrichton , any ideas?
The start of a testing guide. This PR relies on the crates and modules one because I shuffled some stuff around, so sorry about that.
I got stuck with how to import this name with cargo. @wycats and @alexcrichton , any ideas?