texinfo-commits
[Top][All Lists]
Advanced

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

branch master updated: * tp/Makefile.am, tp/t/test_utils.pl, tp/Texinfo/


From: Patrice Dumas
Subject: branch master updated: * tp/Makefile.am, tp/t/test_utils.pl, tp/Texinfo/Tests.pm (compare_dirs_files, unlink_dir_files): add tp/Texinfo/Tests.pm for common code to be used in tests.
Date: Fri, 24 May 2024 06:48:19 -0400

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 2014a4db13 * tp/Makefile.am, tp/t/test_utils.pl, tp/Texinfo/Tests.pm 
(compare_dirs_files, unlink_dir_files): add tp/Texinfo/Tests.pm for common code 
to be used in tests.
2014a4db13 is described below

commit 2014a4db1374ca0d9b10f34e80c9af7c20f2223c
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Fri May 24 12:48:05 2024 +0200

    * tp/Makefile.am, tp/t/test_utils.pl, tp/Texinfo/Tests.pm
    (compare_dirs_files, unlink_dir_files): add tp/Texinfo/Tests.pm for
    common code to be used in tests.
    
    * tp/Texinfo/Convert/TexinfoMarkup.pm (_convert): avoid incorrect
    autovivification for bracketed_arg parent parent.
    
    * tp/Texinfo/XS/convert/convert_html.c (html_default_format_contents):
    do contents only if there is one section.
    
    * tp/Texinfo/Convert/DocBook.pm (_docbook_section_element, _convert),
    tp/Texinfo/Convert/HTML.pm (_convert_heading_command)
    (_prepare_output_units_global_targets, _default_format_contents),
    tp/Texinfo/Convert/TexinfoMarkup.pm (_convert),
    tp/Texinfo/OutputUnits.pm (units_directions),
    tp/Texinfo/Structuring.pm (section_level_adjusted_command_name),
    tp/Texinfo/XS/convert/convert_html.c (html_default_format_contents)
    (convert_heading_command), tp/Texinfo/XS/main/utils.c
    (section_level_adjusted_command_name): handle better extra
    section_level, section_directions and section_childs not set, in case
    there is a conversion without structuring information available.
    
    * tp/Makefile.tres, t/no_structure_test.t: add tests of conversion
    without calling Structuring code after parsing.
---
 ChangeLog                                          |  27 ++
 tp/Makefile.am                                     |   1 +
 tp/Makefile.tres                                   |   3 +
 tp/TODO                                            |   5 +
 tp/Texinfo/Convert/DocBook.pm                      |  33 ++-
 tp/Texinfo/Convert/HTML.pm                         |  25 +-
 tp/Texinfo/Convert/TexinfoMarkup.pm                |   9 +-
 tp/Texinfo/OutputUnits.pm                          |  14 +-
 tp/Texinfo/Structuring.pm                          |  21 +-
 tp/Texinfo/Tests.pm                                | 116 ++++++++
 tp/Texinfo/XS/convert/convert_html.c               |  15 +-
 tp/Texinfo/XS/main/utils.c                         |  14 +-
 tp/t/no_structure_test.t                           | 301 +++++++++++++++++++++
 .../one/res_html/test_struct.html                  |  85 ++++++
 .../one/res_info/test_struct.info                  | Bin 0 -> 510 bytes
 tp/t/test_utils.pl                                 |  92 +------
 16 files changed, 634 insertions(+), 127 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 1d4ee5bf91..c342721f07 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,30 @@
+2024-05-24  Patrice Dumas  <pertusus@free.fr>
+
+       * tp/Makefile.am, tp/t/test_utils.pl, tp/Texinfo/Tests.pm
+       (compare_dirs_files, unlink_dir_files): add tp/Texinfo/Tests.pm for
+       common code to be used in tests.
+
+       * tp/Texinfo/Convert/TexinfoMarkup.pm (_convert): avoid incorrect
+       autovivification for bracketed_arg parent parent.
+
+       * tp/Texinfo/XS/convert/convert_html.c (html_default_format_contents):
+       do contents only if there is one section.
+
+       * tp/Texinfo/Convert/DocBook.pm (_docbook_section_element, _convert),
+       tp/Texinfo/Convert/HTML.pm (_convert_heading_command)
+       (_prepare_output_units_global_targets, _default_format_contents),
+       tp/Texinfo/Convert/TexinfoMarkup.pm (_convert),
+       tp/Texinfo/OutputUnits.pm (units_directions),
+       tp/Texinfo/Structuring.pm (section_level_adjusted_command_name),
+       tp/Texinfo/XS/convert/convert_html.c (html_default_format_contents)
+       (convert_heading_command), tp/Texinfo/XS/main/utils.c
+       (section_level_adjusted_command_name): handle better extra
+       section_level, section_directions and section_childs not set, in case
+       there is a conversion without structuring information available.
+
+       * tp/Makefile.tres, t/no_structure_test.t: add tests of conversion
+       without calling Structuring code after parsing.
+
 2024-05-23  Patrice Dumas  <pertusus@free.fr>
 
        * tp/Texinfo/XS/main/document.c (wipe_document_errors)
diff --git a/tp/Makefile.am b/tp/Makefile.am
index 617154ffb9..86abf569ba 100644
--- a/tp/Makefile.am
+++ b/tp/Makefile.am
@@ -83,6 +83,7 @@ dist_modules_DATA = \
  Texinfo/Report.pm \
  Texinfo/StructTransfXS.pm \
  Texinfo/Structuring.pm \
