From d36212f2dc4638004fb96a17c29623981273f941 Mon Sep 17 00:00:00 2001 From: y3owk1n Date: Sat, 6 Jan 2024 19:19:39 +0800 Subject: [PATCH] chore: another test trying --- tests/_test_fzf_cmd_history.fish | 38 ++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/tests/_test_fzf_cmd_history.fish b/tests/_test_fzf_cmd_history.fish index 6ccb622..b9cd1f7 100644 --- a/tests/_test_fzf_cmd_history.fish +++ b/tests/_test_fzf_cmd_history.fish @@ -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