Repository navigation
Expand file tree
/
Copy patherrors.rs
More file actions
26 lines (26 loc) · 1.64 KB
/
Copy patherrors.rs
File metadata and controls
26 lines (26 loc) · 1.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
use std::{fs, process::Command};
#[test]
#[ignore = "native ABI 2 gate"]
fn structured_error_detection_propagation_and_recovery() {
let dir = tempfile::tempdir().unwrap();
let root = dir.path().join("main.z");
fs::write(&root,"Function decodeQuantity using raw.\nLet result be call numberResult with raw.\nIf not (call succeeded with result).\nReturn result.\nEnd if.\nLet quantity be call unwrap with result.\nIf quantity < 0.\nReturn call failure with (call error with \"NegativeQuantity\", \"Quantity must be positive\").\nEnd if.\nReturn call success with quantity * 2.\nEnd function.\nFor each raw in (list of \"12\", \"invalid\", \"-3\").\nLet result be call decodeQuantity with raw.\nIf call succeeded with result.\nPrint call unwrap with result.\nElse.\nPrint call errorCode with (call unwrap with result).\nEnd if.\nEnd for.\nLet missing be call readResult with \"absent-file.txt\".\nPrint call succeeded with missing.\nPrint call errorCode with (call unwrap with missing).\nLet saved be call writeResult with \"report.txt\", \"computed output\".\nPrint call succeeded with saved.\nPrint call unwrap with (call readResult with \"report.txt\").").unwrap();
let out = Command::new(env!("CARGO_BIN_EXE_zpp-driver"))
.arg(root)
.current_dir(dir.path())
.output()
.unwrap();
assert!(
out.status.success(),
"{}",
String::from_utf8_lossy(&out.stderr)
);
assert_eq!(
out.stdout,
b"24\nNumberError\nNegativeQuantity\nfalse\nReadError\ntrue\ncomputed output\n"
);
assert_eq!(
fs::read(dir.path().join("report.txt")).unwrap(),
b"computed output"
);
}