From 193189ed91050b601a39cb612f96a1729d1becf5 Mon Sep 17 00:00:00 2001 From: Raphael Reitzig <4246780+reitzig@users.noreply.github.com> Date: Mon, 14 Dec 2020 02:07:25 +0100 Subject: [PATCH 01/19] Add tests for 5.9.1 compatibility cf. issue #35 --- README.md | 2 +- test/features/completions.feature | 44 ++++++++++++++++++++----- test/features/step_definitions/setup.rb | 7 ++++ test/features/wrapper.feature | 8 ++++- 4 files changed, 50 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 95a6ead..1100e00 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ Also adds binaries from installed SDKs to the PATH. Version 1.4.0 tested with - fish 2.7.1 and 3.1.2, and - - SDKMAN! 5.8.2, on + - SDKMAN! 5.9.1, on - Ubuntu 18.04 LTS and macOS 10.13 ## Install diff --git a/test/features/completions.feature b/test/features/completions.feature index d2a2710..feaaa6f 100644 --- a/test/features/completions.feature +++ b/test/features/completions.feature @@ -20,8 +20,11 @@ Feature: Shell Completion | b | b, broadcast | /^[^b]+$/ | | c | c, current | /^[^c]+$/ | | d | d, default | /^[^d]+$/ | + | e | e, env | /^[^e]+$/ | | f | flush | /^[^f]+$/ | - | h | h, help | /^[^h]+$/ | + | h | h, help, home | /^[^h]+$/ | + | he | help | | + | ho | home | | | i | i, install | /^[^i]+$/ | | in | install | | | l | list, ls | /^[^l]+$/ | @@ -36,7 +39,6 @@ Feature: Shell Completion # Currently uncovered (except by fuzzy matches); # include negatives to prevent accidents: | a | | /^a/ | - | e | | /^e/ | | g | | /^g/ | | j | | /^j/ | | k | | /^k/ | @@ -175,14 +177,38 @@ Feature: Shell Completion Then completion should propose "" But completion should not propose Examples: - | cmd | completions | exclusions | - | | archives, broadcast, temp | /^(?!archives\|broadcast\|temp).*$/ | - | b | broadcast | /^(?!broadcast).*$/ | - | a | archives | /^(?!archives\|broadcast).*$/ | - | t | temp | /^(?!temp\|broadcast).*$/ | - | x | | /.*/ | - | 'temp ' | | /.*/ | + | cmd | completions | exclusions | + | | archives, broadcast, tmp, version | /^(?!archives\|broadcast\|tmp\|version).*$/ | + | b | broadcast | /^(?!broadcast).*$/ | + | a | archives | /^(?!archives\|broadcast).*$/ | + | t | tmp | /^(?!tmp\|broadcast).*$/ | + | v | version | /^(?!version\|archives).*$/ | + | x | | /.*/ | + | 'tmp ' | | /.*/ | + Scenario Outline: Completion for 'home' + When the user enters "home " into the prompt + Then completion should propose "" + But completion should not propose + Examples: + | cmd | completions | exclusions | + | | ant, crash | gradle | + | an | ant | crash, gradle | + | j | | /.*/ | + | 1. | | /.*/ | + | 'ant ' | 1.10.1, 1.9.9 | /^\w+$/ | + | 'ant 1.10.1 ' | | /.*/ | + + Scenario Outline: Completion for 'env' + When the user enters "env " into the prompt + Then completion should propose "" + But completion should not propose + Examples: + | cmd | completions | exclusions | + | | init | /^(?!init).*$/ | + | i | init | /^(?!init).*$/ | + | a | | /.*/ | + | 'init ' | | /.*/ | Scenario Outline: Completion for commands without parameters When the user enters "" into the prompt diff --git a/test/features/step_definitions/setup.rb b/test/features/step_definitions/setup.rb index 69fdd04..90c6ae9 100644 --- a/test/features/step_definitions/setup.rb +++ b/test/features/step_definitions/setup.rb @@ -1,3 +1,5 @@ +require 'fileutils' + $index_updated = false # TODO: Hack since Cucumber doesn't have Feature-level hooks Given(/^SDKMAN! candidate list is up to date$/) do unless $index_updated @@ -39,6 +41,11 @@ When(/^candidate (\w+) is uninstalled$/) do |candidate| puts `ls ~/.sdkman/candidates/#{candidate}` end +Given(/^file ([a-zA-Z0-9-_.\/]+) exists with content/) do |filename,content| + FileUtils.mkdir_p(File.dirname(filename)) + File.write(filename, content) +end + # Uninstall all SDKMAN! candidates # TODO: Run after every scenario, this makes tests very slow. # Currently, Cucumber doesn't have Feature-level hooks, so we have to work around: diff --git a/test/features/wrapper.feature b/test/features/wrapper.feature index 529c61f..3e3304f 100644 --- a/test/features/wrapper.feature +++ b/test/features/wrapper.feature @@ -4,12 +4,16 @@ Feature: Wrapping of Bash the effect sdk has on the Bash environment carries over the current Fish session. - We verifiy equality of (standard) output, exit code, and environment variables. + We verify equality of (standard) output, exit code, and environment variables. Background: Given SDKMAN! candidate list is up to date And candidate ant is installed at version 1.9.9 And candidate ant is installed at version 1.10.1 + And file /tmp/env-test/.sdkmanrc exists with content + """ + ant=1.9.9 + """ Scenario Outline: When we run "" in Bash and Fish @@ -28,3 +32,5 @@ Feature: Wrapping of Bash | sdk use ant 1.9.9 | | sdk offline enable > /dev/null; sdk install ant foo | | sdk use ant 1.9.9 > /dev/null; sdk broadcast | + | sdk home ant 1.9.9 | + | cd /tmp/env-test; sdk env | From 8fe9d790c6483aaff0e51f2be60d8537113120d9 Mon Sep 17 00:00:00 2001 From: Raphael Reitzig <4246780+reitzig@users.noreply.github.com> Date: Mon, 14 Dec 2020 02:48:47 +0100 Subject: [PATCH 02/19] Fix completions. cf. issue #35 --- completions/sdk.fish | 34 +++++++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/completions/sdk.fish b/completions/sdk.fish index 054c203..e332cd7 100644 --- a/completions/sdk.fish +++ b/completions/sdk.fish @@ -174,7 +174,7 @@ complete -c sdk -f -n '__fish_sdkman_command_has_enough_parameters 0 b broadcast # help complete -c sdk -f -n '__fish_sdkman_no_command' \ - -a 'h help' \ + -a 'help' \ -d 'Display help message' complete -c sdk -f -n '__fish_sdkman_command_has_enough_parameters 0 h help' # block @@ -212,15 +212,39 @@ complete -c sdk -f -n '__fish_sdkman_command_has_enough_parameters 0 update' # flush complete -c sdk -f -n '__fish_sdkman_no_command' \ -a 'flush' \ - -d 'Clear out caches' + -d 'Clear out archives and temporary storage folders' complete -c sdk -f -n '__fish_sdkman_using_command flush' \ -a 'broadcast' \ - -d 'Re-download news' + -d 'Clear out the broadcast/news cache' complete -c sdk -f -n '__fish_sdkman_using_command flush' \ -a 'archives' \ -d 'Remove downloads' complete -c sdk -f -n '__fish_sdkman_using_command flush' \ - -a 'temp' \ - -d 'Clear installation prep folder' + -a 'tmp' \ + -d 'Clear out staging work folder' +complete -c sdk -f -n '__fish_sdkman_using_command flush' \ + -a 'version' \ + -d 'Flush version file' complete -c sdk -f -n '__fish_sdkman_command_has_enough_parameters 1 flush' # block + +# env +complete -c sdk -f -n '__fish_sdkman_no_command' \ + -a 'e env' \ + -d 'Load environment from .sdkmanrc file' +complete -c sdk -f -n '__fish_sdkman_using_command e env' \ + -a 'init' \ + -d 'Initialize .sdkmanrc file' +complete -c sdk -f -n '__fish_sdkman_command_has_enough_parameters 1 e env' + # block + +# home +complete -c sdk -f -n '__fish_sdkman_no_command' \ + -a 'h home' \ + -d 'Show installation folder of given candidate' +complete -c sdk -f -n '__fish_sdkman_using_command h home' \ + -a "(__fish_sdkman_candidates_with_versions)" +complete -c sdk -f -n '__fish_sdkman_specifying_candidate h home' \ + -a "(__fish_sdkman_installed_versions)" +complete -c sdk -f -n '__fish_sdkman_command_has_enough_parameters 2 h home' + # block From 16d432313feac25ddde818401286d3caf4dc3cb4 Mon Sep 17 00:00:00 2001 From: Raphael Reitzig <4246780+reitzig@users.noreply.github.com> Date: Fri, 22 Jan 2021 00:38:01 +0100 Subject: [PATCH 03/19] Add tests for 5.9.2 compatibility --- test/features/completions.feature | 53 +++++++++++++++++-------------- test/features/wrapper.feature | 1 + 2 files changed, 30 insertions(+), 24 deletions(-) diff --git a/test/features/completions.feature b/test/features/completions.feature index feaaa6f..0024bbe 100644 --- a/test/features/completions.feature +++ b/test/features/completions.feature @@ -125,6 +125,35 @@ Feature: Shell Completion | 'ant ' | 1.10.1, 1.9.9 | /^\w+$/ | | 'ant 1.10.1 ' | | /.*/ | + Scenario Outline: Completion for 'home' + When the user enters "home " into the prompt + Then completion should propose "" + But completion should not propose + Examples: + | cmd | completions | exclusions | + | | ant, crash | gradle | + | an | ant | crash, gradle | + | j | | /.*/ | + | 1. | | /.*/ | + | 'ant ' | 1.10.1, 1.9.9 | /^\w+$/ | + | 'ant 1.10.1 ' | | /.*/ | + + Scenario Outline: Completion for 'env' + When the user enters "env " into the prompt + Then completion should propose "" + But completion should not propose + Examples: + | cmd | completions | exclusions | + | | init, install, clear | /^(?!init\|install\|clear).*$/ | + | i | init, install | /^(?!init\|install).*$/ | + | ini | init | /^(?!init).*$/ | + | ins | install | /^(?!install).*$/ | + | c | clear | /^(?!clear).*$/ | + | a | | /.*/ | + | 'init ' | | /.*/ | + | 'clear ' | | /.*/ | + | 'install ' | | /.*/ | + Scenario Outline: Completion for 'current' When the user enters "current " into the prompt Then completion should propose "" @@ -186,30 +215,6 @@ Feature: Shell Completion | x | | /.*/ | | 'tmp ' | | /.*/ | - Scenario Outline: Completion for 'home' - When the user enters "home " into the prompt - Then completion should propose "" - But completion should not propose - Examples: - | cmd | completions | exclusions | - | | ant, crash | gradle | - | an | ant | crash, gradle | - | j | | /.*/ | - | 1. | | /.*/ | - | 'ant ' | 1.10.1, 1.9.9 | /^\w+$/ | - | 'ant 1.10.1 ' | | /.*/ | - - Scenario Outline: Completion for 'env' - When the user enters "env " into the prompt - Then completion should propose "" - But completion should not propose - Examples: - | cmd | completions | exclusions | - | | init | /^(?!init).*$/ | - | i | init | /^(?!init).*$/ | - | a | | /.*/ | - | 'init ' | | /.*/ | - Scenario Outline: Completion for commands without parameters When the user enters "" into the prompt Then completion should not propose /.*/ diff --git a/test/features/wrapper.feature b/test/features/wrapper.feature index 3e3304f..2bb6a3e 100644 --- a/test/features/wrapper.feature +++ b/test/features/wrapper.feature @@ -34,3 +34,4 @@ Feature: Wrapping of Bash | sdk use ant 1.9.9 > /dev/null; sdk broadcast | | sdk home ant 1.9.9 | | cd /tmp/env-test; sdk env | + | cd /tmp/env-test; sdk env; sdk env clear | From a8a9a17c91a8cf1f26cc051cef7c1ecd0dd4ae49 Mon Sep 17 00:00:00 2001 From: Raphael Reitzig <4246780+reitzig@users.noreply.github.com> Date: Fri, 22 Jan 2021 00:38:07 +0100 Subject: [PATCH 04/19] Fix completions --- completions/sdk.fish | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/completions/sdk.fish b/completions/sdk.fish index e332cd7..678688c 100644 --- a/completions/sdk.fish +++ b/completions/sdk.fish @@ -235,6 +235,12 @@ complete -c sdk -f -n '__fish_sdkman_no_command' \ complete -c sdk -f -n '__fish_sdkman_using_command e env' \ -a 'init' \ -d 'Initialize .sdkmanrc file' +complete -c sdk -f -n '__fish_sdkman_using_command e env' \ + -a 'install' \ + -d 'Install all candidate versions listed in .sdkmanrc' +complete -c sdk -f -n '__fish_sdkman_using_command e env' \ + -a 'clear' \ + -d 'Unload currently loaded environment' complete -c sdk -f -n '__fish_sdkman_command_has_enough_parameters 1 e env' # block From 04ecbe7361c0d180f61aa0c19e5ab62160b93755 Mon Sep 17 00:00:00 2001 From: Raphael Reitzig <4246780+reitzig@users.noreply.github.com> Date: Fri, 22 Jan 2021 00:47:19 +0100 Subject: [PATCH 05/19] Fix `sdk env clear` --- conf.d/sdk.fish | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/conf.d/sdk.fish b/conf.d/sdk.fish index 507b212..270a018 100644 --- a/conf.d/sdk.fish +++ b/conf.d/sdk.fish @@ -42,7 +42,8 @@ function __fish_sdkman_run_in_bash echo -e \"\$?\" > $pipe; env | grep -e '^SDKMAN_\|^PATH' >> $pipe; env | grep -i -E \"^(`echo \${SDKMAN_CANDIDATES_CSV} | sed 's/,/|/g'`)_HOME\" >> $pipe; - echo \"SDKMAN_OFFLINE_MODE=\${SDKMAN_OFFLINE_MODE}\" >> $pipe" # it's not an environment variable! + echo \"SDKMAN_OFFLINE_MODE=\${SDKMAN_OFFLINE_MODE}\" >> $pipe; + echo \"SDKMAN_ENV=\${SDKMAN_ENV}\" >> $pipe" # it's not an environment variable! set bashDump (cat $pipe; rm $pipe) set sdkStatus $bashDump[1] @@ -65,7 +66,7 @@ function __fish_sdkman_run_in_bash if test -n value set -gx $var $value - # Note: This makes SDKMAN_OFFLINE_MODE an environment variable. + # Note: This makes SDKMAN_{OFFLINE_MODE,ENV} environment variables. # That gives it the behaviour we _want_! end end From 244456c68147af5536d8786bbc990b02923a2f54 Mon Sep 17 00:00:00 2001 From: Raphael Reitzig <4246780+reitzig@users.noreply.github.com> Date: Mon, 14 Dec 2020 03:25:46 +0100 Subject: [PATCH 06/19] Add GitHub workflows for test and release Also: - Fix test scenario that failed due to fuzzy completions - Bump Cucumber Fixes #36 --- .github/workflows/release.yml | 30 ++++++++ .github/workflows/test.yml | 93 ++++++++++++++++++++++++ CHANGELOG.md | 61 ++++++++++++++++ README.md | 17 +++-- test/Dockerfile | 6 +- test/Gemfile | 4 +- test/features/completions.feature | 2 +- test/features/step_definitions/setup.rb | 6 +- test/features/support/parameter_types.rb | 1 + 9 files changed, 205 insertions(+), 15 deletions(-) create mode 100644 .github/workflows/release.yml create mode 100644 .github/workflows/test.yml create mode 100644 CHANGELOG.md diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..8b442ce --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,30 @@ +name: Release + +on: + push: + tags: + - 'v*' + +jobs: + release: + name: "Create Release" + runs-on: ubuntu-latest + steps: + - name: Is pre-release? + id: is_pre_release + run: | + version="${GITHUB_REF#refs/tags/}" + if [[ "${version}" =~ -.*$ ]]; then + echo ::set-output name=IS_PRERELEASE::true + else + echo ::set-output name=IS_PRERELEASE::false + fi + - name: Release + uses: docker://antonyurchenko/git-release:v3 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + DRAFT_RELEASE: "false" + PRE_RELEASE: ${{ steps.is_pre_release.outputs.IS_PRERELEASE }} + CHANGELOG_FILE: "CHANGELOG.md" + ALLOW_EMPTY_CHANGELOG: "false" + ALLOW_TAG_PREFIX: "true" diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..dc27012 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,93 @@ +name: Tests + +on: + push: + pull_request: + types: + - opened + - synchronize + - reopened + +jobs: + tests: + name: "Scenarios" + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: + - 'ubuntu-20.04' + - 'macos-latest' + steps: + - uses: actions/checkout@v2 + + - uses: ruby/setup-ruby@v1 + with: + ruby-version: 2.7 + + - name: Install Test Dependencies + working-directory: test + run: | + gem install bundler + bundle install + + - name: Install SDKMAN! + run: | + curl -s "https://get.sdkman.io" | bash + source "$HOME/.sdkman/bin/sdkman-init.sh" + sdk version + + - name: Install fish (Linux) + if: matrix.os == 'ubuntu-20.04' + uses: fish-actions/install-fish@v1.0.0 + + - name: Install fish (macOS) + if: matrix.os == 'macos-latest' + run: | + brew install fish + + - name: Install sdkman-for-fish + shell: fish "{0}" + run: | + fish --version + curl -sL https://git.io/fisher | source && fisher install jorgebucaran/fisher + fisher install . + + - name: Confirm install + shell: fish "{0}" + run: | + fish --version + sdk version + + - name: Run Tests + working-directory: test + run: | + cucumber --publish-quiet + + confirm-installation: + name: "Check fisher install" + runs-on: ubuntu-latest + steps: + - name: Install fish + uses: fish-actions/install-fish@v1.0.0 + + - name: Install SDKMAN! + run: | + curl -s "https://get.sdkman.io" | bash + + - name: Install fisher + shell: fish "{0}" + run: | + fish --version + curl -sL https://git.io/fisher | source && fisher install jorgebucaran/fisher + fisher --version + + - name: Install sdkman-for-fish + shell: fish "{0}" + run: | + fisher install reitzig/sdkman-for-fish + + - name: Confirm install + shell: fish "{0}" + run: | + fisher ls + sdk version diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..d89de9c --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,61 @@ +# Changelog + +All notable changes to this project will be documented in this file. + +The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and +this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). + +## [2.0.0] - upcoming + +### Breaking + +- Drop (explicit) support for Fish 2 + +### Features + +- Compatibility with SDKMAN! 5.9.2 + - Completions for `env`, `home`, `flush` (issue #35) + - Correct behaviour of `env clear`. + - TODO: autoenv (issue #38) + - TODO: custom SDKMAN! install path (issue #34) +- Compatibility with fisher 4 (PR #37, #39) + +## [1.4.0] - 2019-11-06 + +### Features + +- Compatibility with macOS (issue #29) + +## [1.3.0] - 2019-11-05 + +### Features + +- Install SDKMAN! if missing (issue #26) + +## [1.2.0] - 2019-07-31 + +### Features + +- Compatibility with fish 3 (issue #27) + +## [1.1.2] - 2019-01-06 + +### Fixes + +- Re-initialize if user has changed (issue #25) + +## [1.1.1] - 2018-11-09 + +### Fixes + +- Set `_HOME` environment variables (issue #24) + +## [1.1.0] - 2018-10-08 + +### Features + +- Compatibility with fisher 3 (PR #22) + +## [1.0.0] - 2018-07-21 + +Initial release. diff --git a/README.md b/README.md index 1100e00..ecb47bf 100644 --- a/README.md +++ b/README.md @@ -1,27 +1,30 @@ # SDKMAN! for fish -[![Build Status][travis-badge]][travis-link] +[![license](https://img.shields.io/github/license/reitzig/sdkman-for-fish.svg)](https://github.com/reitzig/sdkman-for-fish/blob/master/LICENSE) +[![release](https://img.shields.io/github/release/reitzig/sdkman-for-fish.svg)](https://github.com/reitzig/sdkman-for-fish/releases/latest) +[![GitHub release date](https://img.shields.io/github/release-date/reitzig/sdkman-for-fish.svg)](https://github.com/reitzig/sdkman-for-fish/releases) +![Tests](https://github.com/reitzig/sdkman-for-fish/workflows/Tests/badge.svg?branch=master) Makes command `sdk` from [SDKMAN!] usable from [fish], including auto-completion. Also adds binaries from installed SDKs to the PATH. -Version 1.4.0 tested with +Version 2.0.0 has been tested with - - fish 2.7.1 and 3.1.2, and - - SDKMAN! 5.9.1, on - - Ubuntu 18.04 LTS and macOS 10.13 + - fish 3.1, and + - SDKMAN! 5.9, on + - Ubuntu 20.04 LTS and macOS 10.15 ## Install With [fisher] (install separately): ``` -fisher add reitzig/sdkman-for-fish@v1.4.0 +fisher add reitzig/sdkman-for-fish@v2.0.0 ``` _Note:_ - - Only compatible with fisher v3 upwards; v2 is no longer supported. + - Only compatible with fisher v4 upwards; v3 is no longer supported. - You have to install [SDKMAN!] separately. ## Usage diff --git a/test/Dockerfile b/test/Dockerfile index 4044d2b..0acbf64 100644 --- a/test/Dockerfile +++ b/test/Dockerfile @@ -1,4 +1,4 @@ -FROM ruby:2.5.8-slim-buster +FROM ruby:2.7-slim-buster # Install dependencies RUN apt-get update \ @@ -7,6 +7,8 @@ RUN apt-get update \ curl \ unzip \ zip \ + ruby-dev \ + build-essential \ && apt-get clean WORKDIR app @@ -38,4 +40,4 @@ RUN ls -R $TEST_HOME/.config/fish/ # Run tests COPY test ./ ENTRYPOINT ["cucumber"] -CMD [] +CMD ["--publish-quiet"] diff --git a/test/Gemfile b/test/Gemfile index 70d69fe..802cef6 100644 --- a/test/Gemfile +++ b/test/Gemfile @@ -1,6 +1,6 @@ source "https://rubygems.org" group :test do - gem 'cucumber', '~> 3.1.0' - gem 'rspec', '~> 3.7.0' + gem 'cucumber', '~> 5' + gem 'rspec', '~> 3' end diff --git a/test/features/completions.feature b/test/features/completions.feature index 0024bbe..a06ff0b 100644 --- a/test/features/completions.feature +++ b/test/features/completions.feature @@ -149,7 +149,7 @@ Feature: Shell Completion | ini | init | /^(?!init).*$/ | | ins | install | /^(?!install).*$/ | | c | clear | /^(?!clear).*$/ | - | a | | /.*/ | + | b | | /.*/ | | 'init ' | | /.*/ | | 'clear ' | | /.*/ | | 'install ' | | /.*/ | diff --git a/test/features/step_definitions/setup.rb b/test/features/step_definitions/setup.rb index 90c6ae9..fa9198a 100644 --- a/test/features/step_definitions/setup.rb +++ b/test/features/step_definitions/setup.rb @@ -34,14 +34,14 @@ def _uninstall_candidate_version(candidate_dir) end When(/^candidate (\w+) is uninstalled$/) do |candidate| - puts `ls ~/.sdkman/candidates/#{candidate}` + log `ls ~/.sdkman/candidates/#{candidate}` Dir["#{ENV['HOME']}/.sdkman/candidates/#{candidate}/*"].each do |candidate_dir| _uninstall_candidate_version(candidate_dir) end - puts `ls ~/.sdkman/candidates/#{candidate}` + log `ls ~/.sdkman/candidates/#{candidate}` end -Given(/^file ([a-zA-Z0-9-_.\/]+) exists with content/) do |filename,content| +Given(/^file ([a-zA-Z0-9\-_.\/]+) exists with content/) do |filename,content| FileUtils.mkdir_p(File.dirname(filename)) File.write(filename, content) end diff --git a/test/features/support/parameter_types.rb b/test/features/support/parameter_types.rb index 492bdde..ba4d39d 100644 --- a/test/features/support/parameter_types.rb +++ b/test/features/support/parameter_types.rb @@ -6,6 +6,7 @@ ParameterType( type: Array, transformer: lambda do |*patterns| patterns \ + .select { |s| !s.nil? } # Huh? Well, if it helps... .map(&:strip) \ .map do |s| s = if %r{^/(.*)/$} =~ s From 7b17fcc4b7e7e9b78ab47453f092dfb34b7f6748 Mon Sep 17 00:00:00 2001 From: Raphael Reitzig <4246780+reitzig@users.noreply.github.com> Date: Fri, 22 Jan 2021 08:41:37 +0100 Subject: [PATCH 07/19] Bump install-fish action --- .github/workflows/test.yml | 27 +++++++++++++---------- .travis.yml | 45 -------------------------------------- README.md | 4 ++-- 3 files changed, 18 insertions(+), 58 deletions(-) delete mode 100644 .travis.yml diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index dc27012..8ec571b 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -20,6 +20,10 @@ jobs: steps: - uses: actions/checkout@v2 + # NB: We have a Docker setup for testing -- why do all this? + # Because we want to confirm it runs on macOS, and + # there are no Docker images based on frickin' macOS. + - uses: ruby/setup-ruby@v1 with: ruby-version: 2.7 @@ -36,14 +40,9 @@ jobs: source "$HOME/.sdkman/bin/sdkman-init.sh" sdk version - - name: Install fish (Linux) - if: matrix.os == 'ubuntu-20.04' - uses: fish-actions/install-fish@v1.0.0 - - - name: Install fish (macOS) - if: matrix.os == 'macos-latest' - run: | - brew install fish + - name: Install fish + # TODO: Change to recent version, when the maintainer creates a tag + uses: fish-actions/install-fish@d6d9d26231a15f8d9a6b3e74b3db45512440e3e8 - name: Install sdkman-for-fish shell: fish "{0}" @@ -65,10 +64,16 @@ jobs: confirm-installation: name: "Check fisher install" - runs-on: ubuntu-latest + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: + - 'ubuntu-20.04' + - 'macos-latest' steps: - name: Install fish - uses: fish-actions/install-fish@v1.0.0 + #uses: fish-actions/install-fish@v1.2.0 + uses: fish-actions/install-fish@master # TODO: change back after #2 - name: Install SDKMAN! run: | @@ -84,7 +89,7 @@ jobs: - name: Install sdkman-for-fish shell: fish "{0}" run: | - fisher install reitzig/sdkman-for-fish + fisher install reitzig/sdkman-for-fish@${{ github.sha }} - name: Confirm install shell: fish "{0}" diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index d17c78f..0000000 --- a/.travis.yml +++ /dev/null @@ -1,45 +0,0 @@ -matrix: - include: - - dist: bionic - env: FISH=2 - addons: - apt: - sources: - - sourceline: "ppa:fish-shell/release-2" - packages: - - fish - - dist: bionic - env: FISH=3 - addons: - apt: - sources: - - sourceline: "ppa:fish-shell/release-3" - packages: - - fish - - os: osx - env: FISH=3 - addons: - homebrew: - packages: - - fish # --> latest, i.e. >=3.1.2 - update: true # TODO: build should be green without, but isn't - -before_install: - - curl -s "https://get.sdkman.io" | bash - - bundle install --gemfile=test/Gemfile --no-cache - - |- - uname -a; - fish --version; - { source ~/.bash_profile || source ~/.bashrc; } && sdk version; - ruby --version; - echo "cucumber $(cucumber --version)"; - -install: - - |- - mkdir -p "${HOME}"/.config/fish/{completions,conf.d,functions} - cp completions/* "${HOME}"/.config/fish/completions/ - cp conf.d/* "${HOME}"/.config/fish/conf.d/ - cp functions/* "${HOME}"/.config/fish/functions/ - -script: - - (cd test && cucumber) diff --git a/README.md b/README.md index ecb47bf..cd37c44 100644 --- a/README.md +++ b/README.md @@ -10,8 +10,8 @@ Also adds binaries from installed SDKs to the PATH. Version 2.0.0 has been tested with - - fish 3.1, and - - SDKMAN! 5.9, on + - fish 3.1.2, and + - SDKMAN! 5.9.2, on - Ubuntu 20.04 LTS and macOS 10.15 ## Install From 61f1cf8efcdff310cfdcdb0d2563e9c351b32f54 Mon Sep 17 00:00:00 2001 From: Raphael Reitzig <4246780+reitzig@users.noreply.github.com> Date: Fri, 29 Jan 2021 13:26:07 +0100 Subject: [PATCH 08/19] Test for `autoenv` setting --- .github/workflows/test.yml | 2 +- README.md | 2 +- test/Dockerfile | 2 +- test/features/autoenv.feature | 85 +++++++++++++++++++++++ test/features/step_definitions/general.rb | 29 ++++++++ test/features/step_definitions/setup.rb | 29 +++++--- test/features/support/hooks.rb | 17 +++++ 7 files changed, 154 insertions(+), 12 deletions(-) create mode 100644 test/features/autoenv.feature create mode 100644 test/features/step_definitions/general.rb create mode 100644 test/features/support/hooks.rb diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 8ec571b..3be08c2 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -60,7 +60,7 @@ jobs: - name: Run Tests working-directory: test run: | - cucumber --publish-quiet + cucumber --publish-quiet --tags "not @pending" confirm-installation: name: "Check fisher install" diff --git a/README.md b/README.md index cd37c44..dff84bd 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ Also adds binaries from installed SDKs to the PATH. Version 2.0.0 has been tested with - fish 3.1.2, and - - SDKMAN! 5.9.2, on + - SDKMAN! 5.11.0, on - Ubuntu 20.04 LTS and macOS 10.15 ## Install diff --git a/test/Dockerfile b/test/Dockerfile index 0acbf64..309e466 100644 --- a/test/Dockerfile +++ b/test/Dockerfile @@ -40,4 +40,4 @@ RUN ls -R $TEST_HOME/.config/fish/ # Run tests COPY test ./ ENTRYPOINT ["cucumber"] -CMD ["--publish-quiet"] +CMD ["--publish-quiet", "--tags", "not @pending"] diff --git a/test/features/autoenv.feature b/test/features/autoenv.feature new file mode 100644 index 0000000..e1d6e09 --- /dev/null +++ b/test/features/autoenv.feature @@ -0,0 +1,85 @@ +Feature: Support autoenv setting + When the user sets `sdkman_auto_env=true`, we should always `use` the + candidates specified in `./.sdkmanrc`, if any. + + Background: + Given SDKMAN! candidate list is up to date + And candidate ant is installed at version 1.9.7 + And candidate ant is installed at version 1.9.9 + And candidate ant is installed at version 1.10.1 + And candidate crash is installed at version 1.2.11 + And candidate crash is installed at version 1.3.0 + + Scenario: No action if autoenv turned off + Given SDKMAN! config sets sdkman_auto_env to false + And file /tmp/autoenv-test/.sdkmanrc exists with content + """ + ant=1.9.9 + """ + When we run fish script + """ + echo (basename $ANT_HOME) > /tmp/autoenv-test.log + cd /tmp/autoenv-test + echo (basename $ANT_HOME) >> /tmp/autoenv-test.log + cd .. + echo (basename $ANT_HOME) >> /tmp/autoenv-test.log + """ + Then file /tmp/autoenv-test.log contains + """ + current + current + current + """ + + Scenario: .sdkmanrc loaded if autoenv turned on + Given SDKMAN! config sets sdkman_auto_env to true + And file /tmp/autoenv-test/.sdkmanrc exists with content + """ + ant=1.9.9 + """ + When we run fish script + """ + echo (basename $ANT_HOME) > /tmp/autoenv-test.log + cd /tmp/autoenv-test + echo (basename $ANT_HOME) >> /tmp/autoenv-test.log + cd .. + echo (basename $ANT_HOME) >> /tmp/autoenv-test.log + """ + Then file /tmp/autoenv-test.log contains + """ + current + 1.9.9 + 1.10.1 + """ + # TODO: we would expect `current` in the last line -- but that's what sdk currently does! + + # TODO: This one doesn't work due to a bug in sdkman. Track: https://github.com/sdkman/sdkman-cli/pull/878 + @pending + Scenario: Switching between directories with .sdkmanrc + Given SDKMAN! config sets sdkman_auto_env to true + And file /tmp/autoenv-test-1/.sdkmanrc exists with content + """ + ant=1.9.9 + crash=1.2.11 + """ + And file /tmp/autoenv-test-2/.sdkmanrc exists with content + """ + ant=1.9.7 + """ + When we run fish script + """ + echo (basename $ANT_HOME),(basename $CRASH_HOME) > /tmp/autoenv-test.log + cd /tmp/autoenv-test-1 + echo (basename $ANT_HOME),(basename $CRASH_HOME) >> /tmp/autoenv-test.log + cd ../autoenv-test-2 + echo (basename $ANT_HOME),(basename $CRASH_HOME) >> /tmp/autoenv-test.log + cd .. + echo (basename $ANT_HOME),(basename $CRASH_HOME) >> /tmp/autoenv-test.log + """ + Then file /tmp/autoenv-test.log contains + """ + current,current + 1.9.9,1.2.11 + 1.9.7,current + current,current + """ diff --git a/test/features/step_definitions/general.rb b/test/features/step_definitions/general.rb new file mode 100644 index 0000000..86f6aa6 --- /dev/null +++ b/test/features/step_definitions/general.rb @@ -0,0 +1,29 @@ +# frozen_string_literal: true + +require 'fileutils' +require 'tempfile' + +module GeneralHelper +end +World GeneralHelper + +When('we run fish script') do |script_content| + script_file = Tempfile.new('fish_script') + File.write(script_file, script_content) + + out, status = Open3.capture2e("fish #{script_file.path}") + unless status.success? + warn(out) + raise "Fish command failed: #{out}" + end + + @response_fish_script = out.strip +end + +Then(/^the output is$/) do |text| + expect(@response_fish_script).to eq(text.strip) +end + +Then(/^file ([a-zA-Z0-9-_.\/]+) contains$/) do |file,content| + expect(File.readlines(file).join("").strip).to eq(content.strip) +end diff --git a/test/features/step_definitions/setup.rb b/test/features/step_definitions/setup.rb index fa9198a..c82eee1 100644 --- a/test/features/step_definitions/setup.rb +++ b/test/features/step_definitions/setup.rb @@ -1,4 +1,5 @@ require 'fileutils' +require 'tempfile' $index_updated = false # TODO: Hack since Cucumber doesn't have Feature-level hooks Given(/^SDKMAN! candidate list is up to date$/) do @@ -46,14 +47,24 @@ Given(/^file ([a-zA-Z0-9\-_.\/]+) exists with content/) do |filename,content| File.write(filename, content) end -# Uninstall all SDKMAN! candidates -# TODO: Run after every scenario, this makes tests very slow. -# Currently, Cucumber doesn't have Feature-level hooks, so we have to work around: -# --> install only if not already installed; -# if the test needs a candidate to _not_ be there, make it explicit. -# --> clean up after _all_ features at least -at_exit do - Dir["#{ENV['HOME']}/.sdkman/candidates/*/*"].each do |candidate_dir| - _uninstall_candidate_version(candidate_dir) +$config_file = "#{ENV['HOME']}/.sdkman/etc/config" +$backup_config_file = nil +def _restore_config # called in After hook + unless $backup_config_file.nil? + FileUtils.mv($backup_config_file, $config_file) + $backup_config_file = nil end end + +Given(/^SDKMAN! config sets ([a-z_]+) to (.*)$/) do |key,value| + if $backup_config_file.nil? + $backup_config_file = Tempfile.new('sdkman_config_backup') + FileUtils.cp($config_file, $backup_config_file) + end + + config = File.readlines($config_file).map { |line| line.split("=").map { |v| v.strip } }.to_h + config[key] = value + new_config_string = config.map { |k,v| "#{k}=#{v}" }.join("\n") + + File.write($config_file, new_config_string) +end diff --git a/test/features/support/hooks.rb b/test/features/support/hooks.rb new file mode 100644 index 0000000..74a6f90 --- /dev/null +++ b/test/features/support/hooks.rb @@ -0,0 +1,17 @@ +require_relative '../step_definitions/setup' + +After do |scenario| + _restore_config +end + +# Uninstall all SDKMAN! candidates +# TODO: Run after every scenario, this makes tests very slow. +# Currently, Cucumber doesn't have Feature-level hooks, so we have to work around: +# --> install only if not already installed; +# if the test needs a candidate to _not_ be there, make it explicit. +# --> clean up after _all_ features at least +at_exit do + Dir["#{ENV['HOME']}/.sdkman/candidates/*/*"].each do |candidate_dir| + _uninstall_candidate_version(candidate_dir) + end +end From 6dc108ec03e6abf523c7b9c6294e59cec08cbb79 Mon Sep 17 00:00:00 2001 From: Raphael Reitzig <4246780+reitzig@users.noreply.github.com> Date: Fri, 26 Feb 2021 17:17:08 +0100 Subject: [PATCH 09/19] Implement `autoenv` feature. Closes issue #38 --- CHANGELOG.md | 2 +- conf.d/sdk.fish | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d89de9c..11f0737 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,7 +16,7 @@ this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm - Compatibility with SDKMAN! 5.9.2 - Completions for `env`, `home`, `flush` (issue #35) - Correct behaviour of `env clear`. - - TODO: autoenv (issue #38) + - Honor `sdkman_auto_env=true` (issue #38) - TODO: custom SDKMAN! install path (issue #34) - Compatibility with fisher 4 (PR #37, #39) diff --git a/conf.d/sdk.fish b/conf.d/sdk.fish index 270a018..bf4f1d6 100644 --- a/conf.d/sdk.fish +++ b/conf.d/sdk.fish @@ -83,3 +83,12 @@ if not set -q SDKMAN_DIR; or test (ls -ld "$SDKMAN_DIR" | awk '{print $3}') != ( __fish_sdkman_run_in_bash "source $__fish_sdkman_init" end +# Set up autoenv +if grep -q "^sdkman_auto_env=true" "$SDKMAN_DIR/etc/config" + function __fish_sdkman_autoenv --on-variable PWD + # Run the (modified) init script, which performs the checks and calls for us! + __fish_sdkman_run_in_bash "source \"$__fish_sdkman_noexport_init\"" + + set -x SDKMAN_OLD_PWD "$PWD" + end +end From 3f0a0b9a9e3ed3df2ffe48aec44bb9db945be4d5 Mon Sep 17 00:00:00 2001 From: Raphael Reitzig <4246780+reitzig@users.noreply.github.com> Date: Fri, 26 Feb 2021 17:30:37 +0100 Subject: [PATCH 10/19] Fix `autoenv` test Using `current` as version doesn't work; it's a symlink that can change. Resolve the symlink before comparison! --- test/features/autoenv.feature | 35 +++++++++++++++++------------------ 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/test/features/autoenv.feature b/test/features/autoenv.feature index e1d6e09..f974643 100644 --- a/test/features/autoenv.feature +++ b/test/features/autoenv.feature @@ -18,17 +18,17 @@ Feature: Support autoenv setting """ When we run fish script """ - echo (basename $ANT_HOME) > /tmp/autoenv-test.log + echo (basename (realpath $ANT_HOME)) > /tmp/autoenv-test.log cd /tmp/autoenv-test - echo (basename $ANT_HOME) >> /tmp/autoenv-test.log + echo (basename (realpath $ANT_HOME)) >> /tmp/autoenv-test.log cd .. - echo (basename $ANT_HOME) >> /tmp/autoenv-test.log + echo (basename (realpath $ANT_HOME)) >> /tmp/autoenv-test.log """ Then file /tmp/autoenv-test.log contains """ - current - current - current + 1.10.1 + 1.10.1 + 1.10.1 """ Scenario: .sdkmanrc loaded if autoenv turned on @@ -39,19 +39,18 @@ Feature: Support autoenv setting """ When we run fish script """ - echo (basename $ANT_HOME) > /tmp/autoenv-test.log + echo (basename (realpath $ANT_HOME)) > /tmp/autoenv-test.log cd /tmp/autoenv-test - echo (basename $ANT_HOME) >> /tmp/autoenv-test.log + echo (basename (realpath $ANT_HOME)) >> /tmp/autoenv-test.log cd .. - echo (basename $ANT_HOME) >> /tmp/autoenv-test.log + echo (basename (realpath $ANT_HOME)) >> /tmp/autoenv-test.log """ Then file /tmp/autoenv-test.log contains """ - current + 1.10.1 1.9.9 1.10.1 """ - # TODO: we would expect `current` in the last line -- but that's what sdk currently does! # TODO: This one doesn't work due to a bug in sdkman. Track: https://github.com/sdkman/sdkman-cli/pull/878 @pending @@ -68,18 +67,18 @@ Feature: Support autoenv setting """ When we run fish script """ - echo (basename $ANT_HOME),(basename $CRASH_HOME) > /tmp/autoenv-test.log + echo (basename (realpath $ANT_HOME)),(basename (realpath $CRASH_HOME)) > /tmp/autoenv-test.log cd /tmp/autoenv-test-1 - echo (basename $ANT_HOME),(basename $CRASH_HOME) >> /tmp/autoenv-test.log + echo (basename (realpath $ANT_HOME)),(basename (realpath $CRASH_HOME)) >> /tmp/autoenv-test.log cd ../autoenv-test-2 - echo (basename $ANT_HOME),(basename $CRASH_HOME) >> /tmp/autoenv-test.log + echo (basename (realpath $ANT_HOME)),(basename (realpath $CRASH_HOME)) >> /tmp/autoenv-test.log cd .. - echo (basename $ANT_HOME),(basename $CRASH_HOME) >> /tmp/autoenv-test.log + echo (basename (realpath $ANT_HOME)),(basename (realpath $CRASH_HOME)) >> /tmp/autoenv-test.log """ Then file /tmp/autoenv-test.log contains """ - current,current + 1.10.1,1.3.0 1.9.9,1.2.11 - 1.9.7,current - current,current + 1.9.7,1.3.0 + 1.10.1,1.3.0 """ From e4e94a265383a601c0ad6d74c1b5bcfdc0bef7bd Mon Sep 17 00:00:00 2001 From: Raphael Reitzig <4246780+reitzig@users.noreply.github.com> Date: Sun, 25 Jun 2023 10:08:17 +0200 Subject: [PATCH 11/19] chore: Update test workflow - fish-actions/install-fish got a tag - Ubuntu 22.04 is the latest LTS - fisher installs differently nowadays --- .github/workflows/test.yml | 18 +++++++++--------- .idea/runConfigurations/Test.xml | 3 --- README.md | 2 +- 3 files changed, 10 insertions(+), 13 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 3be08c2..43fdf44 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -15,10 +15,10 @@ jobs: strategy: matrix: os: - - 'ubuntu-20.04' + - 'ubuntu-22.04' - 'macos-latest' steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 # NB: We have a Docker setup for testing -- why do all this? # Because we want to confirm it runs on macOS, and @@ -41,14 +41,14 @@ jobs: sdk version - name: Install fish - # TODO: Change to recent version, when the maintainer creates a tag - uses: fish-actions/install-fish@d6d9d26231a15f8d9a6b3e74b3db45512440e3e8 + uses: fish-actions/install-fish@v1.1.0 - name: Install sdkman-for-fish shell: fish "{0}" run: | fish --version - curl -sL https://git.io/fisher | source && fisher install jorgebucaran/fisher + curl -sL https://raw.githubusercontent.com/jorgebucaran/fisher/main/functions/fisher.fish | source \ + && fisher install jorgebucaran/fisher fisher install . - name: Confirm install @@ -68,12 +68,11 @@ jobs: strategy: matrix: os: - - 'ubuntu-20.04' + - 'ubuntu-22.04' - 'macos-latest' steps: - name: Install fish - #uses: fish-actions/install-fish@v1.2.0 - uses: fish-actions/install-fish@master # TODO: change back after #2 + uses: fish-actions/install-fish@v1.1.0 - name: Install SDKMAN! run: | @@ -83,7 +82,8 @@ jobs: shell: fish "{0}" run: | fish --version - curl -sL https://git.io/fisher | source && fisher install jorgebucaran/fisher + curl -sL https://raw.githubusercontent.com/jorgebucaran/fisher/main/functions/fisher.fish | source \ + && fisher install jorgebucaran/fisher fisher --version - name: Install sdkman-for-fish diff --git a/.idea/runConfigurations/Test.xml b/.idea/runConfigurations/Test.xml index 700aee0..f354de3 100644 --- a/.idea/runConfigurations/Test.xml +++ b/.idea/runConfigurations/Test.xml @@ -3,11 +3,8 @@ diff --git a/README.md b/README.md index dff84bd..a68c575 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ Version 2.0.0 has been tested with With [fisher] (install separately): ``` -fisher add reitzig/sdkman-for-fish@v2.0.0 +fisher install reitzig/sdkman-for-fish@v2.0.0 ``` _Note:_ From 063579dc667fed73ecf632ed90ea28475b630bcc Mon Sep 17 00:00:00 2001 From: Raphael Reitzig <4246780+reitzig@users.noreply.github.com> Date: Sun, 25 Jun 2023 10:35:39 +0200 Subject: [PATCH 12/19] fix: Put hacked init script where fisher installs stuff This changed with fisher 4; we now copy their exact code that determines where to put functions. --- conf.d/sdk.fish | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/conf.d/sdk.fish b/conf.d/sdk.fish index bf4f1d6..a37cbf5 100644 --- a/conf.d/sdk.fish +++ b/conf.d/sdk.fish @@ -8,7 +8,10 @@ # https://github.com/reitzig/sdkman-for-fish set __fish_sdkman_init "$HOME/.sdkman/bin/sdkman-init.sh" -set __fish_sdkman_noexport_init "$HOME/.config/fisher/github.com/reitzig/sdkman-for-fish/sdkman-noexport-init.sh" + +# Copied from https://github.com/jorgebucaran/fisher/blob/main/functions/fisher.fish to be consistent: +set --query fisher_path || set --local fisher_path $__fish_config_dir +set __fish_sdkman_noexport_init "$fisher_path/functions/__sdkman-noexport-init.sh" # Guard: SDKMAN! needs to be installed if not test -f "$__fish_sdkman_init" From 1b2824d37f15f49d5fc652860e4952396255ba97 Mon Sep 17 00:00:00 2001 From: Raphael Reitzig <4246780+reitzig@users.noreply.github.com> Date: Sun, 25 Jun 2023 10:47:17 +0200 Subject: [PATCH 13/19] feat(ci): Tests print OS and version --- .github/workflows/test.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 43fdf44..274ea9e 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -54,7 +54,9 @@ jobs: - name: Confirm install shell: fish "{0}" run: | + cat /etc/os-release || sw_vers || true fish --version + fisher --version sdk version - name: Run Tests @@ -94,5 +96,7 @@ jobs: - name: Confirm install shell: fish "{0}" run: | + cat /etc/os-release || sw_vers || true + fish --version fisher ls sdk version From e9f967501c335bd22e4eab4981973e9438783294 Mon Sep 17 00:00:00 2001 From: Raphael Reitzig <4246780+reitzig@users.noreply.github.com> Date: Sun, 25 Jun 2023 18:53:17 +0200 Subject: [PATCH 14/19] fix(test): Use kscript as test candidate instead of crash, which doesn't exist anymore --- test/features/autoenv.feature | 22 +++--- test/features/completions.feature | 84 +++++++++++------------ test/features/corner_cases.feature | 6 +- test/features/step_definitions/general.rb | 2 +- 4 files changed, 57 insertions(+), 57 deletions(-) diff --git a/test/features/autoenv.feature b/test/features/autoenv.feature index f974643..bfe259f 100644 --- a/test/features/autoenv.feature +++ b/test/features/autoenv.feature @@ -7,8 +7,8 @@ Feature: Support autoenv setting And candidate ant is installed at version 1.9.7 And candidate ant is installed at version 1.9.9 And candidate ant is installed at version 1.10.1 - And candidate crash is installed at version 1.2.11 - And candidate crash is installed at version 1.3.0 + And candidate kscript is installed at version 1.5.0 + And candidate kscript is installed at version 1.6.0 Scenario: No action if autoenv turned off Given SDKMAN! config sets sdkman_auto_env to false @@ -59,7 +59,7 @@ Feature: Support autoenv setting And file /tmp/autoenv-test-1/.sdkmanrc exists with content """ ant=1.9.9 - crash=1.2.11 + kscript=1.5.0 """ And file /tmp/autoenv-test-2/.sdkmanrc exists with content """ @@ -67,18 +67,18 @@ Feature: Support autoenv setting """ When we run fish script """ - echo (basename (realpath $ANT_HOME)),(basename (realpath $CRASH_HOME)) > /tmp/autoenv-test.log + echo (basename (realpath $ANT_HOME)),(basename (realpath $KSCRIPT_HOME)) > /tmp/autoenv-test.log cd /tmp/autoenv-test-1 - echo (basename (realpath $ANT_HOME)),(basename (realpath $CRASH_HOME)) >> /tmp/autoenv-test.log + echo (basename (realpath $ANT_HOME)),(basename (realpath $KSCRIPT_HOME)) >> /tmp/autoenv-test.log cd ../autoenv-test-2 - echo (basename (realpath $ANT_HOME)),(basename (realpath $CRASH_HOME)) >> /tmp/autoenv-test.log + echo (basename (realpath $ANT_HOME)),(basename (realpath $KSCRIPT_HOME)) >> /tmp/autoenv-test.log cd .. - echo (basename (realpath $ANT_HOME)),(basename (realpath $CRASH_HOME)) >> /tmp/autoenv-test.log + echo (basename (realpath $ANT_HOME)),(basename (realpath $KSCRIPT_HOME)) >> /tmp/autoenv-test.log """ Then file /tmp/autoenv-test.log contains """ - 1.10.1,1.3.0 - 1.9.9,1.2.11 - 1.9.7,1.3.0 - 1.10.1,1.3.0 + 1.10.1,1.6.0 + 1.9.9,1.5.0 + 1.9.7,1.6.0 + 1.10.1,1.6.0 """ diff --git a/test/features/completions.feature b/test/features/completions.feature index a06ff0b..9955fe1 100644 --- a/test/features/completions.feature +++ b/test/features/completions.feature @@ -5,7 +5,7 @@ Feature: Shell Completion Given SDKMAN! candidate list is up to date And candidate ant is installed at version 1.9.9 And candidate ant is installed at version 1.10.1 - And candidate crash is installed + And candidate kscript is installed Scenario: Command list correct When the user enters " " into the prompt @@ -74,19 +74,19 @@ Feature: Shell Completion Then completion should propose "" But completion should not propose Examples: - | cmd | completions | exclusions | - | | ant, crash | gradle | - | a | ant | gradle | - | j | | /.*/ | - | 1. | | /.*/ | - | an | ant | gradle, crash | # some installed - | gr | | /.*/ | # none installed - | xyz | | /.*/ | # no such candidate - | 'an ' | | /.*/ | # no such candidate installed - | 'ant 1' | 1.10.1, 1.9.9 | /^\w+$/ | - | 'ant 1.10.' | 1.10.1 | 1.9.9 | - | 'ant 2' | | /.*/ | - | 'ant 1.10.1 ' | | /.*/ | # only one version at a time + | cmd | completions | exclusions | + | | ant, kscript | gradle | + | a | ant | gradle | + | j | | /.*/ | + | 1. | | /.*/ | + | an | ant | gradle, kscript | # some installed + | gr | | /.*/ | # none installed + | xyz | | /.*/ | # no such candidate + | 'an ' | | /.*/ | # no such candidate installed + | 'ant 1' | 1.10.1, 1.9.9 | /^\w+$/ | + | 'ant 1.10.' | 1.10.1 | 1.9.9 | + | 'ant 2' | | /.*/ | + | 'ant 1.10.1 ' | | /.*/ | # only one version at a time Scenario Outline: Completion for 'list' When the user enters "list " into the prompt @@ -94,7 +94,7 @@ Feature: Shell Completion But completion should not propose Examples: | cmd | completions | exclusions | - | an | ant | crash | + | an | ant | kscript | | xyz | | /.*/ | | 1. | | /.*/ | | 'ant ' | | /.*/ | @@ -104,39 +104,39 @@ Feature: Shell Completion Then completion should propose "" But completion should not propose Examples: - | cmd | completions | exclusions | - | | ant, crash | gradle | - | an | ant | crash, gradle | - | j | | /.*/ | - | 1. | | /.*/ | - | 'ant ' | 1.10.1, 1.9.9 | /^\w+$/ | - | 'ant 1.10.1 ' | | /.*/ | + | cmd | completions | exclusions | + | | ant, kscript | gradle | + | an | ant | kscript, gradle | + | j | | /.*/ | + | 1. | | /.*/ | + | 'ant ' | 1.10.1, 1.9.9 | /^\w+$/ | + | 'ant 1.10.1 ' | | /.*/ | Scenario Outline: Completion for 'default' When the user enters "default " into the prompt Then completion should propose "" But completion should not propose Examples: - | cmd | completions | exclusions | - | | ant, crash | gradle | - | an | ant | crash, gradle | - | j | | /.*/ | - | 1. | | /.*/ | - | 'ant ' | 1.10.1, 1.9.9 | /^\w+$/ | - | 'ant 1.10.1 ' | | /.*/ | + | cmd | completions | exclusions | + | | ant, kscript | gradle | + | an | ant | kscript, gradle | + | j | | /.*/ | + | 1. | | /.*/ | + | 'ant ' | 1.10.1, 1.9.9 | /^\w+$/ | + | 'ant 1.10.1 ' | | /.*/ | Scenario Outline: Completion for 'home' When the user enters "home " into the prompt Then completion should propose "" But completion should not propose Examples: - | cmd | completions | exclusions | - | | ant, crash | gradle | - | an | ant | crash, gradle | - | j | | /.*/ | - | 1. | | /.*/ | - | 'ant ' | 1.10.1, 1.9.9 | /^\w+$/ | - | 'ant 1.10.1 ' | | /.*/ | + | cmd | completions | exclusions | + | | ant, kscript | gradle | + | an | ant | kscript, gradle | + | j | | /.*/ | + | 1. | | /.*/ | + | 'ant ' | 1.10.1, 1.9.9 | /^\w+$/ | + | 'ant 1.10.1 ' | | /.*/ | Scenario Outline: Completion for 'env' When the user enters "env " into the prompt @@ -171,12 +171,12 @@ Feature: Shell Completion Then completion should propose "" But completion should not propose Examples: - | cmd | completions | exclusions | - | | ant, crash | gradle | - | an | ant | crash, gradle | - | j | | /.*/ | - | 1. | | /.*/ | - | 'ant ' | | /^\w+$/ | + | cmd | completions | exclusions | + | | ant, kscript | gradle | + | an | ant | kscript, gradle | + | j | | /.*/ | + | 1. | | /.*/ | + | 'ant ' | | /^\w+$/ | Scenario Outline: Completion for 'offline' When the user enters "offline " into the prompt diff --git a/test/features/corner_cases.feature b/test/features/corner_cases.feature index a2c211f..df27e43 100644 --- a/test/features/corner_cases.feature +++ b/test/features/corner_cases.feature @@ -13,6 +13,6 @@ Feature: Corner Cases # TODO: add test that fails if `test` in conf.d/sdk.fish:80 errors (cf issue #28 et al.) Scenario: PATH should contain only valid paths - Given candidate crash is installed - When candidate crash is uninstalled - Then environment variable PATH cannot contain "sdkman/candidates/crash/" + Given candidate kscript is installed + When candidate kscript is uninstalled + Then environment variable PATH cannot contain "sdkman/candidates/kscript/" diff --git a/test/features/step_definitions/general.rb b/test/features/step_definitions/general.rb index 86f6aa6..32b1b9a 100644 --- a/test/features/step_definitions/general.rb +++ b/test/features/step_definitions/general.rb @@ -24,6 +24,6 @@ Then(/^the output is$/) do |text| expect(@response_fish_script).to eq(text.strip) end -Then(/^file ([a-zA-Z0-9-_.\/]+) contains$/) do |file,content| +Then(/^file ([a-zA-Z0-9\-_.\/]+) contains$/) do |file,content| expect(File.readlines(file).join("").strip).to eq(content.strip) end From ee7edbd9aa0515cfefa9238ff15edf5c34a9c264 Mon Sep 17 00:00:00 2001 From: Raphael Reitzig <4246780+reitzig@users.noreply.github.com> Date: Sun, 25 Jun 2023 19:00:02 +0200 Subject: [PATCH 15/19] fix(test): Adapt tests to changes 5.9 -> 5.18 ref: issue #41 --- .idea/runConfigurations/Test.xml | 4 +-- CHANGELOG.md | 3 +- README.md | 6 ++-- test/features/autoenv.feature | 4 +-- test/features/completions.feature | 54 ++++++++++++++---------------- test/features/corner_cases.feature | 1 + test/features/wrapper.feature | 2 +- 7 files changed, 36 insertions(+), 38 deletions(-) diff --git a/.idea/runConfigurations/Test.xml b/.idea/runConfigurations/Test.xml index f354de3..d9dacd3 100644 --- a/.idea/runConfigurations/Test.xml +++ b/.idea/runConfigurations/Test.xml @@ -3,9 +3,9 @@ diff --git a/CHANGELOG.md b/CHANGELOG.md index 11f0737..e49d4e6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,10 +13,11 @@ this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm ### Features -- Compatibility with SDKMAN! 5.9.2 +- Compatibility with SDKMAN! 5.18.2 - Completions for `env`, `home`, `flush` (issue #35) - Correct behaviour of `env clear`. - Honor `sdkman_auto_env=true` (issue #38) + - `broadcast` removed - TODO: custom SDKMAN! install path (issue #34) - Compatibility with fisher 4 (PR #37, #39) diff --git a/README.md b/README.md index a68c575..7e82e95 100644 --- a/README.md +++ b/README.md @@ -10,9 +10,9 @@ Also adds binaries from installed SDKs to the PATH. Version 2.0.0 has been tested with - - fish 3.1.2, and - - SDKMAN! 5.11.0, on - - Ubuntu 20.04 LTS and macOS 10.15 + - fish 3.6.1, and + - SDKMAN! 5.18.2, on + - Ubuntu 22.04 LTS and macOS 12.6 ## Install diff --git a/test/features/autoenv.feature b/test/features/autoenv.feature index bfe259f..f13209d 100644 --- a/test/features/autoenv.feature +++ b/test/features/autoenv.feature @@ -52,8 +52,8 @@ Feature: Support autoenv setting 1.10.1 """ - # TODO: This one doesn't work due to a bug in sdkman. Track: https://github.com/sdkman/sdkman-cli/pull/878 - @pending + # TODO: But that PR had been merged back when -- re-investigate + @pending # This one doesn't work due to a bug in sdkman. Track: https://github.com/sdkman/sdkman-cli/pull/878 Scenario: Switching between directories with .sdkmanrc Given SDKMAN! config sets sdkman_auto_env to true And file /tmp/autoenv-test-1/.sdkmanrc exists with content diff --git a/test/features/completions.feature b/test/features/completions.feature index 9955fe1..6565e10 100644 --- a/test/features/completions.feature +++ b/test/features/completions.feature @@ -9,7 +9,7 @@ Feature: Shell Completion Scenario: Command list correct When the user enters " " into the prompt - Then completion should propose "b, broadcast, c, current, d, default, flush, h, help, i, install, list, ls, offline, rm, selfupdate, u, ug, uninstall, update, upgrade, use, v, version" + Then completion should propose "c, current, d, default, flush, h, help, i, install, list, ls, offline, rm, selfupdate, u, ug, uninstall, update, upgrade, use, v, version" Scenario Outline: Commands complete When the user enters "" into the prompt @@ -17,7 +17,6 @@ Feature: Shell Completion But completion should not propose Examples: | cmd | completions | exclusions | - | b | b, broadcast | /^[^b]+$/ | | c | c, current | /^[^c]+$/ | | d | d, default | /^[^d]+$/ | | e | e, env | /^[^e]+$/ | @@ -39,6 +38,7 @@ Feature: Shell Completion # Currently uncovered (except by fuzzy matches); # include negatives to prevent accidents: | a | | /^a/ | + | b | | /^b/ | | g | | /^g/ | | j | | /^j/ | | k | | /^k/ | @@ -143,16 +143,16 @@ Feature: Shell Completion Then completion should propose "" But completion should not propose Examples: - | cmd | completions | exclusions | - | | init, install, clear | /^(?!init\|install\|clear).*$/ | - | i | init, install | /^(?!init\|install).*$/ | - | ini | init | /^(?!init).*$/ | - | ins | install | /^(?!install).*$/ | - | c | clear | /^(?!clear).*$/ | - | b | | /.*/ | - | 'init ' | | /.*/ | - | 'clear ' | | /.*/ | - | 'install ' | | /.*/ | + | cmd | completions | exclusions | + | | init, install, clear | /^(?!init\|install\|clear).*$/ | + | i | init, install | /^(?!init\|install).*$/ | + | ini | init | /^(?!init).*$/ | + | ins | install | /^(?!install).*$/ | + | c | clear | /^(?!clear).*$/ | + | b | | /.*/ | + | 'init ' | | /.*/ | + | 'clear ' | | /.*/ | + | 'install ' | | /.*/ | Scenario Outline: Completion for 'current' When the user enters "current " into the prompt @@ -206,25 +206,21 @@ Feature: Shell Completion Then completion should propose "" But completion should not propose Examples: - | cmd | completions | exclusions | - | | archives, broadcast, tmp, version | /^(?!archives\|broadcast\|tmp\|version).*$/ | - | b | broadcast | /^(?!broadcast).*$/ | - | a | archives | /^(?!archives\|broadcast).*$/ | - | t | tmp | /^(?!tmp\|broadcast).*$/ | - | v | version | /^(?!version\|archives).*$/ | - | x | | /.*/ | - | 'tmp ' | | /.*/ | + | cmd | completions | exclusions | + | | temp, version | /^(?!temp\|version).*$/ | + | t | temp | /^(?!temp).*$/ | + | v | version | /^(?!version).*$/ | + | x | | /.*/ | + | 'tmp ' | | /.*/ | Scenario Outline: Completion for commands without parameters When the user enters "" into the prompt Then completion should not propose /.*/ Examples: - | cmd | - | 'version ' | - | 'version a' | - | 'broadcast ' | - | 'broadcast a' | - | 'help ' | - | 'help a' | - | 'update ' | - | 'update a' | + | cmd | + | 'version ' | + | 'version a' | + | 'help ' | + | 'help a' | + | 'update ' | + | 'update a' | diff --git a/test/features/corner_cases.feature b/test/features/corner_cases.feature index df27e43..23e2c16 100644 --- a/test/features/corner_cases.feature +++ b/test/features/corner_cases.feature @@ -12,6 +12,7 @@ Feature: Corner Cases # TODO: add test that fails if `test` in conf.d/sdk.fish:80 errors (cf issue #28 et al.) + @pending # cf. issue #10 Scenario: PATH should contain only valid paths Given candidate kscript is installed When candidate kscript is uninstalled diff --git a/test/features/wrapper.feature b/test/features/wrapper.feature index 2bb6a3e..f6942f5 100644 --- a/test/features/wrapper.feature +++ b/test/features/wrapper.feature @@ -31,7 +31,7 @@ Feature: Wrapping of Bash | sdk update | | sdk use ant 1.9.9 | | sdk offline enable > /dev/null; sdk install ant foo | - | sdk use ant 1.9.9 > /dev/null; sdk broadcast | + | sdk use ant 1.9.9 > /dev/null; sdk version | | sdk home ant 1.9.9 | | cd /tmp/env-test; sdk env | | cd /tmp/env-test; sdk env; sdk env clear | From a211fbc9d0874fff348bc47ff29410897d8c48c6 Mon Sep 17 00:00:00 2001 From: Raphael Reitzig <4246780+reitzig@users.noreply.github.com> Date: Sun, 25 Jun 2023 19:24:59 +0200 Subject: [PATCH 16/19] fix: Adapt to changes 5.9 -> 5.18 ref: issue #41 --- completions/sdk.fish | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) diff --git a/completions/sdk.fish b/completions/sdk.fish index 678688c..034d14b 100644 --- a/completions/sdk.fish +++ b/completions/sdk.fish @@ -165,13 +165,6 @@ complete -c sdk -f -n '__fish_sdkman_no_command' \ complete -c sdk -f -n '__fish_sdkman_command_has_enough_parameters 0 v version' # block -# broadcast -complete -c sdk -f -n '__fish_sdkman_no_command' \ - -a 'b broadcast' \ - -d 'Display broadcast message' -complete -c sdk -f -n '__fish_sdkman_command_has_enough_parameters 0 b broadcast' - # block - # help complete -c sdk -f -n '__fish_sdkman_no_command' \ -a 'help' \ @@ -214,13 +207,7 @@ complete -c sdk -f -n '__fish_sdkman_no_command' \ -a 'flush' \ -d 'Clear out archives and temporary storage folders' complete -c sdk -f -n '__fish_sdkman_using_command flush' \ - -a 'broadcast' \ - -d 'Clear out the broadcast/news cache' -complete -c sdk -f -n '__fish_sdkman_using_command flush' \ - -a 'archives' \ - -d 'Remove downloads' -complete -c sdk -f -n '__fish_sdkman_using_command flush' \ - -a 'tmp' \ + -a 'temp' \ -d 'Clear out staging work folder' complete -c sdk -f -n '__fish_sdkman_using_command flush' \ -a 'version' \ From 7c0ece3dfbcd553b19e6a96cdac80c660651f5b4 Mon Sep 17 00:00:00 2001 From: Raphael Reitzig <4246780+reitzig@users.noreply.github.com> Date: Mon, 26 Jun 2023 09:00:24 +0200 Subject: [PATCH 17/19] fix(test): Move local test to more current fish ... ... by means of using a more current OS, and fix a test helper that used a feature now removed from fish. --- .github/workflows/test.yml | 2 +- test/Dockerfile | 12 +++++++----- test/features/support/helpers.rb | 2 +- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 274ea9e..5ee35a6 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -15,7 +15,7 @@ jobs: strategy: matrix: os: - - 'ubuntu-22.04' + - 'ubuntu-latest' - 'macos-latest' steps: - uses: actions/checkout@v3 diff --git a/test/Dockerfile b/test/Dockerfile index 309e466..bc0d1e1 100644 --- a/test/Dockerfile +++ b/test/Dockerfile @@ -1,15 +1,17 @@ -FROM ruby:2.7-slim-buster +FROM ubuntu # Install dependencies RUN apt-get update \ && apt-get -y install \ - fish \ + build-essential \ curl \ + fish \ + ruby \ + ruby-dev \ unzip \ zip \ - ruby-dev \ - build-essential \ - && apt-get clean + && apt-get clean \ + && gem install bundler WORKDIR app COPY test/Gemfile ./ diff --git a/test/features/support/helpers.rb b/test/features/support/helpers.rb index 4ea155c..1b36c84 100644 --- a/test/features/support/helpers.rb +++ b/test/features/support/helpers.rb @@ -64,7 +64,7 @@ def run_fish_command(cmd) end.to_h out, status = Open3.capture2e(<<~FISH - fish -c '#{cmd} > #{files[:stdout]} ^ #{files[:stderr]}; \ + fish -c '#{cmd} > #{files[:stdout]} 2> #{files[:stderr]}; \ echo $status > #{files[:status]}; \ env > #{files[:env]}; \ ' From 4c15f15ced5a67e00b161b2a5e83df7d660405d3 Mon Sep 17 00:00:00 2001 From: Raphael Reitzig <4246780+reitzig@users.noreply.github.com> Date: Tue, 8 Mar 2022 23:12:29 +0100 Subject: [PATCH 18/19] feat(test): Tests for custom install dir ref: issue #34 --- LICENSE | 2 +- README.md | 11 ++++ test/Dockerfile | 14 +++-- test/features/corner_cases.feature | 15 +++++- .../features/step_definitions/corner_cases.rb | 22 ++++++++ test/features/step_definitions/general.rb | 23 +++++++- test/features/step_definitions/setup.rb | 54 ++++++++++++++++++- test/features/support/hooks.rb | 4 ++ 8 files changed, 135 insertions(+), 10 deletions(-) diff --git a/LICENSE b/LICENSE index 0b10c1a..fa759ed 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2018 Raphael Reitzig +Copyright (c) 2018-2022 Raphael Reitzig Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index 7e82e95..c9635db 100644 --- a/README.md +++ b/README.md @@ -26,12 +26,22 @@ _Note:_ - Only compatible with fisher v4 upwards; v3 is no longer supported. - You have to install [SDKMAN!] separately. + - If you have installed SDKMAN! at a custom location, you need to add + ```fish + set -g __sdkman_custom_dir /your/path/to/sdkman + ``` + to a fish config file + [run _before_](https://fishshell.com/docs/current/language.html#configuration-files) + `.config/fish/conf.d/sdk.fish`; + for example, you can use `.config/fish/conf.d/config_sdk.fish`. + ## Usage It's all in the background; you should be able to run `sdk` and binaries installed with `sdk` as you would expect. + ## Contribute When you make changes, @@ -64,6 +74,7 @@ done wait ``` + ## Acknowledgements * Completion originally by [Ted Wise](https://github.com/ctwise); see his diff --git a/test/Dockerfile b/test/Dockerfile index bc0d1e1..9638acd 100644 --- a/test/Dockerfile +++ b/test/Dockerfile @@ -6,8 +6,10 @@ RUN apt-get update \ build-essential \ curl \ fish \ + nano \ ruby \ ruby-dev \ + tree \ unzip \ zip \ && apt-get clean \ @@ -26,11 +28,13 @@ USER test RUN curl -s "https://get.sdkman.io" | bash # To speed up tests, uncomment this shared setup: -#SHELL ["/bin/bash", "-c"] -#RUN source "$TEST_HOME/.sdkman/bin/sdkman-init.sh" \ -# && sdk install ant 1.9.9 \ -# && sdk install ant 1.10.1 \ -# && sdk install crash +SHELL ["/bin/bash", "-c"] +RUN source "$TEST_HOME/.sdkman/bin/sdkman-init.sh" \ + && sdk install ant 1.9.7 \ + && sdk install ant 1.9.9 \ + && sdk install ant 1.10.1 \ + && sdk install kscript 1.5.0 \ + && sdk install kscript 1.6.0 # "Install" sdkman-for-fish RUN mkdir -p $TEST_HOME/.config/fish/ diff --git a/test/features/corner_cases.feature b/test/features/corner_cases.feature index 23e2c16..a41338c 100644 --- a/test/features/corner_cases.feature +++ b/test/features/corner_cases.feature @@ -6,14 +6,27 @@ Feature: Corner Cases Then environment variable SDKMAN_DIR has the original value Scenario: sdk initialized for another user in this shell + # Use any directory outside of the user's home directory Given environment variable SDKMAN_DIR is set to "/" When a new Fish shell is launched Then environment variable SDKMAN_DIR has the original value - # TODO: add test that fails if `test` in conf.d/sdk.fish:80 errors (cf issue #28 et al.) + Scenario: Custom installation path + Given SDKMAN! is installed at /tmp/sdkman + And fish config file config_sdk.fish exists with content + """ + set -g __sdkman_custom_dir /tmp/sdkman + """ + When we run "sdk version" in Fish + Then the exit code is 0 + And the output contains "SDKMAN!" + And environment variable SDKMAN_DIR has value "/tmp/sdkman" + And environment variable ANT_HOME has value "/tmp/sdkman/candidates/ant/current" @pending # cf. issue #10 Scenario: PATH should contain only valid paths Given candidate kscript is installed When candidate kscript is uninstalled Then environment variable PATH cannot contain "sdkman/candidates/kscript/" + + # TODO: add test that fails if `test` in conf.d/sdk.fish:80 errors (cf issue #28 et al.) diff --git a/test/features/step_definitions/corner_cases.rb b/test/features/step_definitions/corner_cases.rb index 198cae4..2ae4120 100644 --- a/test/features/step_definitions/corner_cases.rb +++ b/test/features/step_definitions/corner_cases.rb @@ -1,5 +1,7 @@ # frozen_string_literal: true +require 'fileutils' + Given('environment variable {env_name} is not set') do |name| @name = name @expect_intermediate_value = false @@ -22,6 +24,26 @@ Given('environment variable {env_name} is set to {string}') do |name, new_value| BASH end +$install_default = "#{ENV['HOME']}/.sdkman" +$install_custom = nil +$install_backup = "#{$install_default}_bak" +Given(/^SDKMAN! is installed at (.*)$/) do |path| + $install_custom = path + FileUtils.cp_r($install_default, $install_custom) + log "Backing up #{$install_default} at #{$install_backup}" + FileUtils.mv($install_default, $install_backup) +end + +def _restore_install # called in After hook + unless $install_custom.nil? + log "Removing #{$install_custom}" + FileUtils.rm_rf($install_custom) + $install_custom = nil + log "Restoring #{$install_default} from #{$install_backup}" + FileUtils.mv($install_backup, $install_default) + end +end + When('a new Fish shell is launched') do @command += <<~BASH fish -lc "env | grep -E \\"^#{@name}=\\"" \\ diff --git a/test/features/step_definitions/general.rb b/test/features/step_definitions/general.rb index 32b1b9a..ca994db 100644 --- a/test/features/step_definitions/general.rb +++ b/test/features/step_definitions/general.rb @@ -17,11 +17,30 @@ When('we run fish script') do |script_content| raise "Fish command failed: #{out}" end - @response_fish_script = out.strip + @output_fish_script = out.strip end Then(/^the output is$/) do |text| - expect(@response_fish_script).to eq(text.strip) + expect(@output_fish_script).to eq(text.strip) +end + +When('we run {string} in Fish') do |command| + @response = run_fish_command(command) +end + +Then('the exit code is {int}') do |code| + expect(@response[:status]).to eq(code) +end + +Then(/^environment variable ([A-Z_]+) has value "([^"]+)"$/) do |key, value| + expect(@response[:env][key]).to eq(value) +end + +And('the output contains {string}') do |content| + output = @response[:stdout] + .select { |line| !line.blank? } + .map { |line| line.strip } + expect(output).to include(content) end Then(/^file ([a-zA-Z0-9\-_.\/]+) contains$/) do |file,content| diff --git a/test/features/step_definitions/setup.rb b/test/features/step_definitions/setup.rb index c82eee1..a295e3b 100644 --- a/test/features/step_definitions/setup.rb +++ b/test/features/step_definitions/setup.rb @@ -47,10 +47,27 @@ Given(/^file ([a-zA-Z0-9\-_.\/]+) exists with content/) do |filename,content| File.write(filename, content) end +$fish_config_files = [] +def _remove_fish_configs # called in After hook + $fish_config_files.each do |f| + log "Removing #{f}" + FileUtils.rm_f(f) + end + $fish_config_files = [] +end + +And(/^fish config file ([a-zA-Z0-9\-_.\/]+) exists with content$/) do |filename,content| + file = "#{ENV['HOME']}/.config/fish/conf.d/#{filename}" + FileUtils.mkdir_p(File.dirname(file)) + File.write(file, content) + $fish_config_files << file +end + $config_file = "#{ENV['HOME']}/.sdkman/etc/config" $backup_config_file = nil def _restore_config # called in After hook unless $backup_config_file.nil? + log "Restoring #{$config_file} from #{$backup_config_file.path}" FileUtils.mv($backup_config_file, $config_file) $backup_config_file = nil end @@ -58,7 +75,8 @@ end Given(/^SDKMAN! config sets ([a-z_]+) to (.*)$/) do |key,value| if $backup_config_file.nil? - $backup_config_file = Tempfile.new('sdkman_config_backup') + $backup_config_file = Tempfile.new('sdkman_config_backup_') + log "Backing up #{$config_file} at #{$backup_config_file.path}" FileUtils.cp($config_file, $backup_config_file) end @@ -68,3 +86,37 @@ Given(/^SDKMAN! config sets ([a-z_]+) to (.*)$/) do |key,value| File.write($config_file, new_config_string) end + +# TODO: create shared helper for both config files +# +$fish_config = "#{ENV['HOME']}/.config/fish/config.fish" +$backup_fish_config = nil +def _restore_fish_config # called in After hook + unless $backup_fish_config.nil? + if $backup_fish_config == :none + log "Deleting #{$fish_config}" + FileUtils.rm($fish_config) + else + log "Restoring #{$fish_config} from #{$backup_fish_config.path}" + FileUtils.mv($backup_fish_config, $fish_config) + end + $backup_fish_config = nil + end +end + +And(/^fish config contains `([^`]+)`$/) do |line| + if $backup_fish_config.nil? + if File.exist?($fish_config) + $backup_fish_config = Tempfile.new('fish_config_backup_') + log "Backing up #{$fish_config} at #{$backup_fish_config.path}" + FileUtils.cp($fish_config, $backup_fish_config) + else + $backup_fish_config = :none + end + end + + config = File.exist?($fish_config) ? File.readlines($fish_config) : '' + config << "\n\n# Added by sdkman-for-fish test\n#{line}" + + File.write($fish_config, config.join("\n")) +end diff --git a/test/features/support/hooks.rb b/test/features/support/hooks.rb index 74a6f90..ea524cb 100644 --- a/test/features/support/hooks.rb +++ b/test/features/support/hooks.rb @@ -1,7 +1,11 @@ require_relative '../step_definitions/setup' +require_relative '../step_definitions/corner_cases.rb' After do |scenario| + _remove_fish_configs + _restore_fish_config _restore_config + _restore_install end # Uninstall all SDKMAN! candidates From 66e2f1e6238295cc985f86ee00382fc4daec10cd Mon Sep 17 00:00:00 2001 From: Raphael Reitzig <4246780+reitzig@users.noreply.github.com> Date: Tue, 27 Jun 2023 00:02:25 +0200 Subject: [PATCH 19/19] feat: Support custom install dir ref: issue #34 --- CHANGELOG.md | 2 +- completions/sdk.fish | 4 ++-- conf.d/sdk.fish | 19 +++++++++++++------ 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e49d4e6..2949750 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,12 +13,12 @@ this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm ### Features +- Support custom SDKMAN! install path (issue #34) - Compatibility with SDKMAN! 5.18.2 - Completions for `env`, `home`, `flush` (issue #35) - Correct behaviour of `env clear`. - Honor `sdkman_auto_env=true` (issue #38) - `broadcast` removed - - TODO: custom SDKMAN! install path (issue #34) - Compatibility with fisher 4 (PR #37, #39) ## [1.4.0] - 2019-11-06 diff --git a/completions/sdk.fish b/completions/sdk.fish index 034d14b..b92a0be 100644 --- a/completions/sdk.fish +++ b/completions/sdk.fish @@ -1,11 +1,11 @@ # Defines autocompletion for SDKMAN! -# Copyright (c) 2018 Raphael Reitzig +# Copyright (c) 2018-2022 Raphael Reitzig # MIT License (MIT) # https://github.com/reitzig/sdkman-for-fish # Guard: SDKMAN! needs to be installed -if not test -f "$HOME/.sdkman/bin/sdkman-init.sh" +if not test -f "$SDKMAN_DIR/bin/sdkman-init.sh" exit 0 end diff --git a/conf.d/sdk.fish b/conf.d/sdk.fish index a37cbf5..aa133f4 100644 --- a/conf.d/sdk.fish +++ b/conf.d/sdk.fish @@ -3,11 +3,19 @@ # Makes command and binaries from SDKMAN! available in fish. # Delegates to bash for the `sdk` command. -# Copyright (c) 2018 Raphael Reitzig +# Copyright (c) 2018-2022 Raphael Reitzig # MIT License (MIT) # https://github.com/reitzig/sdkman-for-fish -set __fish_sdkman_init "$HOME/.sdkman/bin/sdkman-init.sh" +# Account for custom install locations +if set -q __sdkman_custom_dir + set -gx SDKMAN_DIR "$__sdkman_custom_dir" +else + # This is the default location: + set -gx SDKMAN_DIR "$HOME/.sdkman" +end + +set __fish_sdkman_init "$SDKMAN_DIR/bin/sdkman-init.sh" # Copied from https://github.com/jorgebucaran/fisher/blob/main/functions/fisher.fish to be consistent: set --query fisher_path || set --local fisher_path $__fish_config_dir @@ -81,17 +89,16 @@ end # If this is a subshell of a(n initialized) fish owned by the same user, # no initialization necessary. # Otherwise: -if not set -q SDKMAN_DIR; or test (ls -ld "$SDKMAN_DIR" | awk '{print $3}') != (whoami) - set -e SDKMAN_DIR +if not set -q SDKMAN_CANDIDATES_DIR; or test (ls -ld "$SDKMAN_CANDIDATES_DIR" | awk '{print $3}') != (whoami) __fish_sdkman_run_in_bash "source $__fish_sdkman_init" end -# Set up autoenv +# Set up auto_env if grep -q "^sdkman_auto_env=true" "$SDKMAN_DIR/etc/config" function __fish_sdkman_autoenv --on-variable PWD # Run the (modified) init script, which performs the checks and calls for us! __fish_sdkman_run_in_bash "source \"$__fish_sdkman_noexport_init\"" - set -x SDKMAN_OLD_PWD "$PWD" + set -x SDKMAN_OLD_PWD "$PWD" # needed by the Bash implementation end end