texinfo-commits
[Top][All Lists]
Advanced

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

branch master updated: * tp/t/test_utils.pl (unsplit, test): unsplit() r


From: Patrice Dumas
Subject: branch master updated: * tp/t/test_utils.pl (unsplit, test): unsplit() returns if unsplitting was needed. Rename $split as $test_split. Add comments on re-splitting in tests.
Date: Mon, 02 Jan 2023 08:09:13 -0500

This is an automated email from the git hooks/post-receive script.

pertusus pushed a commit to branch master
in repository texinfo.

The following commit(s) were added to refs/heads/master by this push:
     new 1c6a8a3caa * tp/t/test_utils.pl (unsplit, test): unsplit() returns if 
unsplitting was needed.  Rename $split as $test_split.  Add comments on 
re-splitting in tests.
1c6a8a3caa is described below

commit 1c6a8a3caa0b924cb1be5c5578bdca0eec230731
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Mon Jan 2 14:08:59 2023 +0100

    * tp/t/test_utils.pl (unsplit, test): unsplit() returns if unsplitting
    was needed.  Rename $split as $test_split.  Add comments on
    re-splitting in tests.
    
    Add comments in other files.
---
 ChangeLog                       |  8 +++++++
 tp/Texinfo/Convert/Plaintext.pm |  3 ++-
 tp/Texinfo/Structuring.pm       | 14 ++++++++++++-
 tp/t/30sectioning.t             |  6 ++++--
 tp/t/test_utils.pl              | 46 +++++++++++++++++++++++++++++------------
 5 files changed, 60 insertions(+), 17 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index a3f3518f8b..5b629687e1 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2023-01-01  Patrice Dumas  <pertusus@free.fr>
+
+       * tp/t/test_utils.pl (unsplit, test): unsplit() returns if unsplitting
+       was needed.  Rename $split as $test_split.  Add comments on
+       re-splitting in tests.
+
+       Add comments in other files.
+
 2023-01-01  Patrice Dumas  <pertusus@free.fr>
 
        * tp/tests/indices/Makefile.am (EXTRA_DIST, distclean-local): remove
diff --git a/tp/Texinfo/Convert/Plaintext.pm b/tp/Texinfo/Convert/Plaintext.pm
index d0806dba4c..bb3a49b170 100644
--- a/tp/Texinfo/Convert/Plaintext.pm
+++ b/tp/Texinfo/Convert/Plaintext.pm
@@ -561,7 +561,8 @@ sub convert($$)
 }
 
 # the initialization of module specific state is not done in output()
-# as output() is generic, so it needs to be done here
+# as output() is the generic Converter::Convert function, so it needs
+# to be done here
 sub convert_tree($$)
 {
   my ($self, $root) = @_;
diff --git a/tp/Texinfo/Structuring.pm b/tp/Texinfo/Structuring.pm
index 7e3ef042a0..6bb5b8f6c4 100644
--- a/tp/Texinfo/Structuring.pm
+++ b/tp/Texinfo/Structuring.pm
@@ -905,6 +905,8 @@ sub section_level_adjusted_command_name($)
 
 # Return a list of tree units to be converted into pages.  Each tree unit
 # starts with a @node as its first child (except possibly the first one).
+# It is important that this function reassociates all the root commands
+# such that the result does not depend on the previous association (if any).
 sub split_by_node($)
 {
   my $root = shift;
@@ -938,6 +940,10 @@ sub split_by_node($)
       @pending_parts = ();
     }
     push @{$current->{'contents'}}, $content;
+    #if (defined($content->{'structure'})
+    #    and defined($content->{'structure'}->{'associated_unit'})) {
+    #  print STDERR "Resetting node associated_unit for $content\n";
+    #}
     #$content->{'structure'} = {} if (! $content->{'structure'});
     $content->{'structure'}->{'associated_unit'} = $current;
   }
@@ -954,7 +960,9 @@ sub split_by_node($)
 
 # Return a list of tree units to be converted into pages.  Each tree unit
 # starts with the @node associated with a sectioning command or with the
-# sectioning command if there is no associated node
+# sectioning command if there is no associated node.
+# It is important that this function reassociates all the root commands
+# such that the result does not depend on the previous association (if any).
 sub split_by_section($)
 {
   my $root = shift;
@@ -1003,6 +1011,10 @@ sub split_by_section($)
       }
     }
     push @{$current->{'contents'}}, $content;
+    #if (defined($content->{'structure'})
+    #    and defined($content->{'structure'}->{'associated_unit'})) {
+    #  print STDERR "Resetting section associated_unit for $content\n";
+    #}
     #$content->{'structure'} = {} if (! $content->{'structure'});
     $content->{'structure'}->{'associated_unit'} = $current;
   }
