Dpkg_Path.t 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #!/usr/bin/perl
  2. #
  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.
  7. #
  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.
  12. #
  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/>.
  15. use strict;
  16. use warnings;
  17. use Test::More tests => 16;
  18. use_ok('Dpkg::Path', 'canonpath', 'resolve_symlink',
  19. 'check_files_are_the_same', 'get_pkg_root_dir',
  20. 'guess_pkg_root_dir', 'relative_to_pkg_root');
  21. my $tmpdir = 't.tmp/Dpkg_Path';
  22. mkdir $tmpdir;
  23. mkdir "$tmpdir/a";
  24. mkdir "$tmpdir/a/b";
  25. mkdir "$tmpdir/a/b/c";
  26. mkdir "$tmpdir/a/DEBIAN";
  27. mkdir "$tmpdir/debian";
  28. mkdir "$tmpdir/debian/a";
  29. mkdir "$tmpdir/debian/a/b";
  30. mkdir "$tmpdir/debian/a/b/c";
  31. symlink 'a/b/c', "$tmpdir/cbis";
  32. symlink '/this/does/not/exist', "$tmpdir/tmp";
  33. symlink '.', "$tmpdir/here";
  34. is(canonpath("$tmpdir/./a///b/c"), "$tmpdir/a/b/c", 'canonpath basic test');
  35. is(canonpath("$tmpdir/a/b/../../a/b/c"), "$tmpdir/a/b/c", 'canonpath and ..');
  36. is(canonpath("$tmpdir/a/b/c/../../"), "$tmpdir/a", 'canonpath .. at end');
  37. is(canonpath("$tmpdir/cbis/../"), "$tmpdir/cbis/..", 'canonpath .. after symlink');
  38. is(resolve_symlink("$tmpdir/here/cbis"), "$tmpdir/here/a/b/c", 'resolve_symlink');
  39. is(resolve_symlink("$tmpdir/tmp"), '/this/does/not/exist', 'resolve_symlink absolute');
  40. is(resolve_symlink("$tmpdir/here"), $tmpdir, 'resolve_symlink .');
  41. ok(!check_files_are_the_same("$tmpdir/here", $tmpdir), 'Symlink is not the same!');
  42. ok(check_files_are_the_same("$tmpdir/here/a", "$tmpdir/a"), 'Same directory');
  43. is(get_pkg_root_dir("$tmpdir/a/b/c"), "$tmpdir/a", 'get_pkg_root_dir');
  44. is(guess_pkg_root_dir("$tmpdir/a/b/c"), "$tmpdir/a", 'guess_pkg_root_dir');
  45. is(relative_to_pkg_root("$tmpdir/a/b/c"), 'b/c', 'relative_to_pkg_root');
  46. chdir($tmpdir);
  47. is(get_pkg_root_dir('debian/a/b/c'), undef, 'get_pkg_root_dir undef');
  48. is(relative_to_pkg_root('debian/a/b/c'), undef, 'relative_to_pkg_root undef');
  49. is(guess_pkg_root_dir('debian/a/b/c'), 'debian/a', 'guess_pkg_root_dir fallback');