github.com/hanks177/podman/v4@v4.1.3-0.20220613032544-16d90015bc83/contrib/cirrus/pr-should-include-tests.t (about)

     1  #!/bin/bash
     2  #
     3  # tests for pr-should-include-tests.t
     4  #
     5  # FIXME: I don't think this will work in CI, because IIRC the git-checkout
     6  # is a shallow one. But it works fine in a developer tree.
     7  #
     8  ME=$(basename $0)
     9  
    10  ###############################################################################
    11  # BEGIN test cases
    12  #
    13  # Feel free to add as needed. Syntax is:
    14  #    <exit status>  <sha of commit>  <branch>=<sha of merge base>  # comments
    15  #
    16  # Where:
    17  #    exit status       is the expected exit status of the script
    18  #    sha of merge base is the SHA of the branch point of the commit
    19  #    sha of commit     is the SHA of a real commit in the podman repo
    20  #
    21  # We need the actual sha of the merge base because once a branch is
    22  # merged 'git merge-base' (used in our test script) becomes useless.
    23  #
    24  #
    25  # FIXME: as of 2021-01-07 we don't have "no tests needed" in our git
    26  #        commit history, but once we do, please add a new '0' test here.
    27  #
    28  tests="
    29  0  68c9e02df  db71759b1   PR 8821: multiple commits, includes tests
    30  0  bb82c37b7  eeb4c129b   PR 8832: single commit, w/tests, merge-base test
    31  1  1f5927699  864592c74   PR 8685, multiple commits, no tests
    32  0  7592f8fbb  6bbe54f2b   PR 8766, no tests, but CI:DOCS in commit message
    33  0  355e38769  bfbd915d6   PR 8884, a vendor bump
    34  0  ffe2b1e95  e467400eb   PR 8899, only .cirrus.yml
    35  0  06a6fd9f2  3cc080151   PR 8695, docs-only, without CI:DOCS
    36  0  a47515008  ecedda63a   PR 8816, unit tests only
    37  0  caa84cd35  e55320efd   PR 8565, hack/podman-socat only
    38  0  c342583da  12f835d12   PR 8523, version.go + podman.spec.in
    39  0  8f75ed958  7b3ad6d89   PR 8835, only a README.md change
    40  0  b6db60e58  f06dd45e0   PR 9420, a test rename
    41  0  c6a896b0c  4ea5d6971   PR 11833, includes magic string
    42  "
    43  
    44  # The script we're testing
    45  test_script=$(dirname $0)/$(basename $0 .t)
    46  
    47  # END   test cases
    48  ###############################################################################
    49  # BEGIN test-script runner and status checker
    50  
    51  function run_test_script() {
    52      local expected_rc=$1
    53      local testname=$2
    54  
    55      testnum=$(( testnum + 1 ))
    56  
    57      # DO NOT COMBINE 'local output=...' INTO ONE LINE. If you do, you lose $?
    58      local output
    59      output=$( $test_script )
    60      local actual_rc=$?
    61  
    62      if [[ $actual_rc != $expected_rc ]]; then
    63          echo "not ok $testnum $testname"
    64          echo "#  expected rc $expected_rc"
    65          echo "#  actual rc   $actual_rc"
    66          if [[ -n "$output" ]]; then
    67              echo "# script output: $output"
    68          fi
    69          rc=1
    70      else
    71          if [[ $expected_rc == 1 ]]; then
    72              # Confirm we get an error message
    73              if [[ ! "$output" =~ "Please write a regression test" ]]; then
    74                  echo "not ok $testnum $testname"
    75                  echo "# Expected: ~ 'Please write a regression test'"
    76                  echo "# Actual:   $output"
    77                  rc=1
    78              else
    79                  echo "ok $testnum $testname"
    80              fi
    81          else
    82              echo "ok $testnum $testname"
    83          fi
    84      fi
    85  
    86      # If we expect an error, confirm that we can override it. We only need
    87      # to do this once.
    88      if [[ $expected_rc == 1 ]]; then
    89          if [[ -z "$tested_override" ]]; then
    90              testnum=$(( testnum + 1 ))
    91  
    92              CIRRUS_CHANGE_TITLE="[CI:DOCS] hi there" $test_script &>/dev/null
    93              if [[ $? -ne 0 ]]; then
    94                  echo "not ok $testnum $rest (override with CI:DOCS)"
    95                  rc=1
    96              else
    97                  echo "ok $testnum $rest (override with CI:DOCS)"
    98              fi
    99  
   100              testnum=$(( testnum + 1 ))
   101              CIRRUS_CHANGE_MESSAGE="hi there [NO TESTS NEEDED] bye" $test_script &>/dev/null
   102              if [[ $? -ne 0 ]]; then
   103                  echo "not ok $testnum $rest (override with '[NO TESTS NEEDED]')"
   104                  rc=1
   105              else
   106                  echo "ok $testnum $rest (override with '[NO TESTS NEEDED]')"
   107              fi
   108  
   109              tested_override=1
   110          fi
   111      fi
   112  }
   113  
   114  # END   test-script runner and status checker
   115  ###############################################################################
   116  # BEGIN test-case parsing
   117  
   118  rc=0
   119  testnum=0
   120  tested_override=
   121  
   122  while read expected_rc parent_sha  commit_sha rest; do
   123      # Skip blank lines
   124      test -z "$expected_rc" && continue
   125  
   126      export DEST_BRANCH=$parent_sha
   127      export CIRRUS_CHANGE_IN_REPO=$commit_sha
   128      export CIRRUS_CHANGE_TITLE=$(git log -1 --format=%s $commit_sha)
   129      export CIRRUS_CHANGE_MESSAGE=
   130  
   131      run_test_script $expected_rc "$rest"
   132  done <<<"$tests"
   133  
   134  echo "1..$testnum"
   135  exit $rc
   136  
   137  # END   Test-case parsing
   138  ###############################################################################