Alex Thiessen | 15aad88 | 2018-01-02 17:40:55 +0000 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
| 3 | ## |
| 4 | ## This file is part of the coreboot project. |
| 5 | ## |
| 6 | ## Copyright (C) 2003-2018 Alex Thiessen <alex.thiessen.de+coreboot@gmail.com> |
| 7 | ## |
| 8 | ## This program is free software; you can redistribute it and/or modify |
| 9 | ## it under the terms of the GNU General Public License as published by |
| 10 | ## the Free Software Foundation; version 3 or later of the License. |
| 11 | ## |
| 12 | ## This program is distributed in the hope that it will be useful, |
| 13 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | ## GNU General Public License for more details. |
| 16 | ## |
| 17 | ## SPDX-License-Identifier: GPL-3.0-or-later |
| 18 | ## <https://spdx.org/licenses/GPL-3.0-or-later.html> |
| 19 | ## |
| 20 | |
| 21 | set -o errexit |
| 22 | set -o nounset |
| 23 | |
| 24 | # static analysis |
| 25 | if command -v shellcheck 1>/dev/null; then |
| 26 | shellcheck --exclude=1090,1091 \ |
| 27 | "${BASH_SOURCE[0]}" \ |
| 28 | "$(dirname "${BASH_SOURCE[0]}")/helpers.sh" |
| 29 | else |
| 30 | echo "shellcheck not found, running unchecked" >&2 |
| 31 | fi |
| 32 | |
| 33 | # dependency check |
| 34 | dependencies=(dirname git make mktemp rm timeout) |
| 35 | for dependency in "${dependencies[@]}"; do |
| 36 | if ! command -v "${dependency}" 1>/dev/null; then |
| 37 | echo "missing ${dependency}, test skipped" >&2 |
| 38 | exit 0 |
| 39 | fi |
| 40 | done |
| 41 | |
| 42 | source "$(dirname "${BASH_SOURCE[0]}")/helpers.sh" |
| 43 | |
| 44 | # setup |
| 45 | base_dir="$(mktemp --directory --tmpdir \ |
| 46 | "test-$(basename "${BASH_SOURCE[0]}" .sh)-XXXXXXXX")" |
| 47 | clone_dir="${base_dir}/coreboot" |
| 48 | git clone "$(git rev-parse --show-toplevel)" "${clone_dir}" \ |
| 49 | 1>"${base_dir}/clone.log" 2>&1 |
| 50 | |
| 51 | ( |
| 52 | set -o errexit |
| 53 | set -o nounset |
| 54 | |
| 55 | clone_submodules "${clone_dir}" "${base_dir}" |
| 56 | |
| 57 | # mock |
| 58 | git config user.name "John Doe" |
| 59 | git config user.email "john.doe@example.com" |
| 60 | |
| 61 | # test |
| 62 | log_file="${base_dir}/gitconfig.log" |
| 63 | timeout 2s make gitconfig \ |
| 64 | 1>"${log_file}" 2>&1 \ |
| 65 | || check_exit_code positive "${log_file}" |
| 66 | ) |
| 67 | |
| 68 | # teardown |
| 69 | rm --force --recursive "${base_dir}" |