Damien Martin-Guillerez | d019eea | 2015-07-24 12:40:48 +0000 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
Damien Martin-Guillerez | f88f4d8 | 2015-09-25 13:56:55 +0000 | [diff] [blame] | 3 | # Copyright 2015 The Bazel Authors. All rights reserved. |
Damien Martin-Guillerez | d019eea | 2015-07-24 12:40:48 +0000 | [diff] [blame] | 4 | # |
| 5 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | # you may not use this file except in compliance with the License. |
| 7 | # You may obtain a copy of the License at |
| 8 | # |
| 9 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | # |
| 11 | # Unless required by applicable law or agreed to in writing, software |
| 12 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | # See the License for the specific language governing permissions and |
| 15 | # limitations under the License. |
| 16 | |
| 17 | # Tests release notes generation (relnotes.sh) |
| 18 | set -eu |
| 19 | |
| 20 | SCRIPT_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) |
| 21 | source ${SCRIPT_DIR}/testenv.sh || { echo "testenv.sh not found!" >&2; exit 1; } |
| 22 | |
| 23 | ### Setup a git repository |
| 24 | setup_git_repository |
| 25 | |
| 26 | ### Load the relnotes script |
| 27 | source ${SCRIPT_DIR}/relnotes.sh || { echo "relnotes.sh not found!" >&2; exit 1; } |
| 28 | |
| 29 | ### Tests method |
| 30 | |
| 31 | function set_up() { |
| 32 | cd ${MASTER_ROOT} |
| 33 | } |
| 34 | |
| 35 | function test_format_release_notes() { |
| 36 | local expected=' - Lorem ipsus I do not know more of latin than that but I need to |
| 37 | type random text that spans multiple line so we can test that the |
| 38 | wrapping of lines works as intended. |
| 39 | - Another thing I must type. |
| 40 | - Yet another test that spans across multiple lines so I must type |
| 41 | some random stuff to test wrapping.' |
| 42 | local input=("Lorem ipsus I do not know more of latin \ |
| 43 | than that but I need to type random text that spans multiple line so we \ |
| 44 | can test that the wrapping of lines works as intended." |
| 45 | "Another thing I must type." |
| 46 | "Yet another test that spans across multiple lines so I must type \ |
| 47 | some random stuff to test wrapping.") |
| 48 | assert_equals "${expected}" "$(format_release_notes "${input[@]}")" |
| 49 | } |
| 50 | |
| 51 | function test_get_release_notes_commits() { |
| 52 | # Generated with git log --grep RELNOTES. |
| 53 | # Only 6d98f6c 53c0748 are removed (rollback). |
| 54 | commits="0188971 957934c 7a99c7f b5ba24a c9041bf 8232d9b 422c731 e9029d4 \ |
| 55 | cc44636 06b09ce 29b05c8 67944d8 e8f6647 6d9fb36 f7c9922 5c0e4b2 9e387dd \ |
| 56 | 98c9274 db4d861 a689f29 db487ce 965c392 bb59d88 d3461db cef25c4 14d905b" |
| 57 | assert_equals "$commits" "$(get_release_notes_commits 00d7223 | xargs)" |
| 58 | assert_equals "$(echo "$commits" | sed 's/957934c //')" \ |
| 59 | "$(get_release_notes_commits 00d7223 957934c | xargs)" |
| 60 | } |
| 61 | |
| 62 | TEST_INC_CHANGE='Incompatible changes: |
| 63 | |
| 64 | - Remove deprecated "make var" INCDIR |
| 65 | |
| 66 | ' |
| 67 | TEST_NEW_CHANGE='New features: |
| 68 | |
| 69 | - added --with_aspect_deps to blaze query, that prints additional |
| 70 | information about aspects of target when --output is set to {xml, |
| 71 | proto, record}. |
| 72 | |
| 73 | ' |
| 74 | TEST_CHANGE='Important changes: |
| 75 | |
| 76 | - Use a default implementation of a progress message, rather than |
| 77 | defaulting to null for all SpawnActions. |
| 78 | - Attribute error messages related to Android resources are easier |
| 79 | to understand now.' |
| 80 | |
| 81 | function test_release_notes() { |
| 82 | assert_equals "$TEST_INC_CHANGE$(echo)$TEST_NEW_CHANGE$(echo)$TEST_CHANGE" \ |
Damien Martin-Guillerez | 0052b80 | 2015-10-07 14:58:06 +0000 | [diff] [blame] | 83 | "$(release_notes 965c392ab1d68d5bc23fdef3d86d635ec9d2da8e)" |
Damien Martin-Guillerez | d019eea | 2015-07-24 12:40:48 +0000 | [diff] [blame] | 84 | assert_equals "$TEST_NEW_CHANGE$(echo)$TEST_CHANGE" \ |
Damien Martin-Guillerez | 0052b80 | 2015-10-07 14:58:06 +0000 | [diff] [blame] | 85 | "$(release_notes 965c392ab1d68d5bc23fdef3d86d635ec9d2da8e bb59d88)" |
Damien Martin-Guillerez | d019eea | 2015-07-24 12:40:48 +0000 | [diff] [blame] | 86 | } |
| 87 | |
| 88 | function test_get_last_release() { |
| 89 | rm -f ${TEST_TMPDIR}/CHANGELOG.md |
| 90 | if (get_last_release "${TEST_TMPDIR}/CHANGELOG.md"); then |
| 91 | fail "Should have returned false for initial release" |
| 92 | fi |
| 93 | cat <<EOF >${TEST_TMPDIR}/CHANGELOG.md |
| 94 | ## No release |
| 95 | EOF |
| 96 | if (get_last_release "${TEST_TMPDIR}/CHANGELOG.md"); then |
| 97 | fail "Should have returned false when no release exists" |
| 98 | fi |
| 99 | cat <<EOF >${TEST_TMPDIR}/CHANGELOG.md |
| 100 | ## New release |
| 101 | |
| 102 | Baseline: 965c392 |
| 103 | |
| 104 | Initial release without cherry-picks |
| 105 | |
| 106 | EOF |
| 107 | assert_equals "965c392" \ |
| 108 | "$(get_last_release "${TEST_TMPDIR}/CHANGELOG.md")" |
| 109 | |
| 110 | |
| 111 | mv ${TEST_TMPDIR}/CHANGELOG.md ${TEST_TMPDIR}/CHANGELOG.md.bak |
| 112 | cat <<EOF >${TEST_TMPDIR}/CHANGELOG.md |
| 113 | ## Cherry-picking bb59d88 |
| 114 | |
| 115 | Baseline: 965c392 |
Kristina Chodorow | e7be839 | 2016-04-22 20:34:37 +0000 | [diff] [blame] | 116 | |
| 117 | Cherry picks: |
Damien Martin-Guillerez | d019eea | 2015-07-24 12:40:48 +0000 | [diff] [blame] | 118 | + bb59d88: RELNOTES[INC]: Remove deprecated "make var" INCDIR |
| 119 | |
| 120 | $TEST_INC_CHANGE |
| 121 | EOF |
| 122 | cat ${TEST_TMPDIR}/CHANGELOG.md.bak >>${TEST_TMPDIR}/CHANGELOG.md |
| 123 | rm ${TEST_TMPDIR}/CHANGELOG.md.bak |
| 124 | assert_equals "965c392 bb59d88" \ |
| 125 | "$(get_last_release "${TEST_TMPDIR}/CHANGELOG.md")" |
| 126 | |
| 127 | mv ${TEST_TMPDIR}/CHANGELOG.md ${TEST_TMPDIR}/CHANGELOG.md.bak |
| 128 | cat <<EOF >${TEST_TMPDIR}/CHANGELOG.md |
| 129 | ## Cherry-picking bb59d88 and 14d905b |
| 130 | |
| 131 | Baseline: 965c392 |
Kristina Chodorow | e7be839 | 2016-04-22 20:34:37 +0000 | [diff] [blame] | 132 | |
| 133 | Cherry picks: |
Damien Martin-Guillerez | d019eea | 2015-07-24 12:40:48 +0000 | [diff] [blame] | 134 | + bb59d88: RELNOTES[INC]: Remove deprecated "make var" INCDIR |
| 135 | + 14d905b: Add --with_aspect_deps flag to blaze query. This flag |
| 136 | should produce additional information about aspect |
| 137 | dependencies when --output is set to {xml, proto}. |
| 138 | |
| 139 | $TEST_INC_CHANGE |
| 140 | $TEST_NEW_CHANGE |
| 141 | EOF |
| 142 | cat ${TEST_TMPDIR}/CHANGELOG.md.bak >>${TEST_TMPDIR}/CHANGELOG.md |
| 143 | rm ${TEST_TMPDIR}/CHANGELOG.md.bak |
| 144 | assert_equals "965c392 bb59d88 14d905b" \ |
| 145 | "$(get_last_release "${TEST_TMPDIR}/CHANGELOG.md")" |
| 146 | |
| 147 | } |
| 148 | |
| 149 | function test_create_release_notes() { |
| 150 | cat <<EOF >${TEST_TMPDIR}/CHANGELOG.md |
| 151 | ## New release |
| 152 | |
| 153 | Baseline: 965c392 |
| 154 | |
| 155 | Initial release without cherry-picks |
| 156 | |
| 157 | EOF |
| 158 | assert_equals "$TEST_INC_CHANGE$(echo)$TEST_NEW_CHANGE$(echo)$TEST_CHANGE" \ |
| 159 | "$(create_release_notes ${TEST_TMPDIR}/CHANGELOG.md)" |
| 160 | |
| 161 | cat <<'EOF' >${TEST_TMPDIR}/CHANGELOG.md |
| 162 | ## Cherry-picking bb59d88 |
| 163 | |
| 164 | ``` |
| 165 | Baseline: 965c392 |
Kristina Chodorow | e7be839 | 2016-04-22 20:34:37 +0000 | [diff] [blame] | 166 | |
| 167 | Cherry picks: |
Damien Martin-Guillerez | d019eea | 2015-07-24 12:40:48 +0000 | [diff] [blame] | 168 | + bb59d88: RELNOTES[INC]: Remove deprecated "make var" INCDIR |
| 169 | ``` |
| 170 | |
| 171 | EOF |
| 172 | cat <<EOF >>${TEST_TMPDIR}/CHANGELOG.md |
| 173 | $TEST_INC_CHANGE |
| 174 | EOF |
| 175 | assert_equals "$TEST_NEW_CHANGE$(echo)$TEST_CHANGE" \ |
| 176 | "$(create_release_notes ${TEST_TMPDIR}/CHANGELOG.md)" |
| 177 | assert_equals "965c392 bb59d88" \ |
| 178 | "$(get_last_release "${TEST_TMPDIR}/CHANGELOG.md")" |
| 179 | |
| 180 | cat <<'EOF' >${TEST_TMPDIR}/CHANGELOG.md |
| 181 | ## Cherry-picking bb59d88 and 14d905b |
| 182 | |
| 183 | ``` |
| 184 | Baseline: 965c392 |
Kristina Chodorow | e7be839 | 2016-04-22 20:34:37 +0000 | [diff] [blame] | 185 | |
| 186 | Cherry picks: |
Damien Martin-Guillerez | d019eea | 2015-07-24 12:40:48 +0000 | [diff] [blame] | 187 | + bb59d88: RELNOTES[INC]: Remove deprecated "make var" INCDIR |
| 188 | + 14d905b: Add --with_aspect_deps flag to blaze query. This flag |
| 189 | should produce additional information about aspect |
| 190 | dependencies when --output is set to {xml, proto}. |
| 191 | ``` |
| 192 | |
| 193 | EOF |
| 194 | cat <<EOF >>${TEST_TMPDIR}/CHANGELOG.md |
| 195 | $TEST_INC_CHANGE |
| 196 | $TEST_NEW_CHANGE |
| 197 | EOF |
| 198 | assert_equals "$TEST_CHANGE" \ |
| 199 | "$(create_release_notes ${TEST_TMPDIR}/CHANGELOG.md)" |
| 200 | } |
| 201 | |
| 202 | function test_create_revision_information() { |
| 203 | expected='Baseline: 965c392 |
Kristina Chodorow | e7be839 | 2016-04-22 20:34:37 +0000 | [diff] [blame] | 204 | |
| 205 | Cherry picks: |
Damien Martin-Guillerez | d019eea | 2015-07-24 12:40:48 +0000 | [diff] [blame] | 206 | + bb59d88: RELNOTES[INC]: Remove deprecated "make var" INCDIR |
| 207 | + 14d905b: Add --with_aspect_deps flag to blaze query. This flag |
| 208 | should produce additional information about aspect |
| 209 | dependencies when --output is set to {xml, proto}.' |
| 210 | assert_equals "$expected" \ |
Damien Martin-Guillerez | 0052b80 | 2015-10-07 14:58:06 +0000 | [diff] [blame] | 211 | "$(create_revision_information 965c392ab1d68d5bc23fdef3d86d635ec9d2da8e bb59d88 14d905b5cce9a1bbc2911331809b03679b23dad1)" |
Damien Martin-Guillerez | d019eea | 2015-07-24 12:40:48 +0000 | [diff] [blame] | 212 | } |
| 213 | |
| 214 | run_suite "Release notes generation tests" |