diff --git a/Library/Homebrew/cask/artifact/bashcompletion.rb b/Library/Homebrew/cask/artifact/bashcompletion.rb index e42f1085ca..3ffe7c6833 100644 --- a/Library/Homebrew/cask/artifact/bashcompletion.rb +++ b/Library/Homebrew/cask/artifact/bashcompletion.rb @@ -9,7 +9,7 @@ module Cask class BashCompletion < ShellCompletion sig { params(target: T.any(String, Pathname)).returns(Pathname) } def resolve_target(target) - name = if target.to_s.end_with? ".bash" + name = if File.extname(target).nil? target else new_name = File.basename(target, File.extname(target)) diff --git a/Library/Homebrew/test/cask/artifact/bashcompletion_spec.rb b/Library/Homebrew/test/cask/artifact/bashcompletion_spec.rb new file mode 100644 index 0000000000..3bdfec62f4 --- /dev/null +++ b/Library/Homebrew/test/cask/artifact/bashcompletion_spec.rb @@ -0,0 +1,44 @@ +# frozen_string_literal: true + +RSpec.describe Cask::Artifact::BashCompletion, :cask do + let(:cask) { Cask::CaskLoader.load(cask_token) } + + context "with install" do + let(:install_phase) do + lambda do + cask.artifacts.select { |a| a.is_a?(described_class) }.each do |artifact| + artifact.install_phase(command: NeverSudoSystemCommand, force: false) + end + end + end + + let(:source_path) { cask.staged_path.join("test.bash") } + let(:target_path) { cask.config.bash_completion.join("test") } + let(:full_source_path) { cask.staged_path.join("test.bash-completion") } + let(:full_target_path) { cask.config.bash_completion.join("test") } + + before do + InstallHelper.install_without_artifacts(cask) + end + + context "with completion" do + let(:cask_token) { "with-shellcompletion" } + + it "links the completion to the proper directory" do + install_phase.call + + expect(File).to be_identical target_path, source_path + end + end + + context "with long completion" do + let(:cask_token) { "with-shellcompletion-long" } + + it "links the completion to the proper directory" do + install_phase.call + + expect(File).to be_identical full_target_path, full_source_path + end + end + end +end diff --git a/Library/Homebrew/test/cask/artifact/fishlcompletion_spec.rb b/Library/Homebrew/test/cask/artifact/fishlcompletion_spec.rb new file mode 100644 index 0000000000..f5e166ff45 --- /dev/null +++ b/Library/Homebrew/test/cask/artifact/fishlcompletion_spec.rb @@ -0,0 +1,44 @@ +# frozen_string_literal: true + +RSpec.describe Cask::Artifact::FishCompletion, :cask do + let(:cask) { Cask::CaskLoader.load(cask_token) } + + context "with install" do + let(:install_phase) do + lambda do + cask.artifacts.select { |a| a.is_a?(described_class) }.each do |artifact| + artifact.install_phase(command: NeverSudoSystemCommand, force: false) + end + end + end + + let(:source_path) { cask.staged_path.join("test.fish") } + let(:target_path) { cask.config.fish_completion.join("test.fish") } + let(:full_source_path) { cask.staged_path.join("test.fish-completion") } + let(:full_target_path) { cask.config.fish_completion.join("test.fish") } + + before do + InstallHelper.install_without_artifacts(cask) + end + + context "with completion" do + let(:cask_token) { "with-shellcompletion" } + + it "links the completion to the proper directory" do + install_phase.call + + expect(File).to be_identical target_path, source_path + end + end + + context "with long completion" do + let(:cask_token) { "with-shellcompletion-long" } + + it "links the completion to the proper directory" do + install_phase.call + + expect(File).to be_identical full_target_path, full_source_path + end + end + end +end diff --git a/Library/Homebrew/test/cask/artifact/zshcompletion_spec.rb b/Library/Homebrew/test/cask/artifact/zshcompletion_spec.rb new file mode 100644 index 0000000000..8a46f84f5e --- /dev/null +++ b/Library/Homebrew/test/cask/artifact/zshcompletion_spec.rb @@ -0,0 +1,44 @@ +# frozen_string_literal: true + +RSpec.describe Cask::Artifact::ZshCompletion, :cask do + let(:cask) { Cask::CaskLoader.load(cask_token) } + + context "with install" do + let(:install_phase) do + lambda do + cask.artifacts.select { |a| a.is_a?(described_class) }.each do |artifact| + artifact.install_phase(command: NeverSudoSystemCommand, force: false) + end + end + end + + let(:source_path) { cask.staged_path.join("_test") } + let(:target_path) { cask.config.zsh_completion.join("_test") } + let(:full_source_path) { cask.staged_path.join("test.zsh-completion") } + let(:full_target_path) { cask.config.zsh_completion.join("_test") } + + before do + InstallHelper.install_without_artifacts(cask) + end + + context "with completion" do + let(:cask_token) { "with-shellcompletion" } + + it "links the completion to the proper directory" do + install_phase.call + + expect(File).to be_identical target_path, source_path + end + end + + context "with long completion" do + let(:cask_token) { "with-shellcompletion-long" } + + it "links the completion to the proper directory" do + install_phase.call + + expect(File).to be_identical full_target_path, full_source_path + end + end + end +end diff --git a/Library/Homebrew/test/support/fixtures/cask/AppWithShellCompletion.zip b/Library/Homebrew/test/support/fixtures/cask/AppWithShellCompletion.zip new file mode 100644 index 0000000000..bd3496ae41 Binary files /dev/null and b/Library/Homebrew/test/support/fixtures/cask/AppWithShellCompletion.zip differ diff --git a/Library/Homebrew/test/support/fixtures/cask/Casks/with-shellcompletion-long.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/with-shellcompletion-long.rb new file mode 100644 index 0000000000..8a0e80ad30 --- /dev/null +++ b/Library/Homebrew/test/support/fixtures/cask/Casks/with-shellcompletion-long.rb @@ -0,0 +1,11 @@ +cask "with-shellcompletion-long" do + version "1.2.3" + sha256 "957978d9b30adfda8e1f914ba8c8019e016545c8f7e16c6ab0234d189fac8146" + + url "file://#{TEST_FIXTURE_DIR}/cask/AppWithShellCompletion.zip" + homepage "https://brew.sh/with-autodetected-manpage-section" + + bash_completion "test.bash-completion" + fish_completion "test.fish-completion" + zsh_completion "test.zsh-completion" +end diff --git a/Library/Homebrew/test/support/fixtures/cask/Casks/with-shellcompletion.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/with-shellcompletion.rb new file mode 100644 index 0000000000..54f518dd4c --- /dev/null +++ b/Library/Homebrew/test/support/fixtures/cask/Casks/with-shellcompletion.rb @@ -0,0 +1,11 @@ +cask "with-shellcompletion" do + version "1.2.3" + sha256 "957978d9b30adfda8e1f914ba8c8019e016545c8f7e16c6ab0234d189fac8146" + + url "file://#{TEST_FIXTURE_DIR}/cask/AppWithShellCompletion.zip" + homepage "https://brew.sh/with-autodetected-manpage-section" + + bash_completion "test.bash" + fish_completion "test.fish" + zsh_completion "_test" +end