Skip to content

Commit be416b9

Browse files
authored
Rollup merge of #114924 - Zalathar:tidy-tests, r=Mark-Simulacrum
coverage: Tidy up `run-coverage` tests in several small ways Prior to #114875 (anonymized line numbers), these tests were very sensitive to lines being added/removed, since doing so would change the line numbers in every subsequent line of output. Therefore they ended up with a few small style issues that weren't worth the hassle of fixing. Now that we can freely rearrange lines without needing to re-bless the entire output, we can tidy up the tests in various trivial ways.
2 parents e877e2a + 8d91e71 commit be416b9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+100
-122
lines changed

tests/run-coverage-rustdoc/doctest.coverage

+3-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ $DIR/auxiliary/doctest_crate.rs:
1010
LL| 3|}
1111

1212
$DIR/doctest.rs:
13+
LL| |// aux-build:doctest_crate.rs
14+
LL| |
1315
LL| |//! This test ensures that code from doctests is properly re-mapped.
1416
LL| |//! See <https://github.com/rust-lang/rust/issues/79417> for more info.
1517
LL| |//!
@@ -78,7 +80,7 @@ $DIR/doctest.rs:
7880
LL| |//! doctest_main()
7981
LL| |//! }
8082
LL| |//! ```
81-
LL| |// aux-build:doctest_crate.rs
83+
LL| |
8284
LL| |/// doctest attached to fn testing external code:
8385
LL| |/// ```
8486
LL| 1|/// extern crate doctest_crate;

tests/run-coverage-rustdoc/doctest.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// aux-build:doctest_crate.rs
2+
13
//! This test ensures that code from doctests is properly re-mapped.
24
//! See <https://github.com/rust-lang/rust/issues/79417> for more info.
35
//!
@@ -63,7 +65,7 @@
6365
//! doctest_main()
6466
//! }
6567
//! ```
66-
// aux-build:doctest_crate.rs
68+
6769
/// doctest attached to fn testing external code:
6870
/// ```
6971
/// extern crate doctest_crate;

