extern crate which;
use std::path;
use std::ffi::OsStr;
pub struct Assert(std::process::Command);
impl Assert {
pub fn new() -> Self {
let executable = which::which("rustdoc").expect("rustdoc not found");
Assert(std::process::Command::new(executable))
}
pub fn library_path<S>(&mut self, path: S) -> &mut Self
where
S: AsRef<OsStr>,
{
self.0.arg("--library-path").arg(path);
self
}
pub fn cfg<S>(&mut self, cfg: S) -> &mut Self
where
S: AsRef<OsStr>,
{
self.0.arg("--cfg").arg(cfg);
self
}
pub fn test_file<P>(&mut self, path: P)
where
P: AsRef<path::Path>,
{
let process = self.0.arg("--test").arg(path.as_ref()).spawn();
let result = process
.expect("rustdoc is runnable")
.wait()
.expect("rustdoc can run");
assert!(
result.success(),
format!("Failed to run rustdoc tests on '{:?}'", path.as_ref())
);
}
}
impl Default for Assert {
fn default() -> Self {
let mut assert = Self::new();
let current_exe = std::env::current_exe()
.and_then(|p| p.canonicalize())
.expect("could not get path to test executable");
assert.library_path(current_exe.parent().expect("parent exists"));
assert
}
}
pub fn assert_file<P>(documentation: P)
where
P: AsRef<path::Path>,
{
Assert::default().test_file(documentation);
}