[gnumeric] Tests: change csv testing method to in-test documents



commit 653ca1fca938a8943b0827a4dba130eccfcafce3
Author: Morten Welinder <terra gnome org>
Date:   Thu May 19 18:06:17 2016 -0400

    Tests: change csv testing method to in-test documents

 samples/csv/date-dmy.csv   |    4 ----
 samples/csv/date-mdy.csv   |    4 ----
 samples/csv/date-ymd.csv   |    2 --
 test/GnumericTest.pm       |   39 +++++++++++++++++++++++++++++++++++++++
 test/Makefile.am           |    9 ++++-----
 test/t5800-cvs-date.pl     |   32 ++++++++++++++++++++++++++++++++
 test/t5910-cvs-date-dmy.pl |   14 --------------
 test/t5911-cvs-date-mdy.pl |   14 --------------
 test/t5912-cvs-date-ymd.pl |   14 --------------
 9 files changed, 75 insertions(+), 57 deletions(-)
---
diff --git a/test/GnumericTest.pm b/test/GnumericTest.pm
index c243624..b138f72 100644
--- a/test/GnumericTest.pm
+++ b/test/GnumericTest.pm
@@ -10,6 +10,7 @@ $| = 1;
 @GnumericTest::ISA = qw (Exporter);
 @GnumericTest::EXPORT = qw(test_sheet_calc test_valgrind
                            test_importer test_exporter test_roundtrip
+                           test_csv_format_guessing
                           test_ssindex sstest test_command message subtest
                           $ssconvert $sstest $ssdiff $topsrc $top_builddir
                           $subtests $samples corpus $PERL);
@@ -497,6 +498,43 @@ sub test_exporter {
 
 # -----------------------------------------------------------------------------
 
+sub test_csv_format_guessing {
+    my (%args) = @_;
+    my $data = $args{'data'};
+
+    my $keep = 0;
+
+    my $datafn = "test-data.csv";
+    &junkfile ($datafn) unless $keep;
+    &write_file ($datafn, $data);
+
+    my $outfn = "test-data.gnumeric";
+    &junkfile ($outfn) unless $keep;
+
+    local $ENV{'GNM_DEBUG'} = 'stf';
+    my $cmd = &quotearg ($ssconvert, $datafn, $outfn);
+    print STDERR "# $cmd\n" if $verbose;
+    my $out = `$cmd 2>&1`;
+
+    if ($out !~ m/^\s*fmt\.0\s*=\s*(\S+)\s*$/m) {
+       die "Failed to guess any format\n";
+    }
+    my $guessed = $1;
+
+    local $_ = $guessed;
+    if (!&{$args{'format'}} ($_)) {
+       foreach (split ("\n", $data)) {
+           print "| $_\n";
+       }
+       die "Guessed wrong format: $guessed\n";
+    }
+
+    &removejunk ($outfn) unless $keep;
+    &removejunk ($datafn) unless $keep;
+}
+
+# -----------------------------------------------------------------------------
+
 # The BIFF formats leave us with a msole:codepage property
 my $drop_codepage_filter =
     "$PERL -p -e '\$_ = \"\" if m{<meta:user-defined meta:name=.msole:codepage.}'";
@@ -750,6 +788,7 @@ sub test_ssindex {
     if (&$test ($_)) {
        print STDERR "Pass\n";
     } else {
+      FAIL:
        die "Fail\n";
     }
 }
diff --git a/test/Makefile.am b/test/Makefile.am
index 79148d4..15ed3b9 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -9,7 +9,8 @@
 # 2xxx: Internal sstest
 #
 # 5xxx: Importers
-# 59xx:   Minor formats
+# 5800:   csv
+# 59xx:   Minor formats with import-db
 #
 # 6xxx: Exporters
 # 69xx:   Minor formats
@@ -58,15 +59,13 @@ TESTS =     t1000-statfuns.pl                       \
        t2003-random-generators.pl              \
        t2004-insdel-colrow.pl                  \
        t2800-style-optimizer.pl                \
+       t5800-csv-date.pl                       \
        t5900-sc.pl                             \
        t5901-qpro.pl                           \
        t5902-applix.pl                         \
        t5903-sylk.pl                           \
        t5904-mps.pl                            \
        t5905-guppi.pl                          \
-       t5910-csv-date-dmy.pl                   \
-       t5911-csv-date-mdy.pl                   \
-       t5912-csv-date-ymd.pl                   \
        t6000-statfuns.pl                       \
        t6001-mathfuns.pl                       \
        t6002-objs.pl                           \
@@ -160,7 +159,7 @@ TESTS =     t1000-statfuns.pl                       \
 SUPPS = common.supp gui.supp t8003-valgrind-pdf.supp
 
 import-db:
-       for t in $(srcdir)/t5[0-9][0-9][0-9]-*.pl; do echo "*** $$t ***"; $(PERL) $$t create-db; done
+       for t in $(srcdir)/t59[0-9][0-9]-*.pl; do echo "*** $$t ***"; $(PERL) $$t create-db; done
 
 
 EXTRA_DIST = GnumericTest.pm $(SUPPS) normalize-gnumeric ods-ext-schema.patch $(TESTS)
diff --git a/test/t5800-cvs-date.pl b/test/t5800-cvs-date.pl
new file mode 100755
index 0000000..7ff17ba
--- /dev/null
+++ b/test/t5800-cvs-date.pl
@@ -0,0 +1,32 @@
+#!/usr/bin/perl -w
+# -----------------------------------------------------------------------------
+
+use strict;
+use lib ($0 =~ m|^(.*/)| ? $1 : ".");
+use GnumericTest;
+
+&message ("Check the csv importer.");
+
+&test_csv_format_guessing
+    (data => <<DATA, format => sub { /^d.*m.*y.*$/i; } );
+"Date"
+"1/2/3"
+"1/2/2000"
+"31/12/2000"
+DATA
+
+&test_csv_format_guessing
+    (data => <<DATA, format => sub { /^m.*d.*y.*$/i; } );
+"Date"
+"1/2/3"
+"1/2/2000"
+"12/31/2000"
+DATA
+
+&test_csv_format_guessing
+    (data => <<DATA, format => sub { /^y.*m.*d.*$/i; } );
+"Date"
+"2000-12-01"
+DATA
+
+print STDERR "Pass\n";


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]