tests.nixpkgs-check-by-name: Introduce --version
This commit is contained in:
parent
fcaa408d00
commit
23541bed72
2 changed files with 24 additions and 4 deletions
|
@ -11,6 +11,12 @@ This API may be changed over time if the CI workflow making use of it is adjuste
|
|||
- Command line: `nixpkgs-check-by-name <NIXPKGS>`
|
||||
- Arguments:
|
||||
- `<NIXPKGS>`: The path to the Nixpkgs to check
|
||||
- `--version <VERSION>`: The version of the checks to perform.
|
||||
|
||||
Possible values:
|
||||
- `v0` (default)
|
||||
|
||||
See [validation](#validity-checks) for the differences.
|
||||
- Exit code:
|
||||
- `0`: If the [validation](#validity-checks) is successful
|
||||
- `1`: If the [validation](#validity-checks) is not successful
|
||||
|
|
|
@ -4,7 +4,7 @@ mod structure;
|
|||
mod utils;
|
||||
|
||||
use anyhow::Context;
|
||||
use clap::Parser;
|
||||
use clap::{Parser, ValueEnum};
|
||||
use colored::Colorize;
|
||||
use std::io;
|
||||
use std::path::{Path, PathBuf};
|
||||
|
@ -15,14 +15,26 @@ use utils::ErrorWriter;
|
|||
/// Program to check the validity of pkgs/by-name
|
||||
#[derive(Parser, Debug)]
|
||||
#[command(about)]
|
||||
struct Args {
|
||||
pub struct Args {
|
||||
/// Path to nixpkgs
|
||||
nixpkgs: PathBuf,
|
||||
/// The version of the checks
|
||||
/// Increasing this may cause failures for a Nixpkgs that succeeded before
|
||||
/// TODO: Remove default once Nixpkgs CI passes this argument
|
||||
#[arg(long, value_enum, default_value_t = Version::V0)]
|
||||
version: Version,
|
||||
}
|
||||
|
||||
/// The version of the checks
|
||||
#[derive(Debug, Clone, PartialEq, PartialOrd, ValueEnum)]
|
||||
pub enum Version {
|
||||
/// Initial version
|
||||
V0,
|
||||
}
|
||||
|
||||
fn main() -> ExitCode {
|
||||
let args = Args::parse();
|
||||
match check_nixpkgs(&args.nixpkgs, vec![], &mut io::stderr()) {
|
||||
match check_nixpkgs(&args.nixpkgs, args.version, vec![], &mut io::stderr()) {
|
||||
Ok(true) => {
|
||||
eprintln!("{}", "Validated successfully".green());
|
||||
ExitCode::SUCCESS
|
||||
|
@ -53,6 +65,7 @@ fn main() -> ExitCode {
|
|||
/// - `Ok(true)` if the structure is valid, nothing will have been written to `error_writer`.
|
||||
pub fn check_nixpkgs<W: io::Write>(
|
||||
nixpkgs_path: &Path,
|
||||
_version: Version,
|
||||
eval_accessible_paths: Vec<&Path>,
|
||||
error_writer: &mut W,
|
||||
) -> anyhow::Result<bool> {
|
||||
|
@ -86,6 +99,7 @@ pub fn check_nixpkgs<W: io::Write>(
|
|||
mod tests {
|
||||
use crate::check_nixpkgs;
|
||||
use crate::structure;
|
||||
use crate::Version;
|
||||
use anyhow::Context;
|
||||
use std::fs;
|
||||
use std::path::Path;
|
||||
|
@ -174,7 +188,7 @@ mod tests {
|
|||
// We don't want coloring to mess up the tests
|
||||
let writer = temp_env::with_var("NO_COLOR", Some("1"), || -> anyhow::Result<_> {
|
||||
let mut writer = vec![];
|
||||
check_nixpkgs(&path, vec![&extra_nix_path], &mut writer)
|
||||
check_nixpkgs(&path, Version::V0, vec![&extra_nix_path], &mut writer)
|
||||
.context(format!("Failed test case {name}"))?;
|
||||
Ok(writer)
|
||||
})?;
|
||||
|
|
Loading…
Reference in a new issue