(filename: &str)
| 83 | // we need rebuild this crate to update the test file list |
| 84 | #[test_resources("tests/integration/*/*.ai")] |
| 85 | fn run_file_test(filename: &str) { |
| 86 | let mut path = PathBuf::from(env!("CARGO_MANIFEST_DIR")); |
| 87 | path.set_file_name(filename); |
| 88 | let expected = parse_comments(&path); |
| 89 | if expected.is_none() { |
| 90 | println!("File ignored: {filename}"); |
| 91 | return; |
| 92 | } |
| 93 | let expected = expected.unwrap(); |
| 94 | |
| 95 | let output = test_command().arg(path).output().unwrap(); |
| 96 | |
| 97 | let out: Vec<String> = String::from_utf8(output.stdout) |
| 98 | .unwrap() |
| 99 | .lines() |
| 100 | .map(|x| x.to_owned()) |
| 101 | .collect(); |
| 102 | let err: Vec<String> = String::from_utf8(output.stderr) |
| 103 | .unwrap() |
| 104 | .lines() |
| 105 | .map(|x| x.to_owned()) |
| 106 | .collect(); |
| 107 | |
| 108 | match ( |
| 109 | expected.runtime_err.is_none(), |
| 110 | expected.compile_err.is_empty(), |
| 111 | ) { |
| 112 | (true, true) => assert!( |
| 113 | output.status.success(), |
| 114 | "Program exited with failure, expected success" |
| 115 | ), |
| 116 | (false, true) => assert_eq!( |
| 117 | output.status.code().unwrap(), |
| 118 | 70, |
| 119 | "Runtime errors should have error code 70" |
| 120 | ), |
| 121 | (true, false) => assert_eq!( |
| 122 | output.status.code().unwrap(), |
| 123 | 65, |
| 124 | "Compile errors should have error code 65" |
| 125 | ), |
| 126 | (false, false) => panic!("Simultaneous error and compile error"), |
| 127 | } |
| 128 | |
| 129 | if let Some(e) = expected.runtime_err { |
| 130 | assert_eq!(e.message, err[0], "Runtime error should match"); |
| 131 | assert_eq!( |
| 132 | err[1][0..e.line_prefix.len()], |
| 133 | e.line_prefix, |
| 134 | "Runtime error line should match" |
| 135 | ); |
| 136 | } else { |
| 137 | if !err.is_empty() { |
| 138 | assert_eq!( |
| 139 | output.status.code().unwrap(), |
| 140 | 65, |
| 141 | "Compile errors should have error code 65" |
| 142 | ); |
nothing calls this directly
no test coverage detected