Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: NixOS/ofborg
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 524cd74056a1
Choose a base ref
...
head repository: NixOS/ofborg
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: d39605727d95
Choose a head ref
  • 5 commits
  • 11 files changed
  • 1 contributor

Commits on Nov 7, 2020

  1. make tests a bit less platform dependent

    NOTE The tests that use nix don't work with nixUnstable since <nix/config.nix>
    was removed, which the test expressions depend on.
    LnL7 committed Nov 7, 2020
    Copy the full SHA
    2ddee3c View commit details
  2. handle nixUnstable output

    LnL7 committed Nov 7, 2020
    Copy the full SHA
    8c91336 View commit details
  3. remove <nix/config.nix> usages

    This was removed in nixUnstable.
    LnL7 committed Nov 7, 2020
    Copy the full SHA
    6449f71 View commit details
  4. test-srcs: apply nixpkgs-fmt

    LnL7 committed Nov 7, 2020
    Copy the full SHA
    502f1dd View commit details

Commits on Nov 8, 2020

  1. Merge pull request #537 from LnL7/fix-tests

    fix tests with nixUnstable
    LnL7 authored Nov 8, 2020
    Copy the full SHA
    d396057 View commit details
3 changes: 2 additions & 1 deletion ofborg/src/checkout.rs
Original file line number Diff line number Diff line change
@@ -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())
10 changes: 8 additions & 2 deletions ofborg/src/maintainers.rs
Original file line number Diff line number Diff line change
@@ -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);
37 changes: 19 additions & 18 deletions ofborg/src/nix.rs
Original file line number Diff line number Diff line change
@@ -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<fs::File, fs::File> = 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"],
);
}

22 changes: 16 additions & 6 deletions ofborg/src/tasks/build.rs
Original file line number Diff line number Diff line change
@@ -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,16 +411,17 @@ mod tests {
let worker = BuildWorker::new(
cloner,
nix,
"x86_64-linux".to_owned(),
SYSTEM.to_owned(),
"cargo-test-build".to_owned(),
);

worker
}

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));
4 changes: 4 additions & 0 deletions ofborg/test-nix/bin/nix-build
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env bash

export PATH=${PATH#*:}
exec nix-build "$@" -I "ofborg-test-bash=$(command -v bash)"
4 changes: 4 additions & 0 deletions ofborg/test-nix/bin/nix-instantiate
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env bash

export PATH=${PATH#*:}
exec nix-instantiate "$@" -I "ofborg-test-bash=$(command -v bash)"
21 changes: 10 additions & 11 deletions ofborg/test-srcs/build-pr/default.nix
Original file line number Diff line number Diff line change
@@ -1,27 +1,26 @@
let
nix = import <nix/config.nix>;
in {
builder = builtins.storePath <ofborg-test-bash>;
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;
};
}
21 changes: 10 additions & 11 deletions ofborg/test-srcs/build/default.nix
Original file line number Diff line number Diff line change
@@ -1,27 +1,26 @@
let
nix = import <nix/config.nix>;
in {
builder = builtins.storePath <ofborg-test-bash>;
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" ];
};
}
33 changes: 13 additions & 20 deletions ofborg/test-srcs/eval-mixed-failure/default.nix
Original file line number Diff line number Diff line change
@@ -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 <nix/config.nix>;
builder = builtins.storePath <ofborg-test-bash>;
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; { };
}
17 changes: 7 additions & 10 deletions ofborg/test-srcs/eval/default.nix
Original file line number Diff line number Diff line change
@@ -1,21 +1,18 @@
let
nix = import <nix/config.nix>;
in rec {
builder = builtins.storePath <ofborg-test-bash>;
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}" ];
};
}
3 changes: 1 addition & 2 deletions ofborg/test-srcs/maintainers/default.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{ ... }:
{
lib = import ./lib;
foo.bar.packageA = {
};
foo.bar.packageA = { };
}