Skip to content

Commit

Permalink
chore: add homebrew in ci
Browse files Browse the repository at this point in the history
  • Loading branch information
y3owk1n committed Jan 6, 2024
1 parent 3878a85 commit 1e9c8f3
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 31 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
55 changes: 24 additions & 31 deletions tests/_test_fzf_cmd_history.fish
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
set temp_dir (mktemp -d)

# Function to set up mocked history
function setup_mocked_history
function history
Expand All @@ -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

0 comments on commit 1e9c8f3

Please sign in to comment.