-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest-overview
executable file
·71 lines (62 loc) · 2.09 KB
/
test-overview
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
#!/usr/bin/perl
# test-overview: generate a Markdown overview of results of a blackbox test data file
use Modern::Perl qw(2013);
use utf8;
use Carp qw(croak);
use Readonly;
use FindBin;
use File::Basename;
use IPC::Run qw(run);
# constants
Readonly::Array my @methods => qw(Core STV Schulze RankedPairs);
Readonly::Scalar my $pvroot => dirname($FindBin::RealBin);
Readonly::Scalar my $count_script => "$pvroot/lab/perl/prefvote/bin/vote-count";
Readonly::Scalar my $acr_compare_script => "$pvroot/test/acr-compare";
Readonly::Array my @yaml_suffixes => qw(.yaml .yml);
Readonly::Scalar my $markdown_suffix => ".md";
# process test data file into a Markdown overview
sub process_test_file
{
my $yaml_file = shift;
# open Markdown overview file for output
my($filename, $dirs, $suffix) = fileparse($yaml_file, @yaml_suffixes);
#say "filename=$filename dirs=$dirs suffix=$suffix";
my $outfile = $dirs.$filename.$markdown_suffix;
if (-f $outfile) {
croak "$0: file exists: $outfile";
}
open (my $out_fh, ">", $outfile)
or croak "$0: failed to open $outfile for writing: $!";
# generate title
say $out_fh "# Black-box test data overview for [$filename$suffix]($filename$suffix)";
say $out_fh "";
# summary table
my $summary_text;
my @s_cmd = ($acr_compare_script, "--html", $yaml_file);
run \@s_cmd, \undef, \$summary_text;
say $out_fh "<blockquote>";
say $out_fh $summary_text;
say $out_fh "</blockquote>";
say $out_fh "";
# results for each voting method
foreach my $method (@methods) {
my $results_text;
my @r_cmd = ($count_script, "--format=html", "--method=$method", $yaml_file);
say $out_fh "## Results for $method method";
say $out_fh "<blockquote>";
run \@r_cmd, \undef, \$results_text;
say $out_fh $results_text;
say $out_fh "</blockquote>";
say $out_fh "";
}
close $out_fh;
}
# main
if (scalar @ARGV == 0) {
say "usage: $0 file [...]";
exit 0;
}
my @yaml_files = @ARGV;
foreach my $yaml_file (@yaml_files) {
process_test_file($yaml_file);
}