in src/seccompiler/src/seccompiler_bin.rs [409:543]
fn test_get_argument_values() {
let arg_parser = build_arg_parser();
// correct arguments
let arguments = &mut arg_parser.arguments().clone();
arguments
.parse(
vec![
"seccompiler-bin",
"--input-file",
"foo.txt",
"--target-arch",
"x86_64",
]
.into_iter()
.map(String::from)
.collect::<Vec<String>>()
.as_ref(),
)
.unwrap();
assert_eq!(
get_argument_values(arguments).unwrap(),
Arguments {
input_file: "foo.txt".to_string(),
output_file: DEFAULT_OUTPUT_FILENAME.to_string(),
target_arch: TargetArch::x86_64,
is_basic: false,
}
);
let arguments = &mut arg_parser.arguments().clone();
arguments
.parse(
vec![
"seccompiler-bin",
"--input-file",
"foo.txt",
"--target-arch",
"x86_64",
"--output-file",
"/path.to/file.txt",
"--basic",
]
.into_iter()
.map(String::from)
.collect::<Vec<String>>()
.as_ref(),
)
.unwrap();
assert_eq!(
get_argument_values(arguments).unwrap(),
Arguments {
input_file: "foo.txt".to_string(),
output_file: "/path.to/file.txt".to_string(),
target_arch: TargetArch::x86_64,
is_basic: true
}
);
// no args
let arguments = &mut arg_parser.arguments().clone();
assert!(arguments
.parse(
vec!["seccompiler-bin"]
.into_iter()
.map(String::from)
.collect::<Vec<String>>()
.as_ref(),
)
.is_err());
// missing --target-arch
let arguments = &mut arg_parser.arguments().clone();
assert!(arguments
.parse(
vec!["seccompiler-bin", "--input-file", "foo.txt"]
.into_iter()
.map(String::from)
.collect::<Vec<String>>()
.as_ref(),
)
.is_err());
// missing --input-file
let arguments = &mut arg_parser.arguments().clone();
assert!(arguments
.parse(
vec!["seccompiler-bin", "--target-arch", "x86_64"]
.into_iter()
.map(String::from)
.collect::<Vec<String>>()
.as_ref(),
)
.is_err());
// invalid --target-arch
let arguments = &mut arg_parser.arguments().clone();
arguments
.parse(
vec![
"seccompiler-bin",
"--input-file",
"foo.txt",
"--target-arch",
"x86_64das",
"--output-file",
"/path.to/file.txt",
]
.into_iter()
.map(String::from)
.collect::<Vec<String>>()
.as_ref(),
)
.unwrap();
assert!(get_argument_values(arguments).is_err());
// invalid value supplied to --basic
let arguments = &mut arg_parser.arguments().clone();
assert!(arguments
.parse(
vec![
"seccompiler-bin",
"--input-file",
"foo.txt",
"--target-arch",
"x86_64",
"--basic",
"invalid",
]
.into_iter()
.map(String::from)
.collect::<Vec<String>>()
.as_ref(),
)
.is_err());
}