diff options
| -rwxr-xr-x | scripts/test.sh | 30 | ||||
| -rw-r--r-- | src/main.rs | 68 |
2 files changed, 98 insertions, 0 deletions
diff --git a/scripts/test.sh b/scripts/test.sh new file mode 100755 index 0000000..b671a94 --- /dev/null +++ b/scripts/test.sh @@ -0,0 +1,30 @@ +#!/bin/bash +# Simple test script for soon CLI tool + +set -e + +echo "๐งช Running Soon CLI Tests..." + +# Test 1: Build succeeds +echo "1. Testing build..." +cargo build --quiet + +# Test 2: Unit tests pass +echo "2. Running unit tests..." +cargo test --quiet + +# Test 3: Basic CLI functionality +echo "3. Testing CLI help..." +./target/debug/soon --help > /dev/null + +echo "4. Testing version command..." +./target/debug/soon version > /dev/null + +echo "5. Testing which command..." +./target/debug/soon which > /dev/null + +# Test 4: Release build +echo "6. Testing release build..." +cargo build --release --quiet + +echo "โ
All tests passed!"
\ No newline at end of file diff --git a/src/main.rs b/src/main.rs index 245810f..443a2ab 100644 --- a/src/main.rs +++ b/src/main.rs @@ -567,3 +567,71 @@ fn main() { } } +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_main_cmd_extraction() { + assert_eq!(main_cmd("git status"), "git"); + assert_eq!(main_cmd("ls -la"), "ls"); + assert_eq!(main_cmd(""), ""); + assert_eq!(main_cmd("single"), "single"); + assert_eq!(main_cmd(" spaced command "), "spaced"); + } + + #[test] + fn test_is_ignored_command() { + assert_eq!(is_ignored_command("soon"), true); + assert_eq!(is_ignored_command("cd"), true); + assert_eq!(is_ignored_command("ls"), true); + assert_eq!(is_ignored_command("pwd"), true); + assert_eq!(is_ignored_command("exit"), true); + assert_eq!(is_ignored_command("clear"), true); + assert_eq!(is_ignored_command("git"), false); + assert_eq!(is_ignored_command("cargo"), false); + } + + #[test] + fn test_detect_shell() { + // This test will depend on the actual environment + let shell = detect_shell(); + assert!(shell == "bash" || shell == "zsh" || shell == "fish" || shell == "unknown"); + } + + #[test] + fn test_history_path() { + let bash_path = history_path("bash"); + assert!(bash_path.is_some()); + assert!(bash_path.unwrap().ends_with(".bash_history")); + + let zsh_path = history_path("zsh"); + assert!(zsh_path.is_some()); + assert!(zsh_path.unwrap().ends_with(".zsh_history")); + + let fish_path = history_path("fish"); + assert!(fish_path.is_some()); + assert!(fish_path.unwrap().ends_with("fish_history")); + + let unknown_path = history_path("unknown"); + assert!(unknown_path.is_some()); + // Unknown shell returns empty PathBuf + } + + #[test] + fn test_get_cache_path() { + let cache_path = get_cache_path(); + assert!(cache_path.ends_with(".soon_cache")); + } + + #[test] + fn test_history_item_creation() { + let item = HistoryItem { + cmd: "test command".to_string(), + path: Some("/home/user".to_string()), + }; + assert_eq!(item.cmd, "test command"); + assert_eq!(item.path, Some("/home/user".to_string())); + } +} + |