mirror of
https://github.com/ethauvin/sdkman-for-fish.git
synced 2025-04-25 13:27:10 -07:00
Migrate reinitialization test to Cucumber.
This commit is contained in:
parent
56bc601b17
commit
0a948c81c1
6 changed files with 67 additions and 30 deletions
|
@ -38,6 +38,5 @@ install:
|
||||||
script:
|
script:
|
||||||
- (cd test && cucumber)
|
- (cd test && cucumber)
|
||||||
# TODO: Migrate these to 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
|
- 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"
|
||||||
|
|
13
test/features/corner_cases.feature
Normal file
13
test/features/corner_cases.feature
Normal 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.)
|
45
test/features/step_definitions/corner_cases.rb
Normal file
45
test/features/step_definitions/corner_cases.rb
Normal 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
|
|
@ -48,7 +48,7 @@ def run_bash_command(cmd)
|
||||||
status: File.read(files[:status]).to_i,
|
status: File.read(files[:status]).to_i,
|
||||||
stdout: File.readlines(files[:stdout]),
|
stdout: File.readlines(files[:stdout]),
|
||||||
stderr: File.readlines(files[:stderr]),
|
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
|
||||||
end
|
end
|
||||||
|
@ -83,7 +83,7 @@ def run_fish_command(cmd)
|
||||||
status: File.read(files[:status]).to_i,
|
status: File.read(files[:status]).to_i,
|
||||||
stdout: File.readlines(files[:stdout]),
|
stdout: File.readlines(files[:stdout]),
|
||||||
stderr: File.readlines(files[:stderr]),
|
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
|
||||||
end
|
end
|
||||||
|
|
|
@ -20,6 +20,13 @@ ParameterType(
|
||||||
end
|
end
|
||||||
)
|
)
|
||||||
|
|
||||||
|
ParameterType(
|
||||||
|
name: 'env_name',
|
||||||
|
regexp: /[A-Z_]+/,
|
||||||
|
type: String,
|
||||||
|
transformer: ->(s) { s }
|
||||||
|
)
|
||||||
|
|
||||||
ParameterType(
|
ParameterType(
|
||||||
name: 'env_glob',
|
name: 'env_glob',
|
||||||
regexp: /[A-Z_*]+/,
|
regexp: /[A-Z_*]+/,
|
||||||
|
|
|
@ -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.)
|
|
Loading…
Add table
Add a link
Reference in a new issue