This is an automated email from the git hooks/post-receive script. guillem pushed a commit to branch main in repository dpkg.
View the commit online: https://git.dpkg.org/cgit/dpkg/dpkg.git/commit/?id=12574b49f1211497aaf6ffd69fa2babd1ed3ca5c commit 12574b49f1211497aaf6ffd69fa2babd1ed3ca5c Author: Guillem Jover <guil...@debian.org> AuthorDate: Fri Dec 17 04:30:40 2021 +0100 test: Rewrite dpkg-realpath test from TAP to autotest This is more naturally implemented via an autotest, instead of a TAP test, as it needs to drive an external command and compare its output. --- src/Makefile.am | 2 +- src/at/atlocal.in | 3 ++ src/at/local.at | 2 + src/at/realpath.at | 86 ++++++++++++++++++++++++++++++++++ src/at/testsuite.at | 4 ++ src/t/dpkg_realpath.t | 127 -------------------------------------------------- 6 files changed, 96 insertions(+), 128 deletions(-) diff --git a/src/Makefile.am b/src/Makefile.am index a3cf09ae9..ed4e910cc 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -153,7 +153,6 @@ test_tmpdir = t.tmp test_scripts = \ t/dpkg_divert.t \ - t/dpkg_realpath.t \ # EOL EXTRA_DIST += $(test_scripts) @@ -169,6 +168,7 @@ TESTSUITE_AT += $(srcdir)/at/deb-format.at TESTSUITE_AT += $(srcdir)/at/deb-fields.at TESTSUITE_AT += $(srcdir)/at/deb-content.at TESTSUITE_AT += $(srcdir)/at/deb-split.at +TESTSUITE_AT += $(srcdir)/at/realpath.at EXTRA_DIST += $(TESTSUITE_AT) TESTSUITE = $(srcdir)/at/testsuite diff --git a/src/at/atlocal.in b/src/at/atlocal.in index f2e30f014..9e5451db7 100644 --- a/src/at/atlocal.in +++ b/src/at/atlocal.in @@ -18,9 +18,12 @@ export TZ SOURCE_DATE_EPOCH=0 export SOURCE_DATE_EPOCH +export DPKG_DATADIR="@abs_top_srcdir@/src" + # Cleanup variables that might affect the tests. unset GZIP unset BZIP unset XZ_OPT unset XZ_DEFAULTS +unset DPKG_ROOT diff --git a/src/at/local.at b/src/at/local.at index af6e8d81e..b1a8b4487 100644 --- a/src/at/local.at +++ b/src/at/local.at @@ -1,6 +1,8 @@ # Dpkg helper macros m4_pattern_forbid([^DPKG_]) +m4_pattern_allow([^DPKG_ROOT$]) +m4_pattern_allow([^DPKG_DATADIR$]) # DPKG_TMPL_CONTROL([$pkgname]) m4_define([DPKG_TMPL_CONTROL], diff --git a/src/at/realpath.at b/src/at/realpath.at new file mode 100644 index 000000000..2919c3eb0 --- /dev/null +++ b/src/at/realpath.at @@ -0,0 +1,86 @@ +AT_SETUP([dpkg-realpath options]) +AT_KEYWORDS([dpkg-realpath command-line]) + +AT_CHECK([dpkg-realpath --version], [], [ignore]) +AT_CHECK([dpkg-realpath --help], [], [ignore]) + +AT_CLEANUP + +AT_SETUP([dpkg-realpath path resolving]) +AT_KEYWORDS([dpkg-realpath canonicalize]) + +mkdir -p aa/bb/cc +mkdir -p zz/yy/xx +mkdir -p usr/bin +AT_DATA([aa/bb/cc/file], []) +ln -sfT aa/bb/cc/file zz/yy/xx/symlink-rel +ln -sfT /aa/bb/cc/file zz/yy/xx/symlink-abs +AT_DATA([usr/bin/a-shell], []) +ln -sfT /usr/bin/a-shell usr/bin/sh + +tmpdir="$(pwd)" +export DPKG_ROOT= + +# Relative paths +AT_CHECK_UNQUOTED([dpkg-realpath aa/bb/cc], [], +[$tmpdir/aa/bb/cc +]) +AT_CHECK_UNQUOTED([dpkg-realpath zz/yy/xx], [], [$tmpdir/zz/yy/xx +]) +AT_CHECK_UNQUOTED([dpkg-realpath usr/bin], [], [$tmpdir/usr/bin +]) +AT_CHECK_UNQUOTED([dpkg-realpath aa/bb/cc/file], [], [$tmpdir/aa/bb/cc/file +]) +AT_CHECK_UNQUOTED([dpkg-realpath zz/yy/xx/symlink-rel], [], +[$tmpdir/zz/yy/xx/aa/bb/cc/file +]) +AT_CHECK([dpkg-realpath zz/yy/xx/symlink-abs], [], [/aa/bb/cc/file +]) +AT_CHECK_UNQUOTED([dpkg-realpath usr/bin/a-shell], [], +[$tmpdir/usr/bin/a-shell +]) +AT_CHECK([dpkg-realpath usr/bin/sh], [], [/usr/bin/a-shell +]) + +# Absolute paths +cd / +AT_CHECK_UNQUOTED([dpkg-realpath "$tmpdir/aa/bb/cc"], [], [$tmpdir/aa/bb/cc +]) +AT_CHECK_UNQUOTED([dpkg-realpath "$tmpdir/zz/yy/xx"], [], [$tmpdir/zz/yy/xx +]) +AT_CHECK_UNQUOTED([dpkg-realpath "$tmpdir/usr/bin"], [], [$tmpdir/usr/bin +]) +AT_CHECK_UNQUOTED([dpkg-realpath "$tmpdir/aa/bb/cc/file"], [], +[$tmpdir/aa/bb/cc/file +]) +AT_CHECK_UNQUOTED([dpkg-realpath "$tmpdir/zz/yy/xx/symlink-rel"], [], +[$tmpdir/zz/yy/xx/aa/bb/cc/file +]) +AT_CHECK([dpkg-realpath "$tmpdir/zz/yy/xx/symlink-abs"], [], [/aa/bb/cc/file +]) +AT_CHECK_UNQUOTED([dpkg-realpath "$tmpdir/usr/bin/a-shell"], [], +[$tmpdir/usr/bin/a-shell +]) +AT_CHECK([dpkg-realpath "$tmpdir/usr/bin/sh"], [], [/usr/bin/a-shell +]) + +# Chrooted paths +DPKG_ROOT="$tmpdir" +AT_CHECK([dpkg-realpath /aa/bb/cc], [], [/aa/bb/cc +]) +AT_CHECK([dpkg-realpath /zz/yy/xx], [], [/zz/yy/xx +]) +AT_CHECK([dpkg-realpath /usr/bin], [], [/usr/bin +]) +AT_CHECK([dpkg-realpath /aa/bb/cc/file], [], [/aa/bb/cc/file +]) +AT_CHECK([dpkg-realpath /zz/yy/xx/symlink-rel], [], [/zz/yy/xx/aa/bb/cc/file +]) +AT_CHECK([dpkg-realpath /zz/yy/xx/symlink-abs], [], [/aa/bb/cc/file +]) +AT_CHECK([dpkg-realpath /usr/bin/a-shell], [], [/usr/bin/a-shell +]) +AT_CHECK([dpkg-realpath /usr/bin/sh], [], [/usr/bin/a-shell +]) + +AT_CLEANUP diff --git a/src/at/testsuite.at b/src/at/testsuite.at index 04edff580..ee89e6afd 100644 --- a/src/at/testsuite.at +++ b/src/at/testsuite.at @@ -10,3 +10,7 @@ m4_include([deb-fields.at]) AT_TESTED([dpkg-split]) AT_BANNER([Split .deb packages]) m4_include([deb-split.at]) + +AT_TESTED([dpkg-realpath]) +AT_BANNER([Resolve pathnames]) +m4_include([realpath.at]) diff --git a/src/t/dpkg_realpath.t b/src/t/dpkg_realpath.t deleted file mode 100644 index a57202d38..000000000 --- a/src/t/dpkg_realpath.t +++ /dev/null @@ -1,127 +0,0 @@ -#!/usr/bin/perl -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see <https://www.gnu.org/licenses/>. - -use strict; -use warnings; - -use Test::More; -use Test::Dpkg qw(:paths); - -use Cwd; -use File::Spec::Functions qw(rel2abs); -use File::Path qw(make_path); - -use Dpkg::IPC; - -plan tests => 48; - -my $srcdir = rel2abs($ENV{srcdir} || '.'); -my $tmpdir = rel2abs(test_get_temp_path()); - -# Delete variables that can affect the tests. -delete $ENV{DPKG_ROOT}; - -sub gen_file -{ - my ($pathname) = @_; - - open my $fh, '>', $pathname or BAIL_OUT("cannot create file $pathname"); - close $fh; -} - -sub gen_hier -{ - my $curdir = getcwd(); - - chdir $tmpdir; - - make_path('aa/bb/cc'); - make_path('zz/yy/xx'); - make_path('usr/bin'); - - gen_file('aa/bb/cc/file'); - symlink('aa/bb/cc/file', 'zz/yy/xx/symlink-rel'); - symlink('/aa/bb/cc/file', 'zz/yy/xx/symlink-abs'); - gen_file('usr/bin/a-shell'); - symlink('/usr/bin/a-shell', 'usr/bin/sh'); - - chdir $curdir; -} - -sub test_realpath -{ - my ($pathname, $realpath, $root) = @_; - my ($stderr, $stdout); - $root //= q{}; - - spawn( - exec => [ $ENV{SHELL}, "$srcdir/dpkg-realpath.sh", $pathname ], - env => { - DPKG_ROOT => $root, - DPKG_DATADIR => rel2abs($srcdir), - }, - error_to_string => \$stderr, - to_string => \$stdout, - wait_child => 1, - nocheck => 1, - ); - - ok($? == 0, "dpkg-realpath $pathname succeeded"); - diag($stderr) unless $? == 0; - - chomp $stdout; - - is($stdout, $realpath, - "resolved realpath for $pathname matches $realpath with root='$root'"); -} - -gen_hier(); - -# Relative paths -my $curdir = getcwd(); -chdir $tmpdir; - -test_realpath('aa/bb/cc', "$tmpdir/aa/bb/cc"); -test_realpath('zz/yy/xx', "$tmpdir/zz/yy/xx"); -test_realpath('usr/bin', "$tmpdir/usr/bin"); -test_realpath('aa/bb/cc/file', "$tmpdir/aa/bb/cc/file"); -test_realpath('zz/yy/xx/symlink-rel', "$tmpdir/zz/yy/xx/aa/bb/cc/file"); -test_realpath('zz/yy/xx/symlink-abs', '/aa/bb/cc/file'); -test_realpath('usr/bin/a-shell', "$tmpdir/usr/bin/a-shell"); -test_realpath('usr/bin/sh', '/usr/bin/a-shell'); - -chdir $curdir; - -# Absolute paths -test_realpath("$tmpdir/aa/bb/cc", "$tmpdir/aa/bb/cc"); -test_realpath("$tmpdir/zz/yy/xx", "$tmpdir/zz/yy/xx"); -test_realpath("$tmpdir/usr/bin", "$tmpdir/usr/bin"); -test_realpath("$tmpdir/aa/bb/cc/file", "$tmpdir/aa/bb/cc/file"); -test_realpath("$tmpdir/zz/yy/xx/symlink-rel", "$tmpdir/zz/yy/xx/aa/bb/cc/file"); -test_realpath("$tmpdir/zz/yy/xx/symlink-abs", '/aa/bb/cc/file'); -test_realpath("$tmpdir/usr/bin/a-shell", "$tmpdir/usr/bin/a-shell"); -test_realpath("$tmpdir/usr/bin/sh", '/usr/bin/a-shell'); - -# Chrooted paths -test_realpath('/aa/bb/cc', '/aa/bb/cc', $tmpdir); -test_realpath('/zz/yy/xx', '/zz/yy/xx', $tmpdir); -test_realpath('/usr/bin', '/usr/bin', $tmpdir); -test_realpath('/aa/bb/cc/file', '/aa/bb/cc/file', $tmpdir); -test_realpath('/zz/yy/xx/symlink-rel', '/zz/yy/xx/aa/bb/cc/file', $tmpdir); -test_realpath('/zz/yy/xx/symlink-abs', '/aa/bb/cc/file', $tmpdir); -test_realpath('/usr/bin/a-shell', '/usr/bin/a-shell', $tmpdir); -test_realpath('/usr/bin/sh', '/usr/bin/a-shell', $tmpdir); - -1; -- Dpkg.Org's dpkg