feat: release Dever 0.1.4 with enforceable project guidance
This commit is contained in:
1 parent
201bdee372
commit
89629c2197
86 files changed
+2798
-338
No files matched your search
@@ -0,0 +1,84 @@
|
||||
use super::{Action, OsString, arguments_for};
|
||||
use std::time::Duration;
|
||||
|
||||
#[test]
|
||||
fn test_options_default_to_sixty_seconds_and_accept_either_order() {
|
||||
for options in [
|
||||
vec![],
|
||||
vec!["--filter", "sample.account.case_2"],
|
||||
vec!["--filter", "sample.account", "--timeout-ms", "15"],
|
||||
vec!["--timeout-ms", "15", "--filter", "sample"],
|
||||
vec!["--timeout-ms", "18446744073709551615"],
|
||||
] {
|
||||
let arguments: Vec<_> = [vec!["test", "project"], options.clone()]
|
||||
.concat()
|
||||
.into_iter()
|
||||
.map(OsString::from)
|
||||
.collect();
|
||||
let (root, action) = arguments_for(&arguments).unwrap();
|
||||
assert_eq!(root.to_str(), Some("project"));
|
||||
let Action::Test(parsed) = action else {
|
||||
panic!("expected test")
|
||||
};
|
||||
let timeout = options
|
||||
.iter()
|
||||
.position(|option| *option == "--timeout-ms")
|
||||
.map(|index| options[index + 1].parse::<u64>().unwrap())
|
||||
.unwrap_or(60_000);
|
||||
assert_eq!(parsed.timeout, Duration::from_millis(timeout));
|
||||
assert_eq!(
|
||||
parsed.filter.as_deref(),
|
||||
options
|
||||
.iter()
|
||||
.position(|option| *option == "--filter")
|
||||
.map(|index| options[index + 1]),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_options_reject_invalid_missing_duplicate_and_unknown_arguments() {
|
||||
let mut invalid = vec![
|
||||
vec!["--filter"],
|
||||
vec!["--timeout-ms"],
|
||||
vec!["--filter", "--timeout-ms", "20"],
|
||||
vec!["--filter", "sample", "--filter", "sample.account"],
|
||||
vec!["--timeout-ms", "20", "--timeout-ms", "30"],
|
||||
vec!["--unknown", "value"],
|
||||
vec!["extra"],
|
||||
];
|
||||
for filter in [
|
||||
"", ".sample", "sample.", "sample..case", "sample.a.b.c", "sam*", "sample/account",
|
||||
"Sample", "sample.__case", "sample.case_", "sample.2case", " sample", "用户",
|
||||
] {
|
||||
invalid.push(vec!["--filter", filter]);
|
||||
}
|
||||
for timeout in [
|
||||
"", "0", "-1", "+1", "1.5", "1ms", " 1", "18446744073709551616",
|
||||
] {
|
||||
invalid.push(vec!["--timeout-ms", timeout]);
|
||||
}
|
||||
for options in invalid {
|
||||
let arguments: Vec<_> = [vec!["test", "project"], options]
|
||||
.concat()
|
||||
.into_iter()
|
||||
.map(OsString::from)
|
||||
.collect();
|
||||
assert!(arguments_for(&arguments).is_err(), "accepted {arguments:?}");
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
#[test]
|
||||
fn test_options_reject_non_utf8_values() {
|
||||
use std::os::unix::ffi::OsStringExt;
|
||||
for option in ["--filter", "--timeout-ms"] {
|
||||
let arguments = [
|
||||
OsString::from("test"),
|
||||
OsString::from("project"),
|
||||
OsString::from(option),
|
||||
OsString::from_vec(vec![0xff]),
|
||||
];
|
||||
assert!(arguments_for(&arguments).is_err());
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user