From 35f964d73b88921759df53c6eccc8805dce2ae9b Mon Sep 17 00:00:00 2001 From: Danny Ben Shitrit Date: Sun, 22 May 2022 13:41:35 +0000 Subject: [PATCH 1/5] add tests for zsh --- lib/completely/templates/tester-template.erb | 9 +++++- spec/README.md | 32 +++++++++++++++++++ spec/approvals/tester/script | 9 +++++- spec/approvals/tester/script_path | 9 +++++- spec/completely/zsh_spec.rb | 33 ++++++++++++++++++++ 5 files changed, 89 insertions(+), 3 deletions(-) create mode 100644 spec/README.md create mode 100644 spec/completely/zsh_spec.rb 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..da45c73 --- /dev/null +++ b/spec/completely/zsh_spec.rb @@ -0,0 +1,33 @@ +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 + `docker run --rm -it -v $PWD/spec/tmp:/app dannyben/zsh #{shell} /app/test.sh`.strip + 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 From 5d8ee57ea40f57a963d660747b3dba4078654850 Mon Sep 17 00:00:00 2001 From: Danny Ben Shitrit Date: Sun, 22 May 2022 13:48:36 +0000 Subject: [PATCH 2/5] debug workflow failure --- .github/workflows/test.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index cd4e3ee..29401e5 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -22,5 +22,8 @@ jobs: ruby-version: '${{ matrix.ruby }}' bundler-cache: true + - name: Pull dannyben/zsh image + run: docker pull dannyben/zsh + - name: Run tests run: bundle exec rspec From 6cc382ffe3284317b10e1ba13ac6e6ed7ae65726 Mon Sep 17 00:00:00 2001 From: Danny Ben Shitrit Date: Sun, 22 May 2022 13:50:11 +0000 Subject: [PATCH 3/5] debug workflow failure --- .github/workflows/test.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 29401e5..d81e72d 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -22,8 +22,8 @@ jobs: ruby-version: '${{ matrix.ruby }}' bundler-cache: true - - name: Pull dannyben/zsh image - run: docker pull dannyben/zsh + - name: Setup tmate session + uses: mxschmitt/action-tmate@v3 - name: Run tests run: bundle exec rspec From 53883ffe71264129b7f788a724279033d831295c Mon Sep 17 00:00:00 2001 From: Danny Ben Shitrit Date: Sun, 22 May 2022 14:07:20 +0000 Subject: [PATCH 4/5] change zsh tests to not use docker --- .github/workflows/test.yml | 3 --- spec/completely/zsh_spec.rb | 4 +++- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index d81e72d..cd4e3ee 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -22,8 +22,5 @@ jobs: ruby-version: '${{ matrix.ruby }}' bundler-cache: true - - name: Setup tmate session - uses: mxschmitt/action-tmate@v3 - - name: Run tests run: bundle exec rspec diff --git a/spec/completely/zsh_spec.rb b/spec/completely/zsh_spec.rb index da45c73..50c811b 100644 --- a/spec/completely/zsh_spec.rb +++ b/spec/completely/zsh_spec.rb @@ -13,7 +13,9 @@ end subject do - `docker run --rm -it -v $PWD/spec/tmp:/app dannyben/zsh #{shell} /app/test.sh`.strip + Dir.chdir 'spec/tmp' do + `#{shell} test.sh`.strip + end end describe "completions script and test script" do From d27dd9886cb76c967531e880b6571acc45e72291 Mon Sep 17 00:00:00 2001 From: Danny Ben Shitrit Date: Sun, 22 May 2022 14:08:52 +0000 Subject: [PATCH 5/5] install zsh in github test workflow --- .github/workflows/test.yml | 3 +++ 1 file changed, 3 insertions(+) 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