2020-08-24 17:23:37 +00:00
|
|
|
#![cfg(not(tarpaulin))]
|
|
|
|
|
2020-08-23 16:49:05 +00:00
|
|
|
use std::ffi::OsStr;
|
|
|
|
use std::fs;
|
|
|
|
use std::process::{Command, Output};
|
|
|
|
|
|
|
|
fn run_example<S: AsRef<str>>(name: S, args: &[&str]) -> Output {
|
2021-11-18 20:27:21 +00:00
|
|
|
let mut all_args = vec!["run", "--example", name.as_ref(), "--"];
|
2020-08-23 16:49:05 +00:00
|
|
|
all_args.extend_from_slice(args);
|
|
|
|
|
|
|
|
Command::new(env!("CARGO"))
|
|
|
|
.args(all_args)
|
|
|
|
.output()
|
|
|
|
.expect("failed to run example")
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn examples_are_functional() {
|
|
|
|
let example_paths = fs::read_dir("examples")
|
|
|
|
.expect("couldn't read examples directory")
|
|
|
|
.map(|result| result.expect("couldn't get directory entry").path())
|
|
|
|
.filter(|path| path.is_file() && path.extension().and_then(OsStr::to_str) == Some("rs"));
|
|
|
|
|
|
|
|
let mut example_count = 0;
|
|
|
|
for path in example_paths {
|
|
|
|
example_count += 1;
|
|
|
|
|
2021-10-12 18:57:32 +00:00
|
|
|
let example_name = match path.file_name().and_then(OsStr::to_str) {
|
2021-10-15 19:59:33 +00:00
|
|
|
Some("24a_multicall_busybox.rs") => {
|
|
|
|
#[cfg(not(feature = "unstable-multicall"))]
|
|
|
|
continue;
|
|
|
|
#[allow(unreachable_code)]
|
2021-11-17 20:23:22 +00:00
|
|
|
"busybox"
|
2021-10-15 20:14:07 +00:00
|
|
|
}
|
2021-10-15 19:59:33 +00:00
|
|
|
Some("24b_multicall_hostname.rs") => {
|
|
|
|
#[cfg(not(feature = "unstable-multicall"))]
|
|
|
|
continue;
|
|
|
|
#[allow(unreachable_code)]
|
2021-11-17 20:23:22 +00:00
|
|
|
"hostname"
|
2021-10-15 20:14:07 +00:00
|
|
|
}
|
2021-10-12 18:57:32 +00:00
|
|
|
_ => path
|
|
|
|
.file_stem()
|
|
|
|
.and_then(OsStr::to_str)
|
|
|
|
.expect("unable to determine example name"),
|
|
|
|
};
|
2020-08-23 16:49:05 +00:00
|
|
|
|
|
|
|
let help_output = run_example(example_name, &["--help"]);
|
|
|
|
assert!(
|
|
|
|
help_output.status.success(),
|
2021-08-18 16:49:43 +00:00
|
|
|
"{} --help exited with nonzero: {}",
|
2020-08-23 16:49:05 +00:00
|
|
|
example_name,
|
2021-08-18 16:49:43 +00:00
|
|
|
String::from_utf8_lossy(&help_output.stderr),
|
2020-08-23 16:49:05 +00:00
|
|
|
);
|
|
|
|
assert!(
|
|
|
|
!help_output.stdout.is_empty(),
|
|
|
|
"{} --help had no output",
|
|
|
|
example_name,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
assert!(example_count > 0);
|
|
|
|
}
|