use lz4::cli::constants::set_lz4c_legacy_commands;
use lz4::cli::help::{print_long_help, print_usage, print_usage_advanced};
#[test]
fn subprocess_helper_error_out() {
if std::env::var("LZ4_TEST_ERROR_OUT").is_ok() {
lz4::cli::help::error_out("test error");
}
}
#[test]
fn subprocess_helper_bad_usage() {
if std::env::var("LZ4_TEST_BAD_USAGE").is_ok() {
lz4::cli::help::print_bad_usage("lz4");
}
}
#[test]
fn subprocess_helper_wait_enter() {
if std::env::var("LZ4_TEST_WAIT_ENTER").is_ok() {
lz4::cli::help::wait_enter();
std::process::exit(0);
}
}
#[test]
fn print_usage_does_not_panic_with_typical_name() {
print_usage("lz4");
}
#[test]
fn print_usage_does_not_panic_with_empty_name() {
print_usage("");
}
#[test]
fn print_usage_does_not_panic_with_path() {
print_usage("/usr/local/bin/lz4");
}
#[test]
fn print_usage_does_not_panic_with_lz4cat_and_unlz4() {
print_usage("lz4cat");
print_usage("unlz4");
}
#[test]
fn print_usage_does_not_panic_with_unicode_name() {
print_usage("lz4-ü");
}
#[test]
fn print_usage_advanced_does_not_panic_with_typical_name() {
print_usage_advanced("lz4");
}
#[test]
fn print_usage_advanced_does_not_panic_with_empty_name() {
print_usage_advanced("");
}
#[test]
fn print_usage_advanced_with_lz4c_legacy_enabled() {
set_lz4c_legacy_commands(true);
print_usage_advanced("lz4c");
set_lz4c_legacy_commands(false);
}
#[test]
fn print_usage_advanced_with_lz4c_legacy_disabled() {
set_lz4c_legacy_commands(false);
print_usage_advanced("lz4");
}
#[test]
fn print_long_help_does_not_panic_with_typical_name() {
print_long_help("lz4");
}
#[test]
fn print_long_help_does_not_panic_with_empty_name() {
print_long_help("");
}
#[test]
fn print_long_help_with_lz4c_legacy_enabled() {
set_lz4c_legacy_commands(true);
print_long_help("lz4c");
set_lz4c_legacy_commands(false);
}
#[test]
fn print_long_help_with_lz4c_legacy_disabled() {
set_lz4c_legacy_commands(false);
print_long_help("lz4");
}
#[test]
fn print_long_help_does_not_panic_with_path_name() {
print_long_help("/usr/bin/lz4");
}
#[test]
fn error_out_exits_with_code_1() {
let exe = std::env::current_exe().expect("could not find test executable");
let output = std::process::Command::new(&exe)
.args([
"help::subprocess_helper_error_out",
"--exact",
"--nocapture",
])
.env("LZ4_TEST_ERROR_OUT", "1")
.output()
.expect("failed to spawn subprocess");
assert_eq!(
output.status.code(),
Some(1),
"error_out must exit with code 1"
);
}
#[test]
fn print_bad_usage_exits_with_code_1() {
let exe = std::env::current_exe().expect("could not find test executable");
let output = std::process::Command::new(&exe)
.args([
"help::subprocess_helper_bad_usage",
"--exact",
"--nocapture",
])
.env("LZ4_TEST_BAD_USAGE", "1")
.output()
.expect("failed to spawn subprocess");
assert_eq!(
output.status.code(),
Some(1),
"print_bad_usage must exit with code 1"
);
}
#[test]
fn wait_enter_returns_gracefully_on_eof_stdin() {
let exe = std::env::current_exe().expect("could not find test executable");
let output = std::process::Command::new(&exe)
.args([
"help::subprocess_helper_wait_enter",
"--exact",
"--nocapture",
])
.env("LZ4_TEST_WAIT_ENTER", "1")
.stdin(std::process::Stdio::null())
.output()
.expect("failed to spawn subprocess");
assert_eq!(
output.status.code(),
Some(0),
"wait_enter must return gracefully on EOF stdin"
);
}