From 3878a8542219aa61c37ee9bfc15757451ee62a3a Mon Sep 17 00:00:00 2001 From: y3owk1n Date: Sat, 6 Jan 2024 19:00:47 +0800 Subject: [PATCH 01/11] chore: add test for _fzf_cmd_history --- .github/workflows/ci.yml | 35 ++++++++++++++++++++ tests/_test_fzf_cmd_history.fish | 57 ++++++++++++++++++++++++++++++++ 2 files changed, 92 insertions(+) create mode 100644 .github/workflows/ci.yml create mode 100644 tests/_test_fzf_cmd_history.fish diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..e620bd3 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,35 @@ +name: CI +on: + pull_request: + branches: ["main"] + # Allows you to run this workflow manually from the Actions tab + workflow_dispatch: +jobs: + tests: + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [macos-latest, ubuntu-latest] + steps: + - uses: actions/checkout@v4 + - uses: fish-actions/install-fish@v1.1.0 + - uses: fish-actions/fisher@v1 + with: + plugins: jorgebucaran/fishtape ilancosman/clownfish $GITHUB_WORKSPACE + - name: Run full test suite + run: fishtape tests/*.fish + shell: fish {0} + timeout-minutes: 3 + syntax-check: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: fish-actions/install-fish@v1 + - uses: fish-actions/syntax-check@v1 + # check Fish format + format-check: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: fish-actions/install-fish@v1 + - uses: fish-actions/format-check@v1 diff --git a/tests/_test_fzf_cmd_history.fish b/tests/_test_fzf_cmd_history.fish new file mode 100644 index 0000000..062d240 --- /dev/null +++ b/tests/_test_fzf_cmd_history.fish @@ -0,0 +1,57 @@ +set temp_dir (mktemp -d) + +# Function to set up mocked history +function setup_mocked_history + function history + echo command1 + echo command2 + echo command3 + echo command4 + echo command5 + end +end + +# Function to delete directories +function cleanup_directories + if test -d $temp_dir + rm -rf $temp_dir + 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 + +# 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 + +# 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 + +# 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 + +# Clean up +cleanup_directories + +rm -rf $temp_dir From 1e9c8f3f7e3ebe43516f584478212f8401dcd7f4 Mon Sep 17 00:00:00 2001 From: y3owk1n Date: Sat, 6 Jan 2024 19:09:03 +0800 Subject: [PATCH 02/11] 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 From 3128881d060b2c4b3b8879daef9a210672918e97 Mon Sep 17 00:00:00 2001 From: y3owk1n Date: Sat, 6 Jan 2024 19:13:01 +0800 Subject: [PATCH 03/11] chore: test amendment --- tests/_test_fzf_cmd_history.fish | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/tests/_test_fzf_cmd_history.fish b/tests/_test_fzf_cmd_history.fish index 64c02d5..1cc4342 100644 --- a/tests/_test_fzf_cmd_history.fish +++ b/tests/_test_fzf_cmd_history.fish @@ -21,26 +21,30 @@ end # Test _fzf_cmd_history without options setup_mocked_history set selected_command (echo "command1" | _fzf_cmd_history) -@test "selected command is correct" $selected_command = command1 +set selected_command_without_equals (string replace '=' '' $selected_command) +@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") -@test "selected command is correct with custom prompt name" $selected_command = command2 +set selected_command_without_equals (string replace '=' '' $selected_command) +@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) -@test "selected command is correct with allow-execute option" $selected_command = command3 +set selected_command_without_equals (string replace '=' '' $selected_command) +@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) -@test "selected command is correct with both options" $selected_command = command4 +set selected_command_without_equals (string replace '=' '' $selected_command) +@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) From 7abda311fcf7ceddfcd64d3e5905641f583976c0 Mon Sep 17 00:00:00 2001 From: y3owk1n Date: Sat, 6 Jan 2024 19:16:01 +0800 Subject: [PATCH 04/11] chore: fixing commandline not available in CI environment --- tests/_test_fzf_cmd_history.fish | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/tests/_test_fzf_cmd_history.fish b/tests/_test_fzf_cmd_history.fish index 1cc4342..6ccb622 100644 --- a/tests/_test_fzf_cmd_history.fish +++ b/tests/_test_fzf_cmd_history.fish @@ -18,16 +18,24 @@ 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 + # 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) +set selected_command_without_equals (string replace '=' '' $selected_command_output) @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) +set selected_command_without_equals (string replace '=' '' $selected_command_output) @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 @@ -35,7 +43,7 @@ set selected_command_without_equals (string replace '=' '' $selected_command) 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) +set selected_command_without_equals (string replace '=' '' $selected_command_output) @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" @@ -43,7 +51,7 @@ set selected_command_without_equals (string replace '=' '' $selected_command) 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) +set selected_command_without_equals (string replace '=' '' $selected_command_output) @test "selected command is correct with both options" "$selected_command_without_equals" = command4 @test "prompt name in fzf is correct" $FZF_PROMPT_NAME = CustomPrompt From d36212f2dc4638004fb96a17c29623981273f941 Mon Sep 17 00:00:00 2001 From: y3owk1n Date: Sat, 6 Jan 2024 19:19:39 +0800 Subject: [PATCH 05/11] 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 From f5451c836f56727a6dfabf851f0f5440062faa38 Mon Sep 17 00:00:00 2001 From: y3owk1n Date: Sat, 6 Jan 2024 19:22:18 +0800 Subject: [PATCH 06/11] chore: fix output_file is unknown --- tests/_test_fzf_cmd_history.fish | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/_test_fzf_cmd_history.fish b/tests/_test_fzf_cmd_history.fish index b9cd1f7..2734d4a 100644 --- a/tests/_test_fzf_cmd_history.fish +++ b/tests/_test_fzf_cmd_history.fish @@ -24,7 +24,7 @@ set output_file $temp_dir/output.txt # Test _fzf_cmd_history without options setup_mocked_history -output_file <(echo "command1" | _fzf_cmd_history) +echo command1 | _fzf_cmd_history >$output_file set selected_command_without_equals (string replace '=' '' (cat $output_file)) @test "selected command is correct" "$selected_command_without_equals" = command1 @@ -32,7 +32,7 @@ set selected_command_without_equals (string replace '=' '' (cat $output_file)) # Test _fzf_cmd_history with custom prompt name setup_mocked_history setup_mocked_fzf -output_file <(echo "command2" | _fzf_cmd_history --prompt-name "CustomPrompt") +echo command2 | _fzf_cmd_history --prompt-name CustomPrompt >$output_file set selected_command_without_equals (string replace '=' '' (cat $output_file)) @test "selected command is correct with custom prompt name" "$selected_command_without_equals" = command2 @@ -41,7 +41,7 @@ set selected_command_without_equals (string replace '=' '' (cat $output_file)) # Test _fzf_cmd_history with allow-execute option setup_mocked_history setup_mocked_fzf -output_file <(echo "command3" | _fzf_cmd_history --allow-execute) +echo command3 | _fzf_cmd_history --allow-execute >$output_file set selected_command_without_equals (string replace '=' '' (cat $output_file)) @test "selected command is correct with allow-execute option" "$selected_command_without_equals" = command3 @@ -50,7 +50,7 @@ set selected_command_without_equals (string replace '=' '' (cat $output_file)) # Test _fzf_cmd_history with both prompt name and allow-execute options setup_mocked_history setup_mocked_fzf -output_file <(echo "command4" | _fzf_cmd_history --prompt-name "CustomPrompt" --allow-execute) +echo command4 | _fzf_cmd_history --prompt-name CustomPrompt --allow-execute >$output_file set selected_command_without_equals (string replace '=' '' (cat $output_file)) @test "selected command is correct with both options" "$selected_command_without_equals" = command4 @@ -58,7 +58,7 @@ set selected_command_without_equals (string replace '=' '' (cat $output_file)) # Test _fzf_cmd_history with allow-execute option (execution validation) setup_mocked_history -output_file <(echo "command5" | _fzf_cmd_history --allow-execute) +echo command5 | _fzf_cmd_history --allow-execute >$output_file eval (cat $output_file) @test "command execution with allow-execute is successful" $status -eq 0 From 7266846529796ba82a71a14828d6439adbf2a9f5 Mon Sep 17 00:00:00 2001 From: y3owk1n Date: Sat, 6 Jan 2024 19:26:18 +0800 Subject: [PATCH 07/11] chore: make output_file into variable --- tests/_test_fzf_cmd_history.fish | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/_test_fzf_cmd_history.fish b/tests/_test_fzf_cmd_history.fish index 2734d4a..a25f3e7 100644 --- a/tests/_test_fzf_cmd_history.fish +++ b/tests/_test_fzf_cmd_history.fish @@ -24,7 +24,7 @@ set output_file $temp_dir/output.txt # Test _fzf_cmd_history without options setup_mocked_history -echo command1 | _fzf_cmd_history >$output_file +$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 @@ -32,7 +32,7 @@ set selected_command_without_equals (string replace '=' '' (cat $output_file)) # Test _fzf_cmd_history with custom prompt name setup_mocked_history setup_mocked_fzf -echo command2 | _fzf_cmd_history --prompt-name CustomPrompt >$output_file +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 @@ -41,7 +41,7 @@ set selected_command_without_equals (string replace '=' '' (cat $output_file)) # Test _fzf_cmd_history with allow-execute option setup_mocked_history setup_mocked_fzf -echo command3 | _fzf_cmd_history --allow-execute >$output_file +$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 @@ -50,7 +50,7 @@ set selected_command_without_equals (string replace '=' '' (cat $output_file)) # Test _fzf_cmd_history with both prompt name and allow-execute options setup_mocked_history setup_mocked_fzf -echo command4 | _fzf_cmd_history --prompt-name CustomPrompt --allow-execute >$output_file +$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 @@ -58,7 +58,7 @@ set selected_command_without_equals (string replace '=' '' (cat $output_file)) # Test _fzf_cmd_history with allow-execute option (execution validation) setup_mocked_history -echo command5 | _fzf_cmd_history --allow-execute >$output_file +$output_file <(echo "command5" | _fzf_cmd_history --allow-execute) eval (cat $output_file) @test "command execution with allow-execute is successful" $status -eq 0 From 7f7a92908e3a46c8262b6e45675e3e675916a283 Mon Sep 17 00:00:00 2001 From: y3owk1n Date: Sat, 6 Jan 2024 19:30:41 +0800 Subject: [PATCH 08/11] chore: make sure output file is created --- tests/_test_fzf_cmd_history.fish | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/_test_fzf_cmd_history.fish b/tests/_test_fzf_cmd_history.fish index a25f3e7..2734d4a 100644 --- a/tests/_test_fzf_cmd_history.fish +++ b/tests/_test_fzf_cmd_history.fish @@ -24,7 +24,7 @@ set output_file $temp_dir/output.txt # Test _fzf_cmd_history without options setup_mocked_history -$output_file <(echo "command1" | _fzf_cmd_history) +echo command1 | _fzf_cmd_history >$output_file set selected_command_without_equals (string replace '=' '' (cat $output_file)) @test "selected command is correct" "$selected_command_without_equals" = command1 @@ -32,7 +32,7 @@ set selected_command_without_equals (string replace '=' '' (cat $output_file)) # Test _fzf_cmd_history with custom prompt name setup_mocked_history setup_mocked_fzf -output_file <(echo "command2" | _fzf_cmd_history --prompt-name "CustomPrompt") +echo command2 | _fzf_cmd_history --prompt-name CustomPrompt >$output_file set selected_command_without_equals (string replace '=' '' (cat $output_file)) @test "selected command is correct with custom prompt name" "$selected_command_without_equals" = command2 @@ -41,7 +41,7 @@ set selected_command_without_equals (string replace '=' '' (cat $output_file)) # Test _fzf_cmd_history with allow-execute option setup_mocked_history setup_mocked_fzf -$output_file <(echo "command3" | _fzf_cmd_history --allow-execute) +echo command3 | _fzf_cmd_history --allow-execute >$output_file set selected_command_without_equals (string replace '=' '' (cat $output_file)) @test "selected command is correct with allow-execute option" "$selected_command_without_equals" = command3 @@ -50,7 +50,7 @@ set selected_command_without_equals (string replace '=' '' (cat $output_file)) # Test _fzf_cmd_history with both prompt name and allow-execute options setup_mocked_history setup_mocked_fzf -$output_file <(echo "command4" | _fzf_cmd_history --prompt-name "CustomPrompt" --allow-execute) +echo command4 | _fzf_cmd_history --prompt-name CustomPrompt --allow-execute >$output_file set selected_command_without_equals (string replace '=' '' (cat $output_file)) @test "selected command is correct with both options" "$selected_command_without_equals" = command4 @@ -58,7 +58,7 @@ set selected_command_without_equals (string replace '=' '' (cat $output_file)) # Test _fzf_cmd_history with allow-execute option (execution validation) setup_mocked_history -$output_file <(echo "command5" | _fzf_cmd_history --allow-execute) +echo command5 | _fzf_cmd_history --allow-execute >$output_file eval (cat $output_file) @test "command execution with allow-execute is successful" $status -eq 0 From 3cef1fba4a5711bf4a46511e511f9710e665d820 Mon Sep 17 00:00:00 2001 From: y3owk1n Date: Sat, 6 Jan 2024 19:35:11 +0800 Subject: [PATCH 09/11] chore: simulate the current token in the command line --- tests/_test_fzf_cmd_history.fish | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tests/_test_fzf_cmd_history.fish b/tests/_test_fzf_cmd_history.fish index 2734d4a..7e5e0b8 100644 --- a/tests/_test_fzf_cmd_history.fish +++ b/tests/_test_fzf_cmd_history.fish @@ -18,11 +18,17 @@ function setup_mocked_fzf end end +# Function to simulate commandline in non-interactive mode +function set_current_token + set -gx COMMANDLINE_CURRENT_TOKEN $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 +set_current_token "" setup_mocked_history echo command1 | _fzf_cmd_history >$output_file @@ -30,6 +36,7 @@ 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 +set_current_token "" setup_mocked_history setup_mocked_fzf echo command2 | _fzf_cmd_history --prompt-name CustomPrompt >$output_file @@ -39,6 +46,7 @@ set selected_command_without_equals (string replace '=' '' (cat $output_file)) @test "prompt name in fzf is correct" $FZF_PROMPT_NAME = CustomPrompt # Test _fzf_cmd_history with allow-execute option +set_current_token "" setup_mocked_history setup_mocked_fzf echo command3 | _fzf_cmd_history --allow-execute >$output_file @@ -48,6 +56,7 @@ set selected_command_without_equals (string replace '=' '' (cat $output_file)) @test "prompt name in fzf is correct" $FZF_PROMPT_NAME = "Command History" # Test _fzf_cmd_history with both prompt name and allow-execute options +set_current_token "" setup_mocked_history setup_mocked_fzf echo command4 | _fzf_cmd_history --prompt-name CustomPrompt --allow-execute >$output_file @@ -57,6 +66,7 @@ set selected_command_without_equals (string replace '=' '' (cat $output_file)) @test "prompt name in fzf is correct" $FZF_PROMPT_NAME = CustomPrompt # Test _fzf_cmd_history with allow-execute option (execution validation) +set_current_token "" setup_mocked_history echo command5 | _fzf_cmd_history --allow-execute >$output_file eval (cat $output_file) From 680c9b69764651a50f0c61da6eccbe9cab3dc912 Mon Sep 17 00:00:00 2001 From: y3owk1n Date: Sat, 6 Jan 2024 19:36:46 +0800 Subject: [PATCH 10/11] chore: remove tests for now --- tests/_test_fzf_cmd_history.fish | 76 -------------------------------- 1 file changed, 76 deletions(-) delete mode 100644 tests/_test_fzf_cmd_history.fish diff --git a/tests/_test_fzf_cmd_history.fish b/tests/_test_fzf_cmd_history.fish deleted file mode 100644 index 7e5e0b8..0000000 --- a/tests/_test_fzf_cmd_history.fish +++ /dev/null @@ -1,76 +0,0 @@ -# Function to set up mocked history -function setup_mocked_history - function history - echo command1 - echo command2 - echo command3 - echo command4 - echo command5 - end -end - -# 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 - -# Function to simulate commandline in non-interactive mode -function set_current_token - set -gx COMMANDLINE_CURRENT_TOKEN $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 -set_current_token "" -setup_mocked_history -echo command1 | _fzf_cmd_history >$output_file - -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 -set_current_token "" -setup_mocked_history -setup_mocked_fzf -echo command2 | _fzf_cmd_history --prompt-name CustomPrompt >$output_file - -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 -set_current_token "" -setup_mocked_history -setup_mocked_fzf -echo command3 | _fzf_cmd_history --allow-execute >$output_file - -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 -set_current_token "" -setup_mocked_history -setup_mocked_fzf -echo command4 | _fzf_cmd_history --prompt-name CustomPrompt --allow-execute >$output_file - -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) -set_current_token "" -setup_mocked_history -echo command5 | _fzf_cmd_history --allow-execute >$output_file -eval (cat $output_file) -@test "command execution with allow-execute is successful" $status -eq 0 - -# Clean up temporary directory -rm -rf $temp_dir From 1032510f90b1c32495634674bff649a7eff9e725 Mon Sep 17 00:00:00 2001 From: y3owk1n Date: Sat, 6 Jan 2024 19:38:31 +0800 Subject: [PATCH 11/11] chore: remove tests from ci for now --- .github/workflows/ci.yml | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d89ab4f..8472169 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -5,26 +5,26 @@ on: # Allows you to run this workflow manually from the Actions tab workflow_dispatch: jobs: - tests: - runs-on: ${{ matrix.os }} - strategy: - matrix: - os: [macos-latest, ubuntu-latest] - steps: - - uses: actions/checkout@v4 - - uses: fish-actions/install-fish@v1.1.0 - - 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} - timeout-minutes: 3 + # tests: + # runs-on: ${{ matrix.os }} + # strategy: + # matrix: + # os: [macos-latest, ubuntu-latest] + # steps: + # - uses: actions/checkout@v4 + # - uses: fish-actions/install-fish@v1.1.0 + # - 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} + # timeout-minutes: 3 syntax-check: runs-on: ubuntu-latest steps: