rust/tests/coverage-map/status-quo/yield.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

38 lines
933 B
Rust

#![feature(generators, generator_trait)]
#![allow(unused_assignments)]
use std::ops::{Generator, GeneratorState};
use std::pin::Pin;
fn main() {
let mut generator = || {
yield 1;
return "foo";
};
match Pin::new(&mut generator).resume(()) {
GeneratorState::Yielded(1) => {}
_ => panic!("unexpected value from resume"),
}
match Pin::new(&mut generator).resume(()) {
GeneratorState::Complete("foo") => {}
_ => panic!("unexpected value from resume"),
}
let mut generator = || {
yield 1;
yield 2;
yield 3;
return "foo";
};
match Pin::new(&mut generator).resume(()) {
GeneratorState::Yielded(1) => {}
_ => panic!("unexpected value from resume"),
}
match Pin::new(&mut generator).resume(()) {
GeneratorState::Yielded(2) => {}
_ => panic!("unexpected value from resume"),
}
}