mirror of
https://github.com/rust-lang/rustlings.git
synced 2026-08-14 22:36:57 +00:00
dev check: allow input files
This commit is contained in:
parent
f63e11aeb6
commit
b054d8759e
@ -133,19 +133,25 @@ fn check_info_file_exercises(info_file: &InfoFile) -> Result<HashSet<PathBuf>> {
|
|||||||
|
|
||||||
file_buf.clear();
|
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)
|
Ok(paths)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check `dir` for unexpected files.
|
// 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.
|
// Only one level of directory nesting is allowed.
|
||||||
fn check_unexpected_files(dir: &str, allowed_rust_files: &HashSet<PathBuf>) -> Result<()> {
|
fn check_unexpected_files(dir: &str, allowed_files: &HashSet<PathBuf>) -> Result<()> {
|
||||||
let unexpected_file = |path: &Path| {
|
let unexpected_file = |path: &Path| {
|
||||||
anyhow!(
|
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()
|
path.display()
|
||||||
)
|
)
|
||||||
};
|
};
|
||||||
@ -160,7 +166,7 @@ fn check_unexpected_files(dir: &str, allowed_rust_files: &HashSet<PathBuf>) -> R
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if !allowed_rust_files.contains(&path) {
|
if !allowed_files.contains(&path) {
|
||||||
return Err(unexpected_file(&path));
|
return Err(unexpected_file(&path));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -187,7 +193,7 @@ fn check_unexpected_files(dir: &str, allowed_rust_files: &HashSet<PathBuf>) -> R
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if !allowed_rust_files.contains(&path) {
|
if !allowed_files.contains(&path) {
|
||||||
return Err(unexpected_file(&path));
|
return Err(unexpected_file(&path));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -17,6 +17,9 @@ pub struct ExerciseInfo<'a> {
|
|||||||
/// Deny all Clippy warnings.
|
/// Deny all Clippy warnings.
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub strict_clippy: bool,
|
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.
|
/// The exercise's hint to be shown to the user on request.
|
||||||
pub hint: String,
|
pub hint: String,
|
||||||
/// The exercise is already solved. Ignore it when checking that all exercises are unsolved.
|
/// The exercise is already solved. Ignore it when checking that all exercises are unsolved.
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user