| 83 | |
| 84 | #[test] |
| 85 | fn test_all_md_files_registered() -> io::Result<()> { |
| 86 | let mut registered = vec![]; |
| 87 | { |
| 88 | let file = File::open(src_path("core/tests/integration_test.rs"))?; |
| 89 | let reader = BufReader::new(file); |
| 90 | for line in reader.lines() { |
| 91 | let line = line?; |
| 92 | |
| 93 | if line.starts_with("one_test!(") { |
| 94 | let delim = line.find([',', ')']).unwrap(); |
| 95 | let name = &line["one_test!(".len()..delim]; |
| 96 | registered.push(format!("{}.md", name)); |
| 97 | } |
| 98 | } |
| 99 | } |
| 100 | |
| 101 | // Sanity-check to ensure that the code right above actually discovered what we expect. |
| 102 | assert!(registered.iter().any(|s| s == "test_types.md")); |
| 103 | |
| 104 | // Make sure that every md test case definition in the file system is in the list of |
| 105 | // tests discovered from code scanning. We don't have to do the opposite because, if |
| 106 | // this program registers a md file that doesn't actually exist, the test itself will |
| 107 | // fail. |
| 108 | let mut found = vec![]; |
| 109 | for entry in fs::read_dir(src_path("core/tests"))? { |
| 110 | let entry = entry?; |
| 111 | |
| 112 | let Ok(name) = entry.file_name().into_string() else { |
| 113 | continue; |
| 114 | }; |
| 115 | |
| 116 | #[allow(clippy::collapsible_if)] |
| 117 | if name.starts_with("test_") && name.ends_with(".md") { |
| 118 | found.push(name); |
| 119 | } |
| 120 | } |
| 121 | |
| 122 | // We want the list of tests below to be sorted, so sort the list of found tests and |
| 123 | // use that when comparing against the list of registered tests. |
| 124 | found.sort(); |
| 125 | |
| 126 | assert_eq!(registered, found); |
| 127 | |
| 128 | Ok(()) |
| 129 | } |