Skip to content

Commit cd52f05

Browse files
committed
dev check: allow input files
1 parent ade352c commit cd52f05

2 files changed

Lines changed: 15 additions & 6 deletions

File tree

src/dev/check.rs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -133,19 +133,25 @@ fn check_info_file_exercises(info_file: &InfoFile) -> Result<HashSet<PathBuf>> {
133133

134134
file_buf.clear();
135135

136-
paths.insert(PathBuf::from(path));
136+
let path = PathBuf::from(path);
137+
138+
for input_file in &exercise_info.input_files {
139+
paths.insert(path.parent().unwrap().join(input_file));
140+
}
141+
142+
paths.insert(path);
137143
}
138144

139145
Ok(paths)
140146
}
141147

142148
// Check `dir` for unexpected files.
143-
// Only Rust files in `allowed_rust_files` and `README.md` files are allowed.
149+
// Only files in `allowed_files` and `README.md` files are allowed.
144150
// Only one level of directory nesting is allowed.
145-
fn check_unexpected_files(dir: &str, allowed_rust_files: &HashSet<PathBuf>) -> Result<()> {
151+
fn check_unexpected_files(dir: &str, allowed_files: &HashSet<PathBuf>) -> Result<()> {
146152
let unexpected_file = |path: &Path| {
147153
anyhow!(
148-
"Found the file `{}`. Only `README.md` and Rust files related to an exercise in `info.toml` are allowed in the `{dir}` directory",
154+
"Found the file `{}`. Only `README.md`, Rust files and input files related to an exercise in `info.toml` are allowed in the `{dir}` directory",
149155
path.display()
150156
)
151157
};
@@ -160,7 +166,7 @@ fn check_unexpected_files(dir: &str, allowed_rust_files: &HashSet<PathBuf>) -> R
160166
continue;
161167
}
162168

163-
if !allowed_rust_files.contains(&path) {
169+
if !allowed_files.contains(&path) {
164170
return Err(unexpected_file(&path));
165171
}
166172

@@ -187,7 +193,7 @@ fn check_unexpected_files(dir: &str, allowed_rust_files: &HashSet<PathBuf>) -> R
187193
continue;
188194
}
189195

190-
if !allowed_rust_files.contains(&path) {
196+
if !allowed_files.contains(&path) {
191197
return Err(unexpected_file(&path));
192198
}
193199
}

src/info_file.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ pub struct ExerciseInfo<'a> {
1717
/// Deny all Clippy warnings.
1818
#[serde(default)]
1919
pub strict_clippy: bool,
20+
// Files that are read by the exercise.
21+
#[serde(default)]
22+
pub input_files: Vec<&'a str>,
2023
/// The exercise's hint to be shown to the user on request.
2124
pub hint: String,
2225
/// The exercise is already solved. Ignore it when checking that all exercises are unsolved.

0 commit comments

Comments
 (0)