use std::io::Read;
use std::process::{Command, Stdio};
use radicle::profile;
use crate::util::environment::Environment;
#[test]
fn config() {
let mut environment = Environment::new();
let profile = environment.profile("alice");
let rad = env!("CARGO_BIN_EXE_rad");
let mut child = Command::new(rad)
.arg("config")
.env("RAD_HOME", profile.home.path())
.env(profile::env::RAD_PASSPHRASE, "radicle")
.stdout(Stdio::piped())
.stderr(Stdio::piped())
.spawn()
.expect("failed to spawn rad");
let mut stdout = child.stdout.take().unwrap();
let mut buf = [0u8; 1];
let _ = stdout.read(&mut buf);
drop(stdout);
let output = child.wait_with_output().expect("failed to wait on rad");
let stderr = String::from_utf8_lossy(&output.stderr);
let code = output.status.code();
assert!(
code != Some(101),
"rad panicked on broken pipe (exit code 101).\nstderr:\n{stderr}"
);
assert!(
!stderr.contains("panicked at"),
"rad panicked on broken pipe.\nstderr:\n{stderr}"
);
}
#[test]
fn help() {
let rad = env!("CARGO_BIN_EXE_rad");
let mut child = Command::new(rad)
.arg("--help")
.stdout(Stdio::piped())
.stderr(Stdio::piped())
.spawn()
.expect("failed to spawn rad");
let mut stdout = child.stdout.take().unwrap();
let mut buf = [0u8; 1];
let _ = stdout.read(&mut buf);
drop(stdout);
let output = child.wait_with_output().expect("failed to wait on rad");
let stderr = String::from_utf8_lossy(&output.stderr);
let code = output.status.code();
assert!(
code != Some(101),
"rad panicked on broken pipe (exit code 101).\nstderr:\n{stderr}"
);
assert!(
!stderr.contains("panicked at"),
"rad panicked on broken pipe.\nstderr:\n{stderr}"
);
}
#[test]
fn rad_self() {
let mut environment = Environment::new();
let profile = environment.profile("alice");
let rad = env!("CARGO_BIN_EXE_rad");
let mut child = Command::new(rad)
.arg("self")
.env("RAD_HOME", profile.home.path())
.env(profile::env::RAD_PASSPHRASE, "radicle")
.stdout(Stdio::piped())
.stderr(Stdio::piped())
.spawn()
.expect("failed to spawn rad");
let mut stdout = child.stdout.take().unwrap();
let mut buf = [0u8; 1];
let _ = stdout.read(&mut buf);
drop(stdout);
let output = child.wait_with_output().expect("failed to wait on rad");
let stderr = String::from_utf8_lossy(&output.stderr);
let code = output.status.code();
assert!(
code != Some(101),
"rad panicked on broken pipe (exit code 101).\nstderr:\n{stderr}"
);
assert!(
!stderr.contains("panicked at"),
"rad panicked on broken pipe.\nstderr:\n{stderr}"
);
}