Skip to content

Commit

Permalink
Run rustfmt
Browse files Browse the repository at this point in the history
  • Loading branch information
alexcrichton committed Sep 9, 2019
1 parent fba0bbd commit 1aab24d
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 66 deletions.
15 changes: 8 additions & 7 deletions tests/client-of-myself.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
extern crate jobserver;

use std::env;
use std::io::BufReader;
use std::io::prelude::*;
use std::io::BufReader;
use std::process::{Command, Stdio};
use std::sync::mpsc;
use std::thread;

use jobserver::Client;

macro_rules! t {
($e:expr) => (match $e {
Ok(e) => e,
Err(e) => panic!("{} failed with {}", stringify!($e), e),
})
($e:expr) => {
match $e {
Ok(e) => e,
Err(e) => panic!("{} failed with {}", stringify!($e), e),
}
};
}

fn main() {
Expand All @@ -28,8 +30,7 @@ fn server() {
let me = t!(env::current_exe());
let client = t!(Client::new(1));
let mut cmd = Command::new(me);
cmd.env("I_AM_THE_CLIENT", "1")
.stdout(Stdio::piped());
cmd.env("I_AM_THE_CLIENT", "1").stdout(Stdio::piped());
client.configure(&mut cmd);
let acq = client.acquire().unwrap();
let mut child = t!(cmd.spawn());
Expand Down
60 changes: 33 additions & 27 deletions tests/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ use std::env;
use std::fs::File;
use std::io::Write;
use std::process::Command;
use std::sync::Arc;
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::mpsc;
use std::sync::Arc;
use std::thread;

use futures::future::{self, Future};
Expand All @@ -22,10 +22,12 @@ use tokio_core::reactor::Core;
use tokio_process::CommandExt;

macro_rules! t {
($e:expr) => (match $e {
Ok(e) => e,
Err(e) => panic!("{} failed with {}", stringify!($e), e),
})
($e:expr) => {
match $e {
Ok(e) => e,
Err(e) => panic!("{} failed with {}", stringify!($e), e),
}
};
}

struct Test {
Expand Down Expand Up @@ -117,7 +119,7 @@ const TESTS: &[Test] = &[

fn main() {
if let Ok(test) = env::var("TEST_TO_RUN") {
return (TESTS.iter().find(|t| t.name == test).unwrap().f)()
return (TESTS.iter().find(|t| t.name == test).unwrap().f)();
}

let me = t!(env::current_exe());
Expand All @@ -126,36 +128,40 @@ fn main() {

let mut core = t!(Core::new());

let futures = TESTS.iter().filter(|test| {
match filter {
let futures = TESTS
.iter()
.filter(|test| match filter {
Some(ref s) => test.name.contains(s),
None => true,
}
}).map(|test| {
let td = t!(TempDir::new("foo"));
let makefile = format!("\
})
.map(|test| {
let td = t!(TempDir::new("foo"));
let makefile = format!(
"\
all: export TEST_TO_RUN={}
all:
\t{}
", test.name, (test.rule)(me));
t!(t!(File::create(td.path().join("Makefile")))
.write_all(makefile.as_bytes()));
let prog = env::var("MAKE").unwrap_or("make".to_string());
let mut cmd = Command::new(prog);
cmd.args(test.make_args);
cmd.current_dir(td.path());
future::lazy(move || {
cmd.output_async().map(move |e| {
drop(td);
(test, e)
",
test.name,
(test.rule)(me)
);
t!(t!(File::create(td.path().join("Makefile"))).write_all(makefile.as_bytes()));
let prog = env::var("MAKE").unwrap_or("make".to_string());
let mut cmd = Command::new(prog);
cmd.args(test.make_args);
cmd.current_dir(td.path());
future::lazy(move || {
cmd.output_async().map(move |e| {
drop(td);
(test, e)
})
})
})
}).collect::<Vec<_>>();
.collect::<Vec<_>>();

println!("\nrunning {} tests\n", futures.len());

let stream = stream::iter(futures.into_iter().map(Ok))
.buffer_unordered(num_cpus::get());
let stream = stream::iter(futures.into_iter().map(Ok)).buffer_unordered(num_cpus::get());

let mut failures = Vec::new();
t!(core.run(stream.for_each(|(test, output)| {
Expand All @@ -170,7 +176,7 @@ all:

if failures.len() == 0 {
println!("\ntest result: ok\n");
return
return;
}

println!("\n----------- failures");
Expand Down
14 changes: 9 additions & 5 deletions tests/helper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ use std::sync::mpsc;
use jobserver::Client;

macro_rules! t {
($e:expr) => (match $e {
Ok(e) => e,
Err(e) => panic!("{} failed with {}", stringify!($e), e),
})
($e:expr) => {
match $e {
Ok(e) => e,
Err(e) => panic!("{} failed with {}", stringify!($e), e),
}
};
}

#[test]
Expand All @@ -26,7 +28,9 @@ fn helper_smoke() {
fn acquire() {
let (tx, rx) = mpsc::channel();
let client = t!(Client::new(1));
let helper = client.into_helper_thread(move |a| drop(tx.send(a))).unwrap();
let helper = client
.into_helper_thread(move |a| drop(tx.send(a)))
.unwrap();
assert!(rx.try_recv().is_err());
helper.request_token();
rx.recv().unwrap().unwrap();
Expand Down
26 changes: 17 additions & 9 deletions tests/make-as-a-client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,19 @@ extern crate tempdir;
use std::env;
use std::fs::File;
use std::io::prelude::*;
use std::net::{TcpStream, TcpListener};
use std::net::{TcpListener, TcpStream};
use std::process::Command;

use jobserver::Client;
use tempdir::TempDir;

macro_rules! t {
($e:expr) => (match $e {
Ok(e) => e,
Err(e) => panic!("{} failed with {}", stringify!($e), e),
})
($e:expr) => {
match $e {
Ok(e) => e,
Err(e) => panic!("{} failed with {}", stringify!($e), e),
}
};
}

fn main() {
Expand All @@ -27,14 +29,14 @@ fn main() {
.status()
.unwrap()
.code()
.unwrap_or(1)
.unwrap_or(1),
);
}

if let Ok(s) = env::var("TEST_ADDR") {
let mut contents = Vec::new();
t!(t!(TcpStream::connect(&s)).read_to_end(&mut contents));
return
return;
}

let c = t!(Client::new(1));
Expand All @@ -50,13 +52,19 @@ fn main() {
cmd.env("MAKE", prog);
cmd.env("_DO_THE_TEST", "1");

t!(t!(File::create(td.path().join("Makefile"))).write_all(format!("\
t!(t!(File::create(td.path().join("Makefile"))).write_all(
format!(
"\
all: foo bar
foo:
\t{0}
bar:
\t{0}
", me).as_bytes()));
",
me
)
.as_bytes()
));

// We're leaking one extra token to `make` sort of violating the makefile
// jobserver protocol. It has the desired effect though.
Expand Down
52 changes: 34 additions & 18 deletions tests/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,21 @@ use std::env;
use std::fs::File;
use std::io::prelude::*;
use std::process::Command;
use std::sync::Arc;
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::mpsc;
use std::sync::Arc;
use std::thread;

use jobserver::Client;
use tempdir::TempDir;

macro_rules! t {
($e:expr) => (match $e {
Ok(e) => e,
Err(e) => panic!("{} failed with {}", stringify!($e), e),
})
($e:expr) => {
match $e {
Ok(e) => e,
Err(e) => panic!("{} failed with {}", stringify!($e), e),
}
};
}

#[test]
Expand Down Expand Up @@ -63,24 +65,30 @@ fn make_as_a_single_thread_client() {
let mut cmd = Command::new(prog);
cmd.current_dir(td.path());

t!(t!(File::create(td.path().join("Makefile"))).write_all(b"
t!(t!(File::create(td.path().join("Makefile"))).write_all(
b"
all: foo bar
foo:
\techo foo
bar:
\techo bar
"));
"
));

// The jobserver protocol means that the `make` process itself "runs with a
// token", so we acquire our one token to drain the jobserver, and this
// should mean that `make` itself never has a second token available to it.
let _a = c.acquire();
c.configure(&mut cmd);
let output = t!(cmd.output());
println!("\n\t=== stderr\n\t\t{}",
String::from_utf8_lossy(&output.stderr).replace("\n", "\n\t\t"));
println!("\t=== stdout\n\t\t{}",
String::from_utf8_lossy(&output.stdout).replace("\n", "\n\t\t"));
println!(
"\n\t=== stderr\n\t\t{}",
String::from_utf8_lossy(&output.stderr).replace("\n", "\n\t\t")
);
println!(
"\t=== stdout\n\t\t{}",
String::from_utf8_lossy(&output.stdout).replace("\n", "\n\t\t")
);

assert!(output.status.success());
assert!(output.stderr.is_empty());
Expand Down Expand Up @@ -111,22 +119,28 @@ fn make_as_a_multi_thread_client() {
let mut cmd = Command::new(prog);
cmd.current_dir(td.path());

t!(t!(File::create(td.path().join("Makefile"))).write_all(b"
t!(t!(File::create(td.path().join("Makefile"))).write_all(
b"
all: foo bar
foo:
\techo foo
bar:
\techo bar
"));
"
));

// We're leaking one extra token to `make` sort of violating the makefile
// jobserver protocol. It has the desired effect though.
c.configure(&mut cmd);
let output = t!(cmd.output());
println!("\n\t=== stderr\n\t\t{}",
String::from_utf8_lossy(&output.stderr).replace("\n", "\n\t\t"));
println!("\t=== stdout\n\t\t{}",
String::from_utf8_lossy(&output.stdout).replace("\n", "\n\t\t"));
println!(
"\n\t=== stderr\n\t\t{}",
String::from_utf8_lossy(&output.stderr).replace("\n", "\n\t\t")
);
println!(
"\t=== stdout\n\t\t{}",
String::from_utf8_lossy(&output.stdout).replace("\n", "\n\t\t")
);

assert!(output.status.success());
}
Expand All @@ -135,7 +149,9 @@ bar:
fn zero_client() {
let client = t!(Client::new(0));
let (tx, rx) = mpsc::channel();
let helper = client.into_helper_thread(move |a| drop(tx.send(a))).unwrap();
let helper = client
.into_helper_thread(move |a| drop(tx.send(a)))
.unwrap();
helper.request_token();
helper.request_token();

Expand Down

0 comments on commit 1aab24d

Please sign in to comment.