From b054d8759e3827d293eee07f880d8bf50e388407 Mon Sep 17 00:00:00 2001 From: Remo Senekowitsch Date: Sun, 9 Aug 2026 14:53:55 +0200 Subject: [PATCH] dev check: allow input files --- src/dev/check.rs | 18 ++++++++++++------ src/info_file.rs | 3 +++ 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/dev/check.rs b/src/dev/check.rs index 58c2a174..925f1d86 100644 --- a/src/dev/check.rs +++ b/src/dev/check.rs @@ -133,19 +133,25 @@ fn check_info_file_exercises(info_file: &InfoFile) -> Result> { file_buf.clear(); - paths.insert(PathBuf::from(path)); + let path = PathBuf::from(path); + + for input_file in &exercise_info.input_files { + paths.insert(path.parent().unwrap().join(input_file)); + } + + paths.insert(path); } Ok(paths) } // Check `dir` for unexpected files. -// Only Rust files in `allowed_rust_files` and `README.md` files are allowed. +// Only files in `allowed_files` and `README.md` files are allowed. // Only one level of directory nesting is allowed. -fn check_unexpected_files(dir: &str, allowed_rust_files: &HashSet) -> Result<()> { +fn check_unexpected_files(dir: &str, allowed_files: &HashSet) -> Result<()> { let unexpected_file = |path: &Path| { anyhow!( - "Found the file `{}`. Only `README.md` and Rust files related to an exercise in `info.toml` are allowed in the `{dir}` directory", + "Found the file `{}`. Only `README.md`, Rust files and input files related to an exercise in `info.toml` are allowed in the `{dir}` directory", path.display() ) }; @@ -160,7 +166,7 @@ fn check_unexpected_files(dir: &str, allowed_rust_files: &HashSet) -> R continue; } - if !allowed_rust_files.contains(&path) { + if !allowed_files.contains(&path) { return Err(unexpected_file(&path)); } @@ -187,7 +193,7 @@ fn check_unexpected_files(dir: &str, allowed_rust_files: &HashSet) -> R continue; } - if !allowed_rust_files.contains(&path) { + if !allowed_files.contains(&path) { return Err(unexpected_file(&path)); } } diff --git a/src/info_file.rs b/src/info_file.rs index da4086aa..ece40afb 100644 --- a/src/info_file.rs +++ b/src/info_file.rs @@ -17,6 +17,9 @@ pub struct ExerciseInfo<'a> { /// Deny all Clippy warnings. #[serde(default)] pub strict_clippy: bool, + // Files that are read by the exercise. + #[serde(default)] + pub input_files: Vec<&'a str>, /// The exercise's hint to be shown to the user on request. pub hint: String, /// The exercise is already solved. Ignore it when checking that all exercises are unsolved.