summaryrefslogtreecommitdiff
path: root/t/svn.t
blob: cce8452a66107dfb89c301200c22035087bf77de (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) {
  12. eval q{
  13. use Test::More skip_all => "svn or svnadmin not available"
  14. }
  15. }
  16. if (! mkdir($dir)) {
  17. die $@;
  18. }
  19. }
  20. use Test::More tests => 12;
  21. BEGIN { use_ok("IkiWiki"); }
  22. %config=IkiWiki::defaultconfig();
  23. $config{rcs} = "svn";
  24. $config{srcdir} = "$dir/src";
  25. $config{svnrepo} = "$dir/repo";
  26. $config{svnpath} = "trunk";
  27. IkiWiki::loadplugins();
  28. IkiWiki::checkconfig();
  29. my $svnrepo = "$dir/repo";
  30. system "svnadmin create $svnrepo >/dev/null";
  31. system "svn mkdir file://$svnrepo/trunk -m add >/dev/null";
  32. system "svn co file://$svnrepo/trunk $config{srcdir} >/dev/null";
  33. # Web commit
  34. my $test1 = readfile("t/test1.mdwn");
  35. writefile('test1.mdwn', $config{srcdir}, $test1);
  36. IkiWiki::rcs_add("test1.mdwn");
  37. IkiWiki::rcs_commit(
  38. file => "test1.mdwn",
  39. message => "Added the first page",
  40. token => "moo",
  41. );
  42. my @changes;
  43. @changes = IkiWiki::rcs_recentchanges(3);
  44. is($#changes, 0);
  45. is($changes[0]{message}[0]{"line"}, "Added the first page");
  46. is($changes[0]{pages}[0]{"page"}, "test1");
  47. # Manual commit
  48. my $message = "Added the second page";
  49. my $test2 = readfile("t/test2.mdwn");
  50. writefile('test2.mdwn', $config{srcdir}, $test2);
  51. system "svn add $config{srcdir}/test2.mdwn >/dev/null";
  52. system "svn commit $config{srcdir}/test2.mdwn -m \"$message\" >/dev/null";
  53. @changes = IkiWiki::rcs_recentchanges(3);
  54. is($#changes, 1);
  55. is($changes[0]{message}[0]{"line"}, $message);
  56. is($changes[0]{pages}[0]{"page"}, "test2");
  57. is($changes[1]{pages}[0]{"page"}, "test1");
  58. # extra slashes in the path shouldn't break things
  59. $config{svnpath} = "/trunk//";
  60. IkiWiki::checkconfig();
  61. @changes = IkiWiki::rcs_recentchanges(3);
  62. is($#changes, 1);
  63. is($changes[0]{message}[0]{"line"}, $message);
  64. is($changes[0]{pages}[0]{"page"}, "test2");
  65. is($changes[1]{pages}[0]{"page"}, "test1");
  66. system "rm -rf $dir";