()
| 996 | |
| 997 | #[test] |
| 998 | fn test_run_after_break_starts_from_beginning() { |
| 999 | let console = Rc::from(RefCell::from(MockConsole::default())); |
| 1000 | let program = Rc::from(RefCell::from(RecordedProgram::default())); |
| 1001 | program.borrow_mut().load(None, r#"PRINT "begin": SLEEP 0: PRINT "done""#); |
| 1002 | |
| 1003 | let (signals_tx, signals_rx) = async_channel::unbounded(); |
| 1004 | let signal_sent = Rc::from(RefCell::from(false)); |
| 1005 | let sleep_tx = signals_tx.clone(); |
| 1006 | let sleep_signal_sent = signal_sent.clone(); |
| 1007 | let datetime = Rc::from(MockDateTime::default()); |
| 1008 | datetime.set_sleep_fn(Box::new( |
| 1009 | move |_d: Duration| -> futures_lite::future::BoxedLocal<Result<(), String>> { |
| 1010 | let sleep_tx = sleep_tx.clone(); |
| 1011 | let sleep_signal_sent = sleep_signal_sent.clone(); |
| 1012 | async move { |
| 1013 | if !*sleep_signal_sent.borrow() { |
| 1014 | *sleep_signal_sent.borrow_mut() = true; |
| 1015 | sleep_tx.send(Signal::Break).await.unwrap(); |
| 1016 | } |
| 1017 | Ok(()) |
| 1018 | } |
| 1019 | .boxed_local() |
| 1020 | }, |
| 1021 | )); |
| 1022 | |
| 1023 | let storage = Rc::from(RefCell::from(Storage::default())); |
| 1024 | let mut machine = MachineBuilder::default() |
| 1025 | .with_console(console.clone()) |
| 1026 | .with_signals_chan((signals_tx, signals_rx)) |
| 1027 | .with_datetime(datetime) |
| 1028 | .make_interactive() |
| 1029 | .with_program(program) |
| 1030 | .with_storage(storage) |
| 1031 | .build(); |
| 1032 | |
| 1033 | machine.compile(&mut "RUN".as_bytes()).unwrap(); |
| 1034 | match block_on(machine.exec()) { |
| 1035 | Err(crate::Error::Break) => (), |
| 1036 | r => panic!("Expected Break but got {:?}", r), |
| 1037 | } |
| 1038 | |
| 1039 | machine.compile(&mut "RUN".as_bytes()).unwrap(); |
| 1040 | match block_on(machine.exec()) { |
| 1041 | Ok(None) => (), |
| 1042 | r => panic!("Expected successful completion but got {:?}", r), |
| 1043 | } |
| 1044 | |
| 1045 | let prints: Vec<String> = console |
| 1046 | .borrow_mut() |
| 1047 | .take_captured_out() |
| 1048 | .into_iter() |
| 1049 | .filter_map(|out| match out { |
| 1050 | CapturedOut::Print(text) => Some(text), |
| 1051 | _ => None, |
| 1052 | }) |
| 1053 | .collect(); |
| 1054 | assert_eq!(vec!["begin", "begin", "done"], prints); |
| 1055 | } |
nothing calls this directly
no test coverage detected