500_Dpkg_Path.t 2.4 KB

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