summaryrefslogtreecommitdiff
path: root/t/cvs.t
blob: 5ed377ed5e7234b369cc456d814e4ceefb51266c (plain)
  1. #!/usr/bin/perl
  2. use warnings;
  3. use strict;
  4. my $dir;
  5. BEGIN {
  6. $dir="/tmp/ikiwiki-test-cvs.$$";
  7. my $cvs=`which cvs`;
  8. chomp $cvs;
  9. my $cvsps=`which cvsps`;
  10. chomp $cvsps;
  11. if (! -x $cvs || ! -x $cvsps) {
  12. eval q{
  13. use Test::More skip_all => "cvs or cvsps not available"
  14. }
  15. }
  16. if (! mkdir($dir)) {
  17. die $@;
  18. }
  19. foreach my $module ('File::ReadBackwards', 'File::MimeInfo') {
  20. eval qq{use $module};
  21. if ($@) {
  22. eval qq{
  23. use Test::More skip_all => "$module not available"
  24. }
  25. }
  26. }
  27. }
  28. use Test::More tests => 12;
  29. BEGIN { use_ok("IkiWiki"); }
  30. %config=IkiWiki::defaultconfig();
  31. $config{rcs} = "cvs";
  32. $config{srcdir} = "$dir/src";
  33. $config{cvsrepo} = "$dir/repo";
  34. $config{cvspath} = "ikiwiki";
  35. IkiWiki::loadplugins();
  36. IkiWiki::checkconfig();
  37. my $cvsrepo = "$dir/repo";
  38. system "cvs -d $cvsrepo init >/dev/null";
  39. system "mkdir $dir/ikiwiki >/dev/null";
  40. system "cd $dir/ikiwiki && cvs -d $cvsrepo import -m import ikiwiki VENDOR RELEASE >/dev/null";
  41. system "rm -rf $dir/ikiwiki >/dev/null";
  42. system "cvs -d $cvsrepo co -d $config{srcdir} ikiwiki >/dev/null";
  43. # Web commit
  44. my $test1 = readfile("t/test1.mdwn");
  45. writefile('test1.mdwn', $config{srcdir}, $test1);
  46. IkiWiki::rcs_add("test1.mdwn");
  47. IkiWiki::rcs_commit(
  48. files => "test1.mdwn",
  49. message => "Added the first page",
  50. token => "moo"
  51. );
  52. my @changes;
  53. @changes = IkiWiki::rcs_recentchanges(3);
  54. is($#changes, 0);
  55. is($changes[0]{message}[0]{"line"}, "Added the first page");
  56. is($changes[0]{pages}[0]{"page"}, "test1");
  57. # Manual commit
  58. my $message = "Added the second page";
  59. my $test2 = readfile("t/test2.mdwn");
  60. writefile('test2.mdwn', $config{srcdir}, $test2);
  61. system "cd $config{srcdir} && cvs add test2.mdwn >/dev/null 2>&1";
  62. system "cd $config{srcdir} && cvs commit -m \"$message\" test2.mdwn >/dev/null";
  63. @changes = IkiWiki::rcs_recentchanges(3);
  64. is($#changes, 1);
  65. is($changes[0]{message}[0]{"line"}, $message);
  66. is($changes[0]{pages}[0]{"page"}, "test2");
  67. is($changes[1]{pages}[0]{"page"}, "test1");
  68. # extra slashes in the path shouldn't break things
  69. $config{cvspath} = "/ikiwiki//";
  70. IkiWiki::checkconfig();
  71. @changes = IkiWiki::rcs_recentchanges(3);
  72. is($#changes, 1);
  73. is($changes[0]{message}[0]{"line"}, $message);
  74. is($changes[0]{pages}[0]{"page"}, "test2");
  75. is($changes[1]{pages}[0]{"page"}, "test1");
  76. system "rm -rf $dir";