blob: 92538ffc593fdc7075d67951909a7fd1f4937447 [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
116 + bb59d88: RELNOTES[INC]: Remove deprecated "make var" INCDIR
117
118$TEST_INC_CHANGE
119EOF
120 cat ${TEST_TMPDIR}/CHANGELOG.md.bak >>${TEST_TMPDIR}/CHANGELOG.md
121 rm ${TEST_TMPDIR}/CHANGELOG.md.bak
122 assert_equals "965c392 bb59d88" \
123 "$(get_last_release "${TEST_TMPDIR}/CHANGELOG.md")"
124
125 mv ${TEST_TMPDIR}/CHANGELOG.md ${TEST_TMPDIR}/CHANGELOG.md.bak
126 cat <<EOF >${TEST_TMPDIR}/CHANGELOG.md
127## Cherry-picking bb59d88 and 14d905b
128
129Baseline: 965c392
130 + bb59d88: RELNOTES[INC]: Remove deprecated "make var" INCDIR
131 + 14d905b: Add --with_aspect_deps flag to blaze query. This flag
132 should produce additional information about aspect
133 dependencies when --output is set to {xml, proto}.
134
135$TEST_INC_CHANGE
136$TEST_NEW_CHANGE
137EOF
138 cat ${TEST_TMPDIR}/CHANGELOG.md.bak >>${TEST_TMPDIR}/CHANGELOG.md
139 rm ${TEST_TMPDIR}/CHANGELOG.md.bak
140 assert_equals "965c392 bb59d88 14d905b" \
141 "$(get_last_release "${TEST_TMPDIR}/CHANGELOG.md")"
142
143}
144
145function test_create_release_notes() {
146 cat <<EOF >${TEST_TMPDIR}/CHANGELOG.md
147## New release
148
149Baseline: 965c392
150
151Initial release without cherry-picks
152
153EOF
154 assert_equals "$TEST_INC_CHANGE$(echo)$TEST_NEW_CHANGE$(echo)$TEST_CHANGE" \
155 "$(create_release_notes ${TEST_TMPDIR}/CHANGELOG.md)"
156
157 cat <<'EOF' >${TEST_TMPDIR}/CHANGELOG.md
158## Cherry-picking bb59d88
159
160```
161Baseline: 965c392
162 + bb59d88: RELNOTES[INC]: Remove deprecated "make var" INCDIR
163```
164
165EOF
166 cat <<EOF >>${TEST_TMPDIR}/CHANGELOG.md
167$TEST_INC_CHANGE
168EOF
169 assert_equals "$TEST_NEW_CHANGE$(echo)$TEST_CHANGE" \
170 "$(create_release_notes ${TEST_TMPDIR}/CHANGELOG.md)"
171 assert_equals "965c392 bb59d88" \
172 "$(get_last_release "${TEST_TMPDIR}/CHANGELOG.md")"
173
174 cat <<'EOF' >${TEST_TMPDIR}/CHANGELOG.md
175## Cherry-picking bb59d88 and 14d905b
176
177```
178Baseline: 965c392
179 + bb59d88: RELNOTES[INC]: Remove deprecated "make var" INCDIR
180 + 14d905b: Add --with_aspect_deps flag to blaze query. This flag
181 should produce additional information about aspect
182 dependencies when --output is set to {xml, proto}.
183```
184
185EOF
186 cat <<EOF >>${TEST_TMPDIR}/CHANGELOG.md
187$TEST_INC_CHANGE
188$TEST_NEW_CHANGE
189EOF
190 assert_equals "$TEST_CHANGE" \
191 "$(create_release_notes ${TEST_TMPDIR}/CHANGELOG.md)"
192}
193
194function test_create_revision_information() {
195 expected='Baseline: 965c392
196 + bb59d88: RELNOTES[INC]: Remove deprecated "make var" INCDIR
197 + 14d905b: Add --with_aspect_deps flag to blaze query. This flag
198 should produce additional information about aspect
199 dependencies when --output is set to {xml, proto}.'
200 assert_equals "$expected" \
Damien Martin-Guillerez0052b802015-10-07 14:58:06 +0000201 "$(create_revision_information 965c392ab1d68d5bc23fdef3d86d635ec9d2da8e bb59d88 14d905b5cce9a1bbc2911331809b03679b23dad1)"
Damien Martin-Guillerezd019eea2015-07-24 12:40:48 +0000202}
203
204run_suite "Release notes generation tests"