[gnumeric] Tests: test ssconvert --export-file-per-sheet



commit a79e594adf2bb39c332593c7ff1662a0aba61d77
Author: Morten Welinder <terra gnome org>
Date:   Fri May 11 11:57:06 2018 -0400

    Tests: test ssconvert --export-file-per-sheet

 NEWS                          |    1 +
 test/Makefile.am              |    1 +
 test/t9006-ssconvert-split.pl |  123 +++++++++++++++++++++++++++++++++++++++++
 3 files changed, 125 insertions(+), 0 deletions(-)
---
diff --git a/NEWS b/NEWS
index 2cf6f19..b63b7b7 100644
--- a/NEWS
+++ b/NEWS
@@ -6,6 +6,7 @@ Morten:
        * Work around gtk+ breakage re. link colors.
        * Fix problems with ssconvert --export-file-per-sheet.  [#694408]
        * Enable --export-file-per-sheet for html, latex, and pdf.
+       * Test suite improvements.
 
 --------------------------------------------------------------------------
 Gnumeric 1.12.41
diff --git a/test/Makefile.am b/test/Makefile.am
index 8c68965..1d7e5d6 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -174,6 +174,7 @@ TESTS =     t1000-statfuns.pl                       \
        t9003-ssdiff-xml.pl                     \
        t9004-ssdiff-highlight.pl               \
        t9005-ssconvert-merge.pl                \
+       t9006-ssconvert-split.pl                \
        t9010-ssgrep.pl                         \
        t9100-number-match.pl                   \
        t9999-epilogue.pl
diff --git a/test/t9006-ssconvert-split.pl b/test/t9006-ssconvert-split.pl
new file mode 100755
index 0000000..0d87989
--- /dev/null
+++ b/test/t9006-ssconvert-split.pl
@@ -0,0 +1,123 @@
+#!/usr/bin/perl -w
+# -----------------------------------------------------------------------------
+
+use strict;
+use lib ($0 =~ m|^(.*/)| ? $1 : ".");
+use GnumericTest;
+use IO::File;
+
+&message ("Check ssconvert split");
+
+my $N = 3;
+
+# -----------------------------------------------------------------------------
+# Create reliable file to split
+
+my @little_files;
+for my $i (1 ... $N) {
+    my $fn = "t9006-file$i.csv";
+    &GnumericTest::junkfile ($fn);
+    push @little_files, $fn;
+    my $f = new IO::File ($fn, "w");
+    die "$0: Failed to write $fn: $!\n" unless $f;
+    print $f "File $i,$i,=$i+1\nLine 2,$i,=$i-1\n";
+}
+
+my $combined = "t9006-combined.gnumeric";
+&GnumericTest::junkfile ($combined);
+
+&test_command ("$ssconvert --merge-to=$combined " . join (" ", @little_files),
+              sub { 1 } );
+
+&GnumericTest::removejunk ($_) foreach @little_files;
+@little_files = ();
+
+# -----------------------------------------------------------------------------
+
+sub read_whole_file {
+    my ($fn) = @_;
+    my $f = new IO::File ($fn, "r");
+    die "$0: Failed to read $fn: $!\n" unless $f;
+    local $/ = undef;
+    my $data = <$f>;
+    return $data;
+}
+
+sub common_test {
+    my ($ext,$args,$post,$pexpected) = @_;
+    my $template = 't9006-out-%n.' . $ext;
+
+    &test_command ("$ssconvert --export-file-per-sheet $args $combined '$template'",
+                  sub { 1 } );
+
+    for my $i (1 ... $N) {
+       my $fn = $template;
+       my $im1 = $i - 1;
+       $fn =~ s/\%n/$im1/;
+
+       my $expected = $pexpected->[$i - 1];
+       my $data = &read_whole_file ($fn);
+
+       if (defined $post) {
+           local $_ = $data;
+           &$post ();
+           $data = $_;
+       }
+
+       if ($data ne $expected) {
+           print STDERR "Difference for format $ext, sheet number $i\n";
+           print STDERR "Observed:\n";
+           &GnumericTest::dump_indented ($data);
+           print STDERR "Expected:\n";
+           &GnumericTest::dump_indented ($expected);
+           die "Fail\n";
+       }
+
+       unlink $fn;
+    }
+}
+
+# -----------------------------------------------------------------------------
+
+if (&subtest ("txt")) {
+    &message ("Check splitting info text files.");
+
+    for my $sep (",", "::") {
+       my @expected;
+       for my $i (1 ... $N) {
+           my $ip1 = $i + 1;
+           my $im1 = $i - 1;
+           push @expected, "\"File $i\"$sep$i$sep$ip1\n\"Line 2\"$sep$i$sep$im1\n";
+       }
+
+       &common_test ('txt', "-O 'separator=$sep'", undef, \@expected);
+    }
+}
+
+if (&subtest ("csv")) {
+    &message ("Check splitting info csv files.");
+
+    my @expected;
+    for my $i (1 ... $N) {
+       my $ip1 = $i + 1;
+       my $im1 = $i - 1;
+       push @expected, "\"File $i\",$i,$ip1\n\"Line 2\",$i,$im1\n";
+    }
+
+    &common_test ('csv', '', undef, \@expected);
+}
+
+if (&subtest ("tex")) {
+    &message ("Check splitting info latex files.");
+
+    my @expected;
+    for my $i (1 ... $N) {
+       my $ip1 = $i + 1;
+       my $im1 = $i - 1;
+       push @expected, "File $i\t&$i\t&$ip1\\\\\nLine 2\t&$i\t&$im1\\\\\n";
+    }
+
+    &common_test ('tex', '-T Gnumeric_html:latex_table',
+                 sub { s/(\%.*$)\n//mg; },
+                 \@expected);
+}


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