forked from Bash-it/bash-it
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpreexec.bats
More file actions
178 lines (131 loc) · 5.01 KB
/
preexec.bats
File metadata and controls
178 lines (131 loc) · 5.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
# shellcheck shell=bats
# shellcheck disable=SC2030 disable=SC2031
load ../test_helper
function local_setup {
setup_test_fixture
export __bp_enable_subshells=yas
}
@test "vendor preexec: __bp_install_after_session_init() without existing" {
test_prompt_string=""
export PROMPT_COMMAND="$test_prompt_string"
run load ../../vendor/github.com/rcaloras/bash-preexec/bash-preexec.sh
assert_success
load ../../vendor/github.com/rcaloras/bash-preexec/bash-preexec.sh
assert_equal "${PROMPT_COMMAND}" $'__bp_trap_string="$(trap -p DEBUG)"\ntrap - DEBUG\n__bp_install'
}
@test "vendor preexec: __bp_install_after_session_init() with existing" {
test_prompt_string="nah"
export PROMPT_COMMAND="$test_prompt_string"
run load ../../vendor/github.com/rcaloras/bash-preexec/bash-preexec.sh
assert_success
load ../../vendor/github.com/rcaloras/bash-preexec/bash-preexec.sh
assert_equal "${PROMPT_COMMAND}" "$test_prompt_string"$'\n__bp_trap_string="$(trap -p DEBUG)"\ntrap - DEBUG\n__bp_install'
}
@test "vendor preexec: __bp_install_after_session_init() delayed" {
test_prompt_string="nah"
export PROMPT_COMMAND="$test_prompt_string"
export __bp_delay_install="blarg"
run load ../../vendor/github.com/rcaloras/bash-preexec/bash-preexec.sh
assert_success
load ../../vendor/github.com/rcaloras/bash-preexec/bash-preexec.sh
assert_equal "${PROMPT_COMMAND}" "$test_prompt_string"
run __bp_install_after_session_init
assert_success
__bp_install_after_session_init
assert_equal "${PROMPT_COMMAND}" "$test_prompt_string"$'\n__bp_trap_string="$(trap -p DEBUG)"\ntrap - DEBUG\n__bp_install'
}
@test "vendor preexec: __bp_install() without existing" {
test_prompt_string=""
export PROMPT_COMMAND="$test_prompt_string"
run load ../../vendor/github.com/rcaloras/bash-preexec/bash-preexec.sh
assert_success
load ../../vendor/github.com/rcaloras/bash-preexec/bash-preexec.sh
run __bp_install
assert_success
__bp_install
if ((BASH_VERSINFO[0] > 5 || (BASH_VERSINFO[0] == 5 && BASH_VERSINFO[1] >= 1))); then
assert_equal "${PROMPT_COMMAND[*]}" $'__bp_precmd_invoke_cmd __bp_interactive_mode'
else
assert_equal "${PROMPT_COMMAND}" $'__bp_precmd_invoke_cmd\n__bp_interactive_mode'
fi
}
@test "vendor preexec: __bp_install() with existing" {
test_prompt_string="nah"
export PROMPT_COMMAND="$test_prompt_string"
run load ../../vendor/github.com/rcaloras/bash-preexec/bash-preexec.sh
assert_success
load ../../vendor/github.com/rcaloras/bash-preexec/bash-preexec.sh
run __bp_install
assert_success
__bp_install
if ((BASH_VERSINFO[0] > 5 || (BASH_VERSINFO[0] == 5 && BASH_VERSINFO[1] >= 1))); then
assert_equal "${PROMPT_COMMAND[*]}" $'__bp_precmd_invoke_cmd\n'"$test_prompt_string"$'\n: __bp_interactive_mode'
else
assert_equal "${PROMPT_COMMAND}" $'__bp_precmd_invoke_cmd\n'"$test_prompt_string"$'\n:\n__bp_interactive_mode'
fi
}
@test "lib preexec: __bp_require_not_readonly()" {
run type -t __bp_require_not_readonly
assert_failure
run load ../../lib/preexec.bash
assert_success
load ../../lib/preexec.bash
run type -t __bp_require_not_readonly
assert_success
export HISTCONTROL=blah:blah PROMPT_COMMAND="silly;rabbit"
readonly HISTCONTROL PROMPT_COMMAND
run __bp_require_not_readonly
assert_success
}
@test "lib preexec: __bp_adjust_histcontrol()" {
run type -t __bp_adjust_histcontrol
assert_failure
run load ../../lib/preexec.bash
assert_success
load ../../lib/preexec.bash
run type -t __bp_adjust_histcontrol
assert_success
test_history_control_string="ignoreall:ignoredups:ignorespace:erasedups"
export HISTCONTROL="${test_history_control_string}"
run __bp_adjust_histcontrol
assert_success
assert_equal "${HISTCONTROL}" "${test_history_control_string}"
}
@test "lib preexec: __check_precmd_conflict()" {
test_precmd_function_name="test"
setup_libs "preexec"
run __check_precmd_conflict "$test_precmd_function_name"
assert_failure
export precmd_functions=("$test_precmd_function_name")
run __check_precmd_conflict "$test_precmd_function_name"
assert_success
}
@test "lib preexec: __check_preexec_conflict()" {
test_preexec_function_name="test"
setup_libs "preexec"
run __check_preexec_conflict "$test_preexec_function_name"
assert_failure
export preexec_functions=("$test_preexec_function_name")
run __check_preexec_conflict "$test_preexec_function_name"
assert_success
}
@test "lib preexec: safe_append_prompt_command()" {
test_precmd_function_name="test"
setup_libs "preexec"
export precmd_functions=()
assert_equal "${precmd_functions[*]}" ""
run safe_append_prompt_command "$test_precmd_function_name"
assert_success
safe_append_prompt_command "$test_precmd_function_name"
assert_equal "${precmd_functions[*]}" "$test_precmd_function_name"
}
@test "lib preexec: safe_append_preexec()" {
test_preexec_function_name="test"
setup_libs "preexec"
export preexec_functions=()
assert_equal "${preexec_functions[*]}" ""
run safe_append_preexec "$test_preexec_function_name"
assert_success
safe_append_preexec "$test_preexec_function_name"
assert_equal "${preexec_functions[*]}" "$test_preexec_function_name"
}