Add tests for option evaluation of nixpkgs 22.11

This commit is contained in:
oxalica 2023-05-05 10:45:13 +08:00
parent 2c65120ddf
commit c2f303fd8b
5 changed files with 125 additions and 24 deletions

28
Cargo.lock generated
View file

@ -541,7 +541,17 @@ checksum = "7d17b78036a60663b797adeaee46f5c9dfebb86948d1255007a1d6be0271ff99"
dependencies = [
"instant",
"lock_api",
"parking_lot_core",
"parking_lot_core 0.8.6",
]
[[package]]
name = "parking_lot"
version = "0.12.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3742b2c103b9f06bc9fff0a37ff4912935851bee6d36f3c02bcc755bcfec228f"
dependencies = [
"lock_api",
"parking_lot_core 0.9.7",
]
[[package]]
@ -558,6 +568,19 @@ dependencies = [
"winapi",
]
[[package]]
name = "parking_lot_core"
version = "0.9.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9069cbb9f99e3a5083476ccb29ceb1de18b9118cafa53e90c9551235de2b9521"
dependencies = [
"cfg-if",
"libc",
"redox_syscall",
"smallvec",
"windows-sys 0.45.0",
]
[[package]]
name = "percent-encoding"
version = "2.2.0"
@ -746,7 +769,7 @@ dependencies = [
"lock_api",
"log",
"oorandom",
"parking_lot",
"parking_lot 0.11.2",
"rustc-hash",
"salsa-macros",
"smallvec",
@ -972,6 +995,7 @@ dependencies = [
"bytes",
"libc",
"mio",
"parking_lot 0.12.1",
"pin-project-lite",
"signal-hook-registry",
"socket2",

View file

@ -14,4 +14,4 @@ syntax = { path = "../syntax" }
tokio = { version = "1.27.0", features = ["io-util", "macros", "process", "sync"] }
[dev-dependencies]
tokio = { version = "1.27.0", features = ["macros", "rt", "sync"] }
tokio = { version = "1.27.0", features = ["macros", "parking_lot", "rt", "sync"] } # parking_lot is required for `OnceCell::const_new`.

View file

@ -157,30 +157,42 @@ pub enum Ty {
#[cfg(test)]
mod tests {
use tokio::sync::OnceCell;
use crate::FlakeUrl;
use super::*;
#[tokio::test]
#[ignore = "requires using 'nix' and '<nixpkgs>'"]
async fn nixos_options() {
let output = Command::new("nix")
.kill_on_drop(true)
.args([
"eval",
"--experimental-features",
"nix-command",
"--impure",
"--expr",
"<nixpkgs>",
])
.stdin(Stdio::null())
.stdout(Stdio::piped())
.stderr(Stdio::inherit())
.output()
async fn check_nixpkgs(name: &str) {
static LOCKED: OnceCell<serde_json::Value> = OnceCell::const_new();
let nixpkgs_path = LOCKED
.get_or_init(|| async {
let output = Command::new("nix")
.kill_on_drop(true)
.args([
"flake",
"archive",
"--experimental-features",
"nix-command flakes",
"--json",
])
.arg(FlakeUrl::new_path("./tests/nixpkgs_revs"))
.stdin(Stdio::null())
// Configures stdout/stderr automatically.
.output()
.await
.unwrap();
serde_json::from_slice::<serde_json::Value>(&output.stdout).unwrap()
})
.await
.unwrap();
assert!(output.status.success());
let nixpkgs_path = String::from_utf8(output.stdout).unwrap();
let opts = eval_all_options("nix".as_ref(), nixpkgs_path.trim().as_ref())
.pointer(&format!("/inputs/{name}/path"))
.unwrap()
.as_str()
.unwrap()
.to_owned();
let opts = eval_all_options("nix".as_ref(), nixpkgs_path.as_ref())
.await
.unwrap();
@ -193,4 +205,16 @@ mod tests {
Some(Doc::Markdown { text }) if text.starts_with("Whether to enable Nix.")
));
}
#[tokio::test]
#[ignore = "requires using 'nix' and network"]
async fn nixos_unstable() {
check_nixpkgs("nixos-unstable").await;
}
#[tokio::test]
#[ignore = "requires using 'nix' and '<nixpkgs>'"]
async fn nixos_22_11() {
check_nixpkgs("nixos-22-11").await;
}
}

View file

@ -0,0 +1,44 @@
{
"nodes": {
"nixos-22-11": {
"locked": {
"lastModified": 1683207485,
"narHash": "sha256-gs+PHt/y/XQB7S8+YyBLAM8LjgYpPZUVFQBwpFSmJro=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "cc45a3f8c98e1c33ca996e3504adefbf660a72d1",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixos-22.11",
"repo": "nixpkgs",
"type": "github"
}
},
"nixos-unstable": {
"locked": {
"lastModified": 1683014792,
"narHash": "sha256-6Va9iVtmmsw4raBc3QKvQT2KT/NGRWlvUlJj46zN8B8=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "1a411f23ba299db155a5b45d5e145b85a7aafc42",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixos-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"root": {
"inputs": {
"nixos-22-11": "nixos-22-11",
"nixos-unstable": "nixos-unstable"
}
}
},
"root": "root",
"version": 7
}

View file

@ -0,0 +1,9 @@
{
# Just for tests. No need to be up-to-date.
inputs = {
nixos-unstable.url = "github:NixOS/nixpkgs/nixos-unstable";
nixos-22-11.url = "github:NixOS/nixpkgs/nixos-22.11";
};
outputs = inputs: { };
}