diff options
| author | Egor Tensin <egor@tensin.name> | 2026-10-14 17:18:39 +0500 |
|---|---|---|
| committer | Egor Tensin <egor@tensin.name> | 2026-10-14 17:27:42 +0500 |
| commit | af2ea0bd8749a20e085f2d1c7483e1ed7829ba76 (patch) | |
| tree | 1bc722b61d53fb67d7ad74bdc2124b569f6bee9f /main.sh | |
| parent | add LICENSE.txt (diff) | |
| download | test-harness-af2ea0bd8749a20e085f2d1c7483e1ed7829ba76.tar.gz test-harness-af2ea0bd8749a20e085f2d1c7483e1ed7829ba76.zip | |
import main files from tag-release
I'm using an identical pattern in a number of projects now, so I'm
factoring this out into a separate repo.
Diffstat (limited to 'main.sh')
| -rwxr-xr-x | main.sh | 75 |
1 files changed, 75 insertions, 0 deletions
@@ -0,0 +1,75 @@ +#!/usr/bin/env bash + +# Copyright (c) 2026 Egor Tensin <egor@tensin.name> +# This file is part of the "test-harness" project. +# For details, see https://github.com/egor-tensin/test-harness +# Distributed under the MIT License. + +set -o errexit -o nounset -o pipefail +shopt -s inherit_errexit lastpipe + +script_dir="$( dirname -- "${BASH_SOURCE[0]}" )" +script_dir="$( cd -- "$script_dir" && pwd )" +readonly script_dir +script_name="$( basename -- "${BASH_SOURCE[0]}" )" +readonly script_name + +readonly tests_dir="$script_dir/.." + +source "$script_dir/lib/log.sh" + +run_test_file() { + local test_file + for test_file; do + source "$script_dir/lib/test.sh" + source "$tests_dir/$test_file" + + log_test_start "$test_file" + + set +e + ( + set -o errexit -o nounset -o pipefail + shopt -s inherit_errexit lastpipe + + trap test_cleanup_global EXIT + test_setup_global + test_run + ) + local ret="$?" + set -e + + log_test_finish "$test_file" "$ret" + done +} + +main() { + if [ "$#" -gt 1 ]; then + echo "usage: $script_name [PATTERN]" >&2 + return 1 + fi + + local -a test_files=() + local test_file + + local pattern='*' + [ "$#" -gt 0 ] && pattern="$1" + + find "$tests_dir" \ + -mindepth 1 \ + -maxdepth 1 \ + -type f \ + -regex '.*/tst-.*\.sh$' \ + -regextype posix-basic \ + -name "$pattern" \ + -printf '%P\0' \ + | sort -z \ + | \ + while IFS= read -d '' -r test_file; do + test_files+=("$test_file") + done + + run_test_file ${test_files[@]+"${test_files[@]}"} + log_tests_summary +} + +main "$@" |
