Migrate PATH zombie test to Cucumber.

This commit is contained in:
Raphael Reitzig 2020-05-26 04:48:12 +02:00
parent 0a948c81c1
commit 42aff3b4c5
5 changed files with 27 additions and 15 deletions

View file

@ -38,5 +38,4 @@ install:
script: script:
- (cd test && cucumber) - (cd test && cucumber)
# TODO: Migrate these to Cucumber: # TODO: Migrate these to Cucumber:
- fish -c "sdk install crash 1.3.0; and sdk uninstall crash 1.3.0" > /dev/null && fish test/check_for_path_zombies.fish
- bash test/remove_sdkman.sh > /dev/null && fish -c "echo 'y' | sdk" > /dev/null && fish -c "sdk version" - bash test/remove_sdkman.sh > /dev/null && fish -c "echo 'y' | sdk" > /dev/null && fish -c "sdk version"

View file

@ -1,9 +0,0 @@
switch "$PATH"
case "*sdkman/candidates/crash/*"
echo "Uninstalled candidate in PATH"
sdk list crash | head -10
echo $PATH
exit 1
case "*"
echo "OKAY"
end

View file

@ -11,3 +11,8 @@ Feature: Corner Cases
Then environment variable SDKMAN_DIR has the original value 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.) # 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/"

View file

@ -43,3 +43,8 @@ Then('environment variable {env_name} has the original value') do |name|
expect(@response[:stdout][-1]).to eq(@response[:stdout][0]) # reinitialization effective expect(@response[:stdout][-1]).to eq(@response[:stdout][0]) # reinitialization effective
end end
Then('environment variable {env_name} cannot contain {string}') do |name, value|
env = run_fish_command('echo noop')[:env]
expect(env[name]).to_not match(/#{Regexp.escape(value)}/)
end

View file

@ -14,6 +14,22 @@ Given(/^candidate (\w+) is installed$/) do |candidate|
run_bash_command("sdk install #{candidate}") unless installed?(candidate) run_bash_command("sdk install #{candidate}") unless installed?(candidate)
end end
def _uninstall_candidate_version(candidate_dir)
%r{/([^/]+)/([^/]+)$}.match(candidate_dir) do |match|
candidate = match[1]
version = match[2]
run_bash_command("sdk rm #{candidate} #{version}") unless version == 'current'
end
end
When(/^candidate (\w+) is uninstalled$/) do |candidate|
puts `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}`
end
# Uninstall all SDKMAN! candidates # Uninstall all SDKMAN! candidates
# TODO: Run after every scenario, this makes tests very slow. # TODO: Run after every scenario, this makes tests very slow.
# Currently, Cucumber doesn't have Feature-level hooks, so we have to work around: # Currently, Cucumber doesn't have Feature-level hooks, so we have to work around:
@ -22,10 +38,6 @@ end
# --> clean up after _all_ features at least # --> clean up after _all_ features at least
at_exit do at_exit do
Dir["#{ENV['HOME']}/.sdkman/candidates/*/*"].each do |candidate_dir| Dir["#{ENV['HOME']}/.sdkman/candidates/*/*"].each do |candidate_dir|
%r{/([^/]+)/([^/]+)$}.match(candidate_dir) do |match| _uninstall_candidate_version(candidate_dir)
candidate = match[1]
version = match[2]
run_bash_command("sdk rm #{candidate} #{version}") unless version == 'current'
end
end end
end end