mirror of
https://github.com/rust-lang/book.git
synced 2026-09-15 04:20:07 -04:00
Update some more code and text for new cargo new test content
This commit is contained in:
@@ -29,15 +29,16 @@ Notice that Cargo generated *src/lib.rs* instead of *src/main.rs*. Inside
|
||||
mod tests {
|
||||
#[test]
|
||||
fn it_works() {
|
||||
assert_eq!(2 + 2, 4);
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Cargo creates an empty test to help us get our library started, rather than the
|
||||
“Hello, world!” binary that we get when we use the `--bin` option. We’ll look
|
||||
at the `#[]` and `mod tests` syntax in the “Using `super` to Access a Parent
|
||||
Module” section later in this chapter, but for now, leave this code at the
|
||||
bottom of *src/lib.rs*.
|
||||
Cargo creates an example test to help us get our library started, rather than
|
||||
the “Hello, world!” binary that we get when we use the `--bin` option. We’ll
|
||||
look at the `#[]` and `mod tests` syntax in the “Using `super` to Access a
|
||||
Parent Module” section later in this chapter, but for now, leave this code at
|
||||
the bottom of *src/lib.rs*.
|
||||
|
||||
Because we don’t have a *src/main.rs* file, there’s nothing for Cargo to
|
||||
execute with the `cargo run` command. Therefore, we’ll use the `cargo build`
|
||||
|
||||
@@ -146,6 +146,7 @@ pub mod network;
|
||||
mod tests {
|
||||
#[test]
|
||||
fn it_works() {
|
||||
assert_eq!(2 + 2, 4);
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
@@ -120,6 +120,7 @@ Give the `it_works` function a different name, such as `exploration`, like so:
|
||||
mod tests {
|
||||
#[test]
|
||||
fn exploration() {
|
||||
assert_eq!(2 + 2, 4);
|
||||
}
|
||||
}
|
||||
```
|
||||
@@ -148,6 +149,7 @@ like Listing 11-3:
|
||||
mod tests {
|
||||
#[test]
|
||||
fn exploration() {
|
||||
assert_eq!(2 + 2, 4);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -253,7 +253,7 @@ time consuming tests with the `ignore` attribute to exclude them:
|
||||
```rust
|
||||
#[test]
|
||||
fn it_works() {
|
||||
assert!(true);
|
||||
assert_eq!(2 + 2, 4);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
Reference in New Issue
Block a user