tests/run-coverage/assert.coverage

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
^1
88
LL| 3|}
99
LL| |
10-
LL| 1|fn main() -> Result<(),u8> {
10+
LL| 1|fn main() -> Result<(), u8> {
1111
LL| 1| let mut countdown = 10;
1212
LL| 11| while countdown > 0 {
1313
LL| 11| if countdown == 1 {

tests/run-coverage/assert.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ fn might_fail_assert(one_plus_one: u32) {
66
assert_eq!(1 + 1, one_plus_one, "the argument was wrong");
77
}
88

9-
fn main() -> Result<(),u8> {
9+
fn main() -> Result<(), u8> {
1010
let mut countdown = 10;
1111
while countdown > 0 {
1212
if countdown == 1 {

tests/run-coverage/async2.coverage

-12
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
11
LL| |// compile-flags: --edition=2018
22
LL| |
3-
LL| |use core::{
4-
LL| | future::Future,
5-
LL| | marker::Send,
6-
LL| | pin::Pin,
7-
LL| |};
8-
LL| |
93
LL| 1|fn non_async_func() {
104
LL| 1| println!("non_async_func was covered");
115
LL| 1| let b = true;
@@ -15,9 +9,6 @@
159
^0
1610
LL| 1|}
1711
LL| |
18-
LL| |
19-
LL| |
20-
LL| |
2112
LL| 1|async fn async_func() {
2213
LL| 1| println!("async_func was covered");
2314
LL| 1| let b = true;
@@ -27,9 +18,6 @@
2718
^0
2819
LL| 1|}
2920
LL| |
30-
LL| |
31-
LL| |
32-
LL| |
3321
LL| 1|async fn async_func_just_println() {
3422
LL| 1| println!("async_func_just_println was covered");
3523
LL| 1|}

tests/run-coverage/async2.rs

-12
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
11
// compile-flags: --edition=2018
22

3-
use core::{
4-
future::Future,
5-
marker::Send,
6-
pin::Pin,
7-
};
8-
93
fn non_async_func() {
104
println!("non_async_func was covered");
115
let b = true;
@@ -14,9 +8,6 @@ fn non_async_func() {
148
}
159
}
1610

17-
18-
19-
2011
async fn async_func() {
2112
println!("async_func was covered");
2213
let b = true;
@@ -25,9 +16,6 @@ async fn async_func() {
2516
}
2617
}
2718

28-
29-
30-
3119
async fn async_func_just_println() {
3220
println!("async_func_just_println was covered");
3321
}

tests/run-coverage/auxiliary/inline_always_with_dead_code.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44

55
mod foo {
66
#[inline(always)]
7-
pub fn called() { }
7+
pub fn called() {}
88

9-
fn uncalled() { }
9+
fn uncalled() {}
1010
}
1111

1212
pub mod bar {
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#[allow(dead_code)]
12
pub fn never_called_function() {
23
println!("I am never called");
34
}

tests/run-coverage/auxiliary/used_crate.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#![allow(unused_assignments, unused_variables)]
2+
// Verify that coverage works with optimizations:
23
// compile-flags: -C opt-level=3
3-
use std::fmt::Debug; // ^^ validates coverage now works with optimizations
4+
5+
use std::fmt::Debug;
46

57
pub fn used_function() {
68
// Initialize test constants in a way that cannot be determined at compile time, to ensure
@@ -42,6 +44,7 @@ pub fn unused_function() {
4244
}
4345
}
4446

47+
#[allow(dead_code)]
4548
fn unused_private_function() {
4649
let is_true = std::env::args().len() == 1;
4750
let mut countdown = 2;

tests/run-coverage/auxiliary/used_inline_crate.rs

+3-8
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#![allow(unused_assignments, unused_variables)]
2-
2+
// Verify that coverage works with optimizations:
33
// compile-flags: -C opt-level=3
4-
// ^^ validates coverage now works with optimizations
4+
55
use std::fmt::Debug;
66

77
pub fn used_function() {
@@ -29,12 +29,6 @@ pub fn used_inline_function() {
2929
use_this_lib_crate();
3030
}
3131

32-
33-
34-
35-
36-
37-
3832
#[inline(always)]
3933
pub fn used_only_from_bin_crate_generic_function<T: Debug>(arg: T) {
4034
println!("used_only_from_bin_crate_generic_function with {:?}", arg);
@@ -71,6 +65,7 @@ pub fn unused_function() {
7165
}
7266

7367
#[inline(always)]
68+
#[allow(dead_code)]
7469
fn unused_private_function() {
7570
let is_true = std::env::args().len() == 1;
7671
let mut countdown = 2;

tests/run-coverage/closure.coverage

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
LL| |#![allow(unused_assignments, unused_variables)]
22
LL| |// compile-flags: -C opt-level=2
3-
LL| 1|fn main() { // ^^ fix described in rustc_middle/mir/mono.rs
3+
LL| |
4+
LL| |// This test used to be sensitive to certain coverage-specific hacks in
5+
LL| |// `rustc_middle/mir/mono.rs`, but those hacks were later cleaned up by
6+
LL| |// <https://github.com/rust-lang/rust/pull/83666>.
7+
LL| |
8+
LL| 1|fn main() {
49
LL| 1| // Initialize test constants in a way that cannot be determined at compile time, to ensure
510
LL| 1| // rustc and LLVM cannot optimize out statements (or coverage counters) downstream from
611
LL| 1| // dependent conditions.
712
LL| 1| let is_true = std::env::args().len() == 1;
8-
LL| 1| let is_false = ! is_true;
13+
LL| 1| let is_false = !is_true;
914
LL| 1|
1015
LL| 1| let mut some_string = Some(String::from("the string content"));
1116
LL| 1| println!(

tests/run-coverage/closure.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
#![allow(unused_assignments, unused_variables)]
22
// compile-flags: -C opt-level=2
3-
fn main() { // ^^ fix described in rustc_middle/mir/mono.rs
3+
4+
// This test used to be sensitive to certain coverage-specific hacks in
5+
// `rustc_middle/mir/mono.rs`, but those hacks were later cleaned up by
6+
// <https://github.com/rust-lang/rust/pull/83666>.
7+
8+
fn main() {
49
// Initialize test constants in a way that cannot be determined at compile time, to ensure
510
// rustc and LLVM cannot optimize out statements (or coverage counters) downstream from
611
// dependent conditions.
712
let is_true = std::env::args().len() == 1;
8-
let is_false = ! is_true;
13+
let is_false = !is_true;
914

1015
let mut some_string = Some(String::from("the string content"));
1116
println!(

tests/run-coverage/closure_macro_async.coverage

+1-5
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
LL| |
4343
LL| |#[no_coverage]
4444
LL| |fn main() {
45-
LL| | executor::block_on(test());
45+
LL| | executor::block_on(test()).unwrap();
4646
LL| |}
4747
LL| |
4848
LL| |mod executor {
@@ -57,16 +57,12 @@
5757
LL| | let mut future = unsafe { Pin::new_unchecked(&mut future) };
5858
LL| | use std::hint::unreachable_unchecked;
5959
LL| | static VTABLE: RawWakerVTable = RawWakerVTable::new(
60-
LL| |
6160
LL| | #[no_coverage]
6261
LL| | |_| unsafe { unreachable_unchecked() }, // clone
63-
LL| |
6462
LL| | #[no_coverage]
6563
LL| | |_| unsafe { unreachable_unchecked() }, // wake
66-
LL| |
6764
LL| | #[no_coverage]
6865
LL| | |_| unsafe { unreachable_unchecked() }, // wake_by_ref
69-
LL| |
7066
LL| | #[no_coverage]
7167
LL| | |_| (),
7268
LL| | );

tests/run-coverage/closure_macro_async.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ pub async fn test() -> Result<(), String> {
4141

4242
#[no_coverage]
4343
fn main() {
44-
executor::block_on(test());
44+
executor::block_on(test()).unwrap();
4545
}
4646

4747
mod executor {
@@ -56,16 +56,12 @@ mod executor {
5656
let mut future = unsafe { Pin::new_unchecked(&mut future) };
5757
use std::hint::unreachable_unchecked;
5858
static VTABLE: RawWakerVTable = RawWakerVTable::new(
59-
6059
#[no_coverage]
6160
|_| unsafe { unreachable_unchecked() }, // clone
62-
6361
#[no_coverage]
6462
|_| unsafe { unreachable_unchecked() }, // wake
65-
6663
#[no_coverage]
6764
|_| unsafe { unreachable_unchecked() }, // wake_by_ref
68-
6965
#[no_coverage]
7066
|_| (),
7167
);

tests/run-coverage/conditions.coverage

-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@
5959
LL| | }
6060
LL| 0| }
6161
LL| |
62-
LL| |
6362
LL| 1| let mut countdown = 0;
6463
LL| 1| if true {
6564
LL| 1| countdown = 1;

tests/run-coverage/conditions.rs

-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ fn main() {
5555
}
5656
}
5757

58-
5958
let mut countdown = 0;
6059
if true {
6160
countdown = 1;

tests/run-coverage/dead_code.coverage

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
LL| |#![allow(unused_assignments, unused_variables)]
1+
LL| |#![allow(dead_code, unused_assignments, unused_variables)]
22
LL| |
33
LL| 0|pub fn unused_pub_fn_not_in_library() {
44
LL| 0| // Initialize test constants in a way that cannot be determined at compile time, to ensure

tests/run-coverage/dead_code.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#![allow(unused_assignments, unused_variables)]
1+
#![allow(dead_code, unused_assignments, unused_variables)]
22

33
pub fn unused_pub_fn_not_in_library() {
44
// Initialize test constants in a way that cannot be determined at compile time, to ensure

tests/run-coverage/drop_trait.coverage

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
LL| 2| }
1212
LL| |}
1313
LL| |
14-
LL| 1|fn main() -> Result<(),u8> {
14+
LL| 1|fn main() -> Result<(), u8> {
1515
LL| 1| let _firecracker = Firework { strength: 1 };
1616
LL| 1|
1717
LL| 1| let _tnt = Firework { strength: 100 };

tests/run-coverage/drop_trait.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ impl Drop for Firework {
1111
}
1212
}
1313

14-
fn main() -> Result<(),u8> {
14+
fn main() -> Result<(), u8> {
1515
let _firecracker = Firework { strength: 1 };
1616

1717
let _tnt = Firework { strength: 100 };

tests/run-coverage/generics.coverage

+1-5
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
------------------
4242
LL| |}
4343
LL| |
44-
LL| 1|fn main() -> Result<(),u8> {
44+
LL| 1|fn main() -> Result<(), u8> {
4545
LL| 1| let mut firecracker = Firework { strength: 1 };
4646
LL| 1| firecracker.set_strength(2);
4747
LL| 1|
@@ -54,10 +54,6 @@
5454
LL| 1| return Err(1);
5555
LL| 0| }
5656
LL| 0|
57-
LL| 0|
58-
LL| 0|
59-
LL| 0|
60-
LL| 0|
6157
LL| 0| let _ = Firework { strength: 1000 };
6258
LL| 0|
6359
LL| 0| Ok(())

tests/run-coverage/generics.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ impl<T> Drop for Firework<T> where T: Copy + std::fmt::Display {
1919
}
2020
}
2121

22-
fn main() -> Result<(),u8> {
22+
fn main() -> Result<(), u8> {
2323
let mut firecracker = Firework { strength: 1 };
2424
firecracker.set_strength(2);
2525

@@ -32,10 +32,6 @@ fn main() -> Result<(),u8> {
3232
return Err(1);
3333
}
3434

35-
36-
37-
38-
3935
let _ = Firework { strength: 1000 };
4036

4137
Ok(())

tests/run-coverage/issue-85461.coverage

+3-2
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ $DIR/auxiliary/inline_always_with_dead_code.rs:
55
LL| |
66
LL| |mod foo {
77
LL| | #[inline(always)]
8-
LL| 2| pub fn called() { }
8+
LL| 2| pub fn called() {}
99
LL| |
10-
LL| 0| fn uncalled() { }
10+
LL| 0| fn uncalled() {}
1111
LL| |}
1212
LL| |
1313
LL| |pub mod bar {
@@ -24,6 +24,7 @@ $DIR/auxiliary/inline_always_with_dead_code.rs:
2424

2525
$DIR/issue-85461.rs:
2626
LL| |// Regression test for #85461: MSVC sometimes fail to link with dead code and #[inline(always)]
27+
LL| |
2728
LL| |// aux-build:inline_always_with_dead_code.rs
2829
LL| |extern crate inline_always_with_dead_code;
2930
LL| |

tests/run-coverage/issue-85461.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// Regression test for #85461: MSVC sometimes fail to link with dead code and #[inline(always)]
2+
23
// aux-build:inline_always_with_dead_code.rs
34
extern crate inline_always_with_dead_code;
45

0 commit comments

Comments
 (0)