|
| 1 | +use snapbox::prelude::*; |
| 2 | +use snapbox::str; |
| 3 | + |
| 4 | +fn test_cmd() -> snapbox::cmd::Command { |
| 5 | + static BIN: once_cell_polyfill::sync::OnceLock<(std::path::PathBuf, std::path::PathBuf)> = |
| 6 | + once_cell_polyfill::sync::OnceLock::new(); |
| 7 | + let (bin, current_dir) = BIN.get_or_init(|| { |
| 8 | + let package_root = crate::util::new_test( |
| 9 | + r#" |
| 10 | +fn main() { |
| 11 | + use libtest2_mimic::Trial; |
| 12 | + use libtest2_mimic::RunError; |
| 13 | + libtest2_mimic::Harness::with_env() |
| 14 | + .cases(vec![ |
| 15 | + Trial::test("one", |_| Ok(())), |
| 16 | + Trial::test("two", |_| Ok(())), |
| 17 | + Trial::test("three", |_| Ok(())), |
| 18 | + Trial::test("one_two", |_| Ok(())), |
| 19 | + ]) |
| 20 | + .main(); |
| 21 | +} |
| 22 | +"#, |
| 23 | + false, |
| 24 | + ); |
| 25 | + let bin = crate::util::compile_test(&package_root); |
| 26 | + (bin, package_root) |
| 27 | + }); |
| 28 | + snapbox::cmd::Command::new(bin).current_dir(current_dir) |
| 29 | +} |
| 30 | + |
| 31 | +fn check( |
| 32 | + args: &[&str], |
| 33 | + argfile: &std::path::Path, |
| 34 | + code: i32, |
| 35 | + single: impl IntoData, |
| 36 | + parallel: impl IntoData, |
| 37 | +) { |
| 38 | + test_cmd() |
| 39 | + .arg(format!("@{}", argfile.to_str().unwrap())) |
| 40 | + .args(args) |
| 41 | + .args(["--test-threads", "1"]) |
| 42 | + .assert() |
| 43 | + .code(code) |
| 44 | + .stdout_eq(single); |
| 45 | + test_cmd() |
| 46 | + .arg(format!("@{}", argfile.to_str().unwrap())) |
| 47 | + .args(args) |
| 48 | + .assert() |
| 49 | + .code(code) |
| 50 | + .stdout_eq(parallel); |
| 51 | +} |
| 52 | + |
| 53 | +#[test] |
| 54 | +fn empty() { |
| 55 | + let argfile = crate::util::new_file("argfile-", ".txt", ""); |
| 56 | + check( |
| 57 | + &[], |
| 58 | + &argfile, |
| 59 | + 0, |
| 60 | + str![[r#" |
| 61 | +
|
| 62 | +running 4 tests |
| 63 | +test one ... ok |
| 64 | +test one_two ... ok |
| 65 | +test three ... ok |
| 66 | +test two ... ok |
| 67 | +
|
| 68 | +test result: ok. 4 passed; 0 failed; 0 ignored; 0 filtered out; finished in [..]s |
| 69 | +
|
| 70 | +
|
| 71 | +"#]], |
| 72 | + str![[r#" |
| 73 | +
|
| 74 | +running 4 tests |
| 75 | +... |
| 76 | +
|
| 77 | +test result: ok. 4 passed; 0 failed; 0 ignored; 0 filtered out; finished in [..]s |
| 78 | +
|
| 79 | +
|
| 80 | +"#]], |
| 81 | + ); |
| 82 | +} |
| 83 | + |
| 84 | +#[test] |
| 85 | +fn list() { |
| 86 | + let argfile = crate::util::new_file("argfile-", ".txt", "--list"); |
| 87 | + check( |
| 88 | + &[], |
| 89 | + &argfile, |
| 90 | + 0, |
| 91 | + str![[r#" |
| 92 | +one: test |
| 93 | +one_two: test |
| 94 | +three: test |
| 95 | +two: test |
| 96 | +
|
| 97 | +4 tests |
| 98 | +
|
| 99 | +
|
| 100 | +"#]], |
| 101 | + str![[r#" |
| 102 | +one: test |
| 103 | +one_two: test |
| 104 | +... |
| 105 | +
|
| 106 | +4 tests |
| 107 | +
|
| 108 | +
|
| 109 | +"#]], |
| 110 | + ); |
| 111 | +} |
| 112 | + |
| 113 | +#[test] |
| 114 | +fn multiline() { |
| 115 | + let argfile = crate::util::new_file( |
| 116 | + "argfile-", |
| 117 | + ".txt", |
| 118 | + "one |
| 119 | +two |
| 120 | +--exact", |
| 121 | + ); |
| 122 | + check( |
| 123 | + &[], |
| 124 | + &argfile, |
| 125 | + 0, |
| 126 | + str![[r#" |
| 127 | +
|
| 128 | +running 2 tests |
| 129 | +test one ... ok |
| 130 | +test two ... ok |
| 131 | +
|
| 132 | +test result: ok. 2 passed; 0 failed; 0 ignored; 2 filtered out; finished in [..]s |
| 133 | +
|
| 134 | +
|
| 135 | +"#]], |
| 136 | + str![[r#" |
| 137 | +
|
| 138 | +running 2 tests |
| 139 | +... |
| 140 | +
|
| 141 | +test result: ok. 2 passed; 0 failed; 0 ignored; 2 filtered out; finished in [..]s |
| 142 | +
|
| 143 | +
|
| 144 | +"#]], |
| 145 | + ); |
| 146 | +} |
| 147 | + |
| 148 | +#[test] |
| 149 | +fn mixed() { |
| 150 | + let argfile = crate::util::new_file( |
| 151 | + "argfile-", ".txt", "one |
| 152 | +two", |
| 153 | + ); |
| 154 | + check( |
| 155 | + &["--exact"], |
| 156 | + &argfile, |
| 157 | + 0, |
| 158 | + str![[r#" |
| 159 | +
|
| 160 | +running 2 tests |
| 161 | +test one ... ok |
| 162 | +test two ... ok |
| 163 | +
|
| 164 | +test result: ok. 2 passed; 0 failed; 0 ignored; 2 filtered out; finished in [..]s |
| 165 | +
|
| 166 | +
|
| 167 | +"#]], |
| 168 | + str![[r#" |
| 169 | +
|
| 170 | +running 2 tests |
| 171 | +... |
| 172 | +
|
| 173 | +test result: ok. 2 passed; 0 failed; 0 ignored; 2 filtered out; finished in [..]s |
| 174 | +
|
| 175 | +
|
| 176 | +"#]], |
| 177 | + ); |
| 178 | +} |
| 179 | + |
| 180 | +#[test] |
| 181 | +fn invalid() { |
| 182 | + let argfile = std::path::Path::new("highly-improbably-non-existent-file.txt"); |
| 183 | + check(&[], argfile, 1, str![""], str![""]); |
| 184 | +} |
0 commit comments