vcs-test.pl 10.4 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14
#!/usr/bin/perl -w

# Quick test harness for the VCS helper modules

use strict;
use Getopt::Long;
use Data::Dumper;
use Digest::MD5 'md5_hex';

# These modules reside under webwml/Perl
use lib ($0 =~ m|(.*)/|, $1 or ".") ."/Perl";
use Local::VCS;
use Webwml::TransCheck;
use Webwml::Langs;
15
use Cwd qw/cwd/;
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30

my $file = "english/CD/faq/index.wml";
my $rev1;
my $rev2;
my $rev3;
my $rev4;
if (-d "CVS") { 
    # Known working revs
    $rev1 = "1.138";
    $rev2 = "1.137";
    $rev3 = "1.136";
    # And one that doesn't exist
    $rev4 = "2.57768";
} else {
    # Known working revs
31 32 33
    $rev1 = "9e4da1d32463262f3e8d3d3bc1f36c64c318b666";
    $rev2 = "7d58ee1b5221c95a82f4a0a7932d0f8721c673fa";
    $rev3 = "caa8fae6f7a40cc9d2ddd6cbd62b1a9a4284352b";
34 35 36 37 38 39 40
    # And one that doesn't exist
    $rev4 = "5653875687436536574367564356874365783465";
}    
my $ret;

my $VCS = Local::VCS->new();
print "Initialising VCS cache for performance\n";
41 42

# Deliberately call these multiple times to validate
43 44 45 46
$VCS->cache_file($file);
$VCS->cache_file($file);
$VCS->cache_repo();
$VCS->cache_repo();
47
$VCS->cache_file($file);
48
$VCS->save_cache_to_database();
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
print " ... done!\n";

########
# Startup check - we depend on there being a change in $file above,
# for diff outputs to actually show something. Check if diff shows
# anything, and abort if not.
my %test_diff = $VCS->get_diff($file);
if (!$test_diff{$file}) {
    print "Need a diff to work with. Run the following and try again:\n";
    print "\n";
    print "echo foo >> $file\n";
    print "\n";
    die "ABORT\n";
}

########
# main
#
# Quickly check all the functionality we know about:
#  $VCS->cmp_rev
#  $VCS->count_changes
#  $VCS->path_info
#  $VCS->file_info
#  $VCS->get_log
#  $VCS->get_diff
#  $VCS->get_file
#  $VCS->get_oldest_revision 
#  $VCS->get_topdir 
##########################################################

##########################################################
print "#############################\n";
print "VCS->cmp_rev:::\n";
$ret = $VCS->cmp_rev($file, , ,);
if (!defined $ret) {
    $ret = "<undef>";
}
print "1. (no revs specified) returned $ret\n";
$ret = $VCS->cmp_rev("english/CD/faq/index.wml", $rev1, $rev1);
if (!defined $ret) {
    $ret = "<undef>";
}
print "2. (equal revs) returned $ret\n";
$ret = $VCS->cmp_rev("english/CD/faq/index.wml", $rev1, $rev2);
if (!defined $ret) {
    $ret = "<undef>";
}
print "3. (new, old) returned $ret\n";
$ret = $VCS->cmp_rev("english/CD/faq/index.wml", $rev2, $rev1);
if (!defined $ret) {
    $ret = "<undef>";
}
print "4. (old, new) returned $ret\n";

##########################################################
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
print "#############################\n";
print "VCS->cmp_rev::: from another directory\n";
my $startdir = cwd;
chdir "/tmp";
$ret = $VCS->cmp_rev("$startdir/$file", , ,);
if (!defined $ret) {
    $ret = "<undef>";
}
print "1. (no revs specified) returned $ret\n";
$ret = $VCS->cmp_rev("$startdir/english/../english/CD/faq/index.wml", $rev1, $rev1);
if (!defined $ret) {
    $ret = "<undef>";
}
print "2. (equal revs) returned $ret\n";
$ret = $VCS->cmp_rev("$startdir/english/CD/faq/index.wml", $rev1, $rev2);
if (!defined $ret) {
    $ret = "<undef>";
}
print "3. (new, old) returned $ret\n";
$ret = $VCS->cmp_rev("$startdir/english/CD/faq/index.wml", $rev2, $rev1);
if (!defined $ret) {
    $ret = "<undef>";
}
print "4. (old, new) returned $ret\n";
chdir "$startdir";

