#[allow(clippy::duplicate_mod)]
#[path = "fixtures/mod.rs"]
mod fixtures;
#[allow(clippy::duplicate_mod)]
#[path = "helpers.rs"]
mod helpers;
#[test]
#[cfg(not(feature = "authentication"))]
fn test_command_with_arguments() {
let mut shell = helpers::create_test_shell();
let output = helpers::execute_command(&mut shell, "echo arg1 arg2 arg3");
helpers::assert_contains_all(&output, &["arg1", "arg2", "arg3"]);
}
#[test]
#[cfg(not(feature = "authentication"))]
fn test_path_based_command_execution() {
let test_cases = [
(
"system/status",
"System OK",
"simple path without navigation",
),
("system/network/status", "Network OK", "deeply nested path"),
("system/hardware/led on", "LED: on", "path with arguments"),
];
for (cmd, expected, description) in test_cases {
let mut shell = helpers::create_test_shell();
let output = helpers::execute_command(&mut shell, cmd);
assert!(
output.contains(expected),
"Failed '{}': expected '{}' in output: {}",
description,
expected,
output
);
}
}
#[test]
#[cfg(not(feature = "authentication"))]
fn test_command_with_leading_spaces() {
let mut shell = helpers::create_test_shell();
let output = helpers::execute_command(&mut shell, " echo test");
assert!(output.contains("test"), "Leading spaces should be trimmed");
}
#[test]
#[cfg(not(feature = "authentication"))]
fn test_command_with_trailing_spaces() {
let mut shell = helpers::create_test_shell();
let output = helpers::execute_command(&mut shell, "echo test ");
assert!(output.contains("test"), "Trailing spaces should be trimmed");
}
#[test]
#[cfg(not(feature = "authentication"))]
fn test_command_with_multiple_spaces_between_args() {
let mut shell = helpers::create_test_shell();
let output = helpers::execute_command(&mut shell, "echo arg1 arg2 arg3");
helpers::assert_contains_all(&output, &["arg1", "arg2", "arg3"]);
}
#[test]
#[cfg(not(feature = "authentication"))]
fn test_command_with_exact_buffer_size() {
let mut shell = helpers::create_test_shell();
let args = "a".repeat(120);
let cmd = format!("echo {}", args);
let output = helpers::execute_command(&mut shell, &cmd);
assert!(
output.contains(&args),
"Should handle command at buffer limit"
);
}
#[test]
#[cfg(not(feature = "authentication"))]
fn test_repeated_command_execution() {
let mut shell = helpers::create_test_shell();
for i in 0..5 {
let output = helpers::execute_command(&mut shell, "echo test");
assert!(
output.contains("test"),
"Repeated execution #{} should work",
i + 1
);
}
}
#[test]
#[cfg(not(feature = "authentication"))]
fn test_rapid_state_changes() {
let mut shell = helpers::create_test_shell();
helpers::execute_command(&mut shell, "system");
helpers::execute_command(&mut shell, "status");
helpers::execute_command(&mut shell, "..");
helpers::execute_command(&mut shell, "debug");
helpers::execute_command(&mut shell, "memory");
helpers::execute_command(&mut shell, "/");
let output = helpers::execute_command(&mut shell, "echo final");
helpers::assert_contains_all(&output, &["@/>", "final"]);
}
#[test]
#[cfg(not(feature = "authentication"))]
fn test_navigate_to_directory() {
let mut shell = helpers::create_test_shell();
helpers::execute_command(&mut shell, "system");
let output = helpers::execute_command(&mut shell, "status");
helpers::assert_contains_all(&output, &["@/system>", "System OK"]);
}
#[test]
#[cfg(not(feature = "authentication"))]
fn test_navigate_with_relative_path() {
let mut shell = helpers::create_test_shell();
helpers::execute_command(&mut shell, "system/network");
let output = helpers::execute_command(&mut shell, "status");
helpers::assert_contains_all(&output, &["@/system/network>", "Network OK"]);
}
#[test]
#[cfg(not(feature = "authentication"))]
fn test_navigate_parent_directory() {
let mut shell = helpers::create_test_shell();
helpers::execute_command(&mut shell, "system/network");
helpers::execute_command(&mut shell, "..");
let output = helpers::execute_command(&mut shell, "status");
helpers::assert_contains_all(&output, &["@/system>", "System OK"]);
}
#[test]
#[cfg(not(feature = "authentication"))]
fn test_navigate_absolute_path() {
let mut shell = helpers::create_test_shell();
helpers::execute_command(&mut shell, "system");
helpers::execute_command(&mut shell, "/debug");
let output = helpers::execute_command(&mut shell, "memory");
helpers::assert_contains_all(&output, &["@/debug>", "Memory"]);
}
#[test]
#[cfg(not(feature = "authentication"))]
fn test_navigate_invalid_directory() {
let mut shell = helpers::create_test_shell();
let output = helpers::execute_command(&mut shell, "nonexistent");
assert!(output.contains("Error: Command not found"));
}
#[test]
#[cfg(not(feature = "authentication"))]
fn test_navigate_parent_beyond_root() {
let mut shell = helpers::create_test_shell();
helpers::execute_command(&mut shell, "..");
let output = helpers::execute_command(&mut shell, "echo still at root");
helpers::assert_contains_all(&output, &["@/>", "still at root"]);
}
#[test]
#[cfg(not(feature = "authentication"))]
fn test_navigate_to_current_directory() {
let mut shell = helpers::create_test_shell();
helpers::execute_command(&mut shell, "system");
let output = helpers::execute_command(&mut shell, ".");
helpers::assert_prompt(&output, "@/system>");
}
#[test]
#[cfg(not(feature = "authentication"))]
fn test_multiple_parent_navigation() {
let mut shell = helpers::create_test_shell();
helpers::execute_command(&mut shell, "system/network");
let output = helpers::execute_command(&mut shell, "../..");
helpers::assert_prompt(&output, "@/>");
}
#[test]
#[cfg(not(feature = "authentication"))]
fn test_navigate_with_mixed_dots() {
let mut shell = helpers::create_test_shell();
helpers::execute_command(&mut shell, "system");
let output = helpers::execute_command(&mut shell, "./network/../hardware");
helpers::assert_prompt(&output, "@/system/hardware>");
}
#[test]
#[cfg(not(feature = "authentication"))]
fn test_absolute_path_from_subdirectory() {
let mut shell = helpers::create_test_shell();
helpers::execute_command(&mut shell, "system/network");
let output = helpers::execute_command(&mut shell, "/debug");
helpers::assert_prompt(&output, "@/debug>");
}
#[test]
#[cfg(not(feature = "authentication"))]
fn test_navigate_to_root_explicitly() {
let mut shell = helpers::create_test_shell();
helpers::execute_command(&mut shell, "system/network");
let output = helpers::execute_command(&mut shell, "/");
helpers::assert_prompt(&output, "@/>");
}
#[test]
#[cfg(not(feature = "authentication"))]
fn test_directory_with_args_returns_error() {
let test_cases = [
("system arg", "system"),
("system arg1 arg2", "system"),
("system/network arg", "system/network"),
];
for (input, path) in &test_cases {
let mut shell = helpers::create_test_shell();
let output = helpers::execute_command(&mut shell, input);
assert!(
output.contains("Expected 0 arguments"),
"Input {:?} (path {:?}): expected 'Expected 0 arguments' in output, got: {:?}",
input,
path,
output
);
}
}
#[test]
#[cfg(not(feature = "authentication"))]
fn test_global_commands() {
let test_cases = [
(
"?",
&["ls", "clear"] as &[&str],
"help command shows available commands",
),
("ls", &["echo", "system"], "ls lists root contents"),
("clear", &["\x1b[2J"], "clear outputs ANSI escape sequence"),
];
for (cmd, expected_fragments, description) in test_cases {
let mut shell = helpers::create_test_shell();
let output = helpers::execute_command(&mut shell, cmd);
for fragment in expected_fragments {
assert!(
output.contains(fragment),
"Failed '{}': expected '{}' in output",
description,
fragment
);
}
}
}
#[test]
#[cfg(not(feature = "authentication"))]
fn test_argument_validation() {
let test_cases = [
(
"system/hardware/led",
"Expected 1 arguments, got 0",
"command requires exactly 1 arg but got 0",
),
(
"system/hardware/led on",
"LED: on",
"command with correct argument count",
),
(
"system/reboot now",
"Expected 0 arguments, got 1",
"command accepts 0 args but got 1",
),
];
for (cmd, expected, description) in test_cases {
let mut shell = helpers::create_test_shell();
let output = helpers::execute_command(&mut shell, cmd);
assert!(
output.contains(expected),
"Failed '{}': expected '{}' in output: {}",
description,
expected,
output
);
}
}
#[test]
#[cfg(feature = "authentication")]
fn test_guest_access_control() {
let mut shell = helpers::create_auth_shell();
helpers::execute_command_auth(&mut shell, "guest:guest123");
let test_cases = [
("echo hello", "hello", true), ("system/reboot", "Command not found", false), ("debug/memory", "Command not found", false), ];
for (cmd, expected, should_succeed) in test_cases {
let output = helpers::execute_command_auth(&mut shell, cmd);
if should_succeed {
assert!(
output.contains(expected),
"Guest should be able to: '{}', got: {}",
cmd,
output
);
} else {
assert!(
output.contains(expected) || output.contains("Invalid path"),
"Guest should not access: '{}', got: {}",
cmd,
output
);
}
}
}
#[test]
#[cfg(feature = "authentication")]
fn test_admin_access_control() {
let mut shell = helpers::create_auth_shell();
helpers::execute_command_auth(&mut shell, "admin:admin123");
let test_cases = [
("system/reboot", "Reboot"), ("debug/memory", "Memory"), ("echo test", "test"), ];
for (cmd, expected) in test_cases {
let output = helpers::execute_command_auth(&mut shell, cmd);
assert!(
output.contains(expected),
"Admin should access '{}', got: {}",
cmd,
output
);
}
}
#[test]
fn test_minimal_features() {
#[cfg(not(feature = "authentication"))]
{
let mut shell = helpers::create_test_shell();
let output = helpers::execute_command(&mut shell, "echo minimal");
assert!(output.contains("minimal"));
}
}