2016-05-26 00:06:25 +00:00
|
|
|
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;
|
|
|
|
|
2016-05-25 20:55:42 +00:00
|
|
|
#[test]
|
|
|
|
fn simple() {
|
2014-07-17 20:00:58 +00:00
|
|
|
let p = project("foo");
|
|
|
|
|
2014-08-21 16:24:34 +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
|
|
|
|
|
|
|
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
|
|
|
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2016-01-31 16:02:47 +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)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-25 20:55:42 +00:00
|
|
|
#[test]
|
|
|
|
fn subcommand_with_version_using_exec_main_without_stdin() {
|
2016-01-31 16:02:47 +00:00
|
|
|
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()));
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|