From 23541bed72c8385acddfc8e7ba0bd15d5a2c26af Mon Sep 17 00:00:00 2001 From: Silvan Mosberger Date: Thu, 12 Oct 2023 01:51:21 +0200 Subject: [PATCH] tests.nixpkgs-check-by-name: Introduce --version --- pkgs/test/nixpkgs-check-by-name/README.md | 6 ++++++ pkgs/test/nixpkgs-check-by-name/src/main.rs | 22 +++++++++++++++++---- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/pkgs/test/nixpkgs-check-by-name/README.md b/pkgs/test/nixpkgs-check-by-name/README.md index 4dd694acd2f0..ebd1cd40aba0 100644 --- a/pkgs/test/nixpkgs-check-by-name/README.md +++ b/pkgs/test/nixpkgs-check-by-name/README.md @@ -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 ` - Arguments: - ``: The path to the Nixpkgs to check + - `--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 diff --git a/pkgs/test/nixpkgs-check-by-name/src/main.rs b/pkgs/test/nixpkgs-check-by-name/src/main.rs index 8c663061bb09..5c51f32b5cec 100644 --- a/pkgs/test/nixpkgs-check-by-name/src/main.rs +++ b/pkgs/test/nixpkgs-check-by-name/src/main.rs @@ -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( nixpkgs_path: &Path, + _version: Version, eval_accessible_paths: Vec<&Path>, error_writer: &mut W, ) -> anyhow::Result { @@ -86,6 +99,7 @@ pub fn check_nixpkgs( 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) })?;