| 150 | type Error = anyhow::Error; |
| 151 | |
| 152 | fn try_from(path: &Path) -> Result<Self> { |
| 153 | let mut tests = TestCollection::default(); |
| 154 | |
| 155 | for entry in walkdir::WalkDir::new(path) { |
| 156 | let entry = entry?; |
| 157 | if !entry.file_type().is_file() { |
| 158 | continue; |
| 159 | } |
| 160 | if entry.path().extension().unwrap_or_default() != "rs" { |
| 161 | continue; |
| 162 | } |
| 163 | let text = fs::read_to_string(entry.path())?; |
| 164 | for test in collect_tests(&text) { |
| 165 | if test.is_ok() { |
| 166 | if let Some(old_test) = tests.ok.insert(test.name.clone(), test) { |
| 167 | anyhow::bail!( |
| 168 | "Duplicate test found: {name:?} (search '// test_ok {name}' for the location)\n", |
| 169 | name = old_test.name |
| 170 | ); |
| 171 | } |
| 172 | } else if let Some(old_test) = tests.err.insert(test.name.clone(), test) { |
| 173 | anyhow::bail!( |
| 174 | "Duplicate test found: {name:?} (search '// test_err {name}' for the location)\n", |
| 175 | name = old_test.name |
| 176 | ); |
| 177 | } |
| 178 | } |
| 179 | } |
| 180 | |
| 181 | Ok(tests) |
| 182 | } |
| 183 | } |
| 184 | |
| 185 | #[derive(Debug, Clone, Copy)] |