+ Texinfo/Tests.pm \
  Texinfo/Transformations.pm \
  Texinfo/Translations.pm \
  Texinfo/XSLoader.pm
diff --git a/tp/Makefile.tres b/tp/Makefile.tres
index 2c3941ed34..e6f90b0f73 100644
--- a/tp/Makefile.tres
+++ b/tp/Makefile.tres
@@ -46,6 +46,7 @@ test_tap_files_generated_list = \
   t/languages.t \
   t/latex_tests.t \
   t/layout.t \
+  t/no_structure_test.t \
   t/nodenormalization.t \
   t/paragraph.t \
   t/plaintext_tests.t \
@@ -1679,6 +1680,8 @@ test_files_generated_list = 
$(test_tap_files_generated_list) \
   t/results/multitable/prototype_no_brace.pl \
   t/results/multitable/ref_in_multitable.pl \
   t/results/multitable/w_in_multitable.pl \
+  t/results/no_structure_test/one/res_html \
+  t/results/no_structure_test/one/res_info \
   t/results/paragraph/close_paragraph_command.pl \
   t/results/paragraph/commands_in_flushright.pl \
   t/results/paragraph/comment_between_text.pl \
diff --git a/tp/TODO b/tp/TODO
index 39445f5236..095d981c75 100644
--- a/tp/TODO
+++ b/tp/TODO
@@ -57,6 +57,11 @@ Document *XS_EXTERNAL_FORMATTING *XS_EXTERNAL_CONVERSION?
 Delayed bugs/features
 =====================
 
+Add the possibility to add text to a parsed document by restarting
+parsing, when called as parse_texi_piece or parse_texi_line, by
+storing the parser document state not already in document in document.
+
+
 Gavin idea to use see/See for cross references in --plaintext output.
 More generally, the plaintext ref_commands formatting code
 could be completly different from the Info code, which is the current
diff --git a/tp/Texinfo/Convert/DocBook.pm b/tp/Texinfo/Convert/DocBook.pm
index fff33f44aa..ff37bf8b8c 100644
--- a/tp/Texinfo/Convert/DocBook.pm
+++ b/tp/Texinfo/Convert/DocBook.pm
@@ -573,13 +573,17 @@ sub _docbook_section_element($$)
   my $self = shift;
   my $element = shift;
 
-  my $heading_level = $element->{'extra'}->{'section_level'};
-  if (exists $docbook_sections{$heading_level}) {
-    return $docbook_sections{$heading_level};
+  if ($element->{'extra'}
+      and defined($element->{'extra'}->{'section_level'})) {
+    my $heading_level = $element->{'extra'}->{'section_level'};
+    if (exists $docbook_sections{$heading_level}) {
+      return $docbook_sections{$heading_level};
+    }
   }
   my $level_adjusted_cmdname
      = Texinfo::Structuring::section_level_adjusted_command_name($element);
   if ($level_adjusted_cmdname eq 'unnumbered'
+      and $element->{'extra'}
       and $element->{'extra'}->{'associated_node'}
       and $element->{'extra'}->{'associated_node'}->{'extra'}
       and $element->{'extra'}->{'associated_node'}->{'extra'}->{'normalized'}
@@ -588,7 +592,15 @@ sub _docbook_section_element($$)
     return 
lc($element->{'extra'}->{'associated_node'}->{'extra'}->{'normalized'});
   }
 
-  return $docbook_sections{$level_adjusted_cmdname};
+  if (defined($docbook_sections{$level_adjusted_cmdname})) {
+    return $docbook_sections{$level_adjusted_cmdname};
+  } else {
+    # special case of no structuring information available for a regular
+    # sectioning command, like @section, @appendix, if Structuring
+    # sectioning_structure was not called.
+    my $heading_level = Texinfo::Common::section_level($element);
+    return $docbook_sections{$heading_level};
+  }
 }
 
 sub _index_entry($$)
@@ -918,9 +930,10 @@ sub _convert($$;$)
             # able to figure it out.  For @unnumbered or if ! NUMBER_SECTIONS
             # having a label (empty) is important.
             my $label = '';
