Skip to content

Commit

Permalink
add warning for known problematic env vars
Browse files Browse the repository at this point in the history
  • Loading branch information
jhoblitt committed Sep 19, 2017
1 parent 7e00d06 commit 5210a76
Show file tree
Hide file tree
Showing 3 changed files with 156 additions and 1 deletion.
50 changes: 49 additions & 1 deletion scripts/newinstall.sh
Original file line number Diff line number Diff line change
Expand Up @@ -784,6 +784,50 @@ n8l::install_eups() {
echo " done."
}

n8l::problem_vars() {
local problems=(
EUPS_PATH
EUPS_PKGROOT
LSST_HOME
REPOSITORY_PATH
)
local found=()

for v in ${problems[*]}; do
if [[ -n ${!v+1} ]]; then
found+=($v)
fi
done

echo -n "${found[@]}"
}

n8l::problem_vars_check() {
local problems=()
problems=($(n8l::problem_vars))

if [[ ${#problems} -gt 0 ]]; then
n8l::print_error "$(cat <<-EOF
WARNING: the following environment variables are defined that will affect
the operation of the LSST build tooling.\n
EOF
)"

for v in ${problems[*]}; do
n8l::print_error "${v}=\"${!v}\""
done

n8l::print_error "$(cat <<-EOF
It is recommended that they are undefined before running this script.
unset ${problems[*]}
EOF
)"
return 1
fi
}

n8l::generate_loader_bash() {
local file_name=$1

Expand Down Expand Up @@ -991,10 +1035,14 @@ n8l::main() {
n8l::up2date_check
fi

if [[ $BATCH_FLAG != true ]]; then
n8l::problem_vars_check
fi

n8l::git_check

# always use miniconda when in batch mode
if [[ $BATCH_FLAG = true ]]; then
if [[ $BATCH_FLAG == true ]]; then
WITH_MINICONDA=true
else
n8l::python_check
Expand Down
56 changes: 56 additions & 0 deletions spec/unit/n8l/problem_vars_check_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
require 'rspec/bash'

describe 'n8l::problem_vars_check' do
include Rspec::Bash

let(:stubbed_env) { create_stubbed_env }
subject(:func) { 'n8l::problem_vars_check' }

let(:problems) do
%w[
EUPS_PATH
EUPS_PKGROOT
LSST_HOME
REPOSITORY_PATH
]
end

context 'no problematic vars defined' do
it 'reports nothing' do
problem_vars = stubbed_env.stub_command('n8l::problem_vars')

out, err, status = stubbed_env.execute_function(
'scripts/newinstall.sh',
func,
)

expect(out).to eq('')
expect(err).to eq('')
expect(status.exitstatus).to be 0

expect(problem_vars).to be_called
end
end

context 'problematic vars defined' do
it 'prints multiple params to stderr' do
problem_vars = stubbed_env.stub_command('n8l::problem_vars').outputs(
problems.join(' ')
)

out, err, status = stubbed_env.execute_function(
'scripts/newinstall.sh',
<<-SCRIPT
#{problems.collect { |var| "#{var}=foo;" }.join(' ')}
#{func}
SCRIPT
)

expect(out).to eq('')
problems.each { |var| expect(err).to match(/#{var}="foo"/) }
expect(status.exitstatus).to_not be 0

expect(problem_vars).to be_called
end
end
end
51 changes: 51 additions & 0 deletions spec/unit/n8l/problem_vars_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
require 'rspec/bash'

describe 'n8l::problem_vars' do
include Rspec::Bash

let(:stubbed_env) { create_stubbed_env }
subject(:func) { 'n8l::problem_vars' }

let(:problems) do
%w[
EUPS_PATH
EUPS_PKGROOT
LSST_HOME
REPOSITORY_PATH
]
end

context 'no problematic vars defined' do
it 'reports nothing' do
problems.each { |var| ENV.delete(var) }

out, err, status = stubbed_env.execute_function(
'scripts/newinstall.sh',
<<-SCRIPT
unset #{problems.join(' ')}
#{func}
SCRIPT
)

expect(out).to eq('')
expect(err).to eq('')
expect(status.exitstatus).to be 0
end
end

context 'problematic vars defined' do
it 'prints multiple params to stderr' do
out, err, status = stubbed_env.execute_function(
'scripts/newinstall.sh',
<<-SCRIPT
#{problems.collect { |var| "#{var}=foo;" }.join(' ')}
#{func}
SCRIPT
)

expect(out).to eq('EUPS_PATH EUPS_PKGROOT LSST_HOME REPOSITORY_PATH')
expect(err).to eq('')
expect(status.exitstatus).to be 0
end
end
end

0 comments on commit 5210a76

Please sign in to comment.