mirror of
https://github.com/ethauvin/sdkman-for-fish.git
synced 2025-04-25 05:17:11 -07:00
59 lines
2.2 KiB
Ruby
59 lines
2.2 KiB
Ruby
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
|
|
run_bash_command('sdk update')
|
|
$index_updated = true
|
|
end
|
|
end
|
|
|
|
Given(/^candidate (\w+) is installed at version (\d+(?:\.\d+)*)$/) do |candidate, version|
|
|
# TODO: Can we mock-install instead?
|
|
# Something like
|
|
#
|
|
# mkdir -p ${SDKMAN_CANDIDATES_DIR}/${candidate}/{version}/bin \
|
|
# && touch ${SDKMAN_CANDIDATES_DIR}/${candidate}/${version}/bin/${candidate} &&
|
|
# ln -s ${SDKMAN_CANDIDATES_DIR}/${candidate}/current ${SDKMAN_CANDIDATES_DIR}/${candidate}/${version}
|
|
#
|
|
# should be quite enough to trick sdk as far as we need it to trick.
|
|
# Or is it?
|
|
run_bash_command("sdk install #{candidate} #{version}") unless installed?(candidate, version)
|
|
end
|
|
|
|
Given(/^candidate (\w+) is installed$/) do |candidate|
|
|
run_bash_command("sdk install #{candidate}") unless installed?(candidate)
|
|
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|
|
|
log `ls ~/.sdkman/candidates/#{candidate}`
|
|
Dir["#{ENV['HOME']}/.sdkman/candidates/#{candidate}/*"].each do |candidate_dir|
|
|
_uninstall_candidate_version(candidate_dir)
|
|
end
|
|
log `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:
|
|
# --> 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
|