cargo/tests/version.rs

52 lines
1.4 KiB
Rust
Raw Normal View History

extern crate cargo;
extern crate cargotest;
extern crate hamcrest;
extern crate rustc_serialize;
use cargotest::support::{project, execs};
2014-07-17 20:00:58 +00:00
use hamcrest::assert_that;
#[test]
fn simple() {
2014-07-17 20:00:58 +00:00
let p = project("foo");
assert_that(p.cargo_process("version"),
2015-03-26 18:17:44 +00:00
execs().with_status(0).with_stdout(&format!("{}\n",
cargo::version())));
2014-12-15 06:17:51 +00:00
assert_that(p.cargo_process("--version"),
2015-03-26 18:17:44 +00:00
execs().with_status(0).with_stdout(&format!("{}\n",
cargo::version())));
2014-12-15 06:17:51 +00:00
}
#[derive(RustcDecodable)]
struct FooFlags {
flag_version: bool,
}
fn real_main(flags: FooFlags, _config: &cargo::Config) ->
cargo::CliResult<Option<String>> {
if flags.flag_version {
Ok(Some("foo <version>".to_string()))
} else {
Ok(None)
}
}
#[test]
fn subcommand_with_version_using_exec_main_without_stdin() {
let usage = "
Usage: cargo foo [--version]
Options:
-V, --version Print version info
";
let args: Vec<String> = vec!["cargo", "foo", "--version"]
.into_iter().map(|s| s.to_string()).collect();
let result = cargo::call_main_without_stdin(
real_main, &cargo::Config::default().unwrap(),
usage, &args, false);
assert_eq!(result.unwrap(), Some("foo <version>".to_string()));
}