From 2afb22f6afe64bdffc15a0396cf62990f09bb01e Mon Sep 17 00:00:00 2001 From: Raphael Reitzig <4246780+reitzig@users.noreply.github.com> Date: Tue, 26 May 2020 06:01:37 +0200 Subject: [PATCH] Fix tests on macOS. Also clarifies a test description. --- test/features/corner_cases.feature | 4 ++-- test/features/support/helpers.rb | 28 ++++++++++++++-------------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/test/features/corner_cases.feature b/test/features/corner_cases.feature index 8a8a443..a2c211f 100644 --- a/test/features/corner_cases.feature +++ b/test/features/corner_cases.feature @@ -1,11 +1,11 @@ Feature: Corner Cases - Scenario: SDKMAN_DIR unset + Scenario: sdk not initialized in this shell Given environment variable SDKMAN_DIR is not set When a new Fish shell is launched Then environment variable SDKMAN_DIR has the original value - Scenario: SDKMAN_DIR set to a location the current user can't write at + Scenario: sdk initialized for another user in this shell Given environment variable SDKMAN_DIR is set to "/" When a new Fish shell is launched Then environment variable SDKMAN_DIR has the original value diff --git a/test/features/support/helpers.rb b/test/features/support/helpers.rb index 99cad9e..4ea155c 100644 --- a/test/features/support/helpers.rb +++ b/test/features/support/helpers.rb @@ -26,9 +26,9 @@ end def run_bash_command(cmd) Dir.mktmpdir(%w[sdkman-for-fish-test_ _fish]) do |tmp_dir| - files = %i[status stdout stderr env].map { |s| + files = %i[status stdout stderr env].map do |s| [s, FileUtils.touch("#{tmp_dir}/#{s}")[0]] - }.to_h + end.to_h out, status = Open3.capture2e(<<~BASH bash -c 'source "#{ENV['HOME']}/.sdkman/bin/sdkman-init.sh" && \ @@ -44,28 +44,24 @@ def run_bash_command(cmd) raise "Bash command failed: #{out}" end - puts File.readlines(files[:env]) # TODO remove { status: File.read(files[:status]).to_i, stdout: File.readlines(files[:stdout]), stderr: File.readlines(files[:stderr]), - env: File.readlines(files[:env]).map { |l| l.strip.split('=', 2) }.to_h + env: File.readlines(files[:env]).map do |l| + l.strip.split('=', 2) \ + if l.include?('=') # NB: on macOS, weird stuff is printed by env + end.compact \ + .to_h } end end -# # For nicer diffs: one entry per line, sorted -# string split ":" (cat path_bash) | sort > path_bash -# string split ":" (cat path_fish) \ -# | string split " " \ -# | sort > path_fish -# # split by spaces for fish 2.* - def run_fish_command(cmd) Dir.mktmpdir(%w[sdkman-for-fish-test_ _fish]) do |tmp_dir| - files = %i[status stdout stderr env].map { |s| + files = %i[status stdout stderr env].map do |s| [s, FileUtils.touch("#{tmp_dir}/#{s}")[0]] - }.to_h + end.to_h out, status = Open3.capture2e(<<~FISH fish -c '#{cmd} > #{files[:stdout]} ^ #{files[:stderr]}; \ @@ -84,7 +80,11 @@ def run_fish_command(cmd) status: File.read(files[:status]).to_i, stdout: File.readlines(files[:stdout]), stderr: File.readlines(files[:stderr]), - env: File.readlines(files[:env]).map { |l| l.strip.split('=', 2) }.to_h + env: File.readlines(files[:env]).map do |l| + l.strip.split('=', 2) \ + if l.include?('=') # NB: on macOS, weird stuff is printed by env + end.compact \ + .to_h } end end