##########################################################
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342
print "#############################\n";
print "VCS->count_changes:::\n";
$ret = $VCS->count_changes("english/CD/faq/index.wml", , ,);
if (!defined $ret) {
    $ret = "<undef>";
}
print "1. (no revs specified) returned $ret\n";
$ret = $VCS->count_changes("english/CD/faq/index.wml", $rev1, $rev1);
if (!defined $ret) {
    $ret = "<undef>";
}
print "2. (equal revs) returned $ret\n";
$ret = $VCS->count_changes("english/CD/faq/index.wml", $rev1, $rev2);
if (!defined $ret) {
    $ret = "<undef>";
}
print "3. (new, old) returned $ret\n";
$ret = $VCS->count_changes("english/CD/faq/index.wml", $rev2, $rev1);
if (!defined $ret) {
    $ret = "<undef>";
}
print "4. (old, new) returned $ret\n";

##########################################################
my $srcdir = "english/MailingLists/desc";
print "#############################\n";
print "VCS->path_info on $srcdir :::\n";
my %revision_info = $VCS->path_info($srcdir, 'recursive' => 1);
my $i = 0;
foreach my $file (keys %revision_info) {
    print "$i: file $file:\n";
    print "    type: $revision_info{$file}{'type'}\n";
    print "    cmt_date: $revision_info{$file}{'cmt_date'}\n";
    print "    cmt_rev: $revision_info{$file}{'cmt_rev'}\n";
    $i++;
    if ($i > 2) {
	last;
    }
}
%revision_info = $VCS->path_info($srcdir, 'recursive' => 0);
$i = 0;
foreach my $file (keys %revision_info) {
    print "$i: file $file:\n";
    print "    type: $revision_info{$file}{'type'}\n";
    print "    cmt_date: $revision_info{$file}{'cmt_date'}\n";
    print "    cmt_rev: $revision_info{$file}{'cmt_rev'}\n";
    $i++;
    if ($i > 2) {
	last;
    }
}

##########################################################
print "#############################\n";
print "VCS->file_info on $file :::\n";
%revision_info = $VCS->file_info($file);
print "file $file:\n";
print "    type: $revision_info{'type'}\n";
print "    cmt_date: $revision_info{'cmt_date'}\n";
print "    cmt_rev: $revision_info{'cmt_rev'}\n";

sub print_log_info {
    my $file = shift;
    my $counter = shift;
    my $info = shift;
    my %tmp = %$info;
    print "$counter: file $file:\n";
    print "    rev: $tmp{'rev'}\n";
    print "    date: $tmp{'date'}\n";
    print "    author: $tmp{'author'}\n";
    print "    message: $tmp{'message'}\n";
}

