Skip to content

Commit 4edc57f

Browse files
committed
Cleanup src/tests/installation/*.sh
Cleaned with: - shellcheck - style.pl - shfmt -i 2
1 parent 9f2265c commit 4edc57f

File tree

2 files changed

+106
-99
lines changed

2 files changed

+106
-99
lines changed

src/tests/installation/installation-scripts.sh

100755100644
Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,23 @@
8181

8282
set -o errtrace
8383

84+
if [[ "${BASH_SOURCE[0]}" != "${0}" ]]; then
85+
# shellcheck disable=SC2154
86+
if [[ -v __usage ]]; then
87+
__b3bp_tmp_source_idx=1
88+
fi
89+
fi
90+
91+
# Set magic variables for current file, directory, os, etc.
92+
__dir="$(cd "$(dirname "${BASH_SOURCE[${__b3bp_tmp_source_idx:-0}]}")" && pwd)"
93+
__file="${__dir}/$(basename "${BASH_SOURCE[${__b3bp_tmp_source_idx:-0}]}")"
94+
8495
# requires `set -o errtrace`
8596
__b3bp_err_report() {
86-
local error_code
87-
error_code=${?}
88-
error "Error in ${__file} in function ${1} on line ${2}"
89-
exit ${error_code}
97+
local error_code
98+
error_code=${?}
99+
error "Error in ${__file} in function ${1} on line ${2}"
100+
exit ${error_code}
90101
}
91102
# Uncomment the following line for always providing an error backtrace
92103
trap '__b3bp_err_report "${FUNCNAME:-.}" ${LINENO}' ERR
@@ -103,8 +114,8 @@ if [[ ! -f "${B3B_USE_CASE:-}/bootstrap.sh" ]]; then
103114
echo "Please set B3B_USE_CASE to the bash3boilerplate use-case directory path."
104115
exit 2
105116
else
106-
# shellcheck source=../../../prerequisites/use-case/bootstrap.sh
107-
source "${B3B_USE_CASE}/bootstrap.sh" "$@"
117+
# shellcheck source=../../../prerequisites/use-case/bootstrap.sh
118+
source "${B3B_USE_CASE}/bootstrap.sh" "$@"
108119
fi
109120
### End of boilerplate -- start user edits below #########################
110121

@@ -113,12 +124,11 @@ export __flag_present=1
113124

114125
# Set up a function to call when receiving an EXIT signal to do some cleanup. Remove if
115126
# not needed. Other signals can be trapped too, like SIGINT and SIGTERM.
116-
function cleanup_before_exit () {
127+
function cleanup_before_exit() {
117128
info "Cleaning up. Done"
118129
}
119130
trap cleanup_before_exit EXIT # The signal is specified here. Could be SIGINT, SIGTERM etc.
120131

121-
122132
pushd "${OPENCOARRAYS_SRC_DIR}"/src/tests/installation
123133

124134
# shellcheck source=../../../prerequisites/stack.sh

src/tests/installation/test-stack.sh

Lines changed: 88 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -1,139 +1,136 @@
1-
functions_exist()
2-
{
3-
: "${1?'Missing function name list'}"
1+
# shellcheck shell=bash
2+
functions_exist() {
3+
: "${1?'Missing function name list'}"
44

5-
for function_name
6-
do
7-
if [[ "`type -t $function_name`" != "function" ]]; then
5+
for function_name; do
6+
if [[ "$(type -t "${function_name}")" != "function" ]]; then
87
emergency "function ${function_name} does not exist"
9-
fi
10-
done
8+
fi
9+
done
1110
}
1211

13-
detect_missing_variable_name()
14-
{
15-
: "${1?'detect_missing_variable name: Missing function name'}"
12+
detect_missing_variable_name() {
13+
: "${1?'detect_missing_variable name: Missing function name'}"
1614

17-
stack_new __dummy_stack
15+
stack_new __dummy_stack
1816

19-
for function_name
20-
do
21-
expected_error="Missing variable name in ${function_name}"
22-
error_message="$($function_name _dummy_stack_name 2>&1 > /dev/null)" || true
23-
error_message="${error_message##*: }" # grab text after final colon/space sequence
24-
if [[ "${error_message}" != ${expected_error} ]]; then
25-
emergency "$function_name failed to detect '${expected_error}'"
26-
fi
17+
for function_name; do
18+
expected_error="Missing variable name in ${function_name}"
19+
error_message="$(${function_name} _dummy_stack_name 2>&1 >/dev/null)" || true
20+
error_message="${error_message##*: }" # grab text after final colon/space sequence
21+
if [[ "${error_message}" != "${expected_error}" ]]; then
22+
emergency "${function_name} failed to detect '${expected_error}'"
23+
fi
2724
done
28-
stack_destroy __dummy_stack
25+
stack_destroy __dummy_stack
2926
}
3027

31-
detect_missing_stack_name()
32-
{
33-
: "${1?'detect_missing_name: Missing function name'}"
34-
35-
expected_error="Missing stack name"
36-
debug "detect_missing_stack_name: \${expected_error}=${expected_error}"
37-
38-
for function_name
39-
do
40-
debug "detect_missing_stack_name: executing \"\$($function_name 2>&1 > /dev/null)\" || true"
41-
error_message="$($function_name 2>&1 > /dev/null)" || true
42-
error_message="${error_message##*: }" # grab text after final colon/space sequence
43-
debug "detect_missing_stack_name: \${error_message}=${error_message}"
44-
if [[ "${error_message}" != ${expected_error} ]]; then
45-
emergency "$function_name failed to detect '${expected_error}'"
46-
fi
47-
done
28+
detect_missing_stack_name() {
29+
: "${1?'detect_missing_name: Missing function name'}"
30+
31+
expected_error="Missing stack name"
32+
debug "detect_missing_stack_name: \${expected_error}=${expected_error}"
33+
34+
for function_name; do
35+
debug "detect_missing_stack_name: executing \"\$(${function_name} 2>&1 > /dev/null)\" || true"
36+
error_message="$(${function_name} 2>&1 >/dev/null)" || true
37+
error_message="${error_message##*: }" # grab text after final colon/space sequence
38+
debug "detect_missing_stack_name: \${error_message}=${error_message}"
39+
if [[ "${error_message}" != "${expected_error}" ]]; then
40+
emergency "${function_name} failed to detect '${expected_error}'"
41+
fi
42+
done
4843
}
4944

50-
detect_no_such_stack()
51-
{
52-
: "${1?'detect_no_such_name: Missing function name'}"
53-
54-
stack_name="__nonexistent_stack"
55-
expected_error="No such stack -- "
56-
debug "detect_no_such_stack: \${expected_error}=${expected_error}"
57-
58-
dummy_variable=""
59-
60-
for function_name
61-
do
62-
debug "detect_no_such_stack: executing \"\$($function_name $stack_name dummy_variable 2>&1 > /dev/null)\" || true"
63-
error_message="$($function_name $stack_name dummy_variable 2>&1 > /dev/null)" || true
64-
missing_stack="${error_message##${expected_error}}" # grab text after final colon/space sequence
65-
debug "detect_no_such_stack: \${missing_stack}=${missing_stack}"
66-
if [[ "${missing_stack}" != ${stack_name} ]]; then
67-
emergency "$function_name failed to detect missing '${stack_name}'"
68-
fi
69-
done
45+
detect_no_such_stack() {
46+
: "${1?'detect_no_such_name: Missing function name'}"
47+
48+
stack_name="__nonexistent_stack"
49+
expected_error="No such stack -- "
50+
debug "detect_no_such_stack: \${expected_error}=${expected_error}"
51+
52+
# shellcheck disable=SC2034
53+
dummy_variable=""
54+
55+
for function_name; do
56+
debug "detect_no_such_stack: executing \"\$(${function_name} ${stack_name} dummy_variable 2>&1 > /dev/null)\" || true"
57+
error_message="$(${function_name} ${stack_name} dummy_variable 2>&1 >/dev/null)" || true
58+
missing_stack="${error_message##${expected_error}}" # grab text after final colon/space sequence
59+
debug "detect_no_such_stack: \${missing_stack}=${missing_stack}"
60+
if [[ "${missing_stack}" != "${stack_name}" ]]; then
61+
emergency "${function_name} failed to detect missing '${stack_name}'"
62+
fi
63+
done
7064
}
7165

72-
detect_duplicate_stack_creation()
73-
{
74-
: "${1?'detect_duplicate_stack_creation: Missing function name'}"
75-
76-
stack_name="__dummy_stack"
77-
stack_new "${stack_name}"
78-
79-
expected_error="Stack already exists -- "
80-
debug "detect_duplicate_stack_creation: \${expected_error}=${expected_error}"
81-
function_name="stack_new"
82-
83-
debug "detect_duplicate_stack_creation: executing \"\$($function_name $stack_name 2>&1 > /dev/null)\" || true"
84-
error_message="$($function_name $stack_name dummy_variable 2>&1 > /dev/null)" || true
85-
duplicate_stack="${error_message##${expected_error}}" # grab text after final colon/space sequence
86-
debug "detect_no_such_stack: \${duplicate_stack}=${duplicate_stack}"
87-
if [[ "${duplicate_stack}" != ${stack_name} ]]; then
88-
emergency "$function_name failed to detect duplicate '${stack_name}'"
89-
fi
90-
stack_destroy ${stack_name}
66+
detect_duplicate_stack_creation() {
67+
: "${1?'detect_duplicate_stack_creation: Missing function name'}"
68+
69+
stack_name="__dummy_stack"
70+
stack_new "${stack_name}"
71+
72+
expected_error="Stack already exists -- "
73+
debug "detect_duplicate_stack_creation: \${expected_error}=${expected_error}"
74+
function_name="stack_new"
75+
76+
debug "detect_duplicate_stack_creation: executing \"\$(${function_name} ${stack_name} 2>&1 > /dev/null)\" || true"
77+
error_message="$(${function_name} ${stack_name} dummy_variable 2>&1 >/dev/null)" || true
78+
duplicate_stack="${error_message##${expected_error}}" # grab text after final colon/space sequence
79+
debug "detect_no_such_stack: \${duplicate_stack}=${duplicate_stack}"
80+
if [[ "${duplicate_stack}" != "${stack_name}" ]]; then
81+
emergency "${function_name} failed to detect duplicate '${stack_name}'"
82+
fi
83+
stack_destroy ${stack_name}
9184
}
9285

93-
verify_stack_size_changes()
94-
{
86+
verify_stack_size_changes() {
9587
stack_new foobar
9688
stack_size foobar __foobar_size
9789
expected_size=0
98-
if [[ "${__foobar_size}" != "${expected_size}" ]]; then
90+
# shellcheck disable=SC2154
91+
if [[ "${__foobar_size}" != "${expected_size}" ]]; then
9992
emergency "verify_stack_size_changes: size=${__foobar_size} (expected ${expected_size})"
10093
fi
10194

10295
stack_push foobar kernel
10396
stack_size foobar __foobar_new_size
104-
(( expected_size += 1 ))
105-
if [[ "${__foobar_new_size}" != "${expected_size}" ]]; then
97+
((expected_size += 1))
98+
# shellcheck disable=SC2154
99+
if [[ "${__foobar_new_size}" != "${expected_size}" ]]; then
106100
emergency "verify_stack_size_changes: size=${__foobar_new_size} (expected 1)"
107101
fi
108102

109103
stack_peek foobar tmp
110-
if [[ "${tmp}" != "kernel" ]]; then
104+
# shellcheck disable=SC2154
105+
if [[ "${tmp}" != "kernel" ]]; then
111106
emergency "verify_stack_size_changes: peeked item ('${tmp}') mismatch with pushed item ('kernel')"
112107
fi
113108

114109
stack_size foobar __should_be_unchanged
115-
if [[ "${__should_be_unchanged}" != "${expected_size}" ]]; then
110+
# shellcheck disable=SC2154
111+
if [[ "${__should_be_unchanged}" != "${expected_size}" ]]; then
116112
emergency "verify_stack_size_changes: size=${__should_be_unchanged} (expected ${expected_size})"
117113
fi
118114

119115
stack_pop foobar popped
120-
if [[ "${popped}" != "kernel" ]]; then
116+
# shellcheck disable=SC2154
117+
if [[ "${popped}" != "kernel" ]]; then
121118
emergency "verify_stack_size_changes: popped item ('${popped}') mismatch with pushed item ('kernel')"
122119
fi
123-
(( expected_size -= 1 )) || true
120+
((expected_size -= 1)) || true
124121

125122
stack_size foobar __final_size
126-
if [[ "${__final_size}" != "${expected_size}" ]]; then
123+
# shellcheck disable=SC2154
124+
if [[ "${__final_size}" != "${expected_size}" ]]; then
127125
emergency "verify_stack_size_changes: size=${__final_size} (expected ${expected_size})"
128126
fi
129127
}
130128

131-
test_stack()
132-
{
129+
test_stack() {
133130
# Verify availability of expected functions:
134131
functions_exist \
135132
stack_new stack_exists stack_print stack_push stack_peek stack_pop stack_size stack_destroy
136-
133+
137134
# Verify that each named function detects missing stack-name arguments:
138135
detect_missing_stack_name \
139136
stack_new stack_exists stack_print stack_push stack_peek stack_pop stack_size stack_destroy
@@ -148,7 +145,7 @@ test_stack()
148145

149146
# Verify that duplicate creation generates the expected error:
150147
detect_duplicate_stack_creation \
151-
stack_new
148+
stack_new
152149

153150
# Verify that push, peek, and pop yield correct size changes or lack thereof:
154151
verify_stack_size_changes

0 commit comments

Comments
 (0)