t9010-ssgrep.pl 3.98 KB
Newer Older
1 2 3 4 5 6 7 8 9 10
#!/usr/bin/perl -w
# -----------------------------------------------------------------------------

use strict;
use lib ($0 =~ m|^(.*/)| ? $1 : ".");
use GnumericTest;

my $src1 = "$samples/excel/statfuns.xls";
my $src2 = "$samples/excel/mathfuns.xls";
my $src3 = "$samples/excel/engfuns.xls";
Morten Welinder's avatar
Morten Welinder committed
11
my $src4 = "$samples/auto-filter-tests.gnumeric";
12 13

&GnumericTest::report_skip ("Missing source files")
Morten Welinder's avatar
Morten Welinder committed
14
    unless -r $src1 && -r $src2 && -r $src3 && -r $src4;
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


my %expected;
&setup_expected ();

my $ngood = 0;
my $nbad = 0;

&message ("Checking ssgrep with single file.");
&check ("$ssgrep SUM $src1", 'TEST1A', 1);
&check ("$ssgrep SUM $src2", 'TEST1B', 0);
&check ("$ssgrep SUM $src3", 'TEST1C', 0);

&message ("Checking ssgrep with multiple files.");
&check ("$ssgrep SUM $src1 $src2 $src3", 'TEST1D', 0);

&message ("Checking ssgrep -n.");
&check ("$ssgrep -n SUM $src2", 'TEST2A', 0);

&message ("Checking ssgrep -c.");
&check ("$ssgrep -c SUM $src1", 'TEST3A', 1);
&check ("$ssgrep -c SUM $src2", 'TEST3B' ,0);
&check ("$ssgrep -c SUM $src3", 'TEST3C', 0);

&message ("Checking ssgrep -H.");
&check ("$ssgrep -H SUM $src2", 'TEST4A', 0);

&message ("Checking ssgrep -h.");
&check ("$ssgrep -h SUM $src1 $src2 $src3", 'TEST5A', 0);

&message ("Checking ssgrep with proper regexp.");
&check ("$ssgrep 'SUM[IS]' $src2", 'TEST6A', 0);

Morten Welinder's avatar
Morten Welinder committed
48 49 50 51 52 53 54 55 56
&message ("Checking ssgrep with hits on multiple sheets.");
&check ("$ssgrep -T -H -n wbc-gtk-actions $src4", 'TEST7A', 0);

&message ("Checking ssgrep -i.");
&check ("$ssgrep -h -i SUMIF $src1 $src2 $src3", 'TEST8A', 0);

&message ("Checking ssgrep -w.");
&check ("$ssgrep -h -i -w COUNT $src1 $src2 $src3", 'TEST9A', 0);

57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169
# -----------------------------------------------------------------------------

if ($nbad > 0) {
    die "Fail\n";
} else {
    print STDERR "Pass\n";
}


sub check {
    my ($cmd,$tag,$ec) = @_;

    my $expected = $expected{$tag};
    die unless defined $expected;

    print STDERR "# $cmd\n" if $GnumericTest::verbose;
    my $output = `$cmd 2>&1`;
    my $err = $?;

    my $bad = 0;
    if ($err != ($ec << 8)) {
	print STDERR "Wrong exit status $err\n";
	$bad++;
    } elsif ($output ne $expected) {
	print STDERR "Wrong output\n";
	$bad++;
    }

    if ($bad) {
	$nbad++;
        &GnumericTest::dump_indented ($output || '(no output)');
    } else {
	$ngood++;
    }
}

sub setup_expected {
    my $tag = undef;
    my $data = undef;

    while (<DATA>) {
	if (/^\*\*\* (\S+) \*\*\*$/) {
	    $expected{$tag} = $data if $tag;
	    $data = '';
	    $tag = $1;
	    next;
	}

	s/\$samples\b/$samples/g;
	$data .= $_;
    }
}

__DATA__
*** TEST1A ***
*** TEST1B ***
SERIESSUM
SUM
SUMIF
SUMPRODUCT
SUMSQ
SUMX2MY2
SUMX2PY2
SUMXMY2
*** TEST1C ***
IMSUM
*** TEST1D ***
$samples/excel/mathfuns.xls:SERIESSUM
$samples/excel/mathfuns.xls:SUM
$samples/excel/mathfuns.xls:SUMIF
$samples/excel/mathfuns.xls:SUMPRODUCT
$samples/excel/mathfuns.xls:SUMSQ
$samples/excel/mathfuns.xls:SUMX2MY2
$samples/excel/mathfuns.xls:SUMX2PY2
$samples/excel/mathfuns.xls:SUMXMY2
$samples/excel/engfuns.xls:IMSUM
*** TEST2A ***
Sheet1!A64:SERIESSUM
Sheet1!A71:SUM
Sheet1!A72:SUMIF
Sheet1!A73:SUMPRODUCT
Sheet1!A74:SUMSQ
Sheet1!A75:SUMX2MY2
Sheet1!A76:SUMX2PY2
Sheet1!A77:SUMXMY2
*** TEST3A ***
0
*** TEST3B ***
8
*** TEST3C ***
1
*** TEST4A ***
$samples/excel/mathfuns.xls:SERIESSUM
$samples/excel/mathfuns.xls:SUM
$samples/excel/mathfuns.xls:SUMIF
$samples/excel/mathfuns.xls:SUMPRODUCT
$samples/excel/mathfuns.xls:SUMSQ
$samples/excel/mathfuns.xls:SUMX2MY2
$samples/excel/mathfuns.xls:SUMX2PY2
$samples/excel/mathfuns.xls:SUMXMY2
*** TEST5A ***
SERIESSUM
SUM
SUMIF
SUMPRODUCT
SUMSQ
SUMX2MY2
SUMX2PY2
SUMXMY2
IMSUM
*** TEST6A ***
SUMIF
SUMSQ
Morten Welinder's avatar
Morten Welinder committed
170 171 172 173 174 175 176 177 178 179 180 181 182 183
*** TEST7A ***
$samples/auto-filter-tests.gnumeric:cell:Sheet1!G4:wbc-gtk-actions.c
$samples/auto-filter-tests.gnumeric:cell:Sheet2!G4:wbc-gtk-actions.c
$samples/auto-filter-tests.gnumeric:cell:Sheet3!G4:wbc-gtk-actions.c
*** TEST8A ***
SUMIF
=sumif(A14:A17,H14)
=sumif(B14:B17,H15)
=sumif(A14:A17,H15,C14:C17)
*** TEST9A ***
COUNT
=count(A14:A17)
=count(G14:G17)
=count(B14:B18)
184
*** END ***