1
0
mirror of https://github.com/rust-lang/rustlings.git synced 2024-09-16 10:51:42 +02:00

Check for tests while test=false

This commit is contained in:
mo8it 2024-05-01 19:16:59 +02:00
parent d425dbe203
commit 74180ba1cc

View File

@ -22,22 +22,17 @@ fn check_info_file_exercises(info_file: &InfoFile) -> Result<hashbrown::HashSet<
let mut file_buf = String::with_capacity(1 << 14); let mut file_buf = String::with_capacity(1 << 14);
for exercise_info in &info_file.exercises { for exercise_info in &info_file.exercises {
if exercise_info.name.is_empty() { let name = exercise_info.name.as_str();
if name.is_empty() {
bail!("Found an empty exercise name in `info.toml`"); bail!("Found an empty exercise name in `info.toml`");
} }
if let Some(c) = forbidden_char(&exercise_info.name) { if let Some(c) = forbidden_char(name) {
bail!( bail!("Char `{c}` in the exercise name `{name}` is not allowed");
"Char `{c}` in the exercise name `{}` is not allowed",
exercise_info.name,
);
} }
if let Some(dir) = &exercise_info.dir { if let Some(dir) = &exercise_info.dir {
if dir.is_empty() { if dir.is_empty() {
bail!( bail!("The exercise `{name}` has an empty dir name in `info.toml`");
"The exercise `{}` has an empty dir name in `info.toml`",
exercise_info.name,
);
} }
if let Some(c) = forbidden_char(dir) { if let Some(c) = forbidden_char(dir) {
bail!("Char `{c}` in the exercise dir `{dir}` is not allowed"); bail!("Char `{c}` in the exercise dir `{dir}` is not allowed");
@ -45,14 +40,11 @@ fn check_info_file_exercises(info_file: &InfoFile) -> Result<hashbrown::HashSet<
} }
if exercise_info.hint.trim().is_empty() { if exercise_info.hint.trim().is_empty() {
bail!("The exercise `{}` has an empty hint. Please provide a hint or at least tell the user why a hint isn't needed for this exercise", exercise_info.name); bail!("The exercise `{name}` has an empty hint. Please provide a hint or at least tell the user why a hint isn't needed for this exercise");
} }
if !names.insert(exercise_info.name.as_str()) { if !names.insert(name) {
bail!( bail!("The exercise name `{name}` is duplicated. Exercise names must all be unique");
"The exercise name `{}` is duplicated. Exercise names must all be unique",
exercise_info.name,
);
} }
let path = exercise_info.path(); let path = exercise_info.path();
@ -68,6 +60,10 @@ fn check_info_file_exercises(info_file: &InfoFile) -> Result<hashbrown::HashSet<
bail!("The `main` function is missing in the file `{path}`.\nCreate at least an empty `main` function to avoid language server errors"); bail!("The `main` function is missing in the file `{path}`.\nCreate at least an empty `main` function to avoid language server errors");
} }
if !exercise_info.test && file_buf.contains("#[test]") {
bail!("The file `{path}` contains tests annotated with `#[test]` but the exercise `{name}` has `test = false` in the `info.toml` file");
}
file_buf.clear(); file_buf.clear();
paths.insert(PathBuf::from(path)); paths.insert(PathBuf::from(path));