Skip to content

Commit

Permalink
namespacify n8l::git_check()
Browse files Browse the repository at this point in the history
  • Loading branch information
jhoblitt committed Sep 15, 2017
1 parent cabbad9 commit 169c7ce
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 3 deletions.
6 changes: 3 additions & 3 deletions scripts/newinstall.sh
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,8 @@ n8l::up2date_check() {
}

# Discuss the state of Git.
git_check() {
# XXX should probably fail git version is insufficient under batch mode.
n8l::git_check() {
if hash git 2>/dev/null; then
local gitvernum
gitvernum=$(git --version | cut -d\ -f 3)
Expand Down Expand Up @@ -552,7 +553,6 @@ git_check() {
else
echo "Detected $(git --version). OK."
fi
echo
}

n8l::pyverok() {
Expand Down Expand Up @@ -984,7 +984,7 @@ main() {
n8l::up2date_check
fi

git_check
n8l::git_check

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

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

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

context 'version good' do
it 'prints version OK' do
stubbed_env.stub_command('hash') # confirm git is in PATH
stubbed_env.stub_command('git').outputs('git version 2.13.4')

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

expect(status.exitstatus).to be 0
expect(out).to eq("Detected git version 2.13.4. OK.\n")
expect(err).to eq('')
end

context 'batch mode' do
it 'prints version OK' do
stubbed_env.stub_command('hash') # confirm git is in PATH
stubbed_env.stub_command('git').outputs('git version 2.13.4')

out, err, status = stubbed_env.execute_function(
'scripts/newinstall.sh',
func,
{ 'BATCH_FLAG' => 'true' },
)

expect(status.exitstatus).to be 0
expect(out).to eq("Detected git version 2.13.4. OK.\n")
expect(err).to eq('')
end
end
end

context 'version bad' do
it 'prints warning' do
stubbed_env.stub_command('hash') # confirm git is in PATH
stubbed_env.stub_command('git').outputs('git version 1.8.2')
stubbed_env.stub_command('read')

out, err, status = stubbed_env.execute_function(
'scripts/newinstall.sh',
func,
{ 'yn' => 'y' },
)
expect(status.exitstatus).to be 0
expect(out).to match('Detected git version 1.8.2')
expect(out).to match('Continuing without git')
expect(err).to eq('')
end

it 'prints warning' do
stubbed_env.stub_command('hash') # confirm git is in PATH
stubbed_env.stub_command('git').outputs('git version 1.8.2')
stubbed_env.stub_command('read')

out, err, status = stubbed_env.execute_function(
'scripts/newinstall.sh',
func,
{ 'yn' => 'n' },
)
expect(status.exitstatus).to be 0
expect(out).to match('Detected git version 1.8.2')
expect(out).to match('Okay install git and rerun the script.')
expect(err).to eq('')
end

context 'batch mode' do
it 'prints nothing' do
stubbed_env.stub_command('hash') # confirm git is in PATH
stubbed_env.stub_command('git').outputs('git version 1.8.2')

out, err, status = stubbed_env.execute_function(
'scripts/newinstall.sh',
func,
{ 'BATCH_FLAG' => 'true' },
)

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

0 comments on commit 169c7ce

Please sign in to comment.