summaryrefslogtreecommitdiff
path: root/t/svn.t
blob: 82b71b5fc1a404fc81159b6585c47997e9a4eb10 (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{svnrepo} = "$dir/repo";
  23. $config{svnpath} = "trunk";
  24. IkiWiki::loadplugins();
  25. IkiWiki::checkconfig();
  26. my $svnrepo = "$dir/repo";
  27. system "svnadmin create $svnrepo >/dev/null";
  28. system "svn mkdir file://$svnrepo/trunk -m add >/dev/null";
  29. system "svn co file://$svnrepo/trunk $config{srcdir} >/dev/null";
  30. # Web commit
  31. my $test1 = readfile("t/test1.mdwn");
  32. writefile('test1.mdwn', $config{srcdir}, $test1);
  33. IkiWiki::rcs_add("test1.mdwn");
  34. IkiWiki::rcs_commit(
  35. file => "test1.mdwn",
  36. message => "Added the first page",
  37. token => "moo",
  38. );
  39. my @changes;
  40. @changes = IkiWiki::rcs_recentchanges(3);
  41. is($#changes, 0);
  42. is($changes[0]{message}[0]{"line"}, "Added the first page");
  43. is($changes[0]{pages}[0]{"page"}, "test1");
  44. # Manual commit
  45. my $message = "Added the second page";
  46. my $test2 = readfile("t/test2.mdwn");
  47. writefile('test2.mdwn', $config{srcdir}, $test2);
  48. system "svn add $config{srcdir}/test2.mdwn >/dev/null";
  49. system "svn commit $config{srcdir}/test2.mdwn -m \"$message\" >/dev/null";
  50. @changes = IkiWiki::rcs_recentchanges(3);
  51. is($#changes, 1);
  52. is($changes[0]{message}[0]{"line"}, $message);
  53. is($changes[0]{pages}[0]{"page"}, "test2");
  54. is($changes[1]{pages}[0]{"page"}, "test1");
  55. # extra slashes in the path shouldn't break things
  56. $config{svnpath} = "/trunk//";
  57. IkiWiki::checkconfig();
  58. @changes = IkiWiki::rcs_recentchanges(3);
  59. is($#changes, 1);
  60. is($changes[0]{message}[0]{"line"}, $message);
  61. is($changes[0]{pages}[0]{"page"}, "test2");
  62. is($changes[1]{pages}[0]{"page"}, "test1");
  63. system "rm -rf $dir";