aboutsummaryrefslogtreecommitdiff
path: root/t/cvs.t
blob: af1786c650325efacc4197135a7299eb706bbcfb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#!/usr/bin/perl
use warnings;
use strict;
use Test::More;
use IkiWiki;

my %ideal_test_plan = (tests => 8);
my $dir;

sub _determine_test_plan {
	my $cvs=`which cvs`; chomp $cvs;
	my $cvsps=`which cvsps`; chomp $cvsps;
	return (skip_all => 'cvs or cvsps not available')
		unless -x $cvs && -x $cvsps;

	foreach my $module ('File::ReadBackwards', 'File::MimeInfo') {
		eval qq{use $module};
		if ($@) {
			return (skip_all => "$module not available");
		}
	}

	return %ideal_test_plan;
}

sub _startup {
	_mktempdir();
	_generate_minimal_config();
	_create_test_repo();
}

sub _shutdown {
	system "rm -rf $dir";
}

sub _mktempdir {
	$dir="/tmp/ikiwiki-test-cvs.$$";
	if (! mkdir($dir)) {
		die $@;
	}
}

sub _generate_minimal_config {
	%config=IkiWiki::defaultconfig();
	$config{rcs} = "cvs";
	$config{srcdir} = "$dir/src";
	$config{cvsrepo} = "$dir/repo";
	$config{cvspath} = "ikiwiki";
	IkiWiki::loadplugins();
	IkiWiki::checkconfig();
}

sub _create_test_repo {
	my $cvsrepo = "$dir/repo";

	system "cvs -d $cvsrepo init >/dev/null";
	system "mkdir $dir/ikiwiki >/dev/null";
	system "cd $dir/ikiwiki && cvs -d $cvsrepo import -m import ikiwiki VENDOR RELEASE >/dev/null";
	system "rm -rf $dir/ikiwiki >/dev/null";
	system "cvs -d $cvsrepo co -d $config{srcdir} ikiwiki >/dev/null";
}

sub test_web_add_and_commit {
	writefile('test1.mdwn', $config{srcdir}, readfile("t/test1.mdwn"));
	IkiWiki::rcs_add("test1.mdwn");
	my $message = "Added the first page";
	IkiWiki::rcs_commit(
		file => "test1.mdwn",
		message => $message,
		token => "moo",
	);

	my @changes = IkiWiki::rcs_recentchanges(3);
	is(
		$#changes,
		0,
		q{1 total commit},
	);
	is(
		$changes[0]{message}[0]{"line"},
		$message,
		q{first line of most recent commit message matches},
	);
	is(
		$changes[0]{pages}[0]{"page"},
		"test1",
		q{first pagename from most recent commit matches},
	);
}

sub test_manual_add_and_commit {
	writefile('test2.mdwn', $config{srcdir}, readfile("t/test2.mdwn"));
	system "cd $config{srcdir} && cvs add test2.mdwn >/dev/null 2>&1";
	my $message = "Added the second page";
	system "cd $config{srcdir} && cvs commit -m \"$message\" test2.mdwn >/dev/null";

	my @changes = IkiWiki::rcs_recentchanges(3);
	is(
		$#changes,
		1,
		q{2 total commits},
	);
	is(
		$changes[0]{message}[0]{"line"},
		$message,
		q{first line of most recent commit message matches},
	);
	is(
		$changes[0]{pages}[0]{"page"},
		"test2",
		q{first pagename from most recent commit matches},
	);
	is(
		$changes[1]{pages}[0]{"page"},
		"test1",
		q{first pagename from second-most-recent commit matches},
	);
}

sub test_extra_path_slashes {
	my $initial_cvspath = $config{cvspath};
	$config{cvspath} = "/ikiwiki//";
	IkiWiki::checkconfig();
	is(
		$config{cvspath},
		$initial_cvspath,
		q{rcs_recentchanges assumes checkconfig sanitizes cvspath},
	);
}

plan(_determine_test_plan());
_startup();
test_web_add_and_commit();
test_manual_add_and_commit();
test_extra_path_slashes();
_shutdown();