rust/tests/coverage-map/status-quo/while_early_ret.rs
Zalathar 3141177995 Copy most of tests/run-coverage into tests/coverage-map/status-quo
The output of these tests is too complicated to comfortably verify by hand, but
we can still use them to observe changes to the underlying mappings produced by
codegen/LLVM.

If these tests fail due to non-coverage changes (e.g. in HIR-to-MIR lowering or
MIR optimizations), it should usually be OK to just `--bless` them, as long as
the `run-coverage` test suite still works.
2023-09-05 11:55:34 +10:00

43 lines
1.1 KiB
Rust

#![allow(unused_assignments)]
// failure-status: 1
fn main() -> Result<(), u8> {
let mut countdown = 10;
while
countdown
>
0
{
if
countdown
<
5
{
return
if
countdown
>
8
{
Ok(())
}
else
{
Err(1)
}
;
}
countdown
-=
1
;
}
Ok(())
}
// ISSUE(77553): Originally, this test had `Err(1)` on line 22 (instead of `Ok(())`) and
// `std::process::exit(2)` on line 26 (instead of `Err(1)`); and this worked as expected on Linux
// and MacOS. But on Windows (MSVC, at least), the call to `std::process::exit()` exits the program
// without saving the InstrProf coverage counters. The use of `std::process:exit()` is not critical
// to the coverage test for early returns, but this is a limitation that should be fixed.