tests.nixpkgs-check-by-name: Intermediate PathInterpolation error

This commit is contained in:
Silvan Mosberger
2023-10-24 01:15:56 +02:00
parent a755aa7d02
commit 96f6a350fa
2 changed files with 24 additions and 12 deletions
@@ -5,6 +5,12 @@ use std::io;
use std::path::PathBuf;
pub enum CheckError {
PathInterpolation {
relative_package_dir: PathBuf,
subpath: PathBuf,
line: usize,
text: String,
},
SearchPath {
relative_package_dir: PathBuf,
subpath: PathBuf,
@@ -35,6 +41,14 @@ impl CheckError {
impl fmt::Display for CheckError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
CheckError::PathInterpolation { relative_package_dir, subpath, line, text } =>
write!(
f,
"{}: File {} at line {line} contains the path expression \"{}\", which is not yet supported and may point outside the directory of that package.",
relative_package_dir.display(),
subpath.display(),
text
),
CheckError::SearchPath { relative_package_dir, subpath, line, text } =>
write!(
f,
@@ -133,18 +133,16 @@ fn check_nix_file<W: io::Write>(
// Filters out ./foo/${bar}/baz
// TODO: We can just check ./foo
if node.children().count() != 0 {
context.error_writer.write(&format!(
"{}: File {} at line {line} contains the path expression \"{}\", which is not yet supported and may point outside the directory of that package.",
context.relative_package_dir.display(),
subpath.display(),
text
))?;
continue;
}
// Filters out search paths like <nixpkgs>
let check_result = if text.starts_with('<') {
let check_result = if node.children().count() != 0 {
CheckError::PathInterpolation {
relative_package_dir: context.relative_package_dir.clone(),
subpath: subpath.to_path_buf(),
line,
text,
}
.into_result()
} else if text.starts_with('<') {
// Filters out search paths like <nixpkgs>
CheckError::SearchPath {
relative_package_dir: context.relative_package_dir.clone(),
subpath: subpath.to_path_buf(),