rust/tests/run-coverage/try_error_result.coverage

126 lines
4.6 KiB
Plaintext
Raw Normal View History

LL| |#![allow(unused_assignments)]
LL| |// failure-status: 1
LL| |
LL| 6|fn call(return_error: bool) -> Result<(),()> {
LL| 6| if return_error {
LL| 1| Err(())
LL| | } else {
LL| 5| Ok(())
LL| | }
LL| 6|}
LL| |
LL| 1|fn test1() -> Result<(),()> {
LL| 1| let mut
LL| 1| countdown = 10
LL| | ;
LL| | for
LL| | _
LL| | in
LL| 6| 0..10
LL| | {
LL| 6| countdown
LL| 6| -= 1
LL| 6| ;
LL| 6| if
LL| 6| countdown < 5
LL| | {
LL| 1| call(/*return_error=*/ true)?;
LL| 0| call(/*return_error=*/ false)?;
LL| | }
LL| | else
LL| | {
LL| 5| call(/*return_error=*/ false)?;
^0
LL| | }
LL| | }
LL| 0| Ok(())
LL| 1|}
LL| |
LL| |struct Thing1;
LL| |impl Thing1 {
LL| 18| fn get_thing_2(&self, return_error: bool) -> Result<Thing2,()> {
LL| 18| if return_error {
LL| 1| Err(())
LL| | } else {
LL| 17| Ok(Thing2{})
LL| | }
LL| 18| }
LL| |}
LL| |
LL| |struct Thing2;
LL| |impl Thing2 {
LL| 17| fn call(&self, return_error: bool) -> Result<u32,()> {
LL| 17| if return_error {
LL| 2| Err(())
LL| | } else {
LL| 15| Ok(57)
LL| | }
LL| 17| }
LL| |}
LL| |
LL| 1|fn test2() -> Result<(),()> {
LL| 1| let thing1 = Thing1{};
LL| 1| let mut
LL| 1| countdown = 10
LL| | ;
LL| | for
LL| | _
LL| | in
LL| 6| 0..10
LL| | {
LL| 6| countdown
LL| 6| -= 1
LL| 6| ;
LL| 6| if
LL| 6| countdown < 5
LL| | {
LL| 1| thing1.get_thing_2(/*err=*/ false)?.call(/*err=*/ true).expect_err("call should fail");
^0
LL| 1| thing1
LL| 1| .
LL| 1| get_thing_2(/*return_error=*/ false)
LL| 0| ?
LL| | .
LL| 1| call(/*return_error=*/ true)
LL| 1| .
LL| 1| expect_err(
LL| 1| "call should fail"
LL| 1| );
LL| 1| let val = thing1.get_thing_2(/*return_error=*/ true)?.call(/*return_error=*/ true)?;
^0 ^0 ^0
LL| 0| assert_eq!(val, 57);
LL| 0| let val = thing1.get_thing_2(/*return_error=*/ true)?.call(/*return_error=*/ false)?;
LL| 0| assert_eq!(val, 57);
LL| | }
LL| | else
LL| | {
LL| 5| let val = thing1.get_thing_2(/*return_error=*/ false)?.call(/*return_error=*/ false)?;
^0 ^0
LL| 5| assert_eq!(val, 57);
LL| 5| let val = thing1
LL| 5| .get_thing_2(/*return_error=*/ false)?
^0
LL| 5| .call(/*return_error=*/ false)?;
^0
LL| 5| assert_eq!(val, 57);
LL| 5| let val = thing1
LL| 5| .get_thing_2(/*return_error=*/ false)
LL| 0| ?
LL| 5| .call(/*return_error=*/ false)
LL| 0| ?
LL| | ;
LL| 5| assert_eq!(val, 57);
LL| | }
LL| | }
LL| 0| Ok(())
LL| 1|}
LL| |
LL| 1|fn main() -> Result<(),()> {
LL| 1| test1().expect_err("test1 should fail");
LL| 1| test2()
LL| 1| ?
LL| | ;
LL| 0| Ok(())
LL| 1|}
Updates to experimental coverage counter injection This is a combination of 18 commits. Commit #2: Additional examples and some small improvements. Commit #3: fixed mir-opt non-mir extensions and spanview title elements Corrected a fairly recent assumption in runtest.rs that all MIR dump files end in .mir. (It was appending .mir to the graphviz .dot and spanview .html file names when generating blessed output files. That also left outdated files in the baseline alongside the files with the incorrect names, which I've now removed.) Updated spanview HTML title elements to match their content, replacing a hardcoded and incorrect name that was left in accidentally when originally submitted. Commit #4: added more test examples also improved Makefiles with support for non-zero exit status and to force validation of tests unless a specific test overrides it with a specific comment. Commit #5: Fixed rare issues after testing on real-world crate Commit #6: Addressed PR feedback, and removed temporary -Zexperimental-coverage -Zinstrument-coverage once again supports the latest capabilities of LLVM instrprof coverage instrumentation. Also fixed a bug in spanview. Commit #7: Fix closure handling, add tests for closures and inner items And cleaned up other tests for consistency, and to make it more clear where spans start/end by breaking up lines. Commit #8: renamed "typical" test results "expected" Now that the `llvm-cov show` tests are improved to normally expect matching actuals, and to allow individual tests to override that expectation. Commit #9: test coverage of inline generic struct function Commit #10: Addressed review feedback * Removed unnecessary Unreachable filter. * Replaced a match wildcard with remining variants. * Added more comments to help clarify the role of successors() in the CFG traversal Commit #11: refactoring based on feedback * refactored `fn coverage_spans()`. * changed the way I expand an empty coverage span to improve performance * fixed a typo that I had accidently left in, in visit.rs Commit #12: Optimized use of SourceMap and SourceFile Commit #13: Fixed a regression, and synched with upstream Some generated test file names changed due to some new change upstream. Commit #14: Stripping out crate disambiguators from demangled names These can vary depending on the test platform. Commit #15: Ignore llvm-cov show diff on test with generics, expand IO error message Tests with generics produce llvm-cov show results with demangled names that can include an unstable "crate disambiguator" (hex value). The value changes when run in the Rust CI Windows environment. I added a sed filter to strip them out (in a prior commit), but sed also appears to fail in the same environment. Until I can figure out a workaround, I'm just going to ignore this specific test result. I added a FIXME to follow up later, but it's not that critical. I also saw an error with Windows GNU, but the IO error did not specify a path for the directory or file that triggered the error. I updated the error messages to provide more info for next, time but also noticed some other tests with similar steps did not fail. Looks spurious. Commit #16: Modify rust-demangler to strip disambiguators by default Commit #17: Remove std::process::exit from coverage tests Due to Issue #77553, programs that call std::process::exit() do not generate coverage results on Windows MSVC. Commit #18: fix: test file paths exceeding Windows max path len
2020-09-01 18:15:17 -05:00