500_Dpkg_Path.t 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. # -*- mode: cperl;-*-
  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 <http://www.gnu.org/licenses/>.
  15. use Test::More tests => 16;
  16. use strict;
  17. use warnings;
  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. mkdir "t.tmp/a";
  22. mkdir "t.tmp/a/b";
  23. mkdir "t.tmp/a/b/c";
  24. mkdir "t.tmp/a/DEBIAN";
  25. mkdir "t.tmp/debian";
  26. mkdir "t.tmp/debian/a";
  27. mkdir "t.tmp/debian/a/b";
  28. mkdir "t.tmp/debian/a/b/c";
  29. symlink "a/b/c", "t.tmp/cbis";
  30. symlink "/this/does/not/exist", "t.tmp/tmp";
  31. symlink ".", "t.tmp/here";
  32. is(canonpath("t.tmp/./a///b/c"), "t.tmp/a/b/c", "canonpath basic test");
  33. is(canonpath("t.tmp/a/b/../../a/b/c"), "t.tmp/a/b/c", "canonpath and ..");
  34. is(canonpath("t.tmp/a/b/c/../../"), "t.tmp/a", "canonpath .. at end");
  35. is(canonpath("t.tmp/cbis/../"), "t.tmp/cbis/..", "canonpath .. after symlink");
  36. is(resolve_symlink("t.tmp/here/cbis"), "t.tmp/here/a/b/c", "resolve_symlink");
  37. is(resolve_symlink("t.tmp/tmp"), "/this/does/not/exist", "resolve_symlink absolute");
  38. is(resolve_symlink("t.tmp/here"), "t.tmp", "resolve_symlink .");
  39. ok(!check_files_are_the_same("t.tmp/here", "t.tmp"), "Symlink is not the same!");
  40. ok(check_files_are_the_same("t.tmp/here/a", "t.tmp/a"), "Same directory");
  41. is(get_pkg_root_dir("t.tmp/a/b/c"), "t.tmp/a", "get_pkg_root_dir");
  42. is(guess_pkg_root_dir("t.tmp/a/b/c"), "t.tmp/a", "guess_pkg_root_dir");
  43. is(relative_to_pkg_root("t.tmp/a/b/c"), "b/c", "relative_to_pkg_root");
  44. chdir("t.tmp");
  45. ok(!defined(get_pkg_root_dir("debian/a/b/c")), "get_pkg_root_dir undef");
  46. ok(!defined(relative_to_pkg_root("debian/a/b/c")), "relative_to_pkg_root");
  47. is(guess_pkg_root_dir("debian/a/b/c"), "debian/a", "guess_pkg_root_dir fallback");