Skip to content

Commit

Permalink
Print the path of the missing file
Browse files Browse the repository at this point in the history
  • Loading branch information
mo8it committed Apr 17, 2024
1 parent b9167e9 commit d42a6e7
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/dev/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ fn forbidden_char(input: &str) -> Option<char> {
fn check_info_file_exercises(info_file: &InfoFile) -> Result<hashbrown::HashSet<PathBuf>> {
let mut names = hashbrown::HashSet::with_capacity(info_file.exercises.len());
let mut paths = hashbrown::HashSet::with_capacity(info_file.exercises.len());

for exercise_info in &info_file.exercises {
if let Some(c) = forbidden_char(&exercise_info.name) {
bail!(
Expand Down Expand Up @@ -49,6 +50,7 @@ fn check_exercise_dir_files(
info_file_paths: hashbrown::HashSet<PathBuf>,
) -> Result<hashbrown::HashSet<String>> {
let mut names = hashbrown::HashSet::with_capacity(info_file.exercises.len());

for entry in read_dir("exercises").context("Failed to open the `exercises` directory")? {
let entry = entry.context("Failed to read the `exercises` directory")?;

Expand Down Expand Up @@ -89,8 +91,11 @@ fn check_exercise_dir_files(
bail!("`{}` is expected to be an exercise file corresponding to some exercise in `info.toml`", path.display());
}

// The file name must be valid Unicode with the `.rs` extension
// because it is part of the info file paths.
let file_name = file_name.to_string_lossy();
names.insert(file_name[..file_name.len() - 3].to_string());
let file_name_without_rs_extension = file_name[..file_name.len() - 3].to_string();
names.insert(file_name_without_rs_extension);
}
}

Expand All @@ -112,10 +117,7 @@ fn check_info_file(info_file: &InfoFile) -> Result<()> {
if names_in_exercises_dir.len() != info_file.exercises.len() {
for exercise_info in &info_file.exercises {
if !names_in_exercises_dir.contains(&exercise_info.name) {
bail!(
"No exercise file found for the exercise `{}`",
exercise_info.name,
);
bail!("The file `{}` is missing", exercise_info.path());
}
}
}
Expand Down Expand Up @@ -178,7 +180,6 @@ fn check_cargo_toml(

pub fn check() -> Result<()> {
let info_file = InfoFile::parse()?;

check_info_file(&info_file)?;

if DEVELOPING_OFFICIAL_RUSTLINGS {
Expand Down

0 comments on commit d42a6e7

Please sign in to comment.