tests.nixpkgs-check-by-name: Make structural check a global function
This commit is contained in:
parent
83b887504c
commit
0475238ec0
2 changed files with 116 additions and 136 deletions
|
@ -4,6 +4,7 @@ mod references;
|
||||||
mod structure;
|
mod structure;
|
||||||
mod utils;
|
mod utils;
|
||||||
|
|
||||||
|
use crate::structure::check_structure;
|
||||||
use anyhow::Context;
|
use anyhow::Context;
|
||||||
use check_result::{flatten_check_results, write_check_result};
|
use check_result::{flatten_check_results, write_check_result};
|
||||||
use clap::{Parser, ValueEnum};
|
use clap::{Parser, ValueEnum};
|
||||||
|
@ -11,7 +12,6 @@ use colored::Colorize;
|
||||||
use std::io;
|
use std::io;
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
use std::process::ExitCode;
|
use std::process::ExitCode;
|
||||||
use structure::Nixpkgs;
|
|
||||||
use utils::ErrorWriter;
|
use utils::ErrorWriter;
|
||||||
|
|
||||||
/// Program to check the validity of pkgs/by-name
|
/// Program to check the validity of pkgs/by-name
|
||||||
|
@ -88,9 +88,9 @@ pub fn check_nixpkgs<W: io::Write>(
|
||||||
utils::BASE_SUBPATH
|
utils::BASE_SUBPATH
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
let nixpkgs = Nixpkgs::new(&nixpkgs_path, &mut error_writer)?;
|
let check_result = check_structure(&nixpkgs_path);
|
||||||
|
|
||||||
if error_writer.empty {
|
if let Some(nixpkgs) = write_check_result(&mut error_writer, check_result)? {
|
||||||
// Only if we could successfully parse the structure, we do the semantic checks
|
// Only if we could successfully parse the structure, we do the semantic checks
|
||||||
let check_result = flatten_check_results(
|
let check_result = flatten_check_results(
|
||||||
[
|
[
|
||||||
|
|
|
@ -1,11 +1,10 @@
|
||||||
use crate::check_result::{
|
use crate::check_result::{
|
||||||
flatten_check_results, pass, sequence_check_results, write_check_result, CheckError,
|
flatten_check_results, pass, sequence_check_results, CheckError, CheckResult,
|
||||||
};
|
};
|
||||||
use crate::utils;
|
use crate::utils;
|
||||||
use crate::utils::{ErrorWriter, BASE_SUBPATH, PACKAGE_NIX_FILENAME};
|
use crate::utils::{BASE_SUBPATH, PACKAGE_NIX_FILENAME};
|
||||||
use lazy_static::lazy_static;
|
use lazy_static::lazy_static;
|
||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
use std::io;
|
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
|
|
||||||
lazy_static! {
|
lazy_static! {
|
||||||
|
@ -42,13 +41,9 @@ impl Nixpkgs {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Nixpkgs {
|
|
||||||
/// Read the structure of a Nixpkgs directory, displaying errors on the writer.
|
/// Read the structure of a Nixpkgs directory, displaying errors on the writer.
|
||||||
/// May return early with I/O errors.
|
/// May return early with I/O errors.
|
||||||
pub fn new<W: io::Write>(
|
pub fn check_structure(path: &Path) -> CheckResult<Nixpkgs> {
|
||||||
path: &Path,
|
|
||||||
error_writer: &mut ErrorWriter<W>,
|
|
||||||
) -> anyhow::Result<Nixpkgs> {
|
|
||||||
let base_dir = path.join(BASE_SUBPATH);
|
let base_dir = path.join(BASE_SUBPATH);
|
||||||
|
|
||||||
let check_results = utils::read_dir_sorted(&base_dir)?
|
let check_results = utils::read_dir_sorted(&base_dir)?
|
||||||
|
@ -133,8 +128,8 @@ impl Nixpkgs {
|
||||||
if shard_name_valid && package_name_valid {
|
if shard_name_valid && package_name_valid {
|
||||||
CheckError::IncorrectShard {
|
CheckError::IncorrectShard {
|
||||||
relative_package_dir: relative_package_dir.clone(),
|
relative_package_dir: relative_package_dir.clone(),
|
||||||
correct_relative_package_dir:
|
correct_relative_package_dir: correct_relative_package_dir
|
||||||
correct_relative_package_dir.clone(),
|
.clone(),
|
||||||
}
|
}
|
||||||
.into_result()
|
.into_result()
|
||||||
} else {
|
} else {
|
||||||
|
@ -170,27 +165,12 @@ impl Nixpkgs {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
sequence_check_results(
|
sequence_check_results(check_result, flatten_check_results(check_results, |x| x))
|
||||||
check_result,
|
|
||||||
flatten_check_results(check_results, |x| x),
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
let check_result = flatten_check_results(check_results, |x| {
|
flatten_check_results(check_results, |x| Nixpkgs {
|
||||||
x.into_iter().flatten().collect::<Vec<_>>()
|
|
||||||
});
|
|
||||||
|
|
||||||
if let Some(package_names) = write_check_result(error_writer, check_result)? {
|
|
||||||
Ok(Nixpkgs {
|
|
||||||
path: path.to_owned(),
|
path: path.to_owned(),
|
||||||
package_names,
|
package_names: x.into_iter().flatten().collect::<Vec<_>>(),
|
||||||
})
|
|
||||||
} else {
|
|
||||||
Ok(Nixpkgs {
|
|
||||||
path: path.to_owned(),
|
|
||||||
package_names: vec![],
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in a new issue