texinfo-commits
[Top][All Lists]
Advanced

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

[no subject]


From: Patrice Dumas
Date: Sun, 8 Sep 2024 17:50:11 -0400 (EDT)

branch: master
commit 7e4bc67861eef8b26a582b80443ace44640392a5
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Sun Sep 8 22:48:43 2024 +0200

    * tp/t/test_utils.pl (test): if $arg_output is set, output EPUB as an
    epub file if Archive::Zip is installed, by simply setting OUTFILE.
    
    * tp/t/test_utils.pl (_set_outfile_name, test): separate code setting
    output file name for $arg_output as _set_outfile_name.  Use
    _set_outfile_name both for converted output for the diverse formats
    and for epub.
---
 ChangeLog          | 10 ++++++++
 tp/t/test_utils.pl | 70 +++++++++++++++++++++++++++++++++++++++---------------
 2 files changed, 61 insertions(+), 19 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 3bec6fafa6..692fdff2e6 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2024-09-08  Patrice Dumas  <pertusus@free.fr>
+
+       * tp/t/test_utils.pl (test): if $arg_output is set, output EPUB as an
+       epub file if Archive::Zip is installed, by simply setting OUTFILE.
+
+       * tp/t/test_utils.pl (_set_outfile_name, test): separate code setting
+       output file name for $arg_output as _set_outfile_name.  Use
+       _set_outfile_name both for converted output for the diverse formats
+       and for epub.
+
 2024-09-08  Patrice Dumas  <pertusus@free.fr>
 
        * tp/t/test_utils.pl (test): if doing epub, set init_files_options
diff --git a/tp/t/test_utils.pl b/tp/t/test_utils.pl
index a925f75ae0..43e135b328 100644
--- a/tp/t/test_utils.pl
+++ b/tp/t/test_utils.pl
@@ -710,6 +710,34 @@ sub output_preamble_postamble_latex($$)
   }
 }
 
+sub _set_outfile_name($$$$)
+{
+  my $test_file_name = shift;
+  my $test_name = shift;
+  my $extension = shift;
+  my $format = shift;
+
+  my $original_test_outfile = "$test_file_name/$test_name.$extension";
+  my $test_outfile = $original_test_outfile;
+  if ($output_files{$original_test_outfile}) {
+    warn "WARNING: $test_file_name: $test_name: $format: same name: 
$original_test_outfile "
+             ."(".join("|", @{$output_files{$original_test_outfile}}).")\n";
+    push @{$output_files{$original_test_outfile}}, $format;
+    $test_outfile = "$test_file_name/${test_name}_${format}.$extension";
+    # we also check that the file name with the format in name
+    # has not already been output
+    if ($output_files{$test_outfile}) {
+      warn "ERROR: $test_file_name: $test_name: $format: same name with 
format: $test_outfile\n";
+    } else {
+      $output_files{$test_outfile} = [$format];
+    }
+  } else {
+    $output_files{$original_test_outfile} = [$format];
+  }
+
+  return $test_outfile;
+}
+
 my %tested_transformations;
 
 # Run a single test case.  Each test case is an array
@@ -903,9 +931,26 @@ sub test($$)
         Texinfo::Config::GNUT_load_init_file($file);
         if ($filename eq 'epub3.pm') {
           $doing_epub = 1;
+          my $create_epub_file = $arg_output;
+          if ($arg_output) {
+            eval { require Archive::Zip; };
+            my $archive_zip_loading_error = $@;
+
+            $create_epub_file = 0 if ($archive_zip_loading_error);
+          }
+          if ($create_epub_file) {
+            # output EPUB as an epub publication file by setting OUTFILE.
+            # EPUB_CREATE_CONTAINER_FILE should be set in the default case.
+            my $extension = 'epub';
+            mkdir ("$output_files_dir/$self->{'name'}")
+              if (! -d "$output_files_dir/$self->{'name'}");
+            my $test_outfile = _set_outfile_name($self->{'name'}, $test_name,
+                                                  $extension, 'epub');
+            my $outfile = "$output_files_dir/$test_outfile";
+            $converter_options->{'OUTFILE'} = $outfile;
+          } elsif 
(!defined($converter_options->{'EPUB_CREATE_CONTAINER_FILE'})) {
           # we override init_files_options, as the priority between
           # converter_options and init_files_options is not well defined.
-          if (!defined($converter_options->{'EPUB_CREATE_CONTAINER_FILE'})) {
             $init_files_options->{'EPUB_CREATE_CONTAINER_FILE'} = 0;
           }
         }
@@ -1157,6 +1202,8 @@ sub test($$)
       = Texinfo::Convert::Text::convert_to_text($tree, {'TEST' => 1,
                           'expanded_formats' => \%expanded_formats});
 
+  # holds conversion function output returned as text for each format.
+  # Should not be set for formats outputting to files.
   my %converted;
   my %converted_errors;
 
@@ -1225,25 +1272,10 @@ sub test($$)
         } else {
           $extension = $format_type;
         }
-
         if (defined ($converted{$format})) {
-          my $original_test_outfile = "$self->{'name'}/$test_name.$extension";
-          my $test_outfile = $original_test_outfile;
-          if ($output_files{$original_test_outfile}) {
-            warn "WARNING: $self->{'name'}: $test_name: $format: same name: 
$original_test_outfile "
-                     ."(".join("|", 
@{$output_files{$original_test_outfile}}).")\n";
-            push @{$output_files{$original_test_outfile}}, $format;
-            $test_outfile = 
"$self->{'name'}/${test_name}_${format}.$extension";
-            # we also check that the file name with the format in name
-            # has not already been output
-            if ($output_files{$test_outfile}) {
-              warn "ERROR: $self->{'name'}: $test_name: $format: same name 
with format: $test_outfile\n";
-            } else {
-              $output_files{$test_outfile} = [$format];
-            }
-          } else {
-            $output_files{$original_test_outfile} = [$format];
-          }
+          my $test_outfile
+            = _set_outfile_name($self->{'name'}, $test_name,
+                                $extension, $format);
           my $outfile = "$output_files_dir/$test_outfile";
           if (!open(OUTFILE, ">$outfile")) {
             warn "ERROR: open $outfile: $!\n";



reply via email to

[Prev in Thread] Current Thread [Next in Thread]