500_Dpkg_Path.t 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. # -*- mode: cperl;-*-
  2. use Test::More tests => 16;
  3. use strict;
  4. use warnings;
  5. use_ok('Dpkg::Path', 'canonpath', 'resolve_symlink',
  6. 'check_files_are_the_same', 'get_pkg_root_dir',
  7. 'guess_pkg_root_dir', 'relative_to_pkg_root');
  8. mkdir "t.tmp/a";
  9. mkdir "t.tmp/a/b";
  10. mkdir "t.tmp/a/b/c";
  11. mkdir "t.tmp/a/DEBIAN";
  12. mkdir "t.tmp/debian";
  13. mkdir "t.tmp/debian/a";
  14. mkdir "t.tmp/debian/a/b";
  15. mkdir "t.tmp/debian/a/b/c";
  16. symlink "a/b/c", "t.tmp/cbis";
  17. symlink "/this/does/not/exist", "t.tmp/tmp";
  18. symlink ".", "t.tmp/here";
  19. is(canonpath("t.tmp/./a///b/c"), "t.tmp/a/b/c", "canonpath basic test");
  20. is(canonpath("t.tmp/a/b/../../a/b/c"), "t.tmp/a/b/c", "canonpath and ..");
  21. is(canonpath("t.tmp/a/b/c/../../"), "t.tmp/a", "canonpath .. at end");
  22. is(canonpath("t.tmp/cbis/../"), "t.tmp/cbis/..", "canonpath .. after symlink");
  23. is(resolve_symlink("t.tmp/here/cbis"), "t.tmp/here/a/b/c", "resolve_symlink");
  24. is(resolve_symlink("t.tmp/tmp"), "/this/does/not/exist", "resolve_symlink absolute");
  25. is(resolve_symlink("t.tmp/here"), "t.tmp", "resolve_symlink .");
  26. ok(!check_files_are_the_same("t.tmp/here", "t.tmp"), "Symlink is not the same!");
  27. ok(check_files_are_the_same("t.tmp/here/a", "t.tmp/a"), "Same directory");
  28. is(get_pkg_root_dir("t.tmp/a/b/c"), "t.tmp/a", "get_pkg_root_dir");
  29. is(guess_pkg_root_dir("t.tmp/a/b/c"), "t.tmp/a", "guess_pkg_root_dir");
  30. is(relative_to_pkg_root("t.tmp/a/b/c"), "b/c", "relative_to_pkg_root");
  31. chdir("t.tmp");
  32. ok(!defined(get_pkg_root_dir("debian/a/b/c")), "get_pkg_root_dir undef");
  33. ok(!defined(relative_to_pkg_root("debian/a/b/c")), "relative_to_pkg_root");
  34. is(guess_pkg_root_dir("debian/a/b/c"), "debian/a", "guess_pkg_root_dir fallback");