Added -f <filename> and -t to the goodie-test.pl
parent
30297654ac
commit
8dbe7b91d3
|
@ -16,4 +16,3 @@ if ( $q_check =~ m/^\!?\s*[A-Za-z]+(\s+or\s+[A-Za-z]+)+\s*$/ ) {
|
|||
$answer_type = 'rand';
|
||||
}
|
||||
|
||||
1;
|
|
@ -0,0 +1,2 @@
|
|||
this or that or none
|
||||
duckduckgo or google or bing or something
|
|
@ -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 (<FILE>) {
|
||||
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 (<FILE>) {
|
||||
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("", <FILE>);
|
||||
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;
|
||||
|
||||
if ($answer_results and !$answer_type) {
|
||||
print 'The goodie doesnt set $answer_type, but has $answer_results. You must give back $answer_results';
|
||||
}
|
||||
print "\n";
|
||||
|
||||
if ($answer_results and $answer_type) {
|
||||
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 {
|
||||
} else {
|
||||
print 'The goodie '.$goodie.' gave no result on "'.$q_check.'"!'."\n";
|
||||
}
|
||||
}
|
||||
|
||||
print "\n";
|
Loading…
Reference in New Issue