summaryrefslogtreecommitdiff
path: root/t/svn.t
blob: 8a8282c73340b8f8095204f24031a3a7a14534c0 (plain)
  1. #!/usr/bin/perl
  2. use warnings;
  3. use strict;
  4. my $dir;
  5. BEGIN {
  6. $dir="/tmp/ikiwiki-test-svn.$$";
  7. my $svn=`which svn`;
  8. chomp $svn;
  9. my $svnadmin=`which svnadmin`;
  10. chomp $svnadmin;
  11. if (! -x $svn || ! -x $svnadmin || ! mkdir($dir)) {
  12. eval q{
  13. use Test::More skip_all => "svn not available or could not make test dir"
  14. }
  15. }
  16. }
  17. use Test::More tests => 12;
  18. BEGIN { use_ok("IkiWiki"); }
  19. %config=IkiWiki::defaultconfig();
  20. $config{rcs} = "svn";
  21. $config{srcdir} = "$dir/src";
  22. $config{svnpath} = "trunk";
  23. IkiWiki::checkconfig();
  24. my $svnrepo = "$dir/repo";
  25. system "svnadmin create $svnrepo >/dev/null";
  26. system "svn mkdir file://$svnrepo/trunk -m add >/dev/null";
  27. system "svn co file://$svnrepo/trunk $config{srcdir} >/dev/null";
  28. # Web commit
  29. my $test1 = readfile("t/test1.mdwn");
  30. writefile('test1.mdwn', $config{srcdir}, $test1);
  31. IkiWiki::rcs_add("test1.mdwn");
  32. IkiWiki::rcs_commit("test1.mdwn", "Added the first page", "moo");
  33. my @changes;
  34. @changes = IkiWiki::rcs_recentchanges(3);
  35. is($#changes, 0);
  36. is($changes[0]{message}[0]{"line"}, "Added the first page");
  37. is($changes[0]{pages}[0]{"page"}, "test1.mdwn");
  38. # Manual commit
  39. my $message = "Added the second page";
  40. my $test2 = readfile("t/test2.mdwn");
  41. writefile('test2.mdwn', $config{srcdir}, $test2);
  42. system "svn add $config{srcdir}/test2.mdwn >/dev/null";
  43. system "svn commit $config{srcdir}/test2.mdwn -m \"$message\" >/dev/null";
  44. @changes = IkiWiki::rcs_recentchanges(3);
  45. is($#changes, 1);
  46. is($changes[0]{message}[0]{"line"}, $message);
  47. is($changes[0]{pages}[0]{"page"}, "test2.mdwn");
  48. is($changes[1]{pages}[0]{"page"}, "test1.mdwn");
  49. # extra slashes in the path shouldn't break things
  50. $config{svnpath} = "/trunk//";
  51. IkiWiki::checkconfig();
  52. @changes = IkiWiki::rcs_recentchanges(3);
  53. is($#changes, 1);
  54. is($changes[0]{message}[0]{"line"}, $message);
  55. is($changes[0]{pages}[0]{"page"}, "test2.mdwn");
  56. is($changes[1]{pages}[0]{"page"}, "test1.mdwn");
  57. system "rm -rf $dir";