File: deb-packaging.tests.sh

package info (click to toggle)
keyman 18.0.245-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 21,316 kB
  • sloc: python: 52,784; cpp: 21,278; sh: 7,633; ansic: 4,823; xml: 3,617; perl: 959; makefile: 139; javascript: 138
file content (333 lines) | stat: -rwxr-xr-x 13,754 bytes parent folder | download | duplicates (2)
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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
#!/usr/bin/env bash
set -eu

## START STANDARD BUILD SCRIPT INCLUDE
# adjust relative paths as necessary
THIS_SCRIPT="$(readlink -f "${BASH_SOURCE[0]}")"
. "${THIS_SCRIPT%/*}/../../../resources/build/build-utils.sh"
## END STANDARD BUILD SCRIPT INCLUDE

. "${THIS_SCRIPT%/*}/test.inc.sh"

test_check_updated_version_number__NoChange_OK() {
  createBase alpha

  echo "readme" > README.md
  git add README.md
  git commit -m "Some change on the branch"

  echo "## Calling API verification"
  pwd
  linux/scripts/deb-packaging.sh --bin-pkg "${BINPKG_NAME}" --git-sha "$(git rev-parse HEAD)" --git-base master verify
}

test_check_updated_version_number__LineAdded_OK() {
  createBase alpha

  sed -i 's/ km_core_actions_dispose@Base 17.0.197/ km_core_actions_dispose@Base 17.0.197\n km_core_added@Base 17.0.255/' linux/debian/libkeymancore1.symbols
  git add linux/debian/libkeymancore1.symbols
  git commit -m "API method added"

  echo "## Calling API verification"
  pwd
  linux/scripts/deb-packaging.sh --bin-pkg "${BINPKG_NAME}" --git-sha "$(git rev-parse HEAD)" --git-base master verify
}

test_check_updated_version_number__LineAddedWithoutVerUpd_ERROR() {
  local output
  createBase alpha

  sed -i 's/ km_core_actions_dispose@Base 17.0.197/ km_core_actions_dispose@Base 17.0.197\n km_core_added@Base 17.0.197/' linux/debian/libkeymancore1.symbols
  git add linux/debian/libkeymancore1.symbols
  git commit -m "API method added"

  echo "## Calling API verification"
  pwd
  output=$(linux/scripts/deb-packaging.sh --bin-pkg "${BINPKG_NAME}" --git-sha "$(git rev-parse HEAD)" --git-base master verify || true)
  echo "${output[*]}" # for logging
  [[ "${output[*]}" == *"ERROR: libkeymancore1.symbols file got changed without changing the package version number of the symbol"* ]]
}

test_check_updated_version_number__LineRemovedWithAPIUpd_OK() {
  createBase alpha
  echo "2.0.0" > core/CORE_API_VERSION.md
  git add core/CORE_API_VERSION.md
  git mv linux/debian/libkeymancore{1,2}.symbols
  sed -i 's/libkeymancore1/libkeymancore2/' linux/debian/libkeymancore2.symbols
  sed -i 's/libkeymancore.so.1/libkeymancore.so.2/' linux/debian/libkeymancore2.symbols
  sed -i '6d' linux/debian/libkeymancore2.symbols
  git add linux/debian/libkeymancore2.symbols
  git commit -m "API method removed"

  echo "## Calling API verification"
  pwd
  linux/scripts/deb-packaging.sh --bin-pkg "${BINPKG_NAME}" --git-sha "$(git rev-parse HEAD)" --git-base master verify
}

test_check_updated_version_number__LineRemoved_OnlyCoreApiUpd_ERROR() {
  local output
  createBase alpha
  echo "2.0.0" > core/CORE_API_VERSION.md
  git add core/CORE_API_VERSION.md
  sed -i '6d' linux/debian/libkeymancore1.symbols
  git add linux/debian/libkeymancore1.symbols
  git commit -m "API method removed"

  echo "## Calling API verification"
  pwd
  output=$(linux/scripts/deb-packaging.sh --bin-pkg "${BINPKG_NAME}" --git-sha "$(git rev-parse HEAD)" --git-base master verify || true)
  echo "${output[*]}" # for logging
  [[ "${output[*]}" == *"ERROR: Missing libkeymancore2.symbols file"* ]]
}

