forked from rurban/smhasher
-
Notifications
You must be signed in to change notification settings - Fork 10
/
checkdoctests.pl
executable file
·63 lines (60 loc) · 1.66 KB
/
checkdoctests.pl
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
#!/usr/bin/perl
use strict;
use File::Copy 'mv';
my $endtest = qr(^(?:---|\[\[\[ |Input vcode 0x));
# mkdir partests; build/SMHasher --list|perl -alne'print $F[0] | parallel -j4 --bar 'build/SMHasher --test=Sparse,Permutation,Cyclic,TwoBytes,DiffDist,Text,Zeroes,Seed,Sanity,Avalanche,BIC,LongNeighbors,Diff,MomentChi2 {} >partests/{}'
my @keysettests = qw(Sparse Permutation Cyclic TwoBytes Window Text Zeroes Seed);
my @othertests = qw(Sanity Speed Hashmap Avalanche Diff DiffDist BIC LongNeighbors MomentChi2);
my %tests = map {$_ => 1} @keysettests, @othertests;
my $testrx = '(' . join('|',@othertests) . ')';
$testrx = qr($testrx);
delete $tests{LongNeighbors}; # invalid license
if (@ARGV) {
readf($_) for @ARGV;
} else {
readf($_) for <doc/*>;
}
sub readf {
my $fn = shift;
my ($n,%r);
open(my $l, "<", $fn) or die "open $fn $!";
while (<$l>) {
if (/^--- Testing ([\w_-]+) \"/) {
#if ($n) { # fixup previous name
# check($n,\%r,$fn) if %r;
#}
$n = $1;
}
NEXT:
if (/^\[\[\[ Keyset '(.+?)' Tests/) {
my $t = $1;
while (<$l>) {
goto NEXT if $_ =~ $endtest;
$r{$t} .= $_;
}
}
if (/^\[\[\[ '?$testrx'? /) {
my $t = $1;
while (<$l>) {
goto NEXT if $_ =~ $endtest;
$r{$t} .= $_;
}
}
}
check($n,\%r,$fn) if $n; # fixup last name
}
sub check {
my ($n,$r,$fn) = @_;
return unless $n;
my @keys = sort keys %$r;
my @tests = sort keys %tests;
my @t;
if (@keys != @tests) {
print "# missing tests in $fn for $n:\n";
print "SMHasher --test=";
for (@tests) {
push @t, $_ unless $r->{$_};
}
print join(',',@t)," $n >>doc/$n\n";
}
}