|
| 1 | +#!/usr/bin/env bash |
| 2 | +# Self-check for extract-release-notes.sh. Does not tag, push, or publish. |
| 3 | + |
| 4 | +set -euo pipefail |
| 5 | + |
| 6 | +dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" |
| 7 | +root="$(dirname "$dir")" |
| 8 | +extract="$dir/extract-release-notes.sh" |
| 9 | +fixture="$dir/testdata/changelog-extract.md" |
| 10 | +fail=0 |
| 11 | + |
| 12 | +assert_eq() { |
| 13 | + local name="$1" got="$2" want="$3" |
| 14 | + if [[ "$got" != "$want" ]]; then |
| 15 | + echo "FAIL: $name" >&2 |
| 16 | + printf 'got:\n%s\nwant:\n%s\n' "$got" "$want" >&2 |
| 17 | + fail=1 |
| 18 | + else |
| 19 | + echo "ok: $name" |
| 20 | + fi |
| 21 | +} |
| 22 | + |
| 23 | +assert_fails() { |
| 24 | + local name="$1" |
| 25 | + shift |
| 26 | + if "$@" >/dev/null 2>&1; then |
| 27 | + echo "FAIL: $name (expected non-zero exit)" >&2 |
| 28 | + fail=1 |
| 29 | + else |
| 30 | + echo "ok: $name" |
| 31 | + fi |
| 32 | +} |
| 33 | + |
| 34 | +got="$("$extract" 0.13.1 "$fixture")" |
| 35 | +want=$'FEATURES:\n\n* first line of 0.13.1\n\nENHANCEMENTS:\n\n* second line of 0.13.1' |
| 36 | +assert_eq "fixture 0.13.1 body" "$got" "$want" |
| 37 | + |
| 38 | +got="$("$extract" v0.13.0 "$fixture")" |
| 39 | +want=$'FEATURES:\n\n* only 0.13.0' |
| 40 | +assert_eq "fixture 0.13.0 strips v prefix" "$got" "$want" |
| 41 | + |
| 42 | +got="$("$extract" 0.13.10 "$fixture")" |
| 43 | +want=$'FEATURES:\n\n* should not leak into 0.13.1' |
| 44 | +assert_eq "fixture 0.13.10 matches its own heading, not 0.13.1" "$got" "$want" |
| 45 | + |
| 46 | +got="$("$extract" 0x13y1 "$fixture")" |
| 47 | +want=$'FEATURES:\n\n* must not match 0.13.1 via regex dots' |
| 48 | +assert_eq "fixture 0x13y1 is not 0.13.1 (dots are not regex)" "$got" "$want" |
| 49 | + |
| 50 | +assert_fails "missing version" "$extract" 9.9.9 "$fixture" |
| 51 | +assert_fails "empty section" "$extract" 0.0.1 "$fixture" |
| 52 | +assert_fails "usage: no args" "$extract" |
| 53 | +assert_fails "changelog missing" "$extract" 0.13.1 "$dir/testdata/does-not-exist.md" |
| 54 | + |
| 55 | +# Live CHANGELOG.md: same shape as GitHub notes for already-shipped versions. |
| 56 | +assert_live() { |
| 57 | + local version="$1" must_have="$2" must_not="$3" |
| 58 | + local got |
| 59 | + got="$("$extract" "$version" "$root/CHANGELOG.md")" |
| 60 | + if printf '%s\n' "$got" | grep -q '^# '; then |
| 61 | + echo "FAIL: live $version included a markdown heading" >&2 |
| 62 | + printf 'got:\n%s\n' "$got" >&2 |
| 63 | + fail=1 |
| 64 | + return |
| 65 | + fi |
| 66 | + if [[ "$got" != FEATURES:* && "$got" != ENHANCEMENTS:* && "$got" != "BUG FIXES:"* && "$got" != NOTES:* && "$got" != "BREAKING CHANGES:"* ]]; then |
| 67 | + echo "FAIL: live $version did not start at a changelog category" >&2 |
| 68 | + printf 'got:\n%s\n' "$got" >&2 |
| 69 | + fail=1 |
| 70 | + return |
| 71 | + fi |
| 72 | + if [[ "$got" != *"$must_have"* ]]; then |
| 73 | + echo "FAIL: live $version missing expected text: $must_have" >&2 |
| 74 | + printf 'got:\n%s\n' "$got" >&2 |
| 75 | + fail=1 |
| 76 | + return |
| 77 | + fi |
| 78 | + if [[ "$got" == *"$must_not"* ]]; then |
| 79 | + echo "FAIL: live $version leaked: $must_not" >&2 |
| 80 | + printf 'got:\n%s\n' "$got" >&2 |
| 81 | + fail=1 |
| 82 | + return |
| 83 | + fi |
| 84 | + echo "ok: live CHANGELOG $version" |
| 85 | +} |
| 86 | + |
| 87 | +assert_live 0.13.0 "encryption_key_path" "linked" |
| 88 | +assert_live 0.13.1 "linked" "encryption_key_path" |
| 89 | + |
| 90 | +if [[ "$fail" -ne 0 ]]; then |
| 91 | + exit 1 |
| 92 | +fi |
| 93 | +echo "extract-release-notes_test.sh: all ok" |
0 commit comments