blob: 9322b5d817239bb6fcf255205d930f7a14823649 [file] [log] [blame]
Damien Martin-Guillerezd019eea2015-07-24 12:40:48 +00001#!/bin/bash
2
Damien Martin-Guillerezf88f4d82015-09-25 13:56:55 +00003# Copyright 2015 The Bazel Authors. All rights reserved.
Damien Martin-Guillerezd019eea2015-07-24 12:40:48 +00004#
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)
18set -eu
19
20SCRIPT_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
21source ${SCRIPT_DIR}/testenv.sh || { echo "testenv.sh not found!" >&2; exit 1; }
22
23### Setup a git repository
24setup_git_repository
25
26### Load the relnotes script
27source ${SCRIPT_DIR}/relnotes.sh || { echo "relnotes.sh not found!" >&2; exit 1; }
28
29### Tests method
30
31function set_up() {
32 cd ${MASTER_ROOT}
33}
34
35function 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 \
43than that but I need to type random text that spans multiple line so we \
44can 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 \
47some random stuff to test wrapping.")
48 assert_equals "${expected}" "$(format_release_notes "${input[@]}")"
49}
50
51function 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 \
55cc44636 06b09ce 29b05c8 67944d8 e8f6647 6d9fb36 f7c9922 5c0e4b2 9e387dd \
5698c9274 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
62TEST_INC_CHANGE='Incompatible changes:
63
64 - Remove deprecated "make var" INCDIR
65
66'
67TEST_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'
74TEST_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
81function test_release_notes() {
82 assert_equals "$TEST_INC_CHANGE$(echo)$TEST_NEW_CHANGE$(echo)$TEST_CHANGE" \
Damien Martin-Guillerez0052b802015-10-07 14:58:06 +000083 "$(release_notes 965c392ab1d68d5bc23fdef3d86d635ec9d2da8e)"
Damien Martin-Guillerezd019eea2015-07-24 12:40:48 +000084 assert_equals "$TEST_NEW_CHANGE$(echo)$TEST_CHANGE" \
Damien Martin-Guillerez0052b802015-10-07 14:58:06 +000085 "$(release_notes 965c392ab1d68d5bc23fdef3d86d635ec9d2da8e bb59d88)"
Damien Martin-Guillerezd019eea2015-07-24 12:40:48 +000086}
87
88function 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
95EOF
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
102Baseline: 965c392
103
104Initial release without cherry-picks
105
106EOF
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
115Baseline: 965c392
Kristina Chodorowe7be8392016-04-22 20:34:37 +0000116
117Cherry picks:
Damien Martin-Guillerezd019eea2015-07-24 12:40:48 +0000118 + bb59d88: RELNOTES[INC]: Remove deprecated "make var" INCDIR
119
120$TEST_INC_CHANGE
121EOF
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
131Baseline: 965c392
Kristina Chodorowe7be8392016-04-22 20:34:37 +0000132
133Cherry picks:
Damien Martin-Guillerezd019eea2015-07-24 12:40:48 +0000134 + 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
141EOF
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
149function test_create_release_notes() {
150 cat <<EOF >${TEST_TMPDIR}/CHANGELOG.md
151## New release
152
153Baseline: 965c392
154
155Initial release without cherry-picks
156
157EOF
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```
165Baseline: 965c392
Kristina Chodorowe7be8392016-04-22 20:34:37 +0000166
167Cherry picks:
Damien Martin-Guillerezd019eea2015-07-24 12:40:48 +0000168 + bb59d88: RELNOTES[INC]: Remove deprecated "make var" INCDIR
169```
170
171EOF
172 cat <<EOF >>${TEST_TMPDIR}/CHANGELOG.md
173$TEST_INC_CHANGE
174EOF
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```
184Baseline: 965c392
Kristina Chodorowe7be8392016-04-22 20:34:37 +0000185
186Cherry picks:
Damien Martin-Guillerezd019eea2015-07-24 12:40:48 +0000187 + 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
193EOF
194 cat <<EOF >>${TEST_TMPDIR}/CHANGELOG.md
195$TEST_INC_CHANGE
196$TEST_NEW_CHANGE
197EOF
198 assert_equals "$TEST_CHANGE" \
199 "$(create_release_notes ${TEST_TMPDIR}/CHANGELOG.md)"
200}
201
202function test_create_revision_information() {
203 expected='Baseline: 965c392
Kristina Chodorowe7be8392016-04-22 20:34:37 +0000204
205Cherry picks:
Damien Martin-Guillerezd019eea2015-07-24 12:40:48 +0000206 + 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-Guillerez0052b802015-10-07 14:58:06 +0000211 "$(create_revision_information 965c392ab1d68d5bc23fdef3d86d635ec9d2da8e bb59d88 14d905b5cce9a1bbc2911331809b03679b23dad1)"
Damien Martin-Guillerezd019eea2015-07-24 12:40:48 +0000212}
213
214run_suite "Release notes generation tests"