Skip to content

Commit

Permalink
chore: another test trying
Browse files Browse the repository at this point in the history
  • Loading branch information
y3owk1n committed Jan 6, 2024
1 parent 7abda31 commit d36212f
Showing 1 changed file with 21 additions and 17 deletions.
38 changes: 21 additions & 17 deletions tests/_test_fzf_cmd_history.fish
Original file line number Diff line number Diff line change
Expand Up @@ -18,45 +18,49 @@ function setup_mocked_fzf
end
end

# Variable to capture the output of _fzf_cmd_history
set selected_command_output

# Function to override echo and capture the output
function echo -e
set selected_command_output $argv[1]
end
# Temporary directory to store output file
set temp_dir (mktemp -d)
set output_file $temp_dir/output.txt

# Test _fzf_cmd_history without options
setup_mocked_history
set selected_command (echo "command1" | _fzf_cmd_history)
set selected_command_without_equals (string replace '=' '' $selected_command_output)
output_file <(echo "command1" | _fzf_cmd_history)

set selected_command_without_equals (string replace '=' '' (cat $output_file))
@test "selected command is correct" "$selected_command_without_equals" = command1

# Test _fzf_cmd_history with custom prompt name
setup_mocked_history
set selected_command (echo "command2" | _fzf_cmd_history --prompt-name "CustomPrompt")
set selected_command_without_equals (string replace '=' '' $selected_command_output)
setup_mocked_fzf
output_file <(echo "command2" | _fzf_cmd_history --prompt-name "CustomPrompt")

set selected_command_without_equals (string replace '=' '' (cat $output_file))
@test "selected command is correct with custom prompt name" "$selected_command_without_equals" = command2
@test "prompt name in fzf is correct" $FZF_PROMPT_NAME = CustomPrompt

# Test _fzf_cmd_history with allow-execute option
setup_mocked_history
setup_mocked_fzf
set selected_command (echo "command3" | _fzf_cmd_history --allow-execute)
set selected_command_without_equals (string replace '=' '' $selected_command_output)
output_file <(echo "command3" | _fzf_cmd_history --allow-execute)

set selected_command_without_equals (string replace '=' '' (cat $output_file))
@test "selected command is correct with allow-execute option" "$selected_command_without_equals" = 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
setup_mocked_fzf
set selected_command (echo "command4" | _fzf_cmd_history --prompt-name "CustomPrompt" --allow-execute)
set selected_command_without_equals (string replace '=' '' $selected_command_output)
output_file <(echo "command4" | _fzf_cmd_history --prompt-name "CustomPrompt" --allow-execute)

set selected_command_without_equals (string replace '=' '' (cat $output_file))
@test "selected command is correct with both options" "$selected_command_without_equals" = command4
@test "prompt name in fzf is correct" $FZF_PROMPT_NAME = CustomPrompt

# 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
output_file <(echo "command5" | _fzf_cmd_history --allow-execute)
eval (cat $output_file)
@test "command execution with allow-execute is successful" $status -eq 0

# Clean up temporary directory
rm -rf $temp_dir

0 comments on commit d36212f

Please sign in to comment.