test_check_updated_version_number__LineRemoved_OnlySymbolsFileUpd_ERROR() {
  local output
  createBase alpha
  git mv linux/debian/libkeymancore{1,2}.symbols
  sed -i 's/libkeymancore1/libkeymancore2/' linux/debian/libkeymancore2.symbols
  sed -i 's/libkeymancore.so.1/libkeymancore.so.2/' linux/debian/libkeymancore2.symbols
  sed -i '6d' linux/debian/libkeymancore2.symbols
  git add linux/debian/libkeymancore2.symbols
  git commit -m "API method removed"

  echo "## Calling API verification"
  pwd
  output=$(linux/scripts/deb-packaging.sh --bin-pkg "${BINPKG_NAME}" --git-sha "$(git rev-parse HEAD)" --git-base master verify || true)
  echo "${output[*]}" # for logging
  [[ "${output[*]}" == *"ERROR: Missing libkeymancore1.symbols file"* ]]
}

test_check_updated_version_number__LineRemovedWithAPIUpd_NotMetadataUpd_ERROR() {
  local output
  createBase alpha
  echo "2.0.0" > core/CORE_API_VERSION.md
  git add core/CORE_API_VERSION.md
  git mv linux/debian/libkeymancore{1,2}.symbols
  sed -i '6d' linux/debian/libkeymancore2.symbols
  git add linux/debian/libkeymancore2.symbols
  git commit -m "API method removed"

  echo "## Calling API verification"
  pwd
  output=$(linux/scripts/deb-packaging.sh --bin-pkg "${BINPKG_NAME}" --git-sha "$(git rev-parse HEAD)" --git-base master verify || true)
  echo "${output[*]}" # for logging
  [[ "${output[*]}" == *"ERROR: API version in .symbols file and in CORE_API_VERSION.md is different"* ]]
}

test_check_updated_version_number__LineRemoved_InAlpha_ChangedBefore_OK() {
  createBase alpha
  git checkout master
  # simulate a commit that already introduced an API version change
  echo "2.0.0" > core/CORE_API_VERSION.md
  git add core/CORE_API_VERSION.md
  git mv linux/debian/libkeymancore{1,2}.symbols
  sed -i 's/libkeymancore1/libkeymancore2/' linux/debian/libkeymancore2.symbols
  sed -i 's/libkeymancore.so.1/libkeymancore.so.2/' linux/debian/libkeymancore2.symbols
  git add linux/debian/libkeymancore2.symbols
  git commit -m "API version change"
  git checkout chore
  git rebase master

  sed -i '6d' linux/debian/libkeymancore2.symbols
  git add linux/debian/libkeymancore2.symbols
  git commit -m "API method removed"

  echo "## Calling API verification"
  pwd
  linux/scripts/deb-packaging.sh --bin-pkg "${BINPKG_NAME}" --git-sha "$(git rev-parse HEAD)" --git-base master verify
}

test_check_updated_version_number__LineRemoved_InAlpha_FileMissingInStable_ApiVerChanged_OK() {
  createBase alpha
  git checkout master
  # simulate a commit that renamed the .symbols file and updated the API version
  git mv linux/debian/libkeymancore1.symbols linux/debian/libfoo2.symbols
  sed -i 's/libkeymancore/libfoo/' linux/scripts/verify_api.inc.sh
  # shellcheck disable=2016 # single quotes are intentional here
  sed -i 's/${SONAME}/2/' linux/scripts/verify_api.inc.sh
  git add  linux/scripts/verify_api.inc.sh
  echo "2.0.0" > core/CORE_API_VERSION.md
  git add core/CORE_API_VERSION.md
  sed -i 's/libkeymancore1/libfoo2/' linux/debian/libfoo2.symbols
  sed -i 's/libkeymancore.so.1/libfoo.so.2/' linux/debian/libfoo2.symbols
  git add linux/debian/libfoo2.symbols
  git commit -m "renamed library"
  git checkout chore
  git rebase master

  sed -i '6d' linux/debian/libfoo2.symbols
  git add linux/debian/libfoo2.symbols
  git commit -m "API method removed"

  echo "## Calling API verification"
  pwd
  linux/scripts/deb-packaging.sh --bin-pkg "${BINPKG_NAME}" --git-sha "$(git rev-parse HEAD)" --git-base master verify
}

