feat: add tests for completion stanzas
This commit is contained in:
parent
ab2b18f78c
commit
fc319f6793
@ -9,7 +9,7 @@ module Cask
|
|||||||
class BashCompletion < ShellCompletion
|
class BashCompletion < ShellCompletion
|
||||||
sig { params(target: T.any(String, Pathname)).returns(Pathname) }
|
sig { params(target: T.any(String, Pathname)).returns(Pathname) }
|
||||||
def resolve_target(target)
|
def resolve_target(target)
|
||||||
name = if target.to_s.end_with? ".bash"
|
name = if File.extname(target).nil?
|
||||||
target
|
target
|
||||||
else
|
else
|
||||||
new_name = File.basename(target, File.extname(target))
|
new_name = File.basename(target, File.extname(target))
|
||||||
|
|||||||
44
Library/Homebrew/test/cask/artifact/bashcompletion_spec.rb
Normal file
44
Library/Homebrew/test/cask/artifact/bashcompletion_spec.rb
Normal file
@ -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
|
||||||
44
Library/Homebrew/test/cask/artifact/fishlcompletion_spec.rb
Normal file
44
Library/Homebrew/test/cask/artifact/fishlcompletion_spec.rb
Normal file
@ -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
|
||||||
44
Library/Homebrew/test/cask/artifact/zshcompletion_spec.rb
Normal file
44
Library/Homebrew/test/cask/artifact/zshcompletion_spec.rb
Normal file
@ -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
|
||||||
Binary file not shown.
@ -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
|
||||||
@ -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
|
||||||
Loading…
x
Reference in New Issue
Block a user