aboutsummaryrefslogtreecommitdiffhomepage
path: root/scripts/release/relnotes_test.sh
blob: 419ed109a65ecfed167f215e9b632556d1c079bd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
#!/bin/bash

# Copyright 2015 Google Inc. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Tests release notes generation (relnotes.sh)
set -eu

SCRIPT_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
source ${SCRIPT_DIR}/testenv.sh || { echo "testenv.sh not found!" >&2; exit 1; }

### Setup a git repository
setup_git_repository

### Load the relnotes script
source ${SCRIPT_DIR}/relnotes.sh || { echo "relnotes.sh not found!" >&2; exit 1; }

### Tests method

function set_up() {
  cd ${MASTER_ROOT}
}

function test_format_release_notes() {
  local expected='  - Lorem ipsus I do not know more of latin than that but I need to
    type random text that spans multiple line so we can test that the
    wrapping of lines works as intended.
  - Another thing I must type.
  - Yet another test that spans across multiple lines so I must type
    some random stuff to test wrapping.'
  local input=("Lorem ipsus I do not know more of latin \
than that but I need to type random text that spans multiple line so we \
can test that the wrapping of lines works as intended."
"Another thing I must type."
"Yet another test that spans across multiple lines so I must type \
some random stuff to test wrapping.")
  assert_equals "${expected}" "$(format_release_notes "${input[@]}")"
}

function test_get_release_notes_commits() {
  # Generated with git log --grep RELNOTES.
  # Only 6d98f6c 53c0748 are removed (rollback).
  commits="0188971 957934c 7a99c7f b5ba24a c9041bf 8232d9b 422c731 e9029d4 \
cc44636 06b09ce 29b05c8 67944d8 e8f6647 6d9fb36 f7c9922 5c0e4b2 9e387dd \
98c9274 db4d861 a689f29 db487ce 965c392 bb59d88 d3461db cef25c4 14d905b"
  assert_equals "$commits" "$(get_release_notes_commits 00d7223 | xargs)"
  assert_equals "$(echo "$commits" | sed 's/957934c //')" \
      "$(get_release_notes_commits 00d7223 957934c | xargs)"
}

TEST_INC_CHANGE='Incompatible changes:

  - Remove deprecated "make var" INCDIR

'
TEST_NEW_CHANGE='New features:

  - added --with_aspect_deps to blaze query, that prints additional
    information about aspects of target when --output is set to {xml,
    proto, record}.

'
TEST_CHANGE='Important changes:

  - Use a default implementation of a progress message, rather than
    defaulting to null for all SpawnActions.
  - Attribute error messages related to Android resources are easier
    to understand now.'

function test_release_notes() {
  assert_equals "$TEST_INC_CHANGE$(echo)$TEST_NEW_CHANGE$(echo)$TEST_CHANGE" \
      "$(release_notes 965c392)"
  assert_equals "$TEST_NEW_CHANGE$(echo)$TEST_CHANGE" \
      "$(release_notes 965c392 bb59d88)"
}

