Debian Codegraph @

util/gitconfig/test/helpers.sh

raw symbols SCIP
1 #!/usr/bin/envscip-shell filesystem . . `/usr/bin/env`. bash
2 ##
3 ## This program is free software; you can redistribute it and/or modify
4 ## it under the terms of the GNU General Public License as published by
5 ## the Free Software Foundation; version 3 or later of the License.
6 ##
7 ## This program is distributed in the hope that it will be useful,
8 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
9 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 ## GNU General Public License for more details.
11 ##
12 ## SPDX-License-Identifier: GPL-3.0-or-later
13 ## <https://spdx.org/licenses/GPL-3.0-or-later.html>
14 ##
15
16 set -o errexit
17 set -o nounset
18
19 # dependency check
20 dependencies=(cut git readlink)
21 for dependency in "${dependencies[@]}"; do
22 if ! command -v "${dependency}" 1>/dev/nullscip-shell filesystem . . `/dev/null`.; then
23 echoscip-shell system . . echo. "missing ${dependency}, test skipped" >&2
24 exit 0
25 fi
26 done
27
28 # helper functions
29 function clone_submodulesscip-shell shell coreboot 25.09+dfsg-1 clone_submodules().() {
30 clone_dir="${1}"
31 log_dir="${2}"
32
33 modules_dir="$(readlinkscip-shell system . . readlink. --canonicalize-missing \
34 "$(git rev-parse --git-dir)/modules")"
35 cd "${clone_dir}"
36 gitscip-shell system . . git. submodule init 1>>"${log_dir}/clone.log" 2>&1
37 for submodule in $(gitscip-shell system . . git. config --get-regexp "submodule\..*\.url" \
38 | cut --delimiter=. --fields=2); do
39 giscip-shell system . . git.tscip-shell system . . git. config "submodule.${submodule}.url" \
40 "${modules_dir}/${submodule}"
41 done
42 gitscip-shell system . . git. submodule update 1>>"${log_dir}/clone.log" 2>&1
43 }
44
45 function check_exit_codescip-shell shell coreboot 25.09+dfsg-1 check_exit_code().() {
46 declare -i err=${?}
47
48 # either "positive" or "negative"
49 polarity="${1}"
50 log_file="${2}"
51
52 # exit code 124 is special as per `timeout` manpage
53 if [scip-shell system . . `[`. "${polarity}" == "positive" ] && [scip-shell system . . `[`. ${err} -eq 124 ]; then
54 echoscip-shell system . . echo. >&2 "timed out"
55 fi
56
57 if [scip-shell system . . `[`. "${polarity}" == "positive" ] && [scip-shell system . . `[`. ${err} -ne 0 ]; then
58 echoscip-shell system . . echo. "bad exit code: expected 0, actually ${err}"
59 echoscip-shell system . . echo. "for details, refer to log file \"${log_file}\""
60 exit ${err}
61 elif [scip-shell system . . `[`. "${polarity}" == "negative" ] && [scip-shell system . . `[`. ${err} -eq 0 ]; then
62 echoscip-shell system . . echo. "bad exit code: expected non-zero, actually 0"
63 echoscip-shell system . . echo. "for details, refer to log file \"${log_file}\""
64 exit 1
65 fi
66 }