Skip to content

Commit 2d07c6f

Browse files
author
chansuke
committed
WIP: Add testing
1 parent 92bcf91 commit 2d07c6f

File tree

2 files changed

+22
-6
lines changed

2 files changed

+22
-6
lines changed

tests/ui/unwrap.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// compile-flags: --test
2+
13
#![warn(clippy::unwrap_used)]
24

35
fn unwrap_option() {
@@ -10,7 +12,13 @@ fn unwrap_result() {
1012
let _ = res.unwrap();
1113
}
1214

13-
fn main() {
14-
unwrap_option();
15-
unwrap_result();
15+
#[cfg(test)]
16+
mod test {
17+
#[test]
18+
fn test_flag() {
19+
let opt = Some(0);
20+
let _ = opt.unwrap();
21+
}
1622
}
23+
24+
fn main() {}

tests/ui/unwrap.stderr

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: used `unwrap()` on `an Option` value
2-
--> $DIR/unwrap.rs:5:13
2+
--> $DIR/unwrap.rs:7:13
33
|
44
LL | let _ = opt.unwrap();
55
| ^^^^^^^^^^^^
@@ -8,12 +8,20 @@ LL | let _ = opt.unwrap();
88
= help: if you don't want to handle the `None` case gracefully, consider using `expect()` to provide a better panic message
99

1010
error: used `unwrap()` on `a Result` value
11-
--> $DIR/unwrap.rs:10:13
11+
--> $DIR/unwrap.rs:12:13
1212
|
1313
LL | let _ = res.unwrap();
1414
| ^^^^^^^^^^^^
1515
|
1616
= help: if you don't want to handle the `Err` case gracefully, consider using `expect()` to provide a better panic message
1717

18-
error: aborting due to 2 previous errors
18+
error: used `unwrap()` on `an Option` value
19+
--> $DIR/unwrap.rs:20:17
20+
|
21+
LL | let _ = opt.unwrap();
22+
| ^^^^^^^^^^^^
23+
|
24+
= help: if you don't want to handle the `None` case gracefully, consider using `expect()` to provide a better panic message
25+
26+
error: aborting due to 3 previous errors
1927

0 commit comments

Comments
 (0)