Skip to content

Commit ca8101b

Browse files
authored
Merge pull request #2031 from gaelicWizard/bats-cleanup
2 parents 9dece7f + 6d422f1 commit ca8101b

24 files changed

+305
-342
lines changed

clean_files.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,6 @@ plugins/available/zoxide.plugin.bash
138138
test/plugins/alias-completion.plugin.bats
139139
test/run
140140
test/test_helper.bash
141-
test/test_helper_libs.bash
142141

143142
# themes
144143
#

test/bash_it/bash_it.bats

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,11 @@
1-
#!/usr/bin/env bats
1+
# shellcheck shell=bats
22

3-
load ../test_helper
4-
5-
function local_setup {
6-
setup_test_fixture
3+
load "${MAIN_BASH_IT_DIR?}/test/test_helper.bash"
74

5+
function local_setup_file() {
86
# Copy the test fixture to the Bash-it folder
9-
if command -v rsync &> /dev/null
10-
then
11-
rsync -a "$BASH_IT/test/fixtures/bash_it/" "$BASH_IT/"
12-
else
13-
find "$BASH_IT/test/fixtures/bash_it" \
14-
-mindepth 1 -maxdepth 1 \
15-
-exec cp -r {} "$BASH_IT/" \;
16-
fi
7+
cp -fRP "${BASH_IT?}/test/fixtures/bash_it"/* "${BASH_IT?}/" || true
8+
# don't load any libraries as the tests here test the *whole* kit
179
}
1810

1911
@test "bash-it: verify that the test fixture is available" {
Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,30 @@
1-
#!/usr/bin/env bats
1+
# shellcheck shell=bats
22

3-
load ../test_helper
4-
load ../test_helper_libs
3+
load "${MAIN_BASH_IT_DIR?}/test/test_helper.bash"
54

6-
# Load something, anything...
7-
load ../../completion/available/capistrano.completion
5+
function local_setup_file() {
6+
setup_libs "helpers"
7+
# Load something, anything...
8+
load ../../completion/available/capistrano.completion
9+
}
810

911
@test "alias-completion: See that aliases with double quotes and brackets do not break the plugin" {
1012
alias gtest="git log --graph --pretty=format:'%C(bold)%h%Creset%C(magenta)%d%Creset %s %C(yellow)<%an> %C(cyan)(%cr)%Creset' --abbrev-commit --date=relative"
11-
run load ../../completion/available/aliases.completion
13+
run load "${BASH_IT?}/completion/available/aliases.completion.bash"
1214

1315
assert_success
1416
}
1517

1618
@test "alias-completion: See that aliases with single quotes and brackets do not break the plugin" {
1719
alias gtest='git log --graph --pretty=format:"%C(bold)%h%Creset%C(magenta)%d%Creset %s %C(yellow)<%an> %C(cyan)(%cr)%Creset" --abbrev-commit --date=relative'
18-
run load ../../completion/available/aliases.completion
20+
run load "${BASH_IT?}/completion/available/aliases.completion.bash"
1921

2022
assert_success
2123
}
2224

2325
@test "alias-completion: See that having aliased rm command does not output unnecessary output" {
2426
alias rm='rm -v'
25-
run load ../../completion/available/aliases.completion
27+
run load "${BASH_IT?}/completion/available/aliases.completion.bash"
2628

2729
refute_output
2830
}

test/completion/bash-it.completion.bats

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
1-
#!/usr/bin/env bats
1+
# shellcheck shell=bats
22

3-
load ../test_helper
4-
load ../../lib/utilities
5-
load ../../lib/helpers
6-
load ../../completion/available/bash-it.completion
3+
load "${MAIN_BASH_IT_DIR?}/test/test_helper.bash"
74

8-
function local_setup {
9-
setup_test_fixture
5+
function local_setup_file() {
6+
setup_libs "helpers"
7+
load "${BASH_IT?}/completion/available/bash-it.completion.bash"
108
}
119

1210
@test "completion bash-it: ensure that the _bash-it function is available" {
13-
type -a _bash-it &> /dev/null
11+
run type -t _bash-it
1412
assert_success
13+
assert_output "function"
1514
}
1615

1716
function __check_completion () {

test/install/install.bats

Lines changed: 31 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,22 @@
1-
#!/usr/bin/env bats
2-
3-
load ../test_helper
4-
5-
# Determine which config file to use based on OS.
6-
case $OSTYPE in
7-
darwin*)
8-
export BASH_IT_CONFIG_FILE=.bash_profile
9-
;;
10-
*)
11-
export BASH_IT_CONFIG_FILE=.bashrc
12-
;;
13-
esac
14-
15-
function local_setup {
16-
setup_test_fixture
1+
# shellcheck shell=bats
2+
3+
load "${MAIN_BASH_IT_DIR?}/test/test_helper.bash"
4+
5+
function local_setup() {
6+
export HOME="$BATS_TEST_TMPDIR"
7+
}
8+
9+
function local_setup_file() {
10+
# Determine which config file to use based on OS.
11+
case $OSTYPE in
12+
darwin*)
13+
export BASH_IT_CONFIG_FILE=.bash_profile
14+
;;
15+
*)
16+
export BASH_IT_CONFIG_FILE=.bashrc
17+
;;
18+
esac
19+
# don't load any libraries as the tests here test the *whole* kit
1720
}
1821

1922
@test "install: verify that the install script exists" {
@@ -25,7 +28,7 @@ function local_setup {
2528

2629
./install.sh --silent
2730

28-
assert_file_exist "$BASH_IT_TEST_HOME/$BASH_IT_CONFIG_FILE"
31+
assert_file_exist "$HOME/$BASH_IT_CONFIG_FILE"
2932

3033
assert_link_exist "$BASH_IT/enabled/150---general.aliases.bash"
3134
assert_link_exist "$BASH_IT/enabled/250---base.plugin.bash"
@@ -37,16 +40,16 @@ function local_setup {
3740
@test "install: verify that a backup file is created" {
3841
cd "$BASH_IT"
3942

40-
touch "$BASH_IT_TEST_HOME/$BASH_IT_CONFIG_FILE"
41-
echo "test file content" > "$BASH_IT_TEST_HOME/$BASH_IT_CONFIG_FILE"
42-
local md5_orig=$(md5sum "$BASH_IT_TEST_HOME/$BASH_IT_CONFIG_FILE" | awk '{print $1}')
43+
touch "$HOME/$BASH_IT_CONFIG_FILE"
44+
echo "test file content" > "$HOME/$BASH_IT_CONFIG_FILE"
45+
local md5_orig=$(md5sum "$HOME/$BASH_IT_CONFIG_FILE" | awk '{print $1}')
4346

4447
./install.sh --silent
4548

46-
assert_file_exist "$BASH_IT_TEST_HOME/$BASH_IT_CONFIG_FILE"
47-
assert_file_exist "$BASH_IT_TEST_HOME/$BASH_IT_CONFIG_FILE.bak"
49+
assert_file_exist "$HOME/$BASH_IT_CONFIG_FILE"
50+
assert_file_exist "$HOME/$BASH_IT_CONFIG_FILE.bak"
4851

49-
local md5_bak=$(md5sum "$BASH_IT_TEST_HOME/$BASH_IT_CONFIG_FILE.bak" | awk '{print $1}')
52+
local md5_bak=$(md5sum "$HOME/$BASH_IT_CONFIG_FILE.bak" | awk '{print $1}')
5053

5154
assert_equal "$md5_orig" "$md5_bak"
5255
}
@@ -70,15 +73,15 @@ function local_setup {
7073
@test "install: verify that the template is appended" {
7174
cd "$BASH_IT"
7275

73-
touch "$BASH_IT_TEST_HOME/$BASH_IT_CONFIG_FILE"
74-
echo "test file content" > "$BASH_IT_TEST_HOME/$BASH_IT_CONFIG_FILE"
76+
touch "$HOME/$BASH_IT_CONFIG_FILE"
77+
echo "test file content" > "$HOME/$BASH_IT_CONFIG_FILE"
7578

7679
./install.sh --silent --append-to-config
7780

78-
assert_file_exist "$BASH_IT_TEST_HOME/$BASH_IT_CONFIG_FILE"
79-
assert_file_exist "$BASH_IT_TEST_HOME/$BASH_IT_CONFIG_FILE.bak"
81+
assert_file_exist "$HOME/$BASH_IT_CONFIG_FILE"
82+
assert_file_exist "$HOME/$BASH_IT_CONFIG_FILE.bak"
8083

81-
run cat $BASH_IT_TEST_HOME/$BASH_IT_CONFIG_FILE
84+
run cat "$HOME/$BASH_IT_CONFIG_FILE"
8285

8386
assert_line "test file content"
8487
assert_line "source \"\$BASH_IT\"/bash_it.sh"

test/install/uninstall.bats

Lines changed: 34 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,22 @@
1-
#!/usr/bin/env bats
2-
3-
load ../test_helper
4-
5-
# Determine which config file to use based on OS.
6-
case $OSTYPE in
7-
darwin*)
8-
export BASH_IT_CONFIG_FILE=.bash_profile
9-
;;
10-
*)
11-
export BASH_IT_CONFIG_FILE=.bashrc
12-
;;
13-
esac
14-
15-
function local_setup {
16-
setup_test_fixture
1+
# shellcheck shell=bats
2+
3+
load "${MAIN_BASH_IT_DIR?}/test/test_helper.bash"
4+
5+
function local_setup() {
6+
export HOME="$BATS_TEST_TMPDIR"
7+
}
8+
9+
function local_setup_file() {
10+
# Determine which config file to use based on OS.
11+
case $OSTYPE in
12+
darwin*)
13+
export BASH_IT_CONFIG_FILE=.bash_profile
14+
;;
15+
*)
16+
export BASH_IT_CONFIG_FILE=.bashrc
17+
;;
18+
esac
19+
# don't load any libraries as the tests here test the *whole* kit
1720
}
1821

1922
@test "uninstall: verify that the uninstall script exists" {
@@ -23,38 +26,36 @@ function local_setup {
2326
@test "uninstall: run the uninstall script with an existing backup file" {
2427
cd "$BASH_IT"
2528

26-
echo "test file content for backup" > "$BASH_IT_TEST_HOME/$BASH_IT_CONFIG_FILE.bak"
27-
echo "test file content for original file" > "$BASH_IT_TEST_HOME/$BASH_IT_CONFIG_FILE"
28-
local md5_bak=$(md5sum "$BASH_IT_TEST_HOME/$BASH_IT_CONFIG_FILE.bak" | awk '{print $1}')
29-
30-
./uninstall.sh
29+
echo "test file content for backup" > "$HOME/$BASH_IT_CONFIG_FILE.bak"
30+
echo "test file content for original file" > "$HOME/$BASH_IT_CONFIG_FILE"
31+
local md5_bak=$(md5sum "$HOME/$BASH_IT_CONFIG_FILE.bak" | awk '{print $1}')
3132

33+
run ./uninstall.sh
3234
assert_success
3335

34-
assert_file_not_exist "$BASH_IT_TEST_HOME/$BASH_IT_CONFIG_FILE.uninstall"
35-
assert_file_not_exist "$BASH_IT_TEST_HOME/$BASH_IT_CONFIG_FILE.bak"
36-
assert_file_exist "$BASH_IT_TEST_HOME/$BASH_IT_CONFIG_FILE"
36+
assert_file_not_exist "$HOME/$BASH_IT_CONFIG_FILE.uninstall"
37+
assert_file_not_exist "$HOME/$BASH_IT_CONFIG_FILE.bak"
38+
assert_file_exist "$HOME/$BASH_IT_CONFIG_FILE"
3739

38-
local md5_conf=$(md5sum "$BASH_IT_TEST_HOME/$BASH_IT_CONFIG_FILE" | awk '{print $1}')
40+
local md5_conf=$(md5sum "$HOME/$BASH_IT_CONFIG_FILE" | awk '{print $1}')
3941

4042
assert_equal "$md5_bak" "$md5_conf"
4143
}
4244

4345
@test "uninstall: run the uninstall script without an existing backup file" {
4446
cd "$BASH_IT"
4547

46-
echo "test file content for original file" > "$BASH_IT_TEST_HOME/$BASH_IT_CONFIG_FILE"
47-
local md5_orig=$(md5sum "$BASH_IT_TEST_HOME/$BASH_IT_CONFIG_FILE" | awk '{print $1}')
48-
49-
./uninstall.sh
48+
echo "test file content for original file" > "$HOME/$BASH_IT_CONFIG_FILE"
49+
local md5_orig=$(md5sum "$HOME/$BASH_IT_CONFIG_FILE" | awk '{print $1}')
5050

51+
run ./uninstall.sh
5152
assert_success
5253

53-
assert_file_exist "$BASH_IT_TEST_HOME/$BASH_IT_CONFIG_FILE.uninstall"
54-
assert_file_not_exist "$BASH_IT_TEST_HOME/$BASH_IT_CONFIG_FILE.bak"
55-
assert_file_not_exist "$BASH_IT_TEST_HOME/$BASH_IT_CONFIG_FILE"
54+
assert_file_exist "$HOME/$BASH_IT_CONFIG_FILE.uninstall"
55+
assert_file_not_exist "$HOME/$BASH_IT_CONFIG_FILE.bak"
56+
assert_file_not_exist "$HOME/$BASH_IT_CONFIG_FILE"
5657

57-
local md5_uninstall=$(md5sum "$BASH_IT_TEST_HOME/$BASH_IT_CONFIG_FILE.uninstall" | awk '{print $1}')
58+
local md5_uninstall=$(md5sum "$HOME/$BASH_IT_CONFIG_FILE.uninstall" | awk '{print $1}')
5859

5960
assert_equal "$md5_orig" "$md5_uninstall"
6061
}

test/lib/composure.bats

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
1-
#!/usr/bin/env bats
1+
# shellcheck shell=bats
22

3-
load ../test_helper
3+
load "${MAIN_BASH_IT_DIR?}/test/test_helper.bash"
4+
5+
function local_setup_file() {
6+
true
7+
# don't load any libraries as the tests here test the *whole* kit
8+
}
49

510
@test "lib composure: _composure_keywords()" {
611
run _composure_keywords

test/lib/helpers.bats

100755100644
Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,15 @@
1-
#!/usr/bin/env bats
1+
# shellcheck shell=bats
22

3-
load ../test_helper
4-
load ../test_helper_libs
5-
load ../../plugins/available/base.plugin
6-
load ../../lib/colors
3+
load "${MAIN_BASH_IT_DIR?}/test/test_helper.bash"
74

8-
function local_setup {
9-
setup_test_fixture
5+
function local_setup_file() {
6+
setup_libs "colors"
7+
load "${BASH_IT?}/plugins/available/base.plugin.bash"
8+
}
109

10+
function local_setup() {
1111
# Copy the test fixture to the Bash-it folder
12-
if command -v rsync &> /dev/null; then
13-
rsync -a "$BASH_IT/test/fixtures/bash_it/" "$BASH_IT/"
14-
else
15-
find "$BASH_IT/test/fixtures/bash_it" \
16-
-mindepth 1 -maxdepth 1 \
17-
-exec cp -r {} "$BASH_IT/" \;
18-
fi
12+
cp -RP "$BASH_IT/test/fixtures/bash_it"/* "$BASH_IT/"
1913
}
2014

2115
# TODO Create global __is_enabled function

test/lib/log.bats

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
#!/usr/bin/env bats
1+
# shellcheck shell=bats
22

3-
load ../test_helper
4-
load ../../lib/colors
3+
load "${MAIN_BASH_IT_DIR?}/test/test_helper.bash"
54

6-
load ../../lib/log
7-
load ../../lib/helpers
8-
load ../../plugins/available/base.plugin
5+
function local_setup_file() {
6+
setup_libs "log"
7+
}
98

109
@test "lib log: basic debug logging with BASH_IT_LOG_LEVEL_ALL" {
1110
BASH_IT_LOG_LEVEL=$BASH_IT_LOG_LEVEL_ALL

test/lib/preexec.bats

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ function local_setup {
111111

112112
@test "lib preexec: __check_precmd_conflict()" {
113113
test_precmd_function_name="test"
114-
load ../test_helper_libs
114+
setup_libs "preexec"
115115

116116
run __check_precmd_conflict "$test_precmd_function_name"
117117
assert_failure
@@ -124,7 +124,7 @@ function local_setup {
124124

125125
@test "lib preexec: __check_preexec_conflict()" {
126126
test_preexec_function_name="test"
127-
load ../test_helper_libs
127+
setup_libs "preexec"
128128

129129
run __check_preexec_conflict "$test_preexec_function_name"
130130
assert_failure
@@ -137,7 +137,7 @@ function local_setup {
137137

138138
@test "lib preexec: safe_append_prompt_command()" {
139139
test_precmd_function_name="test"
140-
load ../test_helper_libs
140+
setup_libs "preexec"
141141

142142
export precmd_functions=()
143143
assert_equal "${precmd_functions[*]}" ""
@@ -151,7 +151,7 @@ function local_setup {
151151

152152
@test "lib preexec: safe_append_preexec()" {
153153
test_preexec_function_name="test"
154-
load ../test_helper_libs
154+
setup_libs "preexec"
155155

156156
export preexec_functions=()
157157
assert_equal "${preexec_functions[*]}" ""

0 commit comments

Comments
 (0)