summaryrefslogtreecommitdiff
path: root/t/cvs.t
blob: c9caa94eb308041e0b78ff4d9eddfe86cb331f65 (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. }
  17. use Test::More tests => 12;
  18. BEGIN { use_ok("IkiWiki"); }
  19. %config=IkiWiki::defaultconfig();
  20. $config{rcs} = "cvs";
  21. $config{srcdir} = "$dir/src";
  22. $config{cvsrepo} = "$dir/repo";
  23. $config{cvspath} = "ikiwiki";
  24. IkiWiki::loadplugins();
  25. IkiWiki::checkconfig();
  26. my $cvsrepo = "$dir/repo";
  27. system "cvs -d $cvsrepo init >/dev/null";
  28. system "mkdir $dir/ikiwiki >/dev/null";
  29. system "cd $dir/ikiwiki && cvs -d $cvsrepo import -m import ikiwiki VENDOR RELEASE >/dev/null";
  30. system "rm -rf $dir/ikiwiki >/dev/null";
  31. system "cvs -d $cvsrepo co -d $config{srcdir} ikiwiki >/dev/null";
  32. # Web commit
  33. my $test1 = readfile("t/test1.mdwn");
  34. writefile('test1.mdwn', $config{srcdir}, $test1);
  35. IkiWiki::rcs_add("test1.mdwn");
  36. IkiWiki::rcs_commit("test1.mdwn", "Added the first page", "moo");
  37. my @changes;
  38. @changes = IkiWiki::rcs_recentchanges(3);
  39. is($#changes, 0);
  40. is($changes[0]{message}[0]{"line"}, "Added the first page");
  41. is($changes[0]{pages}[0]{"page"}, "test1");
  42. # Manual commit
  43. my $message = "Added the second page";
  44. my $test2 = readfile("t/test2.mdwn");
  45. writefile('test2.mdwn', $config{srcdir}, $test2);
  46. system "cd $config{srcdir} && cvs add test2.mdwn >/dev/null 2>&1";
  47. system "cd $config{srcdir} && cvs commit -m \"$message\" test2.mdwn >/dev/null";
  48. @changes = IkiWiki::rcs_recentchanges(3);
  49. is($#changes, 1);
  50. is($changes[0]{message}[0]{"line"}, $message);
  51. is($changes[0]{pages}[0]{"page"}, "test2");
  52. is($changes[1]{pages}[0]{"page"}, "test1");
  53. # extra slashes in the path shouldn't break things
  54. $config{cvspath} = "/ikiwiki//";
  55. IkiWiki::checkconfig();
  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. system "rm -rf $dir";