mirror of
https://github.com/ethauvin/sdkman-for-fish.git
synced 2025-04-25 21:27:11 -07:00
Test for autoenv
setting
This commit is contained in:
parent
7b17fcc4b7
commit
61f1cf8efc
7 changed files with 154 additions and 12 deletions
29
test/features/step_definitions/general.rb
Normal file
29
test/features/step_definitions/general.rb
Normal file
|
@ -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
|
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue