mirror of
https://github.com/ethauvin/sdkman-for-fish.git
synced 2025-04-25 05:17:11 -07:00
parent
7c0ece3dfb
commit
4c15f15ced
8 changed files with 135 additions and 10 deletions
|
@ -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/
|
||||
|
|
|
@ -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.)
|
||||
|
|
|
@ -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}=\\"" \\
|
||||
|
|
|
@ -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|
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue