3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 2 of the License, or
6 # (at your option) any later version.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program. If not, see <https://www.gnu.org/licenses/>.
19 use Test::More tests => 16;
21 use_ok('Dpkg::Path', 'canonpath', 'resolve_symlink',
22 'check_files_are_the_same', 'get_pkg_root_dir',
23 'guess_pkg_root_dir', 'relative_to_pkg_root');
25 my $tmpdir = 't.tmp/Dpkg_Path';
30 mkdir "$tmpdir/a/b/c";
31 mkdir "$tmpdir/a/DEBIAN";
32 mkdir "$tmpdir/debian";
33 mkdir "$tmpdir/debian/a";
34 mkdir "$tmpdir/debian/a/b";
35 mkdir "$tmpdir/debian/a/b/c";
36 symlink 'a/b/c', "$tmpdir/cbis";
37 symlink '/this/does/not/exist', "$tmpdir/tmp";
38 symlink '.', "$tmpdir/here";
40 is(canonpath("$tmpdir/./a///b/c"), "$tmpdir/a/b/c", 'canonpath basic test');
41 is(canonpath("$tmpdir/a/b/../../a/b/c"), "$tmpdir/a/b/c", 'canonpath and ..');
42 is(canonpath("$tmpdir/a/b/c/../../"), "$tmpdir/a", 'canonpath .. at end');
43 is(canonpath("$tmpdir/cbis/../"), "$tmpdir/cbis/..", 'canonpath .. after symlink');
45 is(resolve_symlink("$tmpdir/here/cbis"), "$tmpdir/here/a/b/c", 'resolve_symlink');
46 is(resolve_symlink("$tmpdir/tmp"), '/this/does/not/exist', 'resolve_symlink absolute');
47 is(resolve_symlink("$tmpdir/here"), $tmpdir, 'resolve_symlink .');
49 ok(!check_files_are_the_same("$tmpdir/here", $tmpdir), 'Symlink is not the same!');
50 ok(check_files_are_the_same("$tmpdir/here/a", "$tmpdir/a"), 'Same directory');
52 is(get_pkg_root_dir("$tmpdir/a/b/c"), "$tmpdir/a", 'get_pkg_root_dir');
53 is(guess_pkg_root_dir("$tmpdir/a/b/c"), "$tmpdir/a", 'guess_pkg_root_dir');
54 is(relative_to_pkg_root("$tmpdir/a/b/c"), 'b/c', 'relative_to_pkg_root');
58 is(get_pkg_root_dir('debian/a/b/c'), undef, 'get_pkg_root_dir undef');
59 is(relative_to_pkg_root('debian/a/b/c'), undef, 'relative_to_pkg_root undef');
60 is(guess_pkg_root_dir('debian/a/b/c'), 'debian/a', 'guess_pkg_root_dir fallback');