|
6 | 6 | # with one or more Puppet versions, with PUPPET_VERSIONS set to a space-separated list |
7 | 7 | # of versions to test. |
8 | 8 |
|
9 | | -[ -z "$PUPPET_VERSIONS" ] && export PUPPET_VERSIONS='3.8.7 4.10.8 5.0.0' |
| 9 | +if [ -z "$PUPPET_VERSIONS" ]; then |
| 10 | + echo "Required PUPPET_VERSIONS!" |
| 11 | + exit 255 |
| 12 | +fi |
| 13 | + |
10 | 14 | [ -z "$RUBOCOP_TEST" ] && export RUBOCOP_TEST='true' |
11 | 15 | [ -z "$RSPEC_TEST" ] && export RSPEC_TEST='true' |
12 | 16 |
|
|
19 | 23 | echo "travis_fold:end:cibuild-environment-dump" |
20 | 24 |
|
21 | 25 | # Create a temporary file to capture output of various steps. |
22 | | -export OUTPUT_FILE="$(mktemp)" |
23 | 26 | function cleanup() { |
24 | | - rm -rf "$OUTPUT_FILE" |
25 | 27 | rm -f "${DIR}/.ruby-version" |
26 | 28 | } |
27 | 29 | trap cleanup EXIT |
|
67 | 69 | if [ "$RSPEC_TEST" = "true" ]; then |
68 | 70 | SAVED_PATH="$PATH" |
69 | 71 | RSPEC_EXITCODE="0" |
| 72 | + COVERAGE_EXITCODE="0" |
70 | 73 | for pv in $PUPPET_VERSIONS ; do |
71 | 74 | export PUPPET_VERSION="$pv" |
72 | 75 |
|
@@ -95,23 +98,63 @@ if [ "$RSPEC_TEST" = "true" ]; then |
95 | 98 | fi |
96 | 99 |
|
97 | 100 | # Run the tests |
98 | | - echo "Running tests" |
99 | | - time bundle exec rake test |
| 101 | + echo "Running rspec unit tests" |
| 102 | + export COVERAGE=true |
| 103 | + time bundle exec rspec "${DIR}/spec/octocatalog-diff/tests" |
100 | 104 | exitcode=$? |
| 105 | + unset COVERAGE |
101 | 106 | if [ "$exitcode" -ne 0 ]; then RSPEC_EXITCODE="$exitcode"; fi |
102 | | - cat "$OUTPUT_FILE" |
| 107 | + |
| 108 | + # Quick coverage report |
| 109 | + cat "$DIR/coverage/coverage.txt" |
| 110 | + if grep -q "100% test coverage. You're all set, friend" "$DIR/coverage/coverage.txt"; then |
| 111 | + : |
| 112 | + else |
| 113 | + COVERAGE_EXITCODE=1 |
| 114 | + fi |
103 | 115 | echo "" |
| 116 | + |
| 117 | + # To avoid travis getting hung if it gets confused, we'll run each of these |
| 118 | + # scripts individually with a timeout. This will hopefully address the problem |
| 119 | + # of hung builds. |
| 120 | + echo "Running rspec integration tests" |
| 121 | + for file in "${DIR}"/spec/octocatalog-diff/integration/*_spec.rb; do |
| 122 | + retry=1 |
| 123 | + for try in 1 2 3 ; do |
| 124 | + if [ $retry -eq 1 ]; then |
| 125 | + retry=0 |
| 126 | + echo "$(basename "$file") try ${try}" |
| 127 | + "$DIR/script/timeout" 180 bundle exec rspec "$file" |
| 128 | + exitcode=$? |
| 129 | + if [ $exitcode -eq 124 ] && [ $try -eq 3 ]; then |
| 130 | + RSPEC_EXITCODE="255" |
| 131 | + elif [ $exitcode -eq 124 ] && [ $try -lt 3 ]; then |
| 132 | + retry=1 |
| 133 | + elif [ $exitcode -ne 0 ]; then |
| 134 | + RSPEC_EXITCODE="$exitcode" |
| 135 | + fi |
| 136 | + fi |
| 137 | + done |
| 138 | + done |
104 | 139 | done |
105 | 140 | export PATH="$SAVED_PATH" |
106 | 141 | unset PUPPET_VERSION |
107 | 142 | rm -f "${DIR}/.puppet_version" |
108 | 143 | else |
109 | 144 | RSPEC_EXITCODE=-1 |
| 145 | + COVERAGE_EXITCODE=-1 |
110 | 146 | echo "" |
111 | 147 | fi |
112 | 148 |
|
113 | 149 | # Finish off script |
114 | 150 | echo "Finished script/cibuild:" |
115 | | -[ "$RUBOCOP_EXITCODE" -ge 0 ] && echo " - rubocop: exit ${RUBOCOP_EXITCODE}" |
116 | | -[ "$RSPEC_EXITCODE" -ge 0 ] && echo " - rspec: exit ${RSPEC_EXITCODE}" |
117 | | -if [ "$RUBOCOP_EXITCODE" -gt 0 ] || [ "$RSPEC_EXITCODE" -gt 0 ]; then exit 1; else exit 0; fi |
| 151 | +[ "$RUBOCOP_EXITCODE" -ge 0 ] && echo " - rubocop: exit ${RUBOCOP_EXITCODE}" |
| 152 | +[ "$RSPEC_EXITCODE" -ge 0 ] && echo " - rspec: exit ${RSPEC_EXITCODE}" |
| 153 | +[ "$COVERAGE_EXITCODE" -ge 0 ] && echo " - coverage: exit ${COVERAGE_EXITCODE}" |
| 154 | +if [ "$RUBOCOP_EXITCODE" -gt 0 ] || [ "$RSPEC_EXITCODE" -gt 0 ]; then |
| 155 | + exit 1 |
| 156 | +fi |
| 157 | +if [ "$COVERAGE_EXITCODE" -gt 0 ] && [ "$ENFORCE_COVERAGE" == "true" ]; then |
| 158 | + exit 1 |
| 159 | +fi |
| 160 | +exit 0 |
0 commit comments