##########################################################
print "#############################\n";
print "VCS->get_log on $file :::\n";
my @log_info;
my $num_logs;
print "1. full range of VCS->get_log on file $file :::\n";
@log_info = $VCS->get_log($file);
if (@log_info and defined($log_info[0])) {
    $num_logs = scalar(@log_info);
    print "   returns $num_logs log entries\n";
    $i = 0;
    foreach my $log (@log_info) {
	print_log_info($file, $i, $log);
	$i++;
	if ($i > 4) {
	    last;
	}
    }
} else {
    print "   returns no data\n";
}
print "2. single rev of VCS->get_log on $file :::\n";
@log_info = $VCS->get_log($file, $rev1);
if (@log_info and defined($log_info[0])) {
    $num_logs = scalar(@log_info);
    print "   returns $num_logs log entries\n";
    $i = 0;
    foreach my $log (@log_info) {
	print_log_info($file, $i, $log);
	$i++;
	if ($i > 4) {
	    last;
	}
    }
} else {
    print "   returns no data\n";
}
print "3. single rev of VCS->get_log on $file :::\n";
@log_info = $VCS->get_log($file, , $rev1);
if (@log_info and defined($log_info[0])) {
    $num_logs = scalar(@log_info);
    print "   returns $num_logs log entries\n";
    $i = 0;
    foreach my $log (@log_info) {
	print_log_info($file, $i, $log);
	$i++;
	if ($i > 4) {
	    last;
	}
    }
} else {
    print "   returns no data\n";
}
print "4. two revs of VCS->get_log on $file :::\n";
@log_info = $VCS->get_log($file, $rev3,$rev1);
if (@log_info and defined($log_info[0])) {
    $num_logs = scalar(@log_info);
    print "   returns $num_logs log entries\n";
    $i = 0;
    foreach my $log (@log_info) {
	print_log_info($file, $i, $log);
	$i++;
	if ($i > 4) {
	    last;
	}
    }
} else {
    print "   returns no data\n";
}
print "5. two revs reversed of VCS->get_log on $file :::\n";
@log_info = $VCS->get_log($file, $rev1,$rev3);
if (@log_info and defined($log_info[0])) {
    $num_logs = scalar(@log_info);
    print "   returns $num_logs log entries\n";
    $i = 0;
    foreach my $log (@log_info) {
	print_log_info($file, $i, $log);
	$i++;
	if ($i > 4) {
	    last;
	}
    }
} else {
    print "   returns no data\n";
}
@log_info = $VCS->get_log($file, $rev1,$rev3);
print "6. two revs if VCS->get_log on file, one non-existent on $file :::\n";
if (@log_info and defined($log_info[0])) {
    $num_logs = scalar(@log_info);
    print "   returns $num_logs log entries\n";
    $i = 0;
    foreach my $log (@log_info) {
	print_log_info($file, $i, $log);
	$i++;
	if ($i > 4) {
	    last;
	}
    }
} else {
    print "   returns no data\n";
}

##########################################################
print "#############################\n";
print "VCS->get_diff on $file :::\n";
my %diffs = $VCS->get_diff($file, $rev2, $rev1);
print "1. diff with two revs on $file:\n";
print "file: $file\n";
print "$diffs{$file}\n";
%diffs = $VCS->get_diff($file, $rev2);
print "2. diff with one older rev on $file:\n";
print "file: $file\n";
print "$diffs{$file}\n";
%diffs = $VCS->get_diff($file);
print "3. diff with no revs on $file:\n";
print "file: $file\n";
print "$diffs{$file}\n";

##########################################################
print "#############################\n";
print "VCS->get_file on $file :::\n";
$ret = $VCS->get_file($file, $rev2);
print "first 120 chars:\n";
print "#############################\n";
print substr $ret, 0, 120;
print "\n";
print "#############################\n";
my $digest = md5_hex($ret);
print "md5 = $digest\n";
if ($digest !~ /^\Q11cbcdde3c0121caaed105435adbf902\E$/) {
    print "FAIL: didn't get the expected checksum\n";
}

##########################################################
print "#############################\n";
print "VCS->get_oldest_revision on $file :::\n";
$ret = $VCS->get_oldest_revision($file);
print "Got \"$ret\"\n";

343 344 345 346 347 348
##########################################################
print "#############################\n";
print "VCS->get_newest_revision on $file :::\n";
$ret = $VCS->get_newest_revision($file);
print "Got \"$ret\"\n";

349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378
##########################################################
print "#############################\n";
print "VCS->next_revision (-1) on $file :::\n";
$ret = $VCS->next_revision($file, $rev1, -1);
print "Got \"$ret\", expecting \"$rev2\"\n";
if ($ret !~ m/$rev2/) {
    print "   FAIL\n";
}
print "VCS->next_revision (1) on $file :::\n";
$ret = $VCS->next_revision($file, $rev2, 1);
print "Got \"$ret\", expecting \"$rev1\"\n";
if ($ret !~ m/$rev1/) {
    print "   FAIL\n";
}

##########################################################
print "#############################\n";
print "VCS->get_topdir in topdir:::\n";
$ret = $VCS->get_topdir();
print "topdir is $ret\n";

chdir("english");
print "VCS->get_topdir in english:::\n";
$ret = $VCS->get_topdir();
print "topdir is $ret\n";

chdir("CD");
print "VCS->get_topdir in english/CD:::\n";
$ret = $VCS->get_topdir();
print "topdir is $ret\n";