File: pr-should-include-tests.t

package info (click to toggle)
golang-github-containers-buildah 1.39.3%2Bds1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 7,724 kB
  • sloc: sh: 2,398; makefile: 236; perl: 187; asm: 16; awk: 12; ansic: 1
file content (131 lines) | stat: -rwxr-xr-x 4,158 bytes parent folder | download
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#!/bin/bash
#
# tests for pr-should-include-tests.t
#
# FIXME: I don't think this will work in CI, because IIRC the git-checkout
# is a shallow one. But it works fine in a developer tree.
#
ME=$(basename $0)

# As of 2024-02 our test script queries github, for which we need token
if [[ -z "$GITHUB_TOKEN" ]]; then
    echo "$ME: Please set \$GITHUB_TOKEN" >&2
    exit 1
fi
export CIRRUS_REPO_CLONE_TOKEN="$GITHUB_TOKEN"

###############################################################################
# BEGIN test cases
#
# Feel free to add as needed. Syntax is:
#    <exit status>  <sha of commit>  <branch>=<sha of merge base>  # comments
#
# Where:
#    exit status       is the expected exit status of the script
#    sha of merge base is the SHA of the branch point of the commit
#    sha of commit     is the SHA of a real commit in the podman repo
#
# We need the actual sha of the merge base because once a branch is
# merged 'git merge-base' (used in our test script) becomes useless.
#
#
# FIXME: as of 2021-01-07 we don't have "no tests needed" in our git
#        commit history, but once we do, please add a new '0' test here.
#
tests="
0  f466086d  88bc27df  2955  two commits, includes tests
1  f466086d  4026fa96  2973  single commit, no tests
0  d460e2ed  371e4ca6  2886  .cirrus.yml and contrib/cirrus/*
0  88bc27df  c5870ff8  2972  vendor only
0  d4c696af  faa86c4f  2470  CI:DOCS as well as only a .md change
0  d460e2ed  f52762a9  2927  .md only, without CI:DOCS
0  d80ec964  8a1bcd51  5366  no tests, allowed due to No New Tests label
"

# The script we're testing
test_script=$(dirname $0)/$(basename $0 .t)

# END   test cases
###############################################################################
# BEGIN test-script runner and status checker

function run_test_script() {
    local expected_rc=$1
    local testname=$2

    testnum=$(( testnum + 1 ))

    # DO NOT COMBINE 'local output=...' INTO ONE LINE. If you do, you lose $?
    local output
    output=$( $test_script )
    local actual_rc=$?

    if [[ $actual_rc != $expected_rc ]]; then
        echo "not ok $testnum $testname"
        echo "#  expected rc $expected_rc"
        echo "#  actual rc   $actual_rc"
        if [[ -n "$output" ]]; then
            echo "# script output: $output"
        fi
        rc=1
    else
        if [[ $expected_rc == 1 ]]; then
            # Confirm we get an error message
            if [[ ! "$output" =~ "Please write a regression test" ]]; then
                echo "not ok $testnum $testname"
                echo "# Expected: ~ 'Please write a regression test'"
                echo "# Actual:   $output"
                rc=1
            else
                echo "ok $testnum $testname - rc=$expected_rc"
            fi
        else
            echo "ok $testnum $testname - rc=$expected_rc"
        fi
    fi

    # If we expect an error, confirm that we can override it. We only need
    # to do this once.
    if [[ $expected_rc == 1 ]]; then
        if [[ -z "$tested_override" ]]; then
            testnum=$(( testnum + 1 ))

            CIRRUS_CHANGE_TITLE="[CI:DOCS] hi there" $test_script &>/dev/null
            if [[ $? -ne 0 ]]; then
                echo "not ok $testnum $testname (override with CI:DOCS)"
                rc=1
            else
                echo "ok $testnum $testname (override with CI:DOCS)"
            fi

            tested_override=1
        fi
    fi
}

# END   test-script runner and status checker
###############################################################################
# BEGIN test-case parsing

rc=0
testnum=0
tested_override=

while read expected_rc parent_sha  commit_sha pr rest; do
    # Skip blank lines
    test -z "$expected_rc" && continue

    export GITVALIDATE_EPOCH=$parent_sha
    export CIRRUS_CHANGE_IN_REPO=$commit_sha
    export CIRRUS_CHANGE_TITLE=$(git log -1 --format=%s $commit_sha)
    export CIRRUS_CHANGE_MESSAGE=
    export CIRRUS_PR=$pr

    run_test_script $expected_rc "PR $pr - $rest"
done <<<"$tests"

echo "1..$testnum"
exit $rc

# END   Test-case parsing
###############################################################################