Skip to content

Commit

Permalink
Rollup merge of rust-lang#114924 - Zalathar:tidy-tests, r=Mark-Simula…
Browse files Browse the repository at this point in the history
…crum

coverage: Tidy up `run-coverage` tests in several small ways

Prior to rust-lang#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.
  • Loading branch information
matthiaskrgr authored Aug 27, 2023
2 parents e877e2a + 8d91e71 commit be416b9
Show file tree
Hide file tree
Showing 45 changed files with 100 additions and 122 deletions.
4 changes: 3 additions & 1 deletion tests/run-coverage-rustdoc/doctest.coverage
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ $DIR/auxiliary/doctest_crate.rs:
LL| 3|}

$DIR/doctest.rs:
LL| |// aux-build:doctest_crate.rs
LL| |
LL| |//! This test ensures that code from doctests is properly re-mapped.
LL| |//! See <https://github.com/rust-lang/rust/issues/79417> for more info.
LL| |//!
Expand Down Expand Up @@ -78,7 +80,7 @@ $DIR/doctest.rs:
LL| |//! doctest_main()
LL| |//! }
LL| |//! ```
LL| |// aux-build:doctest_crate.rs
LL| |
LL| |/// doctest attached to fn testing external code:
LL| |/// ```
LL| 1|/// extern crate doctest_crate;
Expand Down
4 changes: 3 additions & 1 deletion tests/run-coverage-rustdoc/doctest.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// aux-build:doctest_crate.rs

//! This test ensures that code from doctests is properly re-mapped.
//! See <https://github.com/rust-lang/rust/issues/79417> for more info.
//!
Expand Down Expand Up @@ -63,7 +65,7 @@
//! doctest_main()
//! }
//! ```
// aux-build:doctest_crate.rs

