summaryrefslogtreecommitdiff
path: root/t/cvs.t
blob: 2808973be55a1819c65d2178cab3cf5e76841872 (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("test1.mdwn", "Added the first page", "moo");
  45. my @changes;
  46. @changes = IkiWiki::rcs_recentchanges(3);
  47. is($#changes, 0);
  48. is($changes[0]{message}[0]{"line"}, "Added the first page");
  49. is($changes[0]{pages}[0]{"page"}, "test1");
  50. # Manual commit
  51. my $message = "Added the second page";
  52. my $test2 = readfile("t/test2.mdwn");
  53. writefile('test2.mdwn', $config{srcdir}, $test2);
  54. system "cd $config{srcdir} && cvs add test2.mdwn >/dev/null 2>&1";
  55. system "cd $config{srcdir} && cvs commit -m \"$message\" test2.mdwn >/dev/null";
  56. @changes = IkiWiki::rcs_recentchanges(3);
  57. is($#changes, 1);
  58. is($changes[0]{message}[0]{"line"}, $message);
  59. is($changes[0]{pages}[0]{"page"}, "test2");
  60. is($changes[1]{pages}[0]{"page"}, "test1");
  61. # extra slashes in the path shouldn't break things
  62. $config{cvspath} = "/ikiwiki//";
  63. IkiWiki::checkconfig();
  64. @changes = IkiWiki::rcs_recentchanges(3);
  65. is($#changes, 1);
  66. is($changes[0]{message}[0]{"line"}, $message);
  67. is($changes[0]{pages}[0]{"page"}, "test2");
  68. is($changes[1]{pages}[0]{"page"}, "test1");
  69. system "rm -rf $dir";