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

UI test cleanup: Extract ifs_same_cond tests #3612

Merged
merged 1 commit into from Jan 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
44 changes: 0 additions & 44 deletions tests/ui/copies.rs
Expand Up @@ -348,50 +348,6 @@ fn if_same_then_else() -> Result<&'static str, ()> {
}
}

#[warn(clippy::ifs_same_cond)]
#[allow(clippy::if_same_then_else)] // all empty blocks
fn ifs_same_cond() {
let a = 0;
let b = false;

if b {
} else if b {
//~ ERROR ifs same condition
}

if a == 1 {
} else if a == 1 {
//~ ERROR ifs same condition
}

if 2 * a == 1 {
} else if 2 * a == 2 {
} else if 2 * a == 1 {
//~ ERROR ifs same condition
} else if a == 1 {
}

// See #659
if cfg!(feature = "feature1-659") {
1
} else if cfg!(feature = "feature2-659") {
2
} else {
3
};

let mut v = vec![1];
if v.pop() == None {
// ok, functions
} else if v.pop() == None {
}

if v.len() == 42 {
// ok, functions
} else if v.len() == 42 {
}
}

fn main() {}

// Issue #2423. This was causing an ICE
Expand Down
39 changes: 1 addition & 38 deletions tests/ui/copies.stderr
Expand Up @@ -351,42 +351,5 @@ LL | | try!(Ok("foo"));
LL | | } else {
| |_____^

error: this `if` has the same condition as a previous if
--> $DIR/copies.rs:358:15
|
LL | } else if b {
| ^
|
= note: `-D clippy::ifs-same-cond` implied by `-D warnings`
note: same as this
--> $DIR/copies.rs:357:8
|
LL | if b {
| ^

error: this `if` has the same condition as a previous if
--> $DIR/copies.rs:363:15
|
LL | } else if a == 1 {
| ^^^^^^
|
note: same as this
--> $DIR/copies.rs:362:8
|
LL | if a == 1 {
| ^^^^^^

error: this `if` has the same condition as a previous if
--> $DIR/copies.rs:369:15
|
LL | } else if 2 * a == 1 {
| ^^^^^^^^^^
|
note: same as this
--> $DIR/copies.rs:367:8
|
LL | if 2 * a == 1 {
| ^^^^^^^^^^

error: aborting due to 20 previous errors
error: aborting due to 17 previous errors

46 changes: 46 additions & 0 deletions tests/ui/ifs_same_cond.rs
@@ -0,0 +1,46 @@
#![warn(clippy::ifs_same_cond)]
#![allow(clippy::if_same_then_else)] // all empty blocks

fn ifs_same_cond() {
let a = 0;
let b = false;

if b {
} else if b {
//~ ERROR ifs same condition
}

if a == 1 {
} else if a == 1 {
//~ ERROR ifs same condition
}

if 2 * a == 1 {
} else if 2 * a == 2 {
} else if 2 * a == 1 {
//~ ERROR ifs same condition
} else if a == 1 {
}

// See #659
if cfg!(feature = "feature1-659") {
1
} else if cfg!(feature = "feature2-659") {
2
} else {
3
};

let mut v = vec![1];
if v.pop() == None {
// ok, functions
} else if v.pop() == None {
}

if v.len() == 42 {
// ok, functions
} else if v.len() == 42 {
}
}

fn main() {}
39 changes: 39 additions & 0 deletions tests/ui/ifs_same_cond.stderr
@@ -0,0 +1,39 @@
error: this `if` has the same condition as a previous if
--> $DIR/ifs_same_cond.rs:9:15
|
LL | } else if b {
| ^
|
= note: `-D clippy::ifs-same-cond` implied by `-D warnings`
note: same as this
--> $DIR/ifs_same_cond.rs:8:8
|
LL | if b {
| ^

error: this `if` has the same condition as a previous if
--> $DIR/ifs_same_cond.rs:14:15
|
LL | } else if a == 1 {
| ^^^^^^
|
note: same as this
--> $DIR/ifs_same_cond.rs:13:8
|
LL | if a == 1 {
| ^^^^^^

error: this `if` has the same condition as a previous if
--> $DIR/ifs_same_cond.rs:20:15
|
LL | } else if 2 * a == 1 {
| ^^^^^^^^^^
|
note: same as this
--> $DIR/ifs_same_cond.rs:18:8
|
LL | if 2 * a == 1 {
| ^^^^^^^^^^

error: aborting due to 3 previous errors