summaryrefslogtreecommitdiffstats
path: root/scripts/t/Dpkg_Path.t
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-06 00:45:20 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-06 00:45:20 +0000
commit9a08cbfcc1ef900a04580f35afe2a4592d7d6030 (patch)
tree004cc7027bca2f2c0bcb5806527c8e0c48df2d6e /scripts/t/Dpkg_Path.t
parentInitial commit. (diff)
downloaddpkg-56b3e277e23b0b6313500e1e330e80b5ab6e6522.tar.xz
dpkg-56b3e277e23b0b6313500e1e330e80b5ab6e6522.zip
Adding upstream version 1.19.8.upstream/1.19.8upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'scripts/t/Dpkg_Path.t')
-rw-r--r--scripts/t/Dpkg_Path.t60
1 files changed, 60 insertions, 0 deletions
diff --git a/scripts/t/Dpkg_Path.t b/scripts/t/Dpkg_Path.t
new file mode 100644
index 0000000..fbf883d
--- /dev/null
+++ b/scripts/t/Dpkg_Path.t
@@ -0,0 +1,60 @@
+#!/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 tests => 16;
+use Test::Dpkg qw(:paths);
+
+use_ok('Dpkg::Path', 'canonpath', 'resolve_symlink',
+ 'check_files_are_the_same', 'get_pkg_root_dir',
+ 'guess_pkg_root_dir', 'relative_to_pkg_root');
+
+my $tmpdir = test_get_temp_path();
+
+mkdir "$tmpdir/a";
+mkdir "$tmpdir/a/b";
+mkdir "$tmpdir/a/b/c";
+mkdir "$tmpdir/a/DEBIAN";
+mkdir "$tmpdir/debian";
+mkdir "$tmpdir/debian/a";
+mkdir "$tmpdir/debian/a/b";
+mkdir "$tmpdir/debian/a/b/c";
+symlink 'a/b/c', "$tmpdir/cbis";
+symlink '/this/does/not/exist', "$tmpdir/tmp";
+symlink '.', "$tmpdir/here";
+
+is(canonpath("$tmpdir/./a///b/c"), "$tmpdir/a/b/c", 'canonpath basic test');
+is(canonpath("$tmpdir/a/b/../../a/b/c"), "$tmpdir/a/b/c", 'canonpath and ..');
+is(canonpath("$tmpdir/a/b/c/../../"), "$tmpdir/a", 'canonpath .. at end');
+is(canonpath("$tmpdir/cbis/../"), "$tmpdir/cbis/..", 'canonpath .. after symlink');
+
+is(resolve_symlink("$tmpdir/here/cbis"), "$tmpdir/here/a/b/c", 'resolve_symlink');
+is(resolve_symlink("$tmpdir/tmp"), '/this/does/not/exist', 'resolve_symlink absolute');
+is(resolve_symlink("$tmpdir/here"), $tmpdir, 'resolve_symlink .');
+
+ok(!check_files_are_the_same("$tmpdir/here", $tmpdir), 'Symlink is not the same!');
+ok(check_files_are_the_same("$tmpdir/here/a", "$tmpdir/a"), 'Same directory');
+
+is(get_pkg_root_dir("$tmpdir/a/b/c"), "$tmpdir/a", 'get_pkg_root_dir');
+is(guess_pkg_root_dir("$tmpdir/a/b/c"), "$tmpdir/a", 'guess_pkg_root_dir');
+is(relative_to_pkg_root("$tmpdir/a/b/c"), 'b/c', 'relative_to_pkg_root');
+
+chdir($tmpdir);
+
+is(get_pkg_root_dir('debian/a/b/c'), undef, 'get_pkg_root_dir undef');
+is(relative_to_pkg_root('debian/a/b/c'), undef, 'relative_to_pkg_root undef');
+is(guess_pkg_root_dir('debian/a/b/c'), 'debian/a', 'guess_pkg_root_dir fallback');