diff --git a/tp/t/30sectioning.t b/tp/t/30sectioning.t
index 9d81806a93..6449003370 100644
--- a/tp/t/30sectioning.t
+++ b/tp/t/30sectioning.t
@@ -2146,8 +2146,10 @@ my @test_out_files = (
 $character_and_spaces_in_refs_text,
 {'test_split' => 'node'},],
 # test the texi2html style to test the style for tests
-# interesting to test diverse splitting options, and already
-# used for that above.
+# interesting to test diverse tree splitting options, and already
+# used for that above.  Since all the options for test_split have
+# already been tested before, it is not useful to do so here, but
+# USE_NODES is used for converters.
 ['nodes_after_top_before_chapter_texi2html',
   $nodes_after_top_before_chapter_text,
   {},
diff --git a/tp/t/test_utils.pl b/tp/t/test_utils.pl
index 0b9b19f808..e02440ac7c 100644
--- a/tp/t/test_utils.pl
+++ b/tp/t/test_utils.pl
@@ -218,17 +218,19 @@ sub unsplit($)
       or !$root->{'contents'}) {
     return;
   }
+  my $unsplit_needed = 0;
   foreach my $content (@{$root->{'contents'}}) {
     if ($content->{'structure'}) {
       if ($content->{'structure'}->{'associated_unit'}) {
         delete $content->{'structure'}->{'associated_unit'};
+        $unsplit_needed = 1;
       }
       if (scalar(keys(%{$content->{'structure'}})) == 0) {
         delete $content->{'structure'};
       }
     }
   }
-  return;
+  return $unsplit_needed;
 }
 
 sub compare_dirs_files($$;$)
@@ -872,11 +874,19 @@ sub test($$)
     $test_input_file_name = $parser_options->{'test_input_file_name'};
     delete $parser_options->{'test_input_file_name'};
   }
-  my $split = '';
+  # test_split should not interfere with output formats conversion
+  # as it is applied after the output formats.  Splitting should not interfere
+  # with conversion anyway.  Output formats using information added by
+  # splitting split themselves and reassociate all the root commands.
+  # Splitting means associating root commands to a unit element in the 
structure
+  # hash.  Converters that do not split can ignore this structure hash key and
+  # therefore should not be affected either.
+
+  my $test_split = '';
   if ($parser_options->{'test_split'}) {
-    $split = $parser_options->{'test_split'};
-    if ($split ne 'node' and $split ne 'section') {
-      warn "In test_utils.pl, test_split should be node or section, not 
$split\n";
+    $test_split = $parser_options->{'test_split'};
+    if ($test_split ne 'node' and $test_split ne 'section') {
+      warn "test_utils.pl: test_split should be node or section: 
$test_split\n";
     }
     delete $parser_options->{'test_split'};
   }
@@ -1308,20 +1318,30 @@ sub test($$)
     }
   }
   my $directions_text;
-  # re-associate top level command with the document_root in case a converter
-  # split the document, by resetting their 'parent' key.
+  # remove the association of top-level commands with element units, in case
+  # a converter split the document.
   # It may be noticed that this is only done after all conversions.  This
   # means that depending on the order of converters call, trees feed to
-  # converters may have a document_root as top level command parent or
-  # elements.  All the converters will have the document_root as argument.
-  unsplit($tree);
+  # converters may have element units.  All the converters will have the
+  # document_root as argument.
+  # It could be possible to unsplit before each converter call, but it is
+  # better to check that this does not have an effect on conversion.
+  # Any conversion to Info, Plaintext or HTML (both with output and convert)
+  # leads to splitting by the converter, and generally the tests order is
+  # first plaintext or info then html, so splitting not having an effect
+  # on conversion should be fairly well tested.  See above the comment
+  # near test_split with more explanation on why previous splitting should
+  # not interfere with conversion.
+  my $unsplit_needed = unsplit($tree);
+  print STDERR "  UNSPLIT: $test_name\n"
+    if ($self->{'DEBUG'} and $unsplit_needed);
   my $elements;
-  if ($split eq 'node') {
+  if ($test_split eq 'node') {
     $elements = Texinfo::Structuring::split_by_node($tree);
-  } elsif ($split eq 'section') {
+  } elsif ($test_split eq 'section') {
     $elements = Texinfo::Structuring::split_by_section($tree);
   }
-  if ($split) {
+  if ($test_split) {
     Texinfo::Structuring::elements_directions($parser, $labels, $elements);
     $directions_text = '';
     foreach my $element (@$elements) {



reply via email to

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