mirror of
https://github.com/clap-rs/clap
synced 2024-11-10 23:04:23 +00:00
test: Add test for default_value_os_t
This commit is contained in:
parent
b1be436eda
commit
4d521429be
1 changed files with 26 additions and 0 deletions
|
@ -1,3 +1,5 @@
|
|||
use std::path::PathBuf;
|
||||
|
||||
use clap::{CommandFactory, Parser};
|
||||
|
||||
use crate::utils;
|
||||
|
@ -44,6 +46,30 @@ fn auto_default_value_t() {
|
|||
assert!(help.contains("[default: 0]"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn default_value_os_t() {
|
||||
#[derive(Parser, PartialEq, Debug)]
|
||||
struct Opt {
|
||||
#[clap(value_parser, default_value_os_t = PathBuf::from("abc.def"))]
|
||||
arg: PathBuf,
|
||||
}
|
||||
assert_eq!(
|
||||
Opt {
|
||||
arg: PathBuf::from("abc.def")
|
||||
},
|
||||
Opt::try_parse_from(&["test"]).unwrap()
|
||||
);
|
||||
assert_eq!(
|
||||
Opt {
|
||||
arg: PathBuf::from("ghi")
|
||||
},
|
||||
Opt::try_parse_from(&["test", "ghi"]).unwrap()
|
||||
);
|
||||
|
||||
let help = utils::get_long_help::<Opt>();
|
||||
assert!(help.contains("[default: abc.def]"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn detect_os_variant() {
|
||||
#![allow(unused_parens)] // needed for `as_ref` call
|
||||
|
|
Loading…
Reference in a new issue