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