Skip to content

[rust template] Add cfg(test) attribute to mod test #1342

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

Merged
merged 1 commit into from
Aug 2, 2023
Merged

Conversation

savil
Copy link
Collaborator

@savil savil commented Aug 2, 2023

Got this error:

cargo run . 
   Compiling rust-stable-hello-world v0.1.0 (/home/savil/repo/rust)
warning: unused import: `super::*`
  --> src/main.rs:10:7
   |
10 |   use super::*;
   |       ^^^^^^^^
   |
help: consider adding a `#[cfg(test)]` to the containing module
  --> src/main.rs:9:1
   |
9  | mod tests {
   | ^^^^^^^^^
   = note: `#[warn(unused_imports)]` on by default

Afterwards:

❯ cargo test 
   Compiling rust-stable-hello-world v0.1.0 (/home/savil/repo/rust)
    Finished test [unoptimized + debuginfo] target(s) in 0.25s
     Running unittests src/main.rs (target/debug/deps/rust_stable_hello_world-5499c8f65b21de0b)

running 1 test
test tests::test_hello_world ... ok

test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s


~/repo/rust is 📦 v0.1.0 via 🦀 v1.71.0 via ❄️  impure (nix-shell-env) 
❯ cargo run 
   Compiling rust-stable-hello-world v0.1.0 (/home/savil/repo/rust)
    Finished dev [unoptimized + debuginfo] target(s) in 0.15s
     Running `target/debug/rust-stable-hello-world`
Hello, world!

Summary

How was it tested?

Got this error:
```
cargo run . 
   Compiling rust-stable-hello-world v0.1.0 (/home/savil/repo/rust)
warning: unused import: `super::*`
  --> src/main.rs:10:7
   |
10 |   use super::*;
   |       ^^^^^^^^
   |
help: consider adding a `#[cfg(test)]` to the containing module
  --> src/main.rs:9:1
   |
9  | mod tests {
   | ^^^^^^^^^
   = note: `#[warn(unused_imports)]` on by default
```

Afterwards:
```
❯ cargo test 
   Compiling rust-stable-hello-world v0.1.0 (/home/savil/repo/rust)
    Finished test [unoptimized + debuginfo] target(s) in 0.25s
     Running unittests src/main.rs (target/debug/deps/rust_stable_hello_world-5499c8f65b21de0b)

running 1 test
test tests::test_hello_world ... ok

test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s


~/repo/rust is 📦 v0.1.0 via 🦀 v1.71.0 via ❄️  impure (nix-shell-env) 
❯ cargo run 
   Compiling rust-stable-hello-world v0.1.0 (/home/savil/repo/rust)
    Finished dev [unoptimized + debuginfo] target(s) in 0.15s
     Running `target/debug/rust-stable-hello-world`
Hello, world!
```

Signed-off-by: savil <[email protected]>
@savil savil requested a review from LucilleH August 2, 2023 18:21
Copy link
Collaborator

@LucilleH LucilleH left a comment

Choose a reason for hiding this comment

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

k

@savil savil merged commit af25096 into main Aug 2, 2023
@savil savil deleted the savil-patch-1 branch August 2, 2023 21:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants