#!/usr/bin/env atf-sh . $(atf_get_srcdir)/test_env.sh init_tests \ abuild_help \ abuild_invalid_opt \ abuild_version \ abuild_simple_pkg_without_deps \ abuild_build_fail \ abuild_invalid_filename \ abuild_usr_lib64 \ abuild_dbg_subpackage \ abuild_SETFATTR_in_dbg \ abuild_reproducible \ abuild_checksum_generation \ abuild_checksum_duplicates export ABUILD_SHAREDIR=$(atf_get_srcdir)/.. export ABUILD_CONF=/dev/null export GIT_CONFIG_GLOBAL="$(atf_get_srcdir)/testdata/gitconfig" export REPODEST="$PWD"/packages testrepo=$(atf_get_srcdir)/testrepo # copy keys cp -ra "$(atf_get_srcdir)"/testdata/.abuild "$PWD" abuild_help_body() { atf_check -s exit:0 \ -o match:"usage:" \ abuild -h } abuild_invalid_opt_body() { atf_check -s exit:1 \ -e match:"usage:" \ abuild -@ } abuild_version_body() { atf_check -s exit:0 \ -o match:"abuild [0-9]+\.[0-9]+" \ abuild -V } abuild_simple_pkg_without_deps_body() { cp -r "$testrepo"/pkg1 . cd pkg1 atf_check -s exit:0 \ -e not-match:"WARNING" \ -e not-match:"fatal" \ abuild } abuild_build_fail_body() { mkdir buildfail cat >buildfail/APKBUILD <<-EOF # Maintainer: Joe User pkgname="buildfail" pkgver="1.0" pkgrel=0 pkgdesc="Dummy test package that fails to build" url="https://gitlab.alpinelinux.org/alpine/aports" arch="noarch" license="MIT" subpackages="\$pkgname-dev \$pkgname-doc" source="" prepare() { mkdir -p "\$builddir" } build() { false } package() { true } EOF cd buildfail atf_check -s exit:1 \ -e match:"ERROR: buildfail: build failed" \ abuild } abuild_invalid_filename_body() { mkdir invalid-filename cd invalid-filename cat >APKBUILD <<-EOF # Maintainer: Joe User pkgname="invalid-filename" pkgver="1.0" pkgrel=0 pkgdesc="Dummy test package that fails to build" url="https://gitlab.alpinelinux.org/alpine/aports" arch="noarch" license="MIT" prepare() { mkdir -p "\$builddir" } build() { touch $'bad\nfile' } check() { true } package() { mkdir -p "\$pkgdir" cp -r * "\$pkgdir"/ } EOF atf_check -s exit:1 \ -e match:"ERROR:.*: Found filenames with newline" \ abuild } abuild_usr_lib64_body() { mkdir lib64test cd lib64test cat >APKBUILD <<-EOF # Maintainer: Joe User pkgname="lib64test" pkgver="1.0" pkgrel=0 pkgdesc="Dummy test package" url="https://gitlab.alpinelinux.org/alpine/aports" arch="noarch" license="MIT" source="" prepare() { mkdir -p "\$builddir" } build() { mkdir -p usr/lib64 } check() { true } package() { mkdir -p "\$pkgdir" cp -r * "\$pkgdir"/ } EOF atf_check -s exit:1 \ -e match:"ERROR:.*: Packages must not put anything under /usr/lib64" \ abuild options=lib64 atf_check -s exit:0 \ -e match:"Build complete" \ abuild } abuild_dbg_subpackage_body() { cp -ra "$testrepo" . cd testrepo/dbgpkg atf_check -s exit:0 \ -o match:"hello world" \ -e match:"Build complete" \ abuild cd ../.. arch=$(abuild -A) tar -zxf "$REPODEST"/testrepo/$arch/dbgpkg-1.0-r0.apk \ || atf_fail "failed to extract dbgpkg-1.0-r0.apk" if [ -e usr/lib/debug ]; then atf_fail "usr/lib/debug should not exist" fi debuginfo=$(readelf -wk usr/bin/hello | grep '^ Separate debug info file: [^/]*\.debug$') debuginfo_file=${debuginfo#" Separate debug info file: "} atf_check -s exit:0 \ -e match:"nm: usr/bin/hello: no symbols" \ nm usr/bin/hello if ! [ usr/bin/hello -ef usr/bin/hello-hard ]; then atf_fail 'hello is not a hardlink of hello-hard' fi rm -r usr tar -xf "$REPODEST"/testrepo/$arch/dbgpkg-dbg-1.0-r0.apk if [ -e usr/bin ]; then atf_fail "usr/bin should not exist" fi find usr atf_check -s exit:0 \ -o match:"T main" \ nm usr/lib/debug/usr/bin/$debuginfo_file if [ -e usr/lib/debug/usr/bin/hello-sym.debug ]; then atf_fail "usr/lib/debug/usr/bin/hello-sym.debug should not exist" fi if [ -e usr/lib/debug/usr/bin/hello.debug ] && [ -e usr/lib/debug/usr/bin/hello-hard.debug ]; then atf_fail "only one of hello.debug and hello-hard.debug should exist" fi } abuild_SETFATTR_in_dbg_body() { cp -ra "$testrepo"/dbgpkg . cd dbgpkg SETFATTR=true atf_check -s exit:0 \ -o match:"hello world" \ -e match:"Build complete" \ abuild } abuild_reproducible_body() { cp -ra "$testrepo" . cd testrepo/pkg1 # set timestamp of APKBUILD to 1 min older than current time touch -d @$(( $(date -u +%s) - 60)) APKBUILD arch=$(abuild -A) pkgs=$(abuild listpkg) abuild || atf_fail "first build failed" checksums=$(cd "$REPODEST"/testrepo/$arch && md5sum $pkgs) echo "$checksums" rm -r "$REPODEST"/testrepo abuild || atf_fail "rebuild failed" checksums2=$(cd "$REPODEST"/testrepo/$arch && md5sum $pkgs) echo "$checksums2" if [ "$checksums" != "$checksums2" ]; then atf_fail "checksums does not match" fi } abuild_checksum_generation_body() { mkdir foo cat > foo/APKBUILD <<-EOF pkgname="foo" pkgver="1.0" source="test.txt" EOF echo "foo" > foo/test.txt cd foo abuild checksum || atf_fail "checksum generation failed" ( . ./APKBUILD && echo "$sha512sums" | sed '/^$/d' > sums ) cat sums sha512sum -c sums || atf_fail "checksum mismatch" } abuild_checksum_duplicates_body() { mkdir -p foo/dir1 foo/dir2 cat > foo/APKBUILD <<-EOF pkgname="foo" pkgver="1.0" source="dir1/testfile dir2/testfile" EOF echo "first" > foo/dir1/testfile echo "second" > foo/dir2/testfile cd foo atf_check -s exit:1 \ -e match:"ERROR:.*duplicate found" \ abuild checksum }