From 8dbe7b91d3859cbf137c3ca7eef98550b248cddf Mon Sep 17 00:00:00 2001 From: Torsten Raudssus Date: Fri, 21 Oct 2011 19:35:05 +0200 Subject: [PATCH] Added -f and -t to the goodie-test.pl --- abc/abc.pl | 1 - abc/queries.txt | 2 ++ goodie-test.pl | 69 +++++++++++++++++++++++++++++++++++++------------ 3 files changed, 55 insertions(+), 17 deletions(-) create mode 100644 abc/queries.txt diff --git a/abc/abc.pl b/abc/abc.pl index 754e89e0d..5a48d719d 100644 --- a/abc/abc.pl +++ b/abc/abc.pl @@ -16,4 +16,3 @@ if ( $q_check =~ m/^\!?\s*[A-Za-z]+(\s+or\s+[A-Za-z]+)+\s*$/ ) { $answer_type = 'rand'; } -1; \ No newline at end of file diff --git a/abc/queries.txt b/abc/queries.txt new file mode 100644 index 000000000..5ac85f313 --- /dev/null +++ b/abc/queries.txt @@ -0,0 +1,2 @@ +this or that or none +duckduckgo or google or bing or something diff --git a/goodie-test.pl b/goodie-test.pl index e287ec7c4..3e37874a9 100755 --- a/goodie-test.pl +++ b/goodie-test.pl @@ -3,6 +3,18 @@ use strict; use warnings; use FindBin qw($Bin); +use Getopt::Std; + +use Data::Dumper; + +my %opts; + +getopts('f:t',\%opts); + +if ($opts{f} and $opts{t}) { + print "Please just use -f or -t not both at once\n"; + exit 1; +} my $goodie = shift @ARGV; @@ -11,8 +23,27 @@ if (!$goodie) { exit 1; } -if (!@ARGV) { - print "Please give a query to test ".$goodie." goodie!\n"; +my @queries; + +if (@ARGV) { + push @queries, join(' ',@ARGV); +} elsif ($opts{f}) { + open FILE, $opts{f} or die "Couldn't open file ".$opts{f}.": $!"; + for () { + chomp; + push @queries, $_; + } + close FILE; +} elsif ($opts{t}) { + my $test_query_file = $Bin."/".$goodie."/queries.txt"; + open FILE, $test_query_file or die "Couldn't open file ".$test_query_file.": $!"; + for () { + chomp; + push @queries, $_; + } + close FILE; +} else { + print "Please give a query to test ".$goodie." goodie or a file with queries via -f or make execute the goodie testset with -t!\n"; exit 1; } @@ -27,22 +58,28 @@ open FILE, $filename or die "Couldn't open file: $!"; my $code = join("", ); close FILE; -my $q_check = join(' ',@ARGV); -my $q_internal = ''; +for (@queries) { + my $q_check = $_; + my $q_internal = ''; -my $answer_results; -my $answer_type; + my $answer_results; + my $answer_type; -eval $code; + eval $code; + + print "\n"; -if ($answer_results and !$answer_type) { - print 'The goodie doesnt set $answer_type, but has $answer_results. You must give back $answer_results'; -} + if ($answer_results and !$answer_type) { + print 'The goodie doesnt set $answer_type, but has $answer_results on "'.$_.'". You must give back $answer_results!'."\n"; + } -if ($answer_results and $answer_type) { - print 'The goodie '.$goodie.' gives back the following on the query "'.$q_check.'":'."\n"; - print 'Answer Type: '.$answer_type."\n"; - print 'Answer Type: '.$answer_results."\n"; -} else { - print 'The goodie '.$goodie.' gave no result on "'.$q_check.'"!'."\n"; + if ($answer_results and $answer_type) { + print 'The goodie '.$goodie.' gives back the following on the query "'.$q_check.'":'."\n"; + print 'Answer Type: '.$answer_type."\n"; + print 'Answer Type: '.$answer_results."\n"; + } else { + print 'The goodie '.$goodie.' gave no result on "'.$q_check.'"!'."\n"; + } } + +print "\n"; \ No newline at end of file