From: "Michał Górny" <mgorny@gentoo.org>
To: gentoo-commits@lists.gentoo.org
Subject: [gentoo-commits] repo/gentoo:master commit in: eclass/tests/
Date: Tue, 27 Sep 2022 20:28:53 +0000 (UTC) [thread overview]
Message-ID: <1664310475.9f8718d9175ede151365ae0472bfc25e0e7e451f.mgorny@gentoo> (raw)
commit: 9f8718d9175ede151365ae0472bfc25e0e7e451f
Author: Michał Górny <mgorny <AT> gentoo <DOT> org>
AuthorDate: Sat Sep 24 13:43:43 2022 +0000
Commit: Michał Górny <mgorny <AT> gentoo <DOT> org>
CommitDate: Tue Sep 27 20:27:55 2022 +0000
URL: https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=9f8718d9
eclass/tests: Add tests for unpacker.eclass
Signed-off-by: Michał Górny <mgorny <AT> gentoo.org>
eclass/tests/tests-common.sh | 7 ++
eclass/tests/unpacker.sh | 233 +++++++++++++++++++++++++++++++++++++++++++
2 files changed, 240 insertions(+)
diff --git a/eclass/tests/tests-common.sh b/eclass/tests/tests-common.sh
index a677842b6ac5..45b1e20b933a 100644
--- a/eclass/tests/tests-common.sh
+++ b/eclass/tests/tests-common.sh
@@ -60,6 +60,13 @@ die() {
exit 1
}
+assert() {
+ local x pipestatus=${PIPESTATUS[*]}
+ for x in ${pipestatus} ; do
+ [[ ${x} -eq 0 ]] || die "$@"
+ done
+}
+
has_version() {
while [[ $1 == -* ]]; do
shift
diff --git a/eclass/tests/unpacker.sh b/eclass/tests/unpacker.sh
new file mode 100755
index 000000000000..7a297d61babd
--- /dev/null
+++ b/eclass/tests/unpacker.sh
@@ -0,0 +1,233 @@
+#!/usr/bin/env bash
+# Copyright 2022 Gentoo Authors
+# Distributed under the terms of the GNU General Public License v2
+
+EAPI=8
+
+source tests-common.sh || exit
+
+inherit unpacker
+
+# silence the output
+unpack_banner() { :; }
+
+TESTFILE=test.in
+TESTDIR=$(mktemp -d || die)
+trap 'cd - >/dev/null && rm -r "${TESTDIR}"' EXIT
+
+# prepare some test data
+# NB: we need something "compressible", as compress(1) will return
+# an error if the file "is larger than before compression"
+cp ../unpacker.eclass "${TESTDIR}/${TESTFILE}" || die
+cd "${TESTDIR}" || die
+
+test_unpack() {
+ local archive=${1}
+ local unpacked=${2}
+ local deps=${3}
+ local packcmd=${4}
+
+ local x
+ for x in ${deps}; do
+ if ! type "${x}" &>/dev/null; then
+ ewarn "Skipping ${archive}, tool ${x} not found"
+ return
+ fi
+ done
+
+ rm -rf testdir || die
+ mkdir -p testdir || die
+
+ tbegin "unpacking ${archive}"
+ eval "${packcmd}"
+ assert "packing ${archive} failed"
+ cd testdir || die
+ local out
+ out=$(
+ _unpacker "../${archive}" 2>&1
+ )
+ ret=$?
+ if [[ ${ret} -eq 0 ]]; then
+ if [[ ! -f ${unpacked} ]]; then
+ eerror "${unpacked} not found after unpacking"
+ ret=1
+ elif ! diff -u "${unpacked}" "../${TESTFILE}"; then
+ eerror "${unpacked} different than input"
+ ret=1
+ fi
+ fi
+ [[ ${ret} -ne 0 ]] && echo "${out}" >&2
+ tend ${ret}
+
+ cd .. || die
+ rm -f "${archive}" || die
+}
+
+test_compressed_file() {
+ local suffix=${1}
+ local tool=${2}
+
+ test_unpack "test${suffix}" test "${tool}" \
+ "${tool} -c \${TESTFILE} > \${archive}"
+}
+
+test_compressed_file_multistream() {
+ local suffix=${1}
+ local tool=${2}
+
+ test_unpack "test+multistream${suffix}" "test+multistream" "${tool}" \
+ "head -n 300 \${TESTFILE} | ${tool} -c > \${archive} &&
+ tail -n +301 \${TESTFILE} | ${tool} -c >> \${archive}"
+}
+
+test_compressed_file_with_junk() {
+ local suffix=${1}
+ local tool=${2}
+ local flag=${3}
+
+ test_unpack "test+junk${suffix}" "test+junk" "${tool}" \
+ "${tool} -c \${TESTFILE} > \${archive} && cat test.in >> \${archive}"
+}
+
+test_compressed_tar() {
+ local suffix=${1}
+ local tool=${2}
+
+ test_unpack "test${suffix}" test.in "tar ${tool}" \
+ "tar -c \${TESTFILE} | ${tool} -c > \${archive}"
+}
+
+test_compressed_cpio() {
+ local suffix=${1}
+ local tool=${2}
+
+ test_unpack "test${suffix}" test.in "cpio ${tool}" \
+ "cpio -o --quiet <<<\${TESTFILE} | ${tool} -c > \${archive}"
+}
+
+create_deb() {
+ local suffix=${1}
+ local tool=${2}
+ local archive=${3}
+ local infile=${4}
+
+ echo 2.0 > debian-binary || die
+ : > control || die
+ tar -cf control.tar control || die
+ tar -c "${infile}" | ${tool} > "data.tar${suffix}"
+ assert "packing data.tar${suffix} failed"
+ ar r "${archive}" debian-binary control.tar "data.tar${suffix}" \
+ 2>/dev/null || die
+ rm -f control control.tar "data.tar${suffix}" debian-binary || die
+}
+
+test_deb() {
+ local suffix=${1}
+ local tool=${2}
+ local tool_cmd
+
+ if [[ -n ${tool} ]]; then
+ tool_cmd="${tool} -c"
+ else
+ tool_cmd=cat
+ fi
+
+ test_unpack "test-${tool}_1.2.3_noarch.deb" test.in "ar tar ${tool}" \
+ "create_deb '${suffix}' '${tool_cmd}' \${archive} \${TESTFILE}"
+}
+
+test_reject_junk() {
+ local suffix=${1}
+ local archive=test${1}
+
+ rm -rf testdir || die
+ mkdir -p testdir || die
+
+ tbegin "rejecting junk named ${archive}"
+ cat test.in >> "${archive}" || die
+ cd testdir || die
+ (
+ # some decompressors (e.g. cpio) are very verbose about junk
+ _unpacker "../${archive}" &>/dev/null
+ )
+ [[ $? -ne 0 ]]
+ ret=$?
+ tend ${ret}
+
+ cd .. || die
+ rm -f "${archive}" || die
+}
+
+test_compressed_file .bz2 bzip2
+test_compressed_file .Z compress
+test_compressed_file .gz gzip
+test_compressed_file .lzma lzma
+test_compressed_file .xz xz
+test_compressed_file .lz lzip
+test_compressed_file .zst zstd
+
+test_compressed_file_multistream .bz2 bzip2
+test_compressed_file_multistream .gz gzip
+test_compressed_file_multistream .xz xz
+test_compressed_file_multistream .lz lzip
+test_compressed_file_multistream .zst zstd
+
+test_compressed_file_with_junk .bz2 bzip2
+test_compressed_file_with_junk .lz lzip
+
+test_unpack test.tar test.in tar 'tar -cf ${archive} ${TESTFILE}'
+test_compressed_tar .tar.bz2 bzip2
+test_compressed_tar .tbz bzip2
+test_compressed_tar .tbz2 bzip2
+test_compressed_tar .tar.Z compress
+test_compressed_tar .tar.gz gzip
+test_compressed_tar .tgz gzip
+test_compressed_tar .tar.lzma lzma
+test_compressed_tar .tar.xz xz
+test_compressed_tar .txz xz
+test_compressed_tar .tar.lz lzip
+test_compressed_tar .tar.zst zstd
+
+test_unpack test.cpio test.in cpio 'cpio -o --quiet <<<${TESTFILE} > ${archive}'
+test_compressed_cpio .cpio.bz2 bzip2
+test_compressed_cpio .cpio.Z compress
+test_compressed_cpio .cpio.gz gzip
+test_compressed_cpio .cpio.lzma lzma
+test_compressed_cpio .cpio.xz xz
+test_compressed_cpio .cpio.lz lzip
+test_compressed_cpio .cpio.zst zstd
+
+test_deb
+test_deb .gz gzip
+test_deb .xz xz
+test_deb .bz2 bzip2
+test_deb .lzma lzma
+
+test_unpack test.zip test.in zip 'zip -q ${archive} ${TESTFILE}'
+# test handling non-adjusted zip with junk prepended
+test_unpack test.zip test.in zip \
+ 'zip -q testdir/tmp.zip ${TESTFILE} && cat test.in testdir/tmp.zip > ${archive}'
+test_unpack test.7z test.in 7z '7z -bso0 a ${archive} ${TESTFILE}'
+test_unpack test.lha test.in lha 'lha a -q ${archive} ${TESTFILE}'
+test_unpack test.lzh test.in lha 'lha a -q ${archive} ${TESTFILE}'
+test_unpack test.rar test.in rar 'rar -idq a ${archive} ${TESTFILE}'
+
+# TODO: .run/.sh/.bin
+
+test_reject_junk .bz2
+test_reject_junk .Z
+test_reject_junk .gz
+test_reject_junk .lzma
+test_reject_junk .xz
+test_reject_junk .lz
+test_reject_junk .zst
+test_reject_junk .tar
+test_reject_junk .cpio
+test_reject_junk .deb
+test_reject_junk .zip
+test_reject_junk .7z
+test_reject_junk .rar
+test_reject_junk .lha
+test_reject_junk .lzh
+
+texit
next reply other threads:[~2022-09-27 20:28 UTC|newest]
Thread overview: 121+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-09-27 20:28 Michał Górny [this message]
-- strict thread matches above, loose matches on Subject: below --
2025-08-15 5:20 [gentoo-commits] repo/gentoo:master commit in: eclass/tests/ Sam James
2025-08-08 17:39 Sam James
2025-08-04 21:22 Sam James
2025-08-04 21:22 Sam James
2025-08-04 20:04 Sam James
2025-08-04 20:03 Sam James
2025-08-04 20:03 Sam James
2025-08-04 19:19 Sam James
2025-08-04 19:19 Sam James
2025-07-23 22:36 Sam James
2025-07-23 22:36 Sam James
2025-06-13 9:21 Sam James
2025-06-13 8:52 Sam James
2025-06-13 8:32 Sam James
2025-06-13 8:32 Sam James
2025-06-10 7:59 Sam James
2025-05-23 18:59 Michał Górny
2025-05-06 8:46 Sam James
2025-05-02 18:25 Michał Górny
2025-05-02 8:06 Petr Vaněk
2025-05-01 11:36 Michał Górny
2024-12-30 11:35 Michał Górny
2024-12-30 11:35 Michał Górny
2024-12-21 8:11 Michał Górny
2024-12-20 20:39 Michał Górny
2024-12-20 20:39 Michał Górny
2024-12-09 18:49 Ulrich Müller
2024-09-19 4:13 Sam James
2024-09-18 15:51 Sam James
2024-09-18 15:51 Sam James
2024-08-07 8:58 Andrew Ammerlaan
2024-08-07 8:58 Andrew Ammerlaan
2024-08-06 8:47 Michał Górny
2024-08-06 8:47 Michał Górny
2024-07-29 17:02 Michał Górny
2024-07-28 9:32 Ulrich Müller
2024-06-13 19:53 Ulrich Müller
2024-06-13 19:53 Ulrich Müller
2024-06-13 18:35 Ulrich Müller
2024-06-13 18:35 Ulrich Müller
2024-06-12 16:47 Ulrich Müller
2024-06-12 15:35 Michał Górny
2024-06-12 15:32 Ulrich Müller
2024-06-12 9:47 Ulrich Müller
2024-05-25 8:24 Ulrich Müller
2023-11-03 19:00 Michał Górny
2023-09-14 5:30 Michał Górny
2023-06-18 14:57 Michał Górny
2023-06-17 10:10 Michał Górny
2023-06-15 12:19 Michał Górny
2023-05-23 4:36 Michał Górny
2023-05-01 13:43 Sam James
2023-04-20 23:14 Sam James
2022-12-14 10:18 Michał Górny
2022-10-28 8:24 Michał Górny
2022-10-15 17:35 Mike Gilbert
2022-10-10 20:52 Michał Górny
2022-10-01 17:19 Michał Górny
2022-10-01 17:19 Michał Górny
2022-05-09 20:33 Michał Górny
2022-05-09 20:33 Michał Górny
2022-04-21 15:19 Michał Górny
2022-04-19 21:32 Mike Gilbert
2022-02-14 21:13 Mike Gilbert
2022-02-14 17:25 Mike Gilbert
2021-12-31 9:10 Michał Górny
2021-12-31 9:10 Michał Górny
2021-12-31 9:10 Michał Górny
2021-06-22 20:44 David Seifert
2021-05-12 20:55 Mike Gilbert
2021-05-12 19:39 Michał Górny
2021-05-05 18:20 Michał Górny
2021-03-28 11:48 Michał Górny
2020-11-23 18:11 Ulrich Müller
2020-07-02 8:29 Michał Górny
2020-07-02 8:29 Michał Górny
2020-07-02 8:29 Michał Górny
2020-07-02 8:29 Michał Górny
2020-06-19 11:52 Michał Górny
2020-05-28 11:41 Michał Górny
2020-05-10 1:02 Sergei Trofimovich
2020-04-30 9:45 Michał Górny
2020-04-19 16:47 Michał Górny
2020-03-30 13:11 Michał Górny
2020-03-30 11:57 Michał Górny
2020-03-27 23:54 Sergei Trofimovich
2020-02-27 16:29 Michał Górny
2020-02-09 18:09 Michał Górny
2019-12-23 11:47 Sergei Trofimovich
2019-12-13 22:37 Sergei Trofimovich
2019-12-07 16:59 Michał Górny
2019-12-01 11:29 Sergei Trofimovich
2019-11-24 15:09 Michał Górny
2019-11-20 20:30 Sergei Trofimovich
2019-11-20 19:51 Sergei Trofimovich
2019-11-20 9:23 Michał Górny
2019-11-20 9:16 Michał Górny
2019-11-20 9:15 Michał Górny
2019-11-20 9:00 Michał Górny
2019-11-20 9:00 Michał Górny
2019-11-20 9:00 Michał Górny
2019-11-20 8:46 Michał Górny
2019-11-20 8:46 Michał Górny
2019-11-20 8:46 Michał Górny
2019-11-20 7:47 Michał Górny
2019-11-06 22:44 Sergei Trofimovich
2018-12-09 20:32 Sergei Trofimovich
2018-12-09 20:32 Sergei Trofimovich
2018-12-09 20:32 Sergei Trofimovich
2017-09-19 13:15 Michał Górny
2017-09-14 19:05 Mike Gilbert
2017-08-08 19:42 Michał Górny
2017-04-14 16:28 Michał Górny
2017-03-08 7:35 Michał Górny
2016-06-27 5:58 Michał Górny
2016-01-08 5:14 Michał Górny
2015-12-09 20:42 Michał Górny
2015-11-21 19:58 Ulrich Müller
2015-11-12 16:03 Michał Górny
2015-11-11 10:27 Michał Górny
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1664310475.9f8718d9175ede151365ae0472bfc25e0e7e451f.mgorny@gentoo \
--to=mgorny@gentoo.org \
--cc=gentoo-commits@lists.gentoo.org \
--cc=gentoo-dev@lists.gentoo.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox