Skip to content

Commit 3d21998

Browse files
committed
tests: Centralise flatpak-builder helpers in libtest
1 parent ae9912f commit 3d21998

6 files changed

Lines changed: 61 additions & 44 deletions

File tree

tests/libtest.sh

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,37 @@ run_sh () {
293293
${CMD_PREFIX} flatpak run --command=bash ${ARGS-} org.test.Hello -c "$*"
294294
}
295295

296+
: "${FORCE_CLEAN:=1}"
297+
298+
builder_run_app () {
299+
local appdir="${APPDIR:-appdir}"
300+
301+
${FLATPAK_BUILDER} --run "$appdir" "$@"
302+
}
303+
304+
_run_build () {
305+
local appdir="${APPDIR:-appdir}"
306+
307+
if [ -n "${BUILD_LOG:-}" ]; then
308+
${FLATPAK_BUILDER} ${FORCE_CLEAN:+--force-clean} \
309+
"$appdir" "$@" >&2 2>"$BUILD_LOG"
310+
else
311+
${FLATPAK_BUILDER} ${FORCE_CLEAN:+--force-clean} \
312+
"$appdir" "$@" >&2
313+
fi
314+
}
315+
316+
run_build () {
317+
_run_build "$@"
318+
}
319+
320+
run_build_fail () {
321+
if _run_build "$@"; then
322+
echo "build of ${!#} unexpectedly succeeded" >&2
323+
exit 1
324+
fi
325+
}
326+
296327
# fuse support is needed (and the kernel module needs to be loaded) for several
297328
# flatpak-builder tests
298329
skip_without_fuse () {

tests/test-builder-cleanup.sh

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,6 @@ install_sdk_repo
3232

3333
cd "$TEST_DATA_DIR"
3434

35-
run_build () {
36-
local manifest=$1
37-
${FLATPAK_BUILDER} --force-clean appdir "$manifest" >&2
38-
}
39-
4035
cat > test-cleanup-toplevel.json <<'EOF'
4136
{
4237
"app-id": "org.test.CleanupToplevel",

tests/test-builder-deprecated.sh

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,49 +42,49 @@ cp "$srcdir"/org.test.Deprecated.SHA1.file.yaml .
4242
cp "$srcdir"/hello.sh .
4343
cp "$srcdir"/hello.tar.xz .
4444

45-
${FLATPAK_BUILDER} --force-clean appdir org.test.Deprecated.MD5.archive.json >&2 2> build-error-log
45+
BUILD_LOG=build-error-log run_build org.test.Deprecated.MD5.archive.json
4646
assert_file_has_content build-error-log 'The "md5" source property is deprecated due to the weakness of MD5 hashes.'
4747
assert_file_has_content build-error-log 'Use the "sha256" property for the more secure SHA256 hash.'
4848

4949
echo "ok deprecated MD5 hash for archive in JSON"
5050

51-
${FLATPAK_BUILDER} --force-clean appdir org.test.Deprecated.MD5.archive.yaml >&2 2> build-error-log
51+
BUILD_LOG=build-error-log run_build org.test.Deprecated.MD5.archive.yaml
5252
assert_file_has_content build-error-log 'The "md5" source property is deprecated due to the weakness of MD5 hashes.'
5353
assert_file_has_content build-error-log 'Use the "sha256" property for the more secure SHA256 hash.'
5454

5555
echo "ok deprecated MD5 hash for archive in YAML"
5656

57-
${FLATPAK_BUILDER} --force-clean appdir org.test.Deprecated.MD5.file.json >&2 2> build-error-log
57+
BUILD_LOG=build-error-log run_build org.test.Deprecated.MD5.file.json
5858
assert_file_has_content build-error-log 'The "md5" source property is deprecated due to the weakness of MD5 hashes.'
5959
assert_file_has_content build-error-log 'Use the "sha256" property for the more secure SHA256 hash.'
6060

6161
echo "ok deprecated MD5 hash for file in JSON"
6262

63-
${FLATPAK_BUILDER} --force-clean appdir org.test.Deprecated.MD5.file.yaml >&2 2> build-error-log
63+
BUILD_LOG=build-error-log run_build org.test.Deprecated.MD5.file.yaml
6464
assert_file_has_content build-error-log 'The "md5" source property is deprecated due to the weakness of MD5 hashes.'
6565
assert_file_has_content build-error-log 'Use the "sha256" property for the more secure SHA256 hash.'
6666

6767
echo "ok deprecated MD5 hash for file in YAML"
6868

69-
${FLATPAK_BUILDER} --force-clean appdir org.test.Deprecated.SHA1.archive.json >&2 2> build-error-log
69+
BUILD_LOG=build-error-log run_build org.test.Deprecated.SHA1.archive.json
7070
assert_file_has_content build-error-log 'The "sha1" source property is deprecated due to the weakness of SHA1 hashes.'
7171
assert_file_has_content build-error-log 'Use the "sha256" property for the more secure SHA256 hash.'
7272

7373
echo "ok deprecated SHA1 hash for archive in JSON"
7474

75-
${FLATPAK_BUILDER} --force-clean appdir org.test.Deprecated.SHA1.archive.yaml >&2 2> build-error-log
75+
BUILD_LOG=build-error-log run_build org.test.Deprecated.SHA1.archive.yaml
7676
assert_file_has_content build-error-log 'The "sha1" source property is deprecated due to the weakness of SHA1 hashes.'
7777
assert_file_has_content build-error-log 'Use the "sha256" property for the more secure SHA256 hash.'
7878

7979
echo "ok deprecated SHA1 hash for archive in YAML"
8080

81-
${FLATPAK_BUILDER} --force-clean appdir org.test.Deprecated.SHA1.file.json >&2 2> build-error-log
81+
BUILD_LOG=build-error-log run_build org.test.Deprecated.SHA1.file.json
8282
assert_file_has_content build-error-log 'The "sha1" source property is deprecated due to the weakness of SHA1 hashes.'
8383
assert_file_has_content build-error-log 'Use the "sha256" property for the more secure SHA256 hash.'
8484

8585
echo "ok deprecated SHA1 hash for file in JSON"
8686

87-
${FLATPAK_BUILDER} --force-clean appdir org.test.Deprecated.SHA1.file.yaml >&2 2> build-error-log
87+
BUILD_LOG=build-error-log run_build org.test.Deprecated.SHA1.file.yaml
8888
assert_file_has_content build-error-log 'The "sha1" source property is deprecated due to the weakness of SHA1 hashes.'
8989
assert_file_has_content build-error-log 'Use the "sha256" property for the more secure SHA256 hash.'
9090

tests/test-builder-licence-paths.sh

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -34,19 +34,6 @@ cd "$TEST_DATA_DIR"
3434

3535
REPO="$(pwd)/repos/test"
3636

37-
run_build () {
38-
local manifest=$1
39-
${FLATPAK_BUILDER} --force-clean appdir "$manifest" >&2
40-
}
41-
42-
run_build_fail () {
43-
local manifest=$1
44-
if ${FLATPAK_BUILDER} --force-clean appdir "$manifest" >&2; then
45-
echo "build of $manifest unexpectedly succeeded" >&2
46-
exit 1
47-
fi
48-
}
49-
5037
mkdir -p source_licence_1
5138
ln -s /proc/self source_licence_1/licenses
5239
tar czf source_licence_1.tar.gz source_licence_1/

tests/test-builder-python.sh

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,22 +42,23 @@ cp -a $(dirname $0)/testpython.py .
4242
cp $(dirname $0)/importme.py .
4343
cp $(dirname $0)/importme2.py .
4444
chmod u+w *.py
45-
flatpak-builder --force-clean appdir org.test.Python.json >&2
45+
46+
run_build org.test.Python.json
4647

4748
assert_has_file appdir/files/bin/importme.pyc
4849

49-
flatpak-builder --run appdir org.test.Python.json testpython.py > testpython.out
50+
builder_run_app org.test.Python.json testpython.py > testpython.out
5051

5152
assert_file_has_content testpython.out ^modified$
5253

5354
echo "ok handled pyc rewriting multiple times"
5455

55-
flatpak-builder --force-clean appdir org.test.Python2.json >&2
56+
run_build org.test.Python2.json
5657

5758
assert_not_has_file appdir/files/bin/importme.py
5859
assert_has_file appdir/files/bin/importme.pyc
5960

60-
flatpak-builder --run appdir org.test.Python2.json testpython.py > testpython.out
61+
builder_run_app org.test.Python2.json testpython.py > testpython.out
6162

6263
assert_file_has_content testpython.out "^first $"
6364

tests/test-builder.sh

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ echo "MY LICENSE" > ./LICENSE
7373

7474
for MANIFEST in test.json test.yaml test-rename.json test-rename-appdata.json ; do
7575
echo "building manifest $MANIFEST" >&2
76-
${FLATPAK_BUILDER} --repo=$REPO $FL_GPGARGS --force-clean appdir $MANIFEST >&2
76+
run_build --repo="$REPO" $FL_GPGARGS "$MANIFEST"
7777

7878
assert_file_has_content appdir/files/share/app-data version1
7979
assert_file_has_content appdir/metadata shared=network;
@@ -120,9 +120,9 @@ assert_file_has_content app_data_1 version1
120120
echo "ok install+run"
121121

122122
echo "version2" > app-data
123-
${FLATPAK_BUILDER} $FL_GPGARGS --repo=$REPO --force-clean appdir test.json >&2
123+
run_build $FL_GPGARGS --repo="$REPO" test.json
124124
assert_file_has_content appdir/files/share/app-data version2
125-
${FLATPAK_BUILDER} $FL_GPGARGS --repo=$REPO --force-clean appdir test.yaml >&2
125+
run_build $FL_GPGARGS --repo="$REPO" test.yaml
126126
assert_file_has_content appdir/files/share/app-data version2
127127

128128
${FLATPAK} ${U} update -y org.test.Hello2 master >&2
@@ -134,27 +134,29 @@ echo "ok update"
134134

135135
# The build-args of --help should prevent the faulty cleanup and
136136
# platform-cleanup commands from executing
137-
${FLATPAK_BUILDER} $FL_GPGARGS --repo=$REPO --force-clean runtimedir \
138-
test-runtime.json >&2
137+
APPDIR=runtimedir run_build $FL_GPGARGS --repo="$REPO" test-runtime.json
139138

140139
echo "ok runtime build cleanup with build-args"
141140

142141
# test screenshot ref commit
143-
${FLATPAK_BUILDER} --repo=$REPO/repo_sc --force-clean builddir_sc \
142+
APPDIR=builddir_sc \
143+
run_build \
144+
--repo="$REPO/repo_sc" \
144145
--mirror-screenshots-url=https://example.org/media \
145-
org.flatpak_builder.gui.json >&2
146+
org.flatpak_builder.gui.json
146147
ostree --repo=$REPO/repo_sc refs|grep -Eq "^screenshots/$(flatpak --default-arch)$"
147148
ostree checkout --repo=$REPO/repo_sc -U screenshots/$(flatpak --default-arch) outdir_sc
148149
find outdir_sc -path "*/icons/64x64/org.test.Hello.png" -type f | grep -q .
149150

150151
echo "ok screenshot ref commit"
151152

152153
# test compose partial url policy
153-
${FLATPAK_BUILDER} --force-clean builddir_sc \
154+
APPDIR=builddir_sc \
155+
run_build \
154156
--mirror-screenshots-url=https://example.org/media \
155157
--state-dir .fp-compose-url-policy-partial \
156158
--compose-url-policy=partial \
157-
org.flatpak.appstream_media.json >&2
159+
org.flatpak.appstream_media.json
158160
# we test for the icon tag instead of screenshot
159161
# the former works offline the latter does not
160162
gzip -cdq builddir_sc/files/share/app-info/xmls/org.flatpak.appstream_media.xml.gz|grep -Eq '>org/flatpak/appstream_media/[^/]+/icons/128x128/org.flatpak.appstream_media.png</icon>'
@@ -163,11 +165,12 @@ echo "ok compose partial url policy"
163165

164166
# test compose full url policy
165167
if appstream_has_version 0 16 3; then
166-
${FLATPAK_BUILDER} --force-clean builddir_sc \
168+
APPDIR=builddir_sc \
169+
run_build \
167170
--mirror-screenshots-url=https://example.org/media \
168171
--state-dir .fp-compose-url-policy-full \
169172
--compose-url-policy=full \
170-
org.flatpak.appstream_media.json >&2
173+
org.flatpak.appstream_media.json
171174

172175
gzip -cdq builddir_sc/files/share/app-info/xmls/org.flatpak.appstream_media.xml.gz|grep -Eq '>https://example.org/media/org/flatpak/appstream_media/[^/]+/icons/128x128/org.flatpak.appstream_media.png</icon>'
173176

@@ -177,16 +180,16 @@ else
177180
fi
178181

179182
# test install
180-
${FLATPAK_BUILDER} --user --install \
181-
--force-clean builddir org.flatpak.install_test.json >&2
183+
APPDIR=builddir run_build --user --install org.flatpak.install_test.json
184+
182185
REFS=$(flatpak list --all --columns=ref 2>/dev/null)
183186
echo "$REFS" | grep -q "org\.flatpak\.install_test"
184187
echo "$REFS" | grep -q "org\.flatpak\.install_test\.Debug"
185188
echo "$REFS" | grep -q "org\.flatpak\.install_test\.Locale"
186189

187190
echo "ok install"
188191

189-
${FLATPAK_BUILDER} --repo=$REPO --force-clean appdir test-locale-cleanup.json >&2
192+
run_build --repo="$REPO" test-locale-cleanup.json
190193

191194
assert_not_has_file appdir/files/share/runtime/locale/es/share/es/testA.mo
192195
assert_has_file appdir/files/share/runtime/locale/es/share/es/testB.mo

0 commit comments

Comments
 (0)