[gnumeric] Tests: add tests for ssgrep
- From: Morten Welinder <mortenw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnumeric] Tests: add tests for ssgrep
- Date: Tue, 5 Dec 2017 01:17:13 +0000 (UTC)
commit f1e0cbd269a1070522e7be6ce23df397ca260785
Author: Morten Welinder <terra gnome org>
Date: Mon Dec 4 20:16:45 2017 -0500
Tests: add tests for ssgrep
test/GnumericTest.pm | 5 +-
test/Makefile.am | 1 +
test/t9010-ssgrep.pl | 160 ++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 164 insertions(+), 2 deletions(-)
---
diff --git a/test/GnumericTest.pm b/test/GnumericTest.pm
index 709914c..df5a0d9 100644
--- a/test/GnumericTest.pm
+++ b/test/GnumericTest.pm
@@ -13,13 +13,13 @@ $| = 1;
test_csv_format_guessing
test_ssindex sstest test_command message subtest
test_tool
- $ssconvert $sstest $ssdiff $gnumeric
+ $ssconvert $sstest $ssdiff $ssgrep $gnumeric
$topsrc $top_builddir
$subtests $samples corpus $PERL);
@GnumericTest::EXPORT_OK = qw(junkfile);
use vars qw($topsrc $top_builddir $samples $default_subtests $default_corpus $PERL $verbose);
-use vars qw($ssconvert $ssindex $sstest $ssdiff $gnumeric);
+use vars qw($ssconvert $ssindex $sstest $ssdiff $ssgrep $gnumeric);
use vars qw($normalize_gnumeric);
$PERL = $Config{'perlpath'};
@@ -35,6 +35,7 @@ $ssconvert = "$top_builddir/src/ssconvert";
$ssindex = "$top_builddir/src/ssindex";
$sstest = "$top_builddir/src/sstest";
$ssdiff = "$top_builddir/src/ssdiff";
+$ssgrep = "$top_builddir/src/ssgrep";
$gnumeric = "$top_builddir/src/gnumeric";
$normalize_gnumeric = "$PERL $topsrc/test/normalize-gnumeric";
$verbose = 0;
diff --git a/test/Makefile.am b/test/Makefile.am
index 444ce5c..66e5b81 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -170,6 +170,7 @@ TESTS = t1000-statfuns.pl \
t9002-ssdiff-self.pl \
t9003-ssdiff-xml.pl \
t9004-ssdiff-highlight.pl \
+ t9010-ssgrep.pl \
t9100-number-match.pl \
t9999-epilogue.pl
diff --git a/test/t9010-ssgrep.pl b/test/t9010-ssgrep.pl
new file mode 100755
index 0000000..73c6e9f
--- /dev/null
+++ b/test/t9010-ssgrep.pl
@@ -0,0 +1,160 @@
+#!/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";
+
+&GnumericTest::report_skip ("Missing source files")
+ unless -r $src1 && -r $src2 && -r $src3;
+
+
+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);
+
+# -----------------------------------------------------------------------------
+
+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
+*** END ***
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]