File indexing completed on 2024-05-12 15:39:11
0001 #!/usr/bin/perl 0002 # 0003 # Copyright (C) 2009 Germain Garand <germain@ebooksfrance.org> 0004 # 0005 # This library is free software; you can redistribute it and/or 0006 # modify it under the terms of the GNU Library General Public 0007 # License as published by the Free Software Foundation; either 0008 # version 2 of the License, or (at your option) any later version. 0009 # 0010 # This library is distributed in the hope that it will be useful, 0011 # but WITHOUT ANY WARRANTY; without even the implied warranty of 0012 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0013 # Library General Public License for more details. 0014 # 0015 # You should have received a copy of the GNU Library General Public License 0016 # along with this library; see the file COPYING.LIB. If not, write to 0017 # the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0018 # Boston, MA 02110-1301, USA. 0019 0020 # v.0.31 0021 0022 use strict; 0023 0024 my %o; 0025 my $f; 0026 my @svn; 0027 my $svn; 0028 my $gen = "-g"; 0029 my %files; 0030 my $numch = 0; 0031 my %output = 0; 0032 0033 use Getopt::Std; 0034 getopts('xdrpsvVie:E:X', \%o) or die; 0035 0036 $ARGV[0] or die "validate [-drp] [-sv] links.html 0037 \tissue testregression file list (for testregression -g), and generated file list (for svn commit line). 0038 \t 0039 \tOptions: 0040 \t -d, r, p: only testcases containing any change among this combination of [DRP] changes are validated. 0041 \t\te.g. r -> [R] or [RP] 0042 \t -i: make specified changes a requirement : all changes among the combination must be present. 0043 \t\te.g. r -> [R], rp -> [RP] or [DRP] 0044 \t -x: make specified changes an exclusive requirement : all changes among the combination must be present, and no more. 0045 \t\te.g. rp -> [RP] 0046 \t 0047 \t -e <pcre>: only testcases which name matches (case insensitively) the provided regular expression are validated. 0048 \t -E <pcre>: exclude testcases which name matches (case insensitively) the provided regular expression. 0049 \t 0050 \tIf none of -d,-r,-p is specified, all changes are validated. 0051 \t 0052 \t -s: output corresponding baseline filelist for svn commit purpose (instead of the defaut testregression -g line) 0053 \t -V: together with -s, removes all files in filelist that do not really exist in the baseline (e.g. svnignore'd) 0054 \t 0055 \t -v: pretty print all selected changes on stderr and exit 0056 \t -X: output filtered links.html content on stdout (i.e. any test matched is removed from the output) and exit 0057 \t 0058 \tExample: 0059 \t validate -dr -i -s output/links.html 0060 \t\t will list all file changes that would result from the regeneration of baseline 0061 \t\tfor testcases containing at least [DR] changes. 0062 \t 0063 \t validate -rp -v output/links.html 0064 \t\t pretty print all [R] or [RP] changes. 0065 \t 0066 \t validate -rp -X output/links.html > output/links.2.html 0067 \t\t output is the same as input, with all matched testcases removed (here [R] or [RP] changes) 0068 \t 0069 \tSuggested usage: 0070 \t 1) testregression -g -o dummy `validate -dr output/links.html` . 0071 \t\t regenerates all [DR] testcases output by validate 0072 \t 0073 \t 2) svn commit `validate -dr -sV output/links.html` 0074 \t\t commit all files generated at the previous step that exist and are referenced by svn (needs 'svn' command in path) 0075 \t 0076 \t 3) mv output/links.html output/links.html.bak && validate -dr -X output/links.html.bak output/links.html 0077 \t\t removes all checked out testcases from links.html 0078 "; 0079 0080 format STDERR_TOP = 0081 Testcase Change 0082 --------------------------------------------------------------------------------------- 0083 . 0084 0085 format STDERR = 0086 @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<[@||||] 0087 $f, $files{$f} 0088 . 0089 0090 0091 open(F, $ARGV[0]) or die $!; 0092 0093 if (not exists $o{'d'} and not exists $o{'r'} and not exists $o{'p'}) { 0094 # default: validate all changes 0095 $o{'d'} = $o{'r'} = $o{'p'} = ''; 0096 } 0097 0098 while (my $l=<F>) { 0099 0100 # retrieve test name, nature of change. 0101 $l =~ /href="(.*?)-compare.html"/ or next; 0102 my $tn = $1; 0103 next if ($tn =~ /^tests\//); ##### 0104 $l =~ /<\/a>\s*\[(.*?)\]/; 0105 my $tc = $1; 0106 0107 $output { $tn } = $l if exists $o{'X'}; 0108 0109 next if $tc =~ /^\s*$/; 0110 0111 if (exists $o{'x'} and 0112 ($tc =~ /D/ && not exists $o{'d'} and 0113 $tc =~ /R/ && not exists $o{'r'} and 0114 $tc =~ /P/ && not exists $o{'p'})) { 0115 next; 0116 } elsif (!exists $o{'i'} and 0117 ($tc =~ /D/ && not exists $o{'d'} or 0118 $tc =~ /R/ && not exists $o{'r'} or 0119 $tc =~ /P/ && not exists $o{'p'})) { 0120 next; 0121 } elsif 0122 ($tc !~ /D/ && exists $o{'d'} or 0123 $tc !~ /R/ && exists $o{'r'} or 0124 $tc !~ /P/ && exists $o{'p'}) { 0125 next; 0126 } 0127 0128 next if exists $o{'e'} and $tn !~ m%$o{'e'}%io; 0129 0130 next if exists $o{'E'} and $tn =~ m%$o{'E'}%io; 0131 0132 # store in a hash 0133 $files { $tn } = $tc; 0134 0135 delete $output { $tn } if exists $o{'X'}; 0136 } 0137 0138 $numch = +(keys %files); 0139 if (exists $o{'v'}) { 0140 print STDERR "Number of test changed: $numch\n\n"; 0141 for $f(sort keys %files) { 0142 write STDERR; 0143 } 0144 exit(); 0145 } 0146 0147 if (exists $o{'X'}) { 0148 for $f(sort keys %output) { 0149 print $output{ $f }; 0150 } 0151 exit(); 0152 } 0153 0154 die "no ./baseline directory in pwd" if exists $o{'V'} and !-d "baseline"; 0155 0156 # generation command 0157 for my $f(sort keys %files) { 0158 $f =~ s/\.html-\d+$/.html/; 0159 $gen .= " -t $f"; 0160 } 0161 0162 # svn commit line 0163 for my $f(sort keys %files) { 0164 my $s = "baseline/$f"; 0165 my ($d, $r, $p); 0166 $files{$f} =~ /D/ and exists $o{'d'} and push @svn, $s . '-dom'; 0167 $files{$f} =~ /R/ and exists $o{'r'} and push @svn, $s . '-render'; 0168 $files{$f} =~ /P/ and exists $o{'p'} and push @svn, $s . '-dump.png'; 0169 } 0170 0171 if (exists $o{'s'}) { 0172 map { (!exists $o{'V'} or (-e $_ and `svn status $_`!~/^\?/)) and $svn .= " $_" } @svn; 0173 print $svn; 0174 } else { 0175 print $gen; 0176 }