/// doctest attached to fn testing external code:
/// ```
/// extern crate doctest_crate;
Expand Down
2 changes: 1 addition & 1 deletion tests/run-coverage/assert.coverage
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
^1
LL| 3|}
LL| |
LL| 1|fn main() -> Result<(),u8> {
LL| 1|fn main() -> Result<(), u8> {
LL| 1| let mut countdown = 10;
LL| 11| while countdown > 0 {
LL| 11| if countdown == 1 {
Expand Down
2 changes: 1 addition & 1 deletion tests/run-coverage/assert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ fn might_fail_assert(one_plus_one: u32) {
assert_eq!(1 + 1, one_plus_one, "the argument was wrong");
}

fn main() -> Result<(),u8> {
fn main() -> Result<(), u8> {
let mut countdown = 10;
while countdown > 0 {
if countdown == 1 {
Expand Down
12 changes: 0 additions & 12 deletions tests/run-coverage/async2.coverage
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
LL| |// compile-flags: --edition=2018
LL| |
LL| |use core::{
LL| | future::Future,
LL| | marker::Send,
LL| | pin::Pin,
LL| |};
LL| |
LL| 1|fn non_async_func() {
LL| 1| println!("non_async_func was covered");
LL| 1| let b = true;
Expand All @@ -15,9 +9,6 @@
^0
LL| 1|}
LL| |
LL| |
LL| |
LL| |
LL| 1|async fn async_func() {
LL| 1| println!("async_func was covered");
LL| 1| let b = true;
Expand All @@ -27,9 +18,6 @@
^0
LL| 1|}
LL| |
LL| |
LL| |
LL| |
LL| 1|async fn async_func_just_println() {
LL| 1| println!("async_func_just_println was covered");
LL| 1|}
Expand Down
12 changes: 0 additions & 12 deletions tests/run-coverage/async2.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
// compile-flags: --edition=2018

use core::{
future::Future,
marker::Send,
pin::Pin,
};

fn non_async_func() {
println!("non_async_func was covered");
let b = true;
Expand All @@ -14,9 +8,6 @@ fn non_async_func() {
}
}




async fn async_func() {
println!("async_func was covered");
let b = true;
Expand All @@ -25,9 +16,6 @@ async fn async_func() {
}
}




async fn async_func_just_println() {
println!("async_func_just_println was covered");
}
Expand Down
4 changes: 2 additions & 2 deletions tests/run-coverage/auxiliary/inline_always_with_dead_code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

mod foo {
#[inline(always)]
pub fn called() { }
pub fn called() {}

fn uncalled() { }
fn uncalled() {}
}

pub mod bar {
Expand Down
1 change: 1 addition & 0 deletions tests/run-coverage/auxiliary/unused_mod_helper.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#[allow(dead_code)]
pub fn never_called_function() {
println!("I am never called");
}
5 changes: 4 additions & 1 deletion tests/run-coverage/auxiliary/used_crate.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#![allow(unused_assignments, unused_variables)]
// Verify that coverage works with optimizations:
// compile-flags: -C opt-level=3
use std::fmt::Debug; // ^^ validates coverage now works with optimizations

use std::fmt::Debug;

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

#[allow(dead_code)]
fn unused_private_function() {
let is_true = std::env::args().len() == 1;
let mut countdown = 2;
Expand Down
11 changes: 3 additions & 8 deletions tests/run-coverage/auxiliary/used_inline_crate.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#![allow(unused_assignments, unused_variables)]

// Verify that coverage works with optimizations:
// compile-flags: -C opt-level=3
// ^^ validates coverage now works with optimizations

use std::fmt::Debug;

pub fn used_function() {
Expand Down Expand Up @@ -29,12 +29,6 @@ pub fn used_inline_function() {
use_this_lib_crate();
}







#[inline(always)]
pub fn used_only_from_bin_crate_generic_function<T: Debug>(arg: T) {
println!("used_only_from_bin_crate_generic_function with {:?}", arg);
Expand Down Expand Up @@ -71,6 +65,7 @@ pub fn unused_function() {
}

#[inline(always)]
#[allow(dead_code)]
fn unused_private_function() {
let is_true = std::env::args().len() == 1;
let mut countdown = 2;
Expand Down
9 changes: 7 additions & 2 deletions tests/run-coverage/closure.coverage
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
LL| |#![allow(unused_assignments, unused_variables)]
LL| |// compile-flags: -C opt-level=2
LL| 1|fn main() { // ^^ fix described in rustc_middle/mir/mono.rs
LL| |
LL| |// This test used to be sensitive to certain coverage-specific hacks in
LL| |// `rustc_middle/mir/mono.rs`, but those hacks were later cleaned up by
LL| |// <https://github.com/rust-lang/rust/pull/83666>.
LL| |
LL| 1|fn main() {
LL| 1| // Initialize test constants in a way that cannot be determined at compile time, to ensure
LL| 1| // rustc and LLVM cannot optimize out statements (or coverage counters) downstream from
LL| 1| // dependent conditions.
LL| 1| let is_true = std::env::args().len() == 1;
LL| 1| let is_false = ! is_true;
LL| 1| let is_false = !is_true;
LL| 1|
LL| 1| let mut some_string = Some(String::from("the string content"));
LL| 1| println!(
Expand Down
9 changes: 7 additions & 2 deletions tests/run-coverage/closure.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
#![allow(unused_assignments, unused_variables)]
// compile-flags: -C opt-level=2
fn main() { // ^^ fix described in rustc_middle/mir/mono.rs

// This test used to be sensitive to certain coverage-specific hacks in
// `rustc_middle/mir/mono.rs`, but those hacks were later cleaned up by
// <https://github.com/rust-lang/rust/pull/83666>.

fn main() {
// Initialize test constants in a way that cannot be determined at compile time, to ensure
// rustc and LLVM cannot optimize out statements (or coverage counters) downstream from
// dependent conditions.
let is_true = std::env::args().len() == 1;
let is_false = ! is_true;
let is_false = !is_true;

let mut some_string = Some(String::from("the string content"));
println!(
Expand Down
6 changes: 1 addition & 5 deletions tests/run-coverage/closure_macro_async.coverage
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
LL| |
LL| |#[no_coverage]
LL| |fn main() {
LL| | executor::block_on(test());
LL| | executor::block_on(test()).unwrap();
LL| |}
LL| |
LL| |mod executor {
Expand All @@ -57,16 +57,12 @@
LL| | let mut future = unsafe { Pin::new_unchecked(&mut future) };
LL| | use std::hint::unreachable_unchecked;
LL| | static VTABLE: RawWakerVTable = RawWakerVTable::new(
LL| |
LL| | #[no_coverage]
LL| | |_| unsafe { unreachable_unchecked() }, // clone
LL| |
LL| | #[no_coverage]
LL| | |_| unsafe { unreachable_unchecked() }, // wake
LL| |
LL| | #[no_coverage]
LL| | |_| unsafe { unreachable_unchecked() }, // wake_by_ref
LL| |
LL| | #[no_coverage]
LL| | |_| (),
LL| | );
Expand Down
6 changes: 1 addition & 5 deletions tests/run-coverage/closure_macro_async.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ pub async fn test() -> Result<(), String> {

#[no_coverage]
fn main() {
executor::block_on(test());
executor::block_on(test()).unwrap();
}

mod executor {
Expand All @@ -56,16 +56,12 @@ mod executor {
let mut future = unsafe { Pin::new_unchecked(&mut future) };
use std::hint::unreachable_unchecked;
static VTABLE: RawWakerVTable = RawWakerVTable::new(

#[no_coverage]
|_| unsafe { unreachable_unchecked() }, // clone

#[no_coverage]
|_| unsafe { unreachable_unchecked() }, // wake

#[no_coverage]
|_| unsafe { unreachable_unchecked() }, // wake_by_ref

#[no_coverage]
|_| (),
);
Expand Down
1 change: 0 additions & 1 deletion tests/run-coverage/conditions.coverage
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@
LL| | }
LL| 0| }
LL| |
LL| |
LL| 1| let mut countdown = 0;
LL| 1| if true {
LL| 1| countdown = 1;
Expand Down
1 change: 0 additions & 1 deletion tests/run-coverage/conditions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ fn main() {
}
}


let mut countdown = 0;
if true {
countdown = 1;
Expand Down
2 changes: 1 addition & 1 deletion tests/run-coverage/dead_code.coverage
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
LL| |#![allow(unused_assignments, unused_variables)]
LL| |#![allow(dead_code, unused_assignments, unused_variables)]
LL| |
LL| 0|pub fn unused_pub_fn_not_in_library() {
LL| 0| // Initialize test constants in a way that cannot be determined at compile time, to ensure
Expand Down
2 changes: 1 addition & 1 deletion tests/run-coverage/dead_code.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![allow(unused_assignments, unused_variables)]
#![allow(dead_code, unused_assignments, unused_variables)]

pub fn unused_pub_fn_not_in_library() {
// Initialize test constants in a way that cannot be determined at compile time, to ensure
Expand Down
2 changes: 1 addition & 1 deletion tests/run-coverage/drop_trait.coverage
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
LL| 2| }
LL| |}
LL| |
LL| 1|fn main() -> Result<(),u8> {
LL| 1|fn main() -> Result<(), u8> {
LL| 1| let _firecracker = Firework { strength: 1 };
LL| 1|
LL| 1| let _tnt = Firework { strength: 100 };
Expand Down
2 changes: 1 addition & 1 deletion tests/run-coverage/drop_trait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ impl Drop for Firework {
}
}

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

let _tnt = Firework { strength: 100 };
Expand Down
6 changes: 1 addition & 5 deletions tests/run-coverage/generics.coverage
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
------------------
LL| |}
LL| |
LL| 1|fn main() -> Result<(),u8> {
LL| 1|fn main() -> Result<(), u8> {
LL| 1| let mut firecracker = Firework { strength: 1 };
LL| 1| firecracker.set_strength(2);
LL| 1|
Expand All @@ -54,10 +54,6 @@
LL| 1| return Err(1);
LL| 0| }
LL| 0|
LL| 0|
LL| 0|
LL| 0|
LL| 0|
LL| 0| let _ = Firework { strength: 1000 };
LL| 0|
LL| 0| Ok(())
Expand Down
6 changes: 1 addition & 5 deletions tests/run-coverage/generics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ impl<T> Drop for Firework<T> where T: Copy + std::fmt::Display {
}
}

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

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





let _ = Firework { strength: 1000 };

Ok(())
Expand Down
5 changes: 3 additions & 2 deletions tests/run-coverage/issue-85461.coverage
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ $DIR/auxiliary/inline_always_with_dead_code.rs:
LL| |
LL| |mod foo {
LL| | #[inline(always)]
LL| 2| pub fn called() { }
LL| 2| pub fn called() {}
LL| |
LL| 0| fn uncalled() { }
LL| 0| fn uncalled() {}
LL| |}
LL| |
LL| |pub mod bar {
Expand All @@ -24,6 +24,7 @@ $DIR/auxiliary/inline_always_with_dead_code.rs:

$DIR/issue-85461.rs:
LL| |// Regression test for #85461: MSVC sometimes fail to link with dead code and #[inline(always)]
LL| |
LL| |// aux-build:inline_always_with_dead_code.rs
LL| |extern crate inline_always_with_dead_code;
LL| |
Expand Down
1 change: 1 addition & 0 deletions tests/run-coverage/issue-85461.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Regression test for #85461: MSVC sometimes fail to link with dead code and #[inline(always)]

// aux-build:inline_always_with_dead_code.rs
extern crate inline_always_with_dead_code;

Expand Down
Loading

0 comments on commit be416b9

Please sign in to comment.