diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index cd4e3ee..10c72e9 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -22,5 +22,8 @@ jobs: ruby-version: '${{ matrix.ruby }}' bundler-cache: true + - name: Install zsh + run: sudo apt install -y zsh + - name: Run tests run: bundle exec rspec diff --git a/lib/completely/templates/tester-template.erb b/lib/completely/templates/tester-template.erb index 85749a5..bcd9223 100644 --- a/lib/completely/templates/tester-template.erb +++ b/lib/completely/templates/tester-template.erb @@ -1,7 +1,14 @@ #!/usr/bin/env bash +if [[ -n $ZSH_VERSION ]]; then + autoload -U +X bashcompinit && bashcompinit + autoload -U +X compinit && compinit +fi + +# === COMPLETION SCRIPT START === + <%= script || %Q[source "#{absolute_script_path}"] %> -# END OF COMPLETION SCRIPT +# === COMPLETION SCRIPT END === COMP_WORDS=( <%= compline %> ) COMP_LINE="<%= compline %>" diff --git a/spec/README.md b/spec/README.md new file mode 100644 index 0000000..25343ef --- /dev/null +++ b/spec/README.md @@ -0,0 +1,32 @@ +# Completely Specs + +## Running tests + +```bash +$ rspec +# or +$ run spec +# or, to run just tests in a given file +$ run spec zsh +# or, to run just specs tagged with :focus +$ run spec :focus +``` + +You might need to prefix the commands with `bundle exec`, depending on the way +Ruby is installed. + +## Interactive Approvals + +Some tests may prompt you for an interactive approval of changes. This +functionality is provided by the [rspec_approvals gem][1]. + +Be sure to only approve changes that are indeed expected. + + +## ZSH Compatibility Test + +ZSH compatibility test is done by running the completely tester script inside a +zsh container. This is all done automatically by `spec/completely/zsh_spec.rb`. + + +[1]: https://github.com/dannyben/rspec_approvals \ No newline at end of file diff --git a/spec/approvals/tester/script b/spec/approvals/tester/script index a1c46a9..327178b 100644 --- a/spec/approvals/tester/script +++ b/spec/approvals/tester/script @@ -1,7 +1,14 @@ #!/usr/bin/env bash +if [[ -n $ZSH_VERSION ]]; then + autoload -U +X bashcompinit && bashcompinit + autoload -U +X compinit && compinit +fi + +# === COMPLETION SCRIPT START === + # some completion script -# END OF COMPLETION SCRIPT +# === COMPLETION SCRIPT END === COMP_WORDS=( cli co ) COMP_LINE="cli co" diff --git a/spec/approvals/tester/script_path b/spec/approvals/tester/script_path index 5b98250..6c39f1c 100644 --- a/spec/approvals/tester/script_path +++ b/spec/approvals/tester/script_path @@ -1,7 +1,14 @@ #!/usr/bin/env bash +if [[ -n $ZSH_VERSION ]]; then + autoload -U +X bashcompinit && bashcompinit + autoload -U +X compinit && compinit +fi + +# === COMPLETION SCRIPT START === + source "" -# END OF COMPLETION SCRIPT +# === COMPLETION SCRIPT END === COMP_WORDS=( cli co ) COMP_LINE="cli co" diff --git a/spec/completely/zsh_spec.rb b/spec/completely/zsh_spec.rb new file mode 100644 index 0000000..50c811b --- /dev/null +++ b/spec/completely/zsh_spec.rb @@ -0,0 +1,35 @@ +require 'spec_helper' + +describe "zsh compatibility" do + let(:completions) { Completely::Completions.load 'spec/fixtures/basic.yaml' } + let(:words) { "completely generate " } + let(:tester_script) { completions.tester.tester_script words } + let(:shell) { 'zsh' } + + before do + reset_tmp_dir + system "mkdir -p spec/tmp/somedir" + File.write "spec/tmp/test.sh", tester_script + end + + subject do + Dir.chdir 'spec/tmp' do + `#{shell} test.sh`.strip + end + end + + describe "completions script and test script" do + it "returns completions without erroring" do + expect(subject).to eq "somedir --help --force" + end + + context "on bash" do + let(:shell) { 'bash' } + + it "returns the same output" do + expect(subject).to eq "somedir --help --force" + end + end + end + +end \ No newline at end of file