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

Guide testing #15992

Merged
merged 1 commit into from
Aug 1, 2014
Merged

Guide testing #15992

merged 1 commit into from
Aug 1, 2014

Conversation

steveklabnik
Copy link
Member

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?

@steveklabnik
Copy link
Member Author

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
Copy link
Member

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)

Copy link
Member Author

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.

@nielsle
Copy link
Contributor

nielsle commented Jul 26, 2014

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
Copy link
Member

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

Copy link
Member Author

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.

@steveklabnik
Copy link
Member Author

We're getting there. First things first.

}
```

By just brining the module into scope, we can keep one level of namespacing.
Copy link
Contributor

Choose a reason for hiding this comment

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

s/brining/bringing/?

Copy link
Member Author

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.

@steveklabnik
Copy link
Member Author

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?

@alexcrichton
Copy link
Member

It looks like you've got one for src/lib.rs, one for src/main.rs, and one for tests/lib.rs (does that sound right?)

@steveklabnik
Copy link
Member Author

Ahh, that makes sense. I guess I should call that out specifically, huh? I thought it was only ever two, not one per file.

@alexcrichton
Copy link
Member

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)

@steveklabnik
Copy link
Member Author

Updated to include this information :)

@steveklabnik
Copy link
Member Author

Rebased to one commit now that the other PR was merged.

bors added a commit that referenced this pull request Aug 1, 2014
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?
@bors bors closed this Aug 1, 2014
@bors bors merged commit 6121d82 into rust-lang:master Aug 1, 2014
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.

8 participants