Skip to content

Commit 4ec1b5f

Browse files
authored
Merge pull request Bash-it#2002 from gaelicWizard/bats
tests: path quoting and boilerplate
2 parents b846c86 + 8a226a7 commit 4ec1b5f

23 files changed

+106
-151
lines changed

clean_files.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,9 @@ plugins/available/zoxide.plugin.bash
122122
# tests
123123
#
124124
test/plugins/alias-completion.plugin.bats
125+
test/run
125126
test/test_helper.bash
127+
test/test_helper_libs.bash
126128

127129
# themes
128130
#

test/bash_it/bash_it.bats

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#!/usr/bin/env bats
22

33
load ../test_helper
4-
load "${BASH_IT}/vendor/github.com/erichs/composure/composure.sh"
54

65
function local_setup {
76
setup_test_fixture

test/completion/bash-it.completion.bats

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#!/usr/bin/env bats
22

33
load ../test_helper
4-
load "${BASH_IT}/vendor/github.com/erichs/composure/composure.sh"
54
load ../../completion/available/bash-it.completion
65

76
function local_setup {

test/install/install.bats

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#!/usr/bin/env bats
22

33
load ../test_helper
4-
load "${BASH_IT}/vendor/github.com/erichs/composure/composure.sh"
54

65
# Determine which config file to use based on OS.
76
case $OSTYPE in

test/install/uninstall.bats

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#!/usr/bin/env bats
22

33
load ../test_helper
4-
load "${BASH_IT}/vendor/github.com/erichs/composure/composure.sh"
54

65
# Determine which config file to use based on OS.
76
case $OSTYPE in

test/lib/composure.bats

100755100644
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#!/usr/bin/env bats
22

33
load ../test_helper
4-
load "${BASH_IT}/vendor/github.com/erichs/composure/composure.sh"
54

65
@test "lib composure: _composure_keywords()" {
76
run _composure_keywords

test/lib/helpers.bats

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,7 @@
11
#!/usr/bin/env bats
22

33
load ../test_helper
4-
load "${BASH_IT}/vendor/github.com/erichs/composure/composure.sh"
5-
load ../../lib/log
6-
load ../../lib/utilities
7-
load ../../lib/search
8-
9-
cite _about _param _example _group _author _version
10-
11-
load ../../lib/helpers
4+
load ../test_helper_libs
125
load ../../plugins/available/base.plugin
136

147
function local_setup {

test/lib/log.bats

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
#!/usr/bin/env bats
22

33
load ../test_helper
4-
load "${BASH_IT}/vendor/github.com/erichs/composure/composure.sh"
5-
load ../../lib/appearance
4+
load ../../themes/colors.theme
65

7-
cite _about _param _example _group _author _version
86
load ../../lib/log
97
load ../../lib/helpers
108
load ../../plugins/available/base.plugin

test/lib/search.bats

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,7 @@
11
#!/usr/bin/env bats
22

33
load ../test_helper
4-
load "${BASH_IT}/vendor/github.com/erichs/composure/composure.sh"
5-
load ../../lib/log
6-
load ../../lib/helpers
7-
load ../../lib/utilities
8-
load ../../lib/search
9-
10-
cite _about _param _example _group _author _version
4+
load ../test_helper_libs
115

126
load ../../plugins/available/base.plugin
137
load ../../aliases/available/git.aliases

test/lib/utilities.bats

Lines changed: 31 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,93 +1,84 @@
11
#!/usr/bin/env bats
22

33
load ../test_helper
4-
load "${BASH_IT}/vendor/github.com/erichs/composure/composure.sh"
5-
load ../../lib/helpers
6-
load ../../lib/utilities
7-
load ../../lib/search
8-
9-
cite _about _param _example _group _author _version
4+
load ../test_helper_libs
105

116
function local_setup {
127
setup_test_fixture
138
}
149

15-
function has_match() {
16-
$(_bash-it-array-contains-element ${@}) && echo "has" "$1"
17-
}
18-
19-
function item_enabled() {
20-
$(_bash-it-component-item-is-enabled ${@}) && echo "$1" "$2" "is enabled"
21-
}
22-
23-
function item_disabled() {
24-
$(_bash-it-component-item-is-disabled ${@}) && echo "$1" "$2" "is disabled"
25-
}
26-
2710
@test "_bash-it-component-item-is-enabled() - for a disabled item" {
28-
run item_enabled aliases svn
29-
assert_line -n 0 ''
11+
run _bash-it-component-item-is-enabled aliases svn
12+
assert_failure
3013
}
3114

3215
@test "_bash-it-component-item-is-enabled() - for an enabled/disabled item" {
3316
run bash-it enable alias svn
3417
assert_line -n 0 'svn enabled with priority 150.'
3518

36-
run item_enabled alias svn
37-
assert_line -n 0 'alias svn is enabled'
19+
run _bash-it-component-item-is-enabled alias svn
20+
assert_success
21+
run _bash-it-component-item-is-disabled alias svn
22+
assert_failure
3823

3924
run bash-it disable alias svn
4025
assert_line -n 0 'svn disabled.'
4126

42-
run item_enabled alias svn
43-
assert_line -n 0 ''
27+
run _bash-it-component-item-is-enabled alias svn
28+
assert_failure
29+
run _bash-it-component-item-is-disabled alias svn
30+
assert_success
4431
}
4532

4633
@test "_bash-it-component-item-is-disabled() - for a disabled item" {
47-
run item_disabled alias svn
48-
assert_line -n 0 'alias svn is disabled'
34+
run _bash-it-component-item-is-disabled alias svn
35+
assert_success
4936
}
5037

5138
@test "_bash-it-component-item-is-disabled() - for an enabled/disabled item" {
5239
run bash-it enable alias svn
5340
assert_line -n 0 'svn enabled with priority 150.'
5441

55-
run item_disabled alias svn
56-
assert_line -n 0 ''
42+
run _bash-it-component-item-is-disabled alias svn
43+
assert_failure
44+
run _bash-it-component-item-is-enabled alias svn
45+
assert_success
5746

5847
run bash-it disable alias svn
5948
assert_line -n 0 'svn disabled.'
6049

61-
run item_disabled alias svn
62-
assert_line -n 0 'alias svn is disabled'
50+
run _bash-it-component-item-is-disabled alias svn
51+
assert_success
52+
run _bash-it-component-item-is-enabled alias svn
53+
assert_failure
6354
}
6455

6556
@test "_bash-it-array-contains-element() - when match is found, and is the first" {
6657
declare -a fruits=(apple pear orange mandarin)
67-
run has_match apple "${fruits[@]}"
68-
assert_line -n 0 'has apple'
58+
run _bash-it-array-contains-element apple "${fruits[@]}"
59+
assert_success
6960
}
7061

7162
@test "_bash-it-array-contains-element() - when match is found, and is the last" {
7263
declare -a fruits=(apple pear orange mandarin)
73-
run has_match mandarin "${fruits[@]}"
74-
assert_line -n 0 'has mandarin'
64+
run _bash-it-array-contains-element mandarin "${fruits[@]}"
65+
assert_success
7566
}
7667

7768
@test "_bash-it-array-contains-element() - when match is found, and is in the middle" {
7869
declare -a fruits=(apple pear orange mandarin)
79-
run has_match pear "${fruits[@]}"
80-
assert_line -n 0 'has pear'
70+
run _bash-it-array-contains-element pear "${fruits[@]}"
71+
assert_success
8172
}
8273

8374
@test "_bash-it-array-contains-element() - when match is found, and it has spaces" {
8475
declare -a fruits=(apple pear orange mandarin "yellow watermelon")
85-
run has_match "yellow watermelon" "${fruits[@]}"
86-
assert_line -n 0 'has yellow watermelon'
76+
run _bash-it-array-contains-element "yellow watermelon" "${fruits[@]}"
77+
assert_success
8778
}
8879

8980
@test "_bash-it-array-contains-element() - when match is not found" {
9081
declare -a fruits=(apple pear orange mandarin)
91-
run has_match xyz "${fruits[@]}"
92-
assert_line -n 0 ''
82+
run _bash-it-array-contains-element xyz "${fruits[@]}"
83+
assert_failure
9384
}

0 commit comments

Comments
 (0)