summaryrefslogtreecommitdiff
path: root/t/file_pruned.t
blob: 4335ed91704cf6bae56b9eb21c6153628a77867b (plain)
  1. #!/usr/bin/perl
  2. use warnings;
  3. use strict;
  4. use Test::More tests => 54;
  5. BEGIN { use_ok("IkiWiki"); }
  6. %config=IkiWiki::defaultconfig();
  7. ok(IkiWiki::file_pruned("src/.htaccess", "src"));
  8. ok(IkiWiki::file_pruned(".htaccess"));
  9. ok(IkiWiki::file_pruned("src/.ikiwiki/", "src"));
  10. ok(IkiWiki::file_pruned(".ikiwiki/"));
  11. ok(IkiWiki::file_pruned("src/.ikiwiki/index", "src"));
  12. ok(IkiWiki::file_pruned(".ikiwiki/index"));
  13. ok(IkiWiki::file_pruned("src/CVS/foo", "src"));
  14. ok(IkiWiki::file_pruned("CVS/foo"));
  15. ok(IkiWiki::file_pruned("src/subdir/CVS/foo", "src"));
  16. ok(IkiWiki::file_pruned("subdir/CVS/foo"));
  17. ok(IkiWiki::file_pruned("src/.svn", "src"));
  18. ok(IkiWiki::file_pruned(".svn"));
  19. ok(IkiWiki::file_pruned("src/subdir/.svn", "src"));
  20. ok(IkiWiki::file_pruned("subdir/.svn"));
  21. ok(IkiWiki::file_pruned("src/subdir/.svn/foo", "src"));
  22. ok(IkiWiki::file_pruned("subdir/.svn/foo"));
  23. ok(IkiWiki::file_pruned("src/.git", "src"));
  24. ok(IkiWiki::file_pruned(".git"));
  25. ok(IkiWiki::file_pruned("src/subdir/.git", "src"));
  26. ok(IkiWiki::file_pruned("subdir/.git"));
  27. ok(IkiWiki::file_pruned("src/subdir/.git/foo", "src"));
  28. ok(IkiWiki::file_pruned("subdir/.git/foo"));
  29. ok(! IkiWiki::file_pruned("src/svn/fo", "src"));
  30. ok(! IkiWiki::file_pruned("svn/fo"));
  31. ok(! IkiWiki::file_pruned("src/git", "src"));
  32. ok(! IkiWiki::file_pruned("git"));
  33. ok(! IkiWiki::file_pruned("src/index.mdwn", "src"));
  34. ok(! IkiWiki::file_pruned("index.mdwn"));
  35. ok(! IkiWiki::file_pruned("src/index.", "src"));
  36. ok(! IkiWiki::file_pruned("index."));
  37. # these are ok because while the filename starts with ".", the canonpathed
  38. # version does not
  39. ok(! IkiWiki::file_pruned("src/.", "src"));
  40. ok(! IkiWiki::file_pruned("src/./", "src"));
  41. # OTOH, without a srcdir, no canonpath, so they're not allowed.
  42. ok(IkiWiki::file_pruned("."));
  43. ok(IkiWiki::file_pruned("./"));
  44. # Without a srcdir, absolute filenames are not allowed.
  45. ok(IkiWiki::file_pruned("/etc/passwd"));
  46. ok(IkiWiki::file_pruned("//etc/passwd"));
  47. ok(IkiWiki::file_pruned("/"));
  48. ok(IkiWiki::file_pruned("//"));
  49. ok(IkiWiki::file_pruned("///"));
  50. ok(IkiWiki::file_pruned("src/..", "src"));
  51. ok(IkiWiki::file_pruned(".."));
  52. ok(IkiWiki::file_pruned("src/../", "src"));
  53. ok(IkiWiki::file_pruned("../"));
  54. ok(IkiWiki::file_pruned("src/../", "src"));
  55. ok(IkiWiki::file_pruned("../"));
  56. # This is perhaps counterintuitive.
  57. ok(! IkiWiki::file_pruned("src", "src"));
  58. # Dots, etc, in the srcdir are ok.
  59. ok(! IkiWiki::file_pruned("/.foo/src", "/.foo/src"));
  60. ok(IkiWiki::file_pruned("/.foo/src/.foo/src", "/.foo/src"));
  61. ok(! IkiWiki::file_pruned("/.foo/src/index.mdwn", "/.foo/src/index.mdwn"));
  62. ok(IkiWiki::file_pruned("src/y/foo.dpkg-tmp", "src"));
  63. ok(IkiWiki::file_pruned("y/foo.dpkg-tmp"));
  64. ok(IkiWiki::file_pruned("src/y/foo.ikiwiki-new", "src"));
  65. ok(IkiWiki::file_pruned("y/foo.ikiwiki-new"));