From 1e9c8f3f7e3ebe43516f584478212f8401dcd7f4 Mon Sep 17 00:00:00 2001 From: y3owk1n Date: Sat, 6 Jan 2024 19:09:03 +0800 Subject: [PATCH] chore: add homebrew in ci --- .github/workflows/ci.yml | 5 +++ tests/_test_fzf_cmd_history.fish | 55 ++++++++++++++------------------ 2 files changed, 29 insertions(+), 31 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e620bd3..d89ab4f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -16,6 +16,11 @@ jobs: - uses: fish-actions/fisher@v1 with: plugins: jorgebucaran/fishtape ilancosman/clownfish $GITHUB_WORKSPACE + - name: Set up Homebrew + uses: Homebrew/actions/setup-homebrew@master + if: matrix.os == 'ubuntu-latest' + - name: Install fzf and fd + run: brew install fzf fd - name: Run full test suite run: fishtape tests/*.fish shell: fish {0} diff --git a/tests/_test_fzf_cmd_history.fish b/tests/_test_fzf_cmd_history.fish index 062d240..64c02d5 100644 --- a/tests/_test_fzf_cmd_history.fish +++ b/tests/_test_fzf_cmd_history.fish @@ -1,5 +1,3 @@ -set temp_dir (mktemp -d) - # Function to set up mocked history function setup_mocked_history function history @@ -11,47 +9,42 @@ function setup_mocked_history end end -# Function to delete directories -function cleanup_directories - if test -d $temp_dir - rm -rf $temp_dir +# Function to set up a mocked fzf function +function setup_mocked_fzf + set -gx FZF_PROMPT_NAME "" + function fzf + set -gx FZF_PROMPT_NAME $argv[1] + echo selected_command end end # Test _fzf_cmd_history without options setup_mocked_history -echo command1 | _fzf_cmd_history >/dev/null - -@test "commandline is replaced with selected command" (commandline) = command1 - -# Clean up -cleanup_directories +set selected_command (echo "command1" | _fzf_cmd_history) +@test "selected command is correct" $selected_command = command1 # Test _fzf_cmd_history with custom prompt name setup_mocked_history -echo command2 | _fzf_cmd_history --prompt-name CustomPrompt >/dev/null - -@test "custom prompt name is used" (commandline) = command2 - -# Clean up -cleanup_directories +set selected_command (echo "command2" | _fzf_cmd_history --prompt-name "CustomPrompt") +@test "selected command is correct with custom prompt name" $selected_command = command2 +@test "prompt name in fzf is correct" $FZF_PROMPT_NAME = CustomPrompt # Test _fzf_cmd_history with allow-execute option setup_mocked_history -echo command3 | _fzf_cmd_history --allow-execute >/dev/null - -@test "allow-execute option executes the command" (commandline) = command3 - -# Clean up -cleanup_directories +setup_mocked_fzf +set selected_command (echo "command3" | _fzf_cmd_history --allow-execute) +@test "selected command is correct with allow-execute option" $selected_command = command3 +@test "prompt name in fzf is correct" $FZF_PROMPT_NAME = "Command History" # Test _fzf_cmd_history with both prompt name and allow-execute options setup_mocked_history -echo command4 | _fzf_cmd_history --prompt-name CustomPrompt --allow-execute >/dev/null - -@test "both prompt name and allow-execute options work" (commandline) = command4 +setup_mocked_fzf +set selected_command (echo "command4" | _fzf_cmd_history --prompt-name "CustomPrompt" --allow-execute) +@test "selected command is correct with both options" $selected_command = command4 +@test "prompt name in fzf is correct" $FZF_PROMPT_NAME = CustomPrompt -# Clean up -cleanup_directories - -rm -rf $temp_dir +# Test _fzf_cmd_history with allow-execute option (execution validation) +setup_mocked_history +set selected_command (echo "command5" | _fzf_cmd_history --allow-execute) +eval $selected_command +@test "command execution with allow-execute is successful" $status -eq 0