test_check_updated_version_number__LineRemoved_InAlpha_FileMissingInStable_ApiVerUnchanged_ERROR() {
  local output
  createBase alpha
  git checkout master
  # simulate a commit that renamed the .symbols file
  git mv linux/debian/libkeymancore1.symbols linux/debian/libfoo1.symbols
  sed -i 's/libkeymancore/libfoo/' linux/scripts/verify_api.inc.sh
  git add linux/scripts/verify_api.inc.sh
  sed -i 's/libkeymancore/libfoo/' linux/debian/libfoo1.symbols
  git add linux/debian/libfoo1.symbols
  git commit -m "renamed library"
  git checkout chore
  git rebase master

  sed -i '6d' linux/debian/libfoo1.symbols
  git add linux/debian/libfoo1.symbols
  git commit -m "API method removed"

  echo "## Calling API verification"
  pwd
  output=$(linux/scripts/deb-packaging.sh --bin-pkg "${BINPKG_NAME}" --git-sha "$(git rev-parse HEAD)" --git-base master verify || true)
  echo "${output[*]}" # for logging
  [[ "${output[*]}" == *" ERROR: Major API change without updating API version number in libfoo1.symbols file"* ]]
}

test_check_updated_version_number__LineRemoved_InAlpha_ChangeFromStable_ERROR() {
  local output
  createBase alpha

  sed -i '6d' linux/debian/libkeymancore1.symbols
  git add linux/debian/libkeymancore1.symbols
  git commit -m "API method removed"

  echo "## Calling API verification"
  pwd
  output=$(linux/scripts/deb-packaging.sh --bin-pkg "${BINPKG_NAME}" --git-sha "$(git rev-parse HEAD)" --git-base master verify || true)
  echo "${output[*]}" # for logging
  [[ "${output[*]}" == *" ERROR: Major API change without updating API version number in libkeymancore1.symbols file"* ]]
}

test_check_updated_version_number__LineRemoved_InBeta_ApiVerUnchanged_ERROR() {
  local output
  createBase beta

  # simulate a commit that already introduced an API version change in Beta
  git checkout -b beta
  echo "2.0.0" > core/CORE_API_VERSION.md
  git add core/CORE_API_VERSION.md
  git mv linux/debian/libkeymancore{1,2}.symbols
  sed -i 's/libkeymancore1/libkeymancore2/' linux/debian/libkeymancore2.symbols
  sed -i 's/libkeymancore.so.1/libkeymancore.so.2/' linux/debian/libkeymancore2.symbols
  git add linux/debian/libkeymancore2.symbols
  git commit -m "API version change"
  git checkout chore
  git rebase beta

  sed -i '6d' linux/debian/libkeymancore2.symbols
  git add linux/debian/libkeymancore2.symbols
  git commit -m "API method removed"

  echo "## Calling API verification"
  pwd
  output=$(linux/scripts/deb-packaging.sh --bin-pkg "${BINPKG_NAME}" --git-sha "$(git rev-parse HEAD)" --git-base beta verify || true)
  echo "${output[*]}" # for logging
  [[ "${output[*]}" == *" ERROR: Major API change without updating API version number in libkeymancore2.symbols file"* ]]
}

test_check_updated_version_number__LineRemoved_InBeta_ApiVerChanged_OK() {
  createBase beta

  # simulate a commit that already introduced an API version change in Beta
  git checkout -b beta
  echo "2.0.0" > core/CORE_API_VERSION.md
  git add core/CORE_API_VERSION.md
  git mv linux/debian/libkeymancore{1,2}.symbols
  sed -i 's/libkeymancore1/libkeymancore2/' linux/debian/libkeymancore2.symbols
  sed -i 's/libkeymancore.so.1/libkeymancore.so.2/' linux/debian/libkeymancore2.symbols
  git add linux/debian/libkeymancore2.symbols
  git commit -m "API version change"
  git checkout chore
  git rebase beta

  echo "3.0.0" > core/CORE_API_VERSION.md
  git add core/CORE_API_VERSION.md
  git mv linux/debian/libkeymancore{2,3}.symbols
  sed -i 's/libkeymancore2/libkeymancore3/' linux/debian/libkeymancore3.symbols
  sed -i 's/libkeymancore.so.2/libkeymancore.so.3/' linux/debian/libkeymancore3.symbols
  sed -i '6d' linux/debian/libkeymancore3.symbols
  git add linux/debian/libkeymancore3.symbols
  git commit -m "API method removed"

  echo "## Calling API verification"
  pwd
  linux/scripts/deb-packaging.sh --bin-pkg "${BINPKG_NAME}" --git-sha "$(git rev-parse HEAD)" --git-base beta verify
}

