Migrate reinitialization test to Cucumber.

This commit is contained in:
Raphael Reitzig 2020-05-26 04:22:01 +02:00
parent 56bc601b17
commit 0a948c81c1
6 changed files with 67 additions and 30 deletions

View file

@ -38,6 +38,5 @@ install:
script:
- (cd test && cucumber)
# TODO: Migrate these to Cucumber:
- fish test/reinitialize.fish
- 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"

View file

@ -0,0 +1,13 @@
Feature: Corner Cases
Scenario: SDKMAN_DIR unset
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
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.)

View file

@ -0,0 +1,45 @@
# frozen_string_literal: true
Given('environment variable {env_name} is not set') do |name|
@name = name
@expect_intermediate_value = false
@command = <<~BASH
( \\
env | grep -E "^#{name}="; \\
export -n #{name}; \\
env | grep -E "^#{name}="; \\
BASH
end
Given('environment variable {env_name} is set to {string}') do |name, new_value|
@name = name
@expect_intermediate_value = true
@command = <<~BASH
( \\
env | grep -E "^#{name}="; \\
export #{name}=#{new_value}; \\
env | grep -E "^#{name}="; \\
BASH
end
When('a new Fish shell is launched') do
@command += <<~BASH
fish -lc "env | grep -E \\"^#{@name}=\\"" \\
) \\
BASH
@response = run_bash_command(@command)
end
Then('environment variable {env_name} has the original value') do |name|
expect(name).to eq(@name) # otherwise the test doesn't make sense
if @expect_intermediate_value
expect(@response[:stdout].count).to eq(3)
expect(@response[:stdout][0]).to_not eq(@response[:stdout][1]) # destruction effective
else
expect(@response[:stdout].count).to eq(2)
end
expect(@response[:stdout][-1]).to eq(@response[:stdout][0]) # reinitialization effective
end

View file

@ -48,7 +48,7 @@ def run_bash_command(cmd)
status: File.read(files[:status]).to_i,
stdout: File.readlines(files[:stdout]),
stderr: File.readlines(files[:stderr]),
env: File.readlines(files[:env])
env: File.readlines(files[:env]).map { |l| l.strip.split('=', 2) }.to_h
}
end
end
@ -83,7 +83,7 @@ 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])
env: File.readlines(files[:env]).map { |l| l.strip.split('=', 2) }.to_h
}
end
end

View file

@ -20,6 +20,13 @@ ParameterType(
end
)
ParameterType(
name: 'env_name',
regexp: /[A-Z_]+/,
type: String,
transformer: ->(s) { s }
)
ParameterType(
name: 'env_glob',
regexp: /[A-Z_*]+/,

View file

@ -1,27 +0,0 @@
# If either of
# - $SDKMAN_DIR is unset
# - $SDKMAN_DIR points to a directory not owned by the current user
# is true, sdkman-for-fish should run sdkman's init script.
# Assumes sdkman-for-fish is installed
set proper_value "$SDKMAN_DIR"
begin
set -e SDKMAN_DIR
set in_new_shell (fish -lc 'echo $SDKMAN_DIR')
if [ "$in_new_shell" != "$proper_value" ]
echo "SDKMAN_DIR initialized to $in_new_shell instead of $proper_value"
exit 1
end
end
begin
set -x SDKMAN_DIR "/" # belongs to root, who hopefully doesn't run this
set in_new_shell (fish -lc 'echo $SDKMAN_DIR')
if [ "$in_new_shell" != "$proper_value" ]
echo "SDKMAN_DIR reinitialized to $in_new_shell instead of $proper_value"
exit 1
end
end
# TODO: add test that fails if `test` in conf.d/sdk.fish:80 errors (cf issue #28 et al.)