summaryrefslogtreecommitdiffstatshomepage
path: root/test/local/main.sh
blob: 5713366febebe0af8447804940217167ad1b3efb (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/usr/bin/env bash

# Copyright (c) 2026 Egor Tensin <egor@tensin.name>
# This file is part of the "config-links" project.
# For details, see https://github.com/egor-tensin/config-links
# Distributed under the MIT License.

set -o errexit -o nounset -o pipefail
shopt -s inherit_errexit 2> /dev/null || true
shopt -s lastpipe

script_dir="$( dirname -- "${BASH_SOURCE[0]}" )"
script_dir="$( cd -- "$script_dir" && pwd )"
readonly 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 "$script_dir/$test_file"

        log_test_start "$test_file"

        set +e
        (
            set -o errexit -o nounset -o pipefail
            shopt -s inherit_errexit 2> /dev/null || true
            shopt -s lastpipe

            if [ "$( type -t test_cleanup )" == function ]; then
                trap test_cleanup EXIT
            else
                trap test_cleanup_default EXIT
            fi

            test_run
        )
        local ret="$?"
        set -e

        log_test_finish "$test_file" "$ret"
    done
}

main() {
    local -a test_files=()
    local test_file

    find "$script_dir" \
        -mindepth 1 \
        -maxdepth 1 \
        -type f \
        -regex '.*/tst-.*\.sh$' \
        -regextype posix-basic \
        -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