function test_get_last_release() {
  rm -f ${TEST_TMPDIR}/CHANGELOG.md
  if (get_last_release "${TEST_TMPDIR}/CHANGELOG.md"); then
    fail "Should have returned false for initial release"
  fi
  cat <<EOF >${TEST_TMPDIR}/CHANGELOG.md
## No release
EOF
  if (get_last_release "${TEST_TMPDIR}/CHANGELOG.md"); then
    fail "Should have returned false when no release exists"
  fi
  cat <<EOF >${TEST_TMPDIR}/CHANGELOG.md
## New release

Baseline: 965c392

Initial release without cherry-picks

EOF
  assert_equals "965c392" \
      "$(get_last_release "${TEST_TMPDIR}/CHANGELOG.md")"


  mv ${TEST_TMPDIR}/CHANGELOG.md ${TEST_TMPDIR}/CHANGELOG.md.bak
  cat <<EOF >${TEST_TMPDIR}/CHANGELOG.md
## Cherry-picking bb59d88

Baseline: 965c392
   + bb59d88: RELNOTES[INC]: Remove deprecated "make var" INCDIR

$TEST_INC_CHANGE
EOF
  cat ${TEST_TMPDIR}/CHANGELOG.md.bak >>${TEST_TMPDIR}/CHANGELOG.md
  rm ${TEST_TMPDIR}/CHANGELOG.md.bak
  assert_equals "965c392 bb59d88" \
      "$(get_last_release "${TEST_TMPDIR}/CHANGELOG.md")"

  mv ${TEST_TMPDIR}/CHANGELOG.md ${TEST_TMPDIR}/CHANGELOG.md.bak
  cat <<EOF >${TEST_TMPDIR}/CHANGELOG.md
## Cherry-picking bb59d88 and 14d905b

Baseline: 965c392
   + bb59d88: RELNOTES[INC]: Remove deprecated "make var" INCDIR
   + 14d905b: Add --with_aspect_deps flag to blaze query. This flag
              should produce additional information about aspect
              dependencies when --output is set to {xml, proto}.

$TEST_INC_CHANGE
$TEST_NEW_CHANGE
EOF
  cat ${TEST_TMPDIR}/CHANGELOG.md.bak >>${TEST_TMPDIR}/CHANGELOG.md
  rm ${TEST_TMPDIR}/CHANGELOG.md.bak
  assert_equals "965c392 bb59d88 14d905b" \
      "$(get_last_release "${TEST_TMPDIR}/CHANGELOG.md")"

}

function test_create_release_notes() {
  cat <<EOF >${TEST_TMPDIR}/CHANGELOG.md
## New release

Baseline: 965c392

Initial release without cherry-picks

EOF
  assert_equals "$TEST_INC_CHANGE$(echo)$TEST_NEW_CHANGE$(echo)$TEST_CHANGE" \
      "$(create_release_notes ${TEST_TMPDIR}/CHANGELOG.md)"

  cat <<'EOF' >${TEST_TMPDIR}/CHANGELOG.md
## Cherry-picking bb59d88

```
Baseline: 965c392
   + bb59d88: RELNOTES[INC]: Remove deprecated "make var" INCDIR
```

EOF
  cat <<EOF >>${TEST_TMPDIR}/CHANGELOG.md
$TEST_INC_CHANGE
EOF
  assert_equals "$TEST_NEW_CHANGE$(echo)$TEST_CHANGE" \
      "$(create_release_notes ${TEST_TMPDIR}/CHANGELOG.md)"
  assert_equals "965c392 bb59d88" \
      "$(get_last_release "${TEST_TMPDIR}/CHANGELOG.md")"

  cat <<'EOF' >${TEST_TMPDIR}/CHANGELOG.md
## Cherry-picking bb59d88 and 14d905b

```
Baseline: 965c392
   + bb59d88: RELNOTES[INC]: Remove deprecated "make var" INCDIR
   + 14d905b: Add --with_aspect_deps flag to blaze query. This flag
              should produce additional information about aspect
              dependencies when --output is set to {xml, proto}.
```

EOF
  cat <<EOF >>${TEST_TMPDIR}/CHANGELOG.md
$TEST_INC_CHANGE
$TEST_NEW_CHANGE
EOF
  assert_equals "$TEST_CHANGE" \
      "$(create_release_notes ${TEST_TMPDIR}/CHANGELOG.md)"
}

function test_create_revision_information() {
  expected='Baseline: 965c392
   + bb59d88: RELNOTES[INC]: Remove deprecated "make var" INCDIR
   + 14d905b: Add --with_aspect_deps flag to blaze query. This flag
              should produce additional information about aspect
              dependencies when --output is set to {xml, proto}.'
   assert_equals "$expected" \
              "$(create_revision_information 965c392 bb59d88 14d905b)"
}

run_suite "Release notes generation tests"