diff --git a/ofborg/src/checkout.rs b/ofborg/src/checkout.rs index 3814054..1c12764 100644 --- a/ofborg/src/checkout.rs +++ b/ofborg/src/checkout.rs @@ -268,8 +268,9 @@ mod tests { } fn make_pr_repo(bare: &Path, co: &Path) -> String { - let output = Command::new("./make-pr.sh") + let output = Command::new("bash") .current_dir(tpath("./test-srcs")) + .arg("./make-pr.sh") .arg(bare) .arg(co) .stdout(Stdio::piped()) diff --git a/ofborg/src/maintainers.rs b/ofborg/src/maintainers.rs index 8d1090c..4eac602 100644 --- a/ofborg/src/maintainers.rs +++ b/ofborg/src/maintainers.rs @@ -136,13 +136,19 @@ mod tests { use std::process::Command; use std::process::Stdio; + #[cfg(target_os = "linux")] + const SYSTEM: &str = "x86_64-linux"; + #[cfg(target_os = "macos")] + const SYSTEM: &str = "x86_64-darwin"; + fn tpath(component: &str) -> PathBuf { return Path::new(env!("CARGO_MANIFEST_DIR")).join(component); } fn make_pr_repo(bare: &Path, co: &Path) -> String { - let output = Command::new("./make-maintainer-pr.sh") + let output = Command::new("bash") .current_dir(tpath("./test-srcs")) + .arg("./make-maintainer-pr.sh") .arg(bare) .arg(co) .stdout(Stdio::piped()) @@ -183,7 +189,7 @@ mod tests { working_co.checkout_ref(&OsStr::new(&hash)).unwrap(); let remote = env::var("NIX_REMOTE").unwrap_or("".to_owned()); - let nix = Nix::new("x86_64-linux".to_owned(), remote, 1800, None); + let nix = Nix::new(SYSTEM.to_owned(), remote, 1800, None); let parsed = ImpactedMaintainers::calculate(&nix, &working_co.clone_to(), &paths, &attributes); diff --git a/ofborg/src/nix.rs b/ofborg/src/nix.rs index df0bada..1180e37 100644 --- a/ofborg/src/nix.rs +++ b/ofborg/src/nix.rs @@ -380,9 +380,21 @@ pub fn wait_for_build_status(spawned: SpawnedAsyncCmd) -> BuildStatus { #[cfg(test)] mod tests { + use super::*; + use std::env; + use std::path::PathBuf; + + #[cfg(target_os = "linux")] + const SYSTEM: &str = "x86_64-linux"; + #[cfg(target_os = "macos")] + const SYSTEM: &str = "x86_64-darwin"; + fn nix() -> Nix { + let path = env::var("PATH").unwrap(); + let test_path = format!("{}/test-nix/bin:{}", env!("CARGO_MANIFEST_DIR"), path); + env::set_var("PATH", test_path); let remote = env::var("NIX_REMOTE").unwrap_or("".to_owned()); - Nix::new("x86_64-linux".to_owned(), remote, 1800, None) + Nix::new(SYSTEM.to_owned(), remote, 1800, None) } fn noop(operation: Operation) -> Operation { @@ -508,10 +520,6 @@ mod tests { } } - use super::*; - use std::env; - use std::path::PathBuf; - #[test] fn test_build_operations() { let nix = nix(); @@ -607,12 +615,7 @@ mod tests { #[test] fn safe_command_custom_gc() { let remote = env::var("NIX_REMOTE").unwrap_or("".to_owned()); - let nix = Nix::new( - "x86_64-linux".to_owned(), - remote, - 1800, - Some("4g".to_owned()), - ); + let nix = Nix::new(SYSTEM.to_owned(), remote, 1800, Some("4g".to_owned())); let ret: Result = nix.run( nix.safe_command::<&OsStr>(&env_noop(), build_path().as_path(), &[], &[]), @@ -752,10 +755,12 @@ mod tests { "trace: You just can't frooble the frozz on this particular system." ); + eprintln!("{:?}", ret.1[1].1); assert_eq!(ret.1[1].0, "missing-attr"); + let s = strip_ansi(&ret.1[1].1.last().unwrap()); assert_eq!( - strip_ansi(&ret.1[1].1[0]), - "error: attribute 'missing-attr' in selection path 'missing-attr' not found" + s.trim_start_matches("error: "), + "attribute 'missing-attr' in selection path 'missing-attr' not found" ); } @@ -817,11 +822,7 @@ mod tests { assert_run( ret, Expect::Fail, - vec![ - "error: while evaluating the attribute", - "access to path", - "is forbidden in restricted mode", - ], + vec!["access to path", "is forbidden in restricted mode"], ); } diff --git a/ofborg/src/tasks/build.rs b/ofborg/src/tasks/build.rs index e4f32bd..597d9cc 100644 --- a/ofborg/src/tasks/build.rs +++ b/ofborg/src/tasks/build.rs @@ -391,6 +391,11 @@ mod tests { use std::process::{Command, Stdio}; use std::vec::IntoIter; + #[cfg(target_os = "linux")] + const SYSTEM: &str = "x86_64-linux"; + #[cfg(target_os = "macos")] + const SYSTEM: &str = "x86_64-darwin"; + fn nix() -> nix::Nix { let remote = env::var("NIX_REMOTE").unwrap_or("".to_owned()); nix::Nix::new("x86_64-linux".to_owned(), remote, 1800, None) @@ -406,7 +411,7 @@ mod tests { let worker = BuildWorker::new( cloner, nix, - "x86_64-linux".to_owned(), + SYSTEM.to_owned(), "cargo-test-build".to_owned(), ); @@ -414,8 +419,9 @@ mod tests { } fn make_pr_repo(bare: &Path, co: &Path) -> String { - let output = Command::new("./make-pr.sh") + let output = Command::new("bash") .current_dir(tpath("./test-srcs")) + .arg("make-pr.sh") .arg(bare) .arg(co) .stderr(Stdio::null()) @@ -442,11 +448,12 @@ mod tests { worker::Action::Publish(ref body) => { let content = String::from_utf8(body.content.clone()).unwrap(); let text = strip_escaped_ansi(&content); + eprintln!("{}", text); if text.contains(text_to_match) { println!(" ok"); return true; } else { - println!(" notContains: {:?}", text); + println!(" notContains: {}", text); return false; } } @@ -456,8 +463,8 @@ mod tests { } }) .expect(&format!( - "Actions should contain a job matching {:?}, after the previous check", - text_to_match + "Actions should contain a job matching {}, after the previous check", + text_to_match, )); } @@ -544,7 +551,10 @@ mod tests { &mut actions, "\"line_number\":1,\"output\":\"Cannot nix-instantiate `not-real\' because:\"", ); - assert_contains_job(&mut actions, "\"line_number\":2,\"output\":\"error: attribute 'not-real' in selection path 'not-real' not found\"}"); + assert_contains_job( + &mut actions, + "attribute 'not-real' in selection path 'not-real' not found\"}", + ); assert_contains_job(&mut actions, "skipped_attrs\":[\"not-real"); // First one to the github poster assert_contains_job(&mut actions, "skipped_attrs\":[\"not-real"); // This one to the logs assert_eq!(actions.next(), Some(worker::Action::Ack)); diff --git a/ofborg/test-nix/bin/nix-build b/ofborg/test-nix/bin/nix-build new file mode 100755 index 0000000..24911e3 --- /dev/null +++ b/ofborg/test-nix/bin/nix-build @@ -0,0 +1,4 @@ +#!/usr/bin/env bash + +export PATH=${PATH#*:} +exec nix-build "$@" -I "ofborg-test-bash=$(command -v bash)" diff --git a/ofborg/test-nix/bin/nix-instantiate b/ofborg/test-nix/bin/nix-instantiate new file mode 100755 index 0000000..5cf75e2 --- /dev/null +++ b/ofborg/test-nix/bin/nix-instantiate @@ -0,0 +1,4 @@ +#!/usr/bin/env bash + +export PATH=${PATH#*:} +exec nix-instantiate "$@" -I "ofborg-test-bash=$(command -v bash)" diff --git a/ofborg/test-srcs/build-pr/default.nix b/ofborg/test-srcs/build-pr/default.nix index 35e2ada..231e584 100644 --- a/ofborg/test-srcs/build-pr/default.nix +++ b/ofborg/test-srcs/build-pr/default.nix @@ -1,27 +1,26 @@ let - nix = import ; -in { + builder = builtins.storePath ; +in +{ success = derivation { name = "success"; system = builtins.currentSystem; - builder = builtins.storePath nix.shell; - args = [ - "-c" - "echo hi; printf '1\n2\n3\n4\n'; echo ${toString builtins.currentTime} > $out" ]; + inherit builder; + args = [ "-c" "echo hi; printf '1\n2\n3\n4\n'; echo ${toString builtins.currentTime} > $out" ]; }; failed = derivation { name = "failed"; system = builtins.currentSystem; - builder = builtins.storePath nix.shell; - args = [ - "-c" - "echo hi; echo ${toString builtins.currentTime}" ]; + inherit builder; + args = [ "-c" "echo hi; echo ${toString builtins.currentTime}" ]; }; sandbox-violation = derivation { name = "sandbox-violation"; system = builtins.currentSystem; - builder = ./../../src; + inherit builder; + args = [ "-c" "echo hi; echo ${toString builtins.currentTime} > $out" ]; + src = ./../../src; }; } diff --git a/ofborg/test-srcs/build/default.nix b/ofborg/test-srcs/build/default.nix index ba7eb25..6c57488 100644 --- a/ofborg/test-srcs/build/default.nix +++ b/ofborg/test-srcs/build/default.nix @@ -1,27 +1,26 @@ let - nix = import ; -in { + builder = builtins.storePath ; +in +{ success = derivation { name = "success"; system = builtins.currentSystem; - builder = builtins.storePath nix.shell; - args = [ - "-c" - "echo hi; echo ${toString builtins.currentTime} > $out" ]; + inherit builder; + args = [ "-c" "echo hi; echo ${toString builtins.currentTime} > $out" ]; }; failed = derivation { name = "failed"; system = builtins.currentSystem; - builder = builtins.storePath nix.shell; - args = [ - "-c" - "echo hi; echo ${toString builtins.currentTime}" ]; + inherit builder; + args = [ "-c" "echo hi; echo ${toString builtins.currentTime}" ]; }; sandbox-violation = derivation { name = "sandbox-violation"; system = builtins.currentSystem; - builder = ./../../src; + src = ./../../src; + inherit builder; + args = [ "-c" "echo hi; echo ${toString builtins.currentTime} > $out" ]; }; } diff --git a/ofborg/test-srcs/eval-mixed-failure/default.nix b/ofborg/test-srcs/eval-mixed-failure/default.nix index 72b8b46..067c72a 100644 --- a/ofborg/test-srcs/eval-mixed-failure/default.nix +++ b/ofborg/test-srcs/eval-mixed-failure/default.nix @@ -1,51 +1,44 @@ let fetchGit = builtins.fetchGit or (path: assert builtins.trace '' error: access to path '/fake' is forbidden in restricted mode - '' false; path); + '' + false; path); - nix = import ; + builder = builtins.storePath ; in - { nixpkgs ? fetchGit /fake }: rec { success = derivation { name = "success"; system = builtins.currentSystem; - builder = builtins.storePath nix.shell; - args = [ - "-c" - "echo hi; echo ${toString builtins.currentTime} > $out" ]; + inherit builder; + args = [ "-c" "echo hi; echo ${toString builtins.currentTime} > $out" ]; }; failed = derivation { name = "failed"; system = builtins.currentSystem; - builder = builtins.storePath nix.shell; - args = [ - "-c" - "echo hi; echo ${toString builtins.currentTime}; echo ${success}" ]; + inherit builder; + args = [ "-c" "echo hi; echo ${toString builtins.currentTime}; echo ${success}" ]; }; passes-instantiation = derivation { name = "passes-instantiation"; system = builtins.currentSystem; - builder = builtins.storePath nix.shell; - args = [ - "-c" - "echo this ones cool" ]; + inherit builder; + args = [ "-c" "echo this ones cool" ]; }; nixpkgs-restricted-mode = derivation { name = "nixpkgs-restricted-mode-fetchgit"; system = builtins.currentSystem; - builder = nix.shell; - args = [ - "-c" - "echo hi; echo ${toString nixpkgs} > $out" ]; + inherit builder; + args = [ "-c" "echo hi; echo ${toString nixpkgs} > $out" ]; }; fails-instantiation = assert builtins.trace '' You just can't frooble the frozz on this particular system. - '' false; {}; + '' + false; { }; } diff --git a/ofborg/test-srcs/eval/default.nix b/ofborg/test-srcs/eval/default.nix index 34a7247..e95f0dd 100644 --- a/ofborg/test-srcs/eval/default.nix +++ b/ofborg/test-srcs/eval/default.nix @@ -1,21 +1,18 @@ let - nix = import ; -in rec { + builder = builtins.storePath ; +in +rec { success = derivation { name = "success"; system = builtins.currentSystem; - builder = builtins.storePath nix.shell; - args = [ - "-c" - "echo hi; echo ${toString builtins.currentTime} > $out" ]; + inherit builder; + args = [ "-c" "echo hi; echo ${toString builtins.currentTime} > $out" ]; }; failed = derivation { name = "failed"; system = builtins.currentSystem; - builder = builtins.storePath nix.shell; - args = [ - "-c" - "echo hi; echo ${toString builtins.currentTime}; echo ${success}" ]; + inherit builder; + args = [ "-c" "echo hi; echo ${toString builtins.currentTime}; echo ${success}" ]; }; } diff --git a/ofborg/test-srcs/maintainers/default.nix b/ofborg/test-srcs/maintainers/default.nix index 712a555..961bb32 100644 --- a/ofborg/test-srcs/maintainers/default.nix +++ b/ofborg/test-srcs/maintainers/default.nix @@ -1,6 +1,5 @@ { ... }: { lib = import ./lib; - foo.bar.packageA = { - }; + foo.bar.packageA = { }; }