New withlist item: [[!meta redir]] -- tell what's going on
[ikiwiki.git] / t / bazaar.t
blob2ca44a65e084ce1395855ae177f4fa8632ba3e5c
1 #!/usr/bin/perl
2 use warnings;
3 use strict;
4 my $dir;
5 BEGIN {
6 $dir = "/tmp/ikiwiki-test-bzr.$$";
7 my $bzr=`which bzr`;
8 chomp $bzr;
9 if (! -x $bzr || ! mkdir($dir)) {
10 eval q{
11 use Test::More skip_all => "bzr not available or could not make test dir"
15 use Test::More tests => 16;
17 BEGIN { use_ok("IkiWiki"); }
19 %config=IkiWiki::defaultconfig();
20 $config{rcs} = "bzr";
21 $config{srcdir} = "$dir/repo";
22 IkiWiki::loadplugins();
23 IkiWiki::checkconfig();
25 system "bzr init $config{srcdir}";
27 # Web commit
28 my $test1 = readfile("t/test1.mdwn");
29 writefile('test1.mdwn', $config{srcdir}, $test1);
30 IkiWiki::rcs_add("test1.mdwn");
31 IkiWiki::rcs_commit("test1.mdwn", "Added the first page", "moo", "Joe User");
33 my @changes;
34 @changes = IkiWiki::rcs_recentchanges(3);
36 is($#changes, 0);
37 is($changes[0]{message}[0]{"line"}, "Added the first page");
38 is($changes[0]{pages}[0]{"page"}, "test1");
39 is($changes[0]{user}, "Joe User");
41 # Manual commit
42 my $username = "Foo Bar";
43 my $user = "$username <foo.bar\@example.com>";
44 my $message = "Added the second page";
46 my $test2 = readfile("t/test2.mdwn");
47 writefile('test2.mdwn', $config{srcdir}, $test2);
48 system "bzr add --quiet $config{srcdir}/test2.mdwn";
49 system "bzr commit --quiet --author \"$user\" -m \"$message\" $config{srcdir}";
51 @changes = IkiWiki::rcs_recentchanges(3);
53 is($#changes, 1);
54 is($changes[0]{message}[0]{"line"}, $message);
55 is($changes[0]{user}, $username);
56 is($changes[0]{pages}[0]{"page"}, "test2");
58 is($changes[1]{pages}[0]{"page"}, "test1");
60 my $ctime = IkiWiki::rcs_getctime("test2.mdwn");
61 ok($ctime >= time() - 20);
63 writefile('test3.mdwn', $config{srcdir}, $test1);
64 IkiWiki::rcs_add("test3.mdwn");
65 IkiWiki::rcs_rename("test3.mdwn", "test4.mdwn");
66 IkiWiki::rcs_commit_staged("Added the 4th page", "moo", "Joe User");
68 @changes = IkiWiki::rcs_recentchanges(4);
70 is($#changes, 2);
71 is($changes[0]{pages}[0]{"page"}, "test4");
73 ok(mkdir($config{srcdir}."/newdir"));
74 IkiWiki::rcs_rename("test4.mdwn", "newdir/test5.mdwn");
75 IkiWiki::rcs_commit_staged("Added the 5th page", "moo", "Joe User");
77 @changes = IkiWiki::rcs_recentchanges(4);
79 is($#changes, 3);
80 is($changes[0]{pages}[0]{"page"}, "newdir/test5");
82 IkiWiki::rcs_remove("newdir/test5.mdwn");
83 IkiWiki::rcs_commit_staged("Remove the 5th page", "moo", "Joe User");
85 system "rm -rf $dir";