test_check_updated_version_number__LineRemoved_InBeta_FileMissingInStable_ApiVerUnchanged_ERROR() {
  local output
  createBase alpha
  git checkout -b beta
  # simulate a commit that renamed the .symbols file
  git mv linux/debian/libkeymancore1.symbols linux/debian/libfoo1.symbols
  sed -i 's/libkeymancore/libfoo/' linux/scripts/verify_api.inc.sh
  git add linux/scripts/verify_api.inc.sh
  sed -i 's/libkeymancore/libfoo/' linux/debian/libfoo1.symbols
  git add linux/debian/libfoo1.symbols
  git commit -m "renamed library"
  git checkout chore
  git rebase beta

  sed -i '6d' linux/debian/libfoo1.symbols
  git add linux/debian/libfoo1.symbols
  git commit -m "API method removed"

  echo "## Calling API verification"
  pwd
  output=$(linux/scripts/deb-packaging.sh --bin-pkg "${BINPKG_NAME}" --git-sha "$(git rev-parse HEAD)" --git-base beta verify || true)
  echo "${output[*]}" # for logging
  [[ "${output[*]}" == *" ERROR: Major API change without updating API version number in libfoo1.symbols file"* ]]
}

test_check_updated_version_number__LineInsertedInBranch_OK() {
  createBase alpha

  local base_sha=$(git rev-parse master)

  # Add a line in chore branch
  echo " km_core_foo@Base 17.0.200" >> linux/debian/libkeymancore1.symbols
  git add linux/debian/libkeymancore1.symbols
  git commit -m "API method added in chore branch"

  # Add a line in master branch
  git checkout master
  echo " km_core_foo@Base 17.0.205" >> linux/debian/libkeymancore1.symbols
  git add linux/debian/libkeymancore1.symbols
  git commit -m "API method changed in master branch"
  echo "readme" > README.md
  git add README.md
  git commit -m "Some change on master"
  git checkout chore

  # merge master into chore
  git merge --strategy-option=ours master

  echo "## Calling API verification"
  pwd
  linux/scripts/deb-packaging.sh --bin-pkg "${BINPKG_NAME}" --git-sha "$(git rev-parse HEAD)" --git-base "${base_sha}" verify
}

echo "(test logs are in /tmp/<testname>.log)"
run_test test_check_updated_version_number__NoChange_OK
run_test test_check_updated_version_number__LineAdded_OK
run_test test_check_updated_version_number__LineAddedWithoutVerUpd_ERROR
run_test test_check_updated_version_number__LineRemovedWithAPIUpd_OK
run_test test_check_updated_version_number__LineRemoved_OnlyCoreApiUpd_ERROR
run_test test_check_updated_version_number__LineRemoved_OnlySymbolsFileUpd_ERROR
run_test test_check_updated_version_number__LineRemovedWithAPIUpd_NotMetadataUpd_ERROR
run_test test_check_updated_version_number__LineRemoved_InAlpha_ChangedBefore_OK
run_test test_check_updated_version_number__LineRemoved_InAlpha_FileMissingInStable_ApiVerChanged_OK
run_test test_check_updated_version_number__LineRemoved_InAlpha_FileMissingInStable_ApiVerUnchanged_ERROR
run_test test_check_updated_version_number__LineRemoved_InAlpha_ChangeFromStable_ERROR
run_test test_check_updated_version_number__LineRemoved_InBeta_ApiVerUnchanged_ERROR
run_test test_check_updated_version_number__LineRemoved_InBeta_ApiVerChanged_OK
run_test test_check_updated_version_number__LineRemoved_InBeta_FileMissingInStable_ApiVerUnchanged_ERROR
run_test test_check_updated_version_number__LineInsertedInBranch_OK

# TODO: still some test cases missing for the different checks