|
136 | 136 | ## Copyright (C) 2025 - 2025 ENCRYPTED SUPPORT LLC <adrelanos@whonix.org> |
137 | 137 | ## See the file COPYING for copying conditions. |
138 | 138 |
|
139 | | -## Code duplication. Copied from |
140 | | -## helper-scripts/usr/libexec/helper-scripts/check_runtime.bsh. |
141 | | -## |
142 | | -## Because check_runtime.bsh cannot be sourced here (this will be run when |
| 139 | +## check_runtime.bsh cannot be sourced here (this will be run when |
143 | 140 | ## derivative-maker is used, and the build host may not have helper-scripts |
144 | 141 | ## installed). |
145 | | -was_executed() { |
146 | | - local caller_bash_source_zero="${1}" |
147 | | - if [[ "${caller_bash_source_zero}" == "${0}" ]] \ |
148 | | - || [[ "${caller_bash_source_zero}" == "$(command -v "${0}")" ]]; then |
149 | | - return 0 |
150 | | - fi |
151 | | - return 1 |
152 | | -} |
153 | | -should_run_unit_tests() { |
154 | | - local caller_bash_source_zero="${1}" |
155 | | - if was_executed "${caller_bash_source_zero}" \ |
156 | | - && ! [ "${SKIP_UNIT_TESTS-}" = 'true' ]; then |
157 | | - return 0 |
158 | | - fi |
159 | | - return 1 |
160 | | -} |
| 142 | +## Literal code duplication is bad. |
| 143 | +## Confuses shellcheck for dist-installer-cli-standalone. |
| 144 | +if test -f /usr/libexec/helper-scripts/check_runtime.bsh; then |
| 145 | + ## Use 'source_encoded' to avoid |
| 146 | + ## /usr/share/usability-misc/build-dist-installer-cli |
| 147 | + ## from in-lining the source code. |
| 148 | + source_encoded=source |
| 149 | + "$source_encoded" /usr/libexec/helper-scripts/check_runtime.bsh |
| 150 | +fi |
161 | 151 |
|
162 | 152 | br_add() { |
163 | 153 | local in out |
@@ -541,8 +531,11 @@ strings_bsh_error_trap() { |
541 | 531 |
|
542 | 532 | ## Useful in case this script is copied verbatim into another script such as |
543 | 533 | ## in package 'usability-misc' file 'dist-installer-cli-standalone'. |
544 | | -if should_run_unit_tests "${BASH_SOURCE[0]}"; then |
545 | | - string_bsh_tests |
| 534 | +## Another option would be to move the unit testing out of this script. |
| 535 | +if declare -F should_run_unit_tests >/dev/null; then |
| 536 | + if should_run_unit_tests "${BASH_SOURCE[0]}"; then |
| 537 | + string_bsh_tests |
| 538 | + fi |
546 | 539 | fi |
547 | 540 |
|
548 | 541 | #trim_collapse_split " aaa bbb ccc ddd " |
|
0 commit comments