-            if (defined($opened_element->{'extra'}->{'section_number'})
-              and ($self->get_conf('NUMBER_SECTIONS')
-                   or !defined($self->get_conf('NUMBER_SECTIONS')))) {
+            if ($opened_element->{'extra'}
+                and defined($opened_element->{'extra'}->{'section_number'})
+                and ($self->get_conf('NUMBER_SECTIONS')
+                     or !defined($self->get_conf('NUMBER_SECTIONS')))) {
               # Looking at docbook2html output, Appendix is appended in the
               # section title, so only the letter is used.
               $label = $opened_element->{'extra'}->{'section_number'};
@@ -1815,13 +1828,15 @@ sub _convert($$;$)
     }
     my $level_adjusted_cmdname
         = Texinfo::Structuring::section_level_adjusted_command_name($element);
-    if (!($element->{'extra'}->{'section_childs'}
+    if (!($element->{'extra'}
+          and $element->{'extra'}->{'section_childs'}
           and scalar(@{$element->{'extra'}->{'section_childs'}}))
         or $level_adjusted_cmdname eq 'top') {
       $result .= "</$docbook_sectioning_element>\n";
       pop @{$self->{'lang_stack'}};
       my $current = $element;
-      while ($current->{'extra'}->{'section_directions'}
+      while ($current->{'extra'}
+             and $current->{'extra'}->{'section_directions'}
              and $current->{'extra'}->{'section_directions'}->{'up'}
              # the most up element is a virtual sectioning root element, this
              # condition avoids getting into it
diff --git a/tp/Texinfo/Convert/HTML.pm b/tp/Texinfo/Convert/HTML.pm
index dc74051a11..7a7ca83753 100644
--- a/tp/Texinfo/Convert/HTML.pm
+++ b/tp/Texinfo/Convert/HTML.pm
@@ -5002,7 +5002,15 @@ sub _convert_heading_command($$$$$)
   # if set, the id is associated to the heading text
   my $heading_id;
   if ($opening_section) {
-    my $level = $opening_section->{'extra'}->{'section_level'};
+    my $level;
+    if ($opening_section->{'extra'}
+        and defined($opening_section->{'extra'}->{'section_level'})) {
+      $level = $opening_section->{'extra'}->{'section_level'};
+    } else {
+      # if Structuring sectioning_structure was not called on the
+      # document (cannot happen in main program or test_utils.pl tests)
+      $level = Texinfo::Common::section_level($opening_section);
+    }
     my $closed_strings = $self->close_registered_sections_level($level);
     $result .= join('', @{$closed_strings});
     $self->register_opened_section_level($level, "</div>\n");
@@ -10520,9 +10528,11 @@ sub _prepare_output_units_global_targets($$$$)
         $root_command = $root_command->{'extra'}->{'associated_section'};
       }
       # find the first level 1 sectioning element to associate the printindex
-      # with
+      # with.  May not work correctly if structuring was not done
       if ($root_command and $root_command->{'cmdname'} ne 'node') {
-        while ($root_command->{'extra'}->{'section_level'} > 1
+        while ($root_command->{'extra'}
+               and defined($root_command->{'extra'}->{'section_level'})
+               and $root_command->{'extra'}->{'section_level'} > 1
                and $root_command->{'extra'}->{'section_directions'}
                and $root_command->{'extra'}->{'section_directions'}->{'up'}
                and $root_command->{'extra'}->{'section_directions'}->{'up'}
@@ -10929,7 +10939,14 @@ sub _default_format_contents($$;$$)
     $sections_list = $document->sections_list();
   }
   return ''
-   if (!$sections_list or !scalar(@$sections_list));
+   if (!$sections_list or !scalar(@$sections_list)
+       # this should not happen with $sections_list as set from Structuring
+       # sectioning_structure, but could happen with another source.
+       # We consider that if sectioning_root is set as usual, all the
+       # fields are set consistently with what sectioning_structure would
+       # have set.
+       or !$sections_list->[0]->{'extra'}
+       or !defined($sections_list->[0]->{'extra'}->{'sectioning_root'}));
 
   my $section_root = $sections_list->[0]
                                    ->{'extra'}->{'sectioning_root'};
diff --git a/tp/Texinfo/Convert/TexinfoMarkup.pm 
b/tp/Texinfo/Convert/TexinfoMarkup.pm
index 36c6ed7b9a..ed98bc26f3 100644
--- a/tp/Texinfo/Convert/TexinfoMarkup.pm
+++ b/tp/Texinfo/Convert/TexinfoMarkup.pm
@@ -1569,7 +1569,8 @@ sub _convert($$;$)
     # 'h{e f}'.
     # @deffn {a b}{c d} h{e f} g h
     } elsif ($element->{'type'} eq 'bracketed_arg'
-             and not ($element->{'parent'}->{'parent'}->{'cmdname'}
+             and not ($element->{'parent'}->{'parent'}
+                      and $element->{'parent'}->{'parent'}->{'cmdname'}
                       and $element->{'parent'}->{'parent'}->{'cmdname'}
                                                            eq 'multitable')
              and (!$element->{'parent'}->{'type'}
@@ -1639,12 +1640,14 @@ sub _convert($$;$)
            and !$self->get_conf('TXI_MARKUP_NO_SECTION_EXTENT')) {
     my $level_adjusted_cmdname
        = Texinfo::Structuring::section_level_adjusted_command_name($element);
-    if (!($element->{'extra'}->{'section_childs'}
+    if (!($element->{'extra'}
+          and $element->{'extra'}->{'section_childs'}
           and scalar(@{$element->{'extra'}->{'section_childs'}}))
         or $level_adjusted_cmdname eq 'top') {
       $result .= $self->txi_markup_close_element($level_adjusted_cmdname)."\n";
       my $current = $element;
-      while ($current->{'extra'}->{'section_directions'}
+      while ($current->{'extra'}
+             and $current->{'extra'}->{'section_directions'}
              and $current->{'extra'}->{'section_directions'}->{'up'}
              # the most up element is a virtual sectioning root element, this
              # condition avoids getting into it
diff --git a/tp/Texinfo/OutputUnits.pm b/tp/Texinfo/OutputUnits.pm
index 5fe7dc1180..86dc147669 100644
--- a/tp/Texinfo/OutputUnits.pm
+++ b/tp/Texinfo/OutputUnits.pm
@@ -31,7 +31,7 @@ use if $] >= 5.014, re => '/a';
 use strict;
 
 # Can be used to check that there is no incorrect autovivfication
-# no autovivification qw(fetch delete exists store strict);
+#no autovivification qw(fetch delete exists store strict);
 
 use Carp qw(cluck confess);
 
@@ -492,13 +492,17 @@ sub units_directions($$;$)
       # fastforward is the next element on same level than the upper parent
       # element.
       my $up = $section;
-      while ($up->{'extra'}->{'section_level'} > 1
+      while ($up->{'extra'}
+             and defined($up->{'extra'}->{'section_level'})
+             and $up->{'extra'}->{'section_level'} > 1
              and $up->{'extra'}->{'section_directions'}
              and $up->{'extra'}->{'section_directions'}->{'up'}) {
         $up = $up->{'extra'}->{'section_directions'}->{'up'};
       }
 
-      if ($up->{'extra'}->{'section_level'} < 1
+      if ($up->{'extra'}
+          and defined($up->{'extra'}->{'section_level'})
+          and $up->{'extra'}->{'section_level'} < 1
           and $up->{'cmdname'} and $up->{'cmdname'} eq 'top'
           and $up->{'extra'}->{'section_childs'}
           and @{$up->{'extra'}->{'section_childs'}}) {
@@ -520,7 +524,9 @@ sub units_directions($$;$)
       if ($up and $up ne $section
           and $up->{'associated_unit'}) {
         $directions->{'FastBack'} = $up->{'associated_unit'};
-      } elsif ($section->{'extra'}->{'section_level'} <= 1
+      } elsif ($section->{'extra'}
+               and defined($section->{'extra'}->{'section_level'})
+               and $section->{'extra'}->{'section_level'} <= 1
                and $directions->{'FastForward'}) {
         # the element is a top level element, we adjust the next
         # toplevel element fastback
diff --git a/tp/Texinfo/Structuring.pm b/tp/Texinfo/Structuring.pm
index 7f47beb8d5..f89735d8f5 100644
--- a/tp/Texinfo/Structuring.pm
+++ b/tp/Texinfo/Structuring.pm
@@ -33,7 +33,7 @@ use if $] >= 5.014, re => '/a';
 use strict;
 
 # Can be used to check that there is no incorrect autovivfication
-# no autovivification qw(fetch delete exists store strict);
+#no autovivification qw(fetch delete exists store strict);
 
 use Carp qw(cluck confess);
 
@@ -1180,17 +1180,20 @@ sub section_level_adjusted_command_name($)
 {
   my $element = shift;
 
-  my $heading_level = $element->{'extra'}->{'section_level'};
-  my $command;
-  if ($heading_level ne $Texinfo::Common::command_structuring_level{
+  # the following condition should only be false if sectioning_structure was
+  # not called
+  if ($element->{'extra'}
+      and defined($element->{'extra'}->{'section_level'})) {
+    my $heading_level = $element->{'extra'}->{'section_level'};
+    if ($heading_level ne $Texinfo::Common::command_structuring_level{
                                                        $element->{'cmdname'}}) 
{
-    $command
-      = $Texinfo::Common::level_to_structuring_command{$element->{'cmdname'}}
+      my $command
+        = $Texinfo::Common::level_to_structuring_command{$element->{'cmdname'}}
                                                             ->[$heading_level];
-  } else {
-    $command = $element->{'cmdname'};
+      return $command;
+    }
   }
-  return $command;
+  return $element->{'cmdname'};
 }
 
 
diff --git a/tp/Texinfo/Tests.pm b/tp/Texinfo/Tests.pm
new file mode 100644
index 0000000000..fe0b37e0ae
--- /dev/null
+++ b/tp/Texinfo/Tests.pm
@@ -0,0 +1,116 @@
+# common code for code test in t/*
+#
+# Copyright 2010-2024 Free Software Foundation, Inc.
+# 
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License,
+# or (at your option) any later version.
+# 
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+# 
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+# 
+# Original author: Patrice Dumas <pertusus@free.fr>
+
+use strict;
+
+use 5.006;
+
+use File::Compare qw(compare); # standard since 5.004
+
+# not that subdirectories are not compared, so subdirectories generated
+# by INFO_JS_DIR, if different, will not trigger an error in test, but
+# will lead to different directories and files in diffs.
+sub compare_dirs_files($$;$)
+{
+  my $dir1 = shift;
+  my $dir2 = shift;
+  my $ignore_files = shift;
+
+  my %dir1_files;
+  my %dir2_files;
+  my @errors;
+  my %ignored_files_hash;
+  foreach my $ignored_file (@$ignore_files) {
+    $ignored_files_hash{$ignored_file} = 1;
+  }
+  if (opendir(DIR1, $dir1)) {
+    my @files = readdir (DIR1);
+    foreach my $file (@files) {
+      next if (! -r "$dir1/$file" or ! -f "$dir1/$file"
+               or $ignored_files_hash{$file});
+      $dir1_files{$file} = 1;
+    }
+    closedir (DIR1);
+  } else {
+    push @errors, "readdir $dir1: $!";
+  }
+  if (opendir(DIR2, $dir2)) {
+    my @files = readdir (DIR2);
+    foreach my $file (@files) {
+      next if (! -r "$dir2/$file" or ! -f "$dir2/$file"
+               or $ignored_files_hash{$file});
+      $dir2_files{$file} = 1;
+    }
+    closedir (DIR2);
+  } else {
+    push @errors, "readdir $dir2: $!";
+  }
+  if (scalar(@errors)) {
+    return \@errors;
+  }
+  foreach my $file (sort(keys(%dir1_files))) {
+    if ($dir2_files{$file}) {
+      my $status = compare("$dir1/$file", "$dir2/$file");
+      if ($status) {
+        push @errors, "$dir1/$file and $dir2/$file differ: $status";
+      }
+      delete $dir2_files{$file};
+    } else {
+      push @errors, "No $file in $dir2";
+    }
+  }
+  foreach my $file (sort(keys(%dir2_files))) {
+    push @errors, "No $file in $dir1"
+  }
+  if (scalar(@errors)) {
+    return \@errors;
+  } else {
+    return undef;
+  }
+}
+
+#my $errors = compare_dirs_files('a', 'b',['nnn']);
+#if ($errors) {
+#  foreach my $error (@$errors) {
+#    warn $error."\n";
+#  }
+#}
+
+sub unlink_dir_files($;$)
+{  
+  my $dir = shift;
+  my $ignore_files = shift;
+  my %ignored_files_hash;
+  foreach my $ignored_file (@$ignore_files) {
+    $ignored_files_hash{$ignored_file} = 1;
+  }         
+  if (opendir(DIR, $dir)) {
+    my @files = readdir (DIR);
+    foreach my $file (@files) {
+      next if (! -f "$dir/$file"
+               or $ignored_files_hash{$file});
+      unlink "$dir/$file" or warn "Could not unlink $dir/$file: $!\n";
+    }     
+    closedir (DIR);
+  } else {
+    warn "readdir $dir: $!";
+  }   
+}     
+
+1;
diff --git a/tp/Texinfo/XS/convert/convert_html.c 
b/tp/Texinfo/XS/convert/convert_html.c
index 5d469aa30c..96ad0a4d6b 100644
--- a/tp/Texinfo/XS/convert/convert_html.c
+++ b/tp/Texinfo/XS/convert/convert_html.c
@@ -6087,10 +6087,17 @@ html_default_format_contents (CONVERTER *self, const 
enum command_id cmd,
   text_append (&result, "");
 
   if (self->document->sections_list
-      && self->document->sections_list->number >= 0)
+      && self->document->sections_list->number > 0)
     {
       const ELEMENT *first = self->document->sections_list->list[0];
       section_root = lookup_extra_element (first, "sectioning_root");
+      /* this should not happen with $sections_list as set from Structuring
+         sectioning_structure, but could happen with another source.
+         We consider that if sectioning_root is set as usual, all the
+         fields are set consistently with what sectioning_structure would
+         have set. */
+      if (!section_root)
+        return result.text;
     }
   else
     return result.text;
@@ -10244,6 +10251,12 @@ convert_heading_command (CONVERTER *self, const enum 
command_id cmd,
         = lookup_extra_integer (opening_section, "section_level", &status);
       STRING_LIST *closed_strings;
 
+       /* if Structuring sectioning_structure was not called on the
+          document (cannot happen in main program or test_utils.pl tests) */
+      /* if (status < 0) */
+      if (status != 0)
+        level = section_level (opening_section);
+
       closed_strings = html_close_registered_sections_level (self, level);
 
       if (closed_strings->number)
diff --git a/tp/Texinfo/XS/main/utils.c b/tp/Texinfo/XS/main/utils.c
index d9e24ae75f..73963d8815 100644
--- a/tp/Texinfo/XS/main/utils.c
+++ b/tp/Texinfo/XS/main/utils.c
@@ -1380,16 +1380,16 @@ section_level_adjusted_command_name (const ELEMENT 
*element)
 
   heading_level = lookup_extra_integer (element, "section_level", &status);
 
-  if (status < 0)
+  /* the following condition should only be false if sectioning_structure was
+     not called */
+  if (status == 0)
     {
-      bug ("section_level_adjusted_command_name: "
-           "unexpected missing section level");
+      if (command_structuring_level[element->cmd] != heading_level)
+        {
+          return level_to_structuring_command[element->cmd][heading_level];
+        }
     }
 
-  if (command_structuring_level[element->cmd] != heading_level)
-    {
-      return level_to_structuring_command[element->cmd][heading_level];
-    }
   return element->cmd;
 }
 
diff --git a/tp/t/no_structure_test.t b/tp/t/no_structure_test.t
new file mode 100644
index 0000000000..14197a96f4
--- /dev/null
+++ b/tp/t/no_structure_test.t
@@ -0,0 +1,301 @@
+use strict;
+
+use lib '.';
+use Texinfo::ModulePath (undef, undef, undef, 'updirs' => 2);
+
+use Test::More;
+
+BEGIN { plan tests => 8; }
+
+use File::Spec;
+
+use Texinfo::Tests qw(compare_dirs_files unlink_dir_files);
+
+use Texinfo::Parser;      
+use Texinfo::Convert::Texinfo;
+use Texinfo::Convert::HTML;
+use Texinfo::Convert::Plaintext;
+use Texinfo::Convert::Info;
+use Texinfo::Convert::LaTeX;
+use Texinfo::Convert::DocBook;
+use Texinfo::Convert::TexinfoXML;
+
+# The test in this file tests outputing with converters without
+# calling the Texinfo Structuring code.  In general we ae not that
+# interested by the results themselves, more by the errors.
+
+
+
+sub _prepare_test_directory($$$$)
+{
+  my $test_name = shift;
+  my $format_type = shift;
+  my $srcdir = shift;
+  my $base = shift;
+
+  my $test_out_dir = $base.'out_'.$format_type;
+  my $reference_dir = "$srcdir$base".'res_'.$format_type;
+
+  mkdir ($base)
+    if (! -d $base);
+  if (! -d $test_out_dir) {
+    mkdir ($test_out_dir);
+  } else {
+    # remove any files from previous runs
+    unlink glob ("$test_out_dir/*");
+  }
+  return ($test_out_dir, $reference_dir);
+}
+
+sub _run_file_test($$$$$$)
+{
+  my $test_name = shift;
+  my $format = shift;
+  my $converter = shift;
+  my $document = shift;
+  my $test_out_dir = shift;
+  my $reference_dir = shift;
+
+  my $format_type = $format;
+
+  my $result = $converter->output($document);
+  if (!defined($result)) {
+    my $converter_errors = $converter->get_converter_errors();
+    my $converter_registrar = Texinfo::Report::new();
+    foreach my $error (@$converter_errors) {
+      $converter_registrar->add_formatted_message($error);
+    }
+    my ($errors, $error_nrs) = $converter_registrar->errors();
+    foreach my $error_message (@$errors) {
+      warn "$format_type: ".$error_message->{'error_line'};
+    }
+  }
+
+  my $results_dir = $test_out_dir;
+  if (-d $reference_dir) {
+    my $errors = compare_dirs_files($reference_dir, $results_dir);
+    ok (!defined($errors), $test_name.' converted '.$format)
+      or diag (join("\n", @$errors));
+  } else {
+    print STDERR "\n$format $test_name: \n$results_dir\n";
+  }
+}
+
+
+
+my $srcdir = $ENV{'srcdir'};
+if (defined($srcdir)) {
+  $srcdir =~ s/\/*$/\//;
+} else {
+  $srcdir = '';
+}
+
+my $debug = 0;
+#my $debug = 1;
+  
+ok(1, "modules loading");
+
+my $texi = '@contents
+
+@top First File
+@node Top
+
+@node chap
+@chapter Chap
+
+@anchor{point}
+
+@cindex c
+
+@node results
+@appendix Results
+
+@xref{point}.
+
+@menu
+* chap::
+@end menu
+
+@subsection subsec
+@printindex cp
+
+';
+
+my $test_parser = Texinfo::Parser::parser({'DEBUG' => $debug});
+
+my $document = $test_parser->Texinfo::Parser::parse_texi_text($texi);
+
+$document->set_document_global_info('input_file_name',
+                                    'test_struct');
+
+# check that the tree is ok by converting back
+my $result_texi
+  = Texinfo::Convert::Texinfo::convert_to_texinfo($document->tree());
+is ($result_texi, $texi, 'back to Texinfo');
+
+
+my ($test_parser_errors, $test_parser_error_count) = $test_parser->errors();
+foreach my $error_message (@$test_parser_errors) {
+  warn "W: ".$error_message->{'error_line'}
+   ;# if ($debug);
+}
+
+foreach my $dir ('t', 't/results', 't/results/no_structure_test') {
+  my $error;
+  # to avoid a race conditon, first create the dir then test that it
+  # exists
+  mkdir $dir or $error = $!;
+  if (! -d $dir) {
+    die "mkdir $dir: $error\n";
+  }
+}
+
+my $test_name = 'one';
+my $base = "t/results/no_structure_test/$test_name/";
+
+my $format = 'html';
+my ($html_test_out_dir, $html_reference_dir)
+   = _prepare_test_directory($test_name, $format, $srcdir, $base);
+
+
+my $html_converter = Texinfo::Convert::HTML->converter(
+                        {'CONTENTS_OUTPUT_LOCATION' => 'inline',
+                         'FORMAT_MENU' => 'menu',
+                         'SUBDIR' => $html_test_out_dir,
+                         'SPLIT' => ''});
+
+# Note that there are no contents, as there is not sections_list
+_run_file_test($test_name, $format, $html_converter, $document,
+               $html_test_out_dir, $html_reference_dir);
+
+my $plaintext_converter = Texinfo::Convert::Plaintext->converter();
+my $plaintext_text = $plaintext_converter->convert($document);
+is ($plaintext_text, 'First File
+**********
+
+Chap
+****
+
+Results
+*******
+
+*Note point::.
+
+subsec
+------
+
+* Menu:
+
+* c:                                     chap.                  (line 5)
+
+'
+, 'plaintext');
+#print STDERR "'$plaintext_text'\n";
+
+$format = 'info';
+my ($info_test_out_dir, $info_reference_dir)
+   = _prepare_test_directory($test_name, $format, $srcdir, $base);
+
+my $info_converter
+  = Texinfo::Convert::Info->converter({'SUBDIR' => $info_test_out_dir});
+
+_run_file_test($test_name, $format, $info_converter, $document,
+               $info_test_out_dir, $info_reference_dir);
+
+
+my $latex_converter = Texinfo::Convert::LaTeX->converter();
+my $latex_text = $latex_converter->convert($document);
+is ($latex_text, '
+\begin{document}
+\part*{{First File}}
+\label{anchor:Top}%
+\chapter{{Chap}}
+\label{anchor:chap}%
+
+\label{anchor:point}%
+
+\index[cp]{c@c}%
+
+\appendix
+\chapter{{Results}}
+\label{anchor:results}%
+
+See point.
+
+
+\subsection{{subsec}}
+\printindex[cp]
+
+'
+, 'latex');
+
+#print STDERR "'$latex_text'\n";
+
+my $docbook_converter = Texinfo::Convert::DocBook->converter();
+my $docbook_text = $docbook_converter->convert($document);
+is ($docbook_text, '<chapter label="">
+<title>First File</title>
+</chapter>
+<chapter label="" id="chap">
+<title>Chap</title>
+
+<anchor id="point"/>
+<indexterm role="cp"><primary>c</primary></indexterm>
+
+</chapter>
+<appendix label="" id="results">
+<title>Results</title>
+
+<para>See <link>point</link>.
+</para>
+
+</appendix>
+<sect2 label="">
+<title>subsec</title>
+<index role="cp"></index>
+
+</sect2>
+'
+, 'docbook');
+
+#print STDERR "'$docbook_text'\n";
+
+my $texinfoxml_converter = Texinfo::Convert::TexinfoXML->converter();
+my $texinfoxml_text = $texinfoxml_converter->convert($document);
+is ($texinfoxml_text, '<contents></contents>
+
+<top spaces=" "><sectiontitle>First File</sectiontitle>
+</top>
+<node name="Top" spaces=" "><nodename>Top</nodename></node>
+
+<node name="chap" spaces=" "><nodename>chap</nodename></node>
+<chapter spaces=" "><sectiontitle>Chap</sectiontitle>
+
+<anchor name="point">point</anchor>
+
+<cindex index="cp" spaces=" "><indexterm index="cp" 
number="1">c</indexterm></cindex>
+
+</chapter>
+<node name="results" spaces=" "><nodename>results</nodename></node>
+<appendix spaces=" "><sectiontitle>Results</sectiontitle>
+
+<para><xref label="point"><xrefnodename>point</xrefnodename></xref>.
+</para>
+<menu endspaces=" ">
+<menuentry><menuleadingtext>* 
</menuleadingtext><menunode>chap</menunode><menuseparator>::</menuseparator><menudescription><pre
 xml:space="preserve">
+</pre></menudescription></menuentry></menu>
+
+</appendix>
+<subsection spaces=" "><sectiontitle>subsec</sectiontitle>
+<printindex spaces=" " value="cp" line="cp"></printindex>
+
+</subsection>
+'
+
+, 'Texinfo XML');
+
+#print STDERR "'$texinfoxml_text'\n";
+
+
+
+
diff --git a/tp/t/results/no_structure_test/one/res_html/test_struct.html 
b/tp/t/results/no_structure_test/one/res_html/test_struct.html
new file mode 100644
index 0000000000..1111c61277
--- /dev/null
+++ b/tp/t/results/no_structure_test/one/res_html/test_struct.html
@@ -0,0 +1,85 @@
+<!DOCTYPE html>
+<html>
+<!-- Created by texinfo, http://www.gnu.org/software/texinfo/ -->
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
+<title>First File</title>
+
+<meta name="description" content="First File">
+<meta name="keywords" content="First File">
+<meta name="resource-type" content="document">
+<meta name="distribution" content="global">
+<meta name="viewport" content="width=device-width,initial-scale=1">
+
+<link href="#Top" rel="start" title="Top">
+<link href="#results" rel="index" title="results">
+<style type="text/css">
+<!--
+a.copiable-link {visibility: hidden; text-decoration: none; line-height: 0em}
+a.summary-letter-printindex {text-decoration: none}
+span:hover a.copiable-link {visibility: visible}
+td.menu-entry-description {vertical-align: top}
+td.menu-entry-destination {vertical-align: top}
+td.printindex-index-entry {vertical-align: top}
+td.printindex-index-section {vertical-align: top; padding-left: 1em}
+th.entries-header-printindex {text-align:left}
+th.sections-header-printindex {text-align:left; padding-left: 1em}
+-->
+</style>
+
+
+</head>
+
+<body lang="en">
+
+<div class="top-level-extent">
+<div class="nav-panel">
+<p>
+[<a href="#results" title="Index" rel="index">Index</a>]</p>
+</div>
+<h1 class="node" id="Top"><span>Top<a class="copiable-link" href="#Top"> 
&para;</a></span></h1>
+
+<hr>
+<div class="chapter-level-extent" id="chap">
+<div class="nav-panel">
+<p>
+[<a href="#results" title="Index" rel="index">Index</a>]</p>
+</div>
+
+<a class="anchor" id="point"></a>
+<a class="index-entry-id" id="index-c"></a>
+
+<hr>
+</div>
+<div class="appendix-level-extent" id="results">
+<div class="nav-panel">
+<p>
+[<a href="#results" title="Index" rel="index">Index</a>]</p>
+</div>
+
+<p>See &lsquo;point&rsquo;.
+</p>
+<table class="menu" border="0" cellspacing="0">
+<tr><td class="menu-entry-destination">&bull; 
chap:</td><td>&nbsp;&nbsp;</td><td class="menu-entry-description">
+</td></tr>
+</table>
+
+<div class="subsection-level-extent">
+<div class="printindex cp-printindex">
+<table class="cp-entries-printindex" border="0">
+<tr><td></td><th class="entries-header-printindex">Index Entry</th><th 
class="sections-header-printindex">Section</th></tr>
+<tr><td colspan="3"><hr></td></tr>
+<tr><th id="results_cp_letter-C">C</th></tr>
+<tr><td></td><td class="printindex-index-entry"><a 
href="#index-c">c</a></td><td class="printindex-index-section"><a 
href="#chap">chap</a></td></tr>
+<tr><td colspan="3"><hr></td></tr>
+</table>
+</div>
+
+</div>
+</div>
+</div>
+
+
+
+</body>
+</html>
diff --git a/tp/t/results/no_structure_test/one/res_info/test_struct.info 
b/tp/t/results/no_structure_test/one/res_info/test_struct.info
new file mode 100644
index 0000000000..a110c90231
Binary files /dev/null and 
b/tp/t/results/no_structure_test/one/res_info/test_struct.info differ
diff --git a/tp/t/test_utils.pl b/tp/t/test_utils.pl
index eeeaae9729..3d68c8d6f8 100644
--- a/tp/t/test_utils.pl
+++ b/tp/t/test_utils.pl
@@ -49,7 +49,6 @@ use I18N::Langinfo qw(langinfo CODESET);
 use Encode ();
 #use File::Basename;
 #use File::Copy;
-use File::Compare qw(compare); # standard since 5.004
 use Data::Dumper ();
 use Data::Compare ();
 use Test::Deep ();
@@ -60,6 +59,8 @@ use Storable qw(dclone); # standard in 5.007003
 use Getopt::Long qw(GetOptions);
 use Locale::Messages ();
 
+use Texinfo::Tests qw(compare_dirs_files unlink_dir_files);
+
 use Texinfo::Commands;
 use Texinfo::Options;
 use Texinfo::Common;
@@ -227,95 +228,6 @@ sub protect_perl_string($)
   return $string;
 }
 
-# not that subdirectories are not compared, so subdirectories generated
-# by INFO_JS_DIR, if different, will not trigger an error in test, but
-# will lead to different directories and files in diffs.
-sub compare_dirs_files($$;$)
-{
-  my $dir1 = shift;
-  my $dir2 = shift;
-  my $ignore_files = shift;
-
-  my %dir1_files;
-  my %dir2_files;
-  my @errors;
-  my %ignored_files_hash;
-  foreach my $ignored_file (@$ignore_files) {
-    $ignored_files_hash{$ignored_file} = 1;
-  }
-  if (opendir(DIR1, $dir1)) {
-    my @files = readdir (DIR1);
-    foreach my $file (@files) {
-      next if (! -r "$dir1/$file" or ! -f "$dir1/$file"
-               or $ignored_files_hash{$file});
-      $dir1_files{$file} = 1;
-    }
-    closedir (DIR1);
-  } else {
-    push @errors, "readdir $dir1: $!";
-  }
-  if (opendir(DIR2, $dir2)) {
-    my @files = readdir (DIR2);
-    foreach my $file (@files) {
-      next if (! -r "$dir2/$file" or ! -f "$dir2/$file"
-               or $ignored_files_hash{$file});
-      $dir2_files{$file} = 1;
-    }
-    closedir (DIR2);
-  } else {
-    push @errors, "readdir $dir2: $!";
-  }
-  if (scalar(@errors)) {
-    return \@errors;
-  }
-  foreach my $file (sort(keys(%dir1_files))) {
-    if ($dir2_files{$file}) {
-      my $status = compare("$dir1/$file", "$dir2/$file");
-      if ($status) {
-        push @errors, "$dir1/$file and $dir2/$file differ: $status";
-      }
-      delete $dir2_files{$file};
-    } else {
-      push @errors, "No $file in $dir2";
-    }
-  }
-  foreach my $file (sort(keys(%dir2_files))) {
-    push @errors, "No $file in $dir1"
-  }
-  if (scalar(@errors)) {
-    return \@errors;
-  } else {
-    return undef;
-  }
-}
-
-#my $errors = compare_dirs_files('a', 'b',['nnn']);
-#if ($errors) {
-#  foreach my $error (@$errors) {
-#    warn $error."\n";
-#  }
-#}
-
-sub unlink_dir_files($;$)
-{
-  my $dir = shift;
-  my $ignore_files = shift;
-  my %ignored_files_hash;
-  foreach my $ignored_file (@$ignore_files) {
-    $ignored_files_hash{$ignored_file} = 1;
-  }
-  if (opendir(DIR, $dir)) {
-    my @files = readdir (DIR);
-    foreach my $file (@files) {
-      next if (! -f "$dir/$file"
-               or $ignored_files_hash{$file});
-      unlink "$dir/$file" or warn "Could not unlink $dir/$file: $!\n";
-    }
-    closedir (DIR);
-  } else {
-    warn "readdir $dir: $!";
-  }
-}
 
 #my $remove_parent = sub {my $h = shift; delete $h->{'parent'}};
 #my $transformer = Data::Transformer->new('hash'=>$remove_parent);



reply via email to

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