texinfo-commits
[Top][All Lists]
Advanced

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

branch master updated: * tp/t/test_parse_texi_line.t: change in variable


From: Patrice Dumas
Subject: branch master updated: * tp/t/test_parse_texi_line.t: change in variable names, test the number of errors in any case.
Date: Sun, 26 May 2024 08:39:04 -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 7e932a3576 * tp/t/test_parse_texi_line.t: change in variable names, 
test the number of errors in any case.
7e932a3576 is described below

commit 7e932a3576b0e85958c36fa8f5fdf380e43aa206
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Sun May 26 14:38:50 2024 +0200

    * tp/t/test_parse_texi_line.t: change in variable names, test the
    number of errors in any case.
    
    * tp/t/test_protect_hashchar_at_line_beginning.t: use
    Texinfo::XSLoader::XS_*_enabled, change in variable names, test the
    number of errors in any case, use a list for reference errors, use the
    same code for errors handling as in test_parse_texi_line.t.
---
 ChangeLog                                      | 10 +++
 tp/t/test_parse_texi_line.t                    | 49 ++++++++------
 tp/t/test_protect_hashchar_at_line_beginning.t | 94 ++++++++++++++------------
 3 files changed, 89 insertions(+), 64 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index ab40262f07..9bb0655c40 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2024-05-26  Patrice Dumas  <pertusus@free.fr>
+
+       * tp/t/test_parse_texi_line.t: change in variable names, test the
+       number of errors in any case.
+
+       * tp/t/test_protect_hashchar_at_line_beginning.t: use
+       Texinfo::XSLoader::XS_*_enabled, change in variable names, test the
+       number of errors in any case, use a list for reference errors, use the
+       same code for errors handling as in test_parse_texi_line.t.
+
 2024-05-25  Patrice Dumas  <pertusus@free.fr>
 
        * tp/Texinfo/XS/convert/convert_html.c (html_id_is_registered)
diff --git a/tp/t/test_parse_texi_line.t b/tp/t/test_parse_texi_line.t
index e8e17633d1..73a1811164 100644
--- a/tp/t/test_parse_texi_line.t
+++ b/tp/t/test_parse_texi_line.t
@@ -5,8 +5,8 @@ use Texinfo::ModulePath (undef, undef, undef, 'updirs' => 2);
 
 use Test::More;
 
-# 2 * (number of tests + number of tests with errors + 2 * number of errors)
-BEGIN { plan tests => 2 * (4 + 3 + 2 * (1 + 1 + 4)); }
+# 1 + 2 * (2 * number of tests + 2 * number of errors)
+BEGIN { plan tests => 1 + 2 * (2 * 4 + 2 * (1 + 1 + 4)); }
 
 use Texinfo::Convert::Texinfo;
 use Texinfo::Parser;
@@ -15,6 +15,8 @@ use Texinfo::Parser;
 $ENV{LC_ALL} = 'C';
 $ENV{LANGUAGE} = 'en';
 
+# modules loaded
+ok(1);
 
 # test regressions specific of parse_texi_line
 
@@ -22,35 +24,40 @@ sub test_line($$$$)
 {
   my $parser = shift;
   my $texinfo_line = shift;
-  my $test_explanation = shift;
+  my $test_name = shift;
   my $errors_references = shift;
 
   if (not defined($parser)) {
     $parser = Texinfo::Parser::parser();
   }
 
-  #$parser->{'DEBUG'} = 1; print STDERR "\n$test_explanation\n\n";
-
   my $tree = $parser->parse_texi_line($texinfo_line);
   my $check_texinfo = Texinfo::Convert::Texinfo::convert_to_texinfo($tree);
-  is ($texinfo_line, $check_texinfo, $test_explanation);
+  is($texinfo_line, $check_texinfo, $test_name);
 
-  my ($error_warnings_list, $error_count) = $parser->errors();
+  my $reference_error_nrs = 0;
   if (defined($errors_references)) {
-    is (scalar(@$error_warnings_list), scalar(@$errors_references),
-        "warning/errors nr $test_explanation");
+    $reference_error_nrs = scalar(@$errors_references);
   }
+
+  my ($error_warnings_list, $error_count) = $parser->errors();
+  is(scalar(@$error_warnings_list), $reference_error_nrs,
+     "error nr $test_name");
+
   my $error_idx = 0;
   foreach my $error_message (@$error_warnings_list) {
-    if (defined($errors_references) and $error_idx < 
scalar(@$errors_references)) {
+    if (defined($errors_references)
+        and $error_idx < scalar(@$errors_references)) {
       my ($error_line_nr_reference, $error_line_reference)
         = @{$errors_references->[$error_idx]};
-      is ($error_message->{'line_nr'}, $error_line_nr_reference,
-          "$test_explanation error line $error_idx");
-      is ($error_message->{'error_line'}, $error_line_reference."\n",
-          "$test_explanation error message $error_idx");
+      is($error_message->{'line_nr'}, $error_line_nr_reference,
+         "$test_name error line $error_idx");
+      is($error_message->{'error_line'}, $error_line_reference."\n",
+         "$test_name error message $error_idx");
     } else {
-      warn "not caught: $error_message->{'error_line'}";
+      my $line = $error_message->{'error_line'};
+      chomp($line);
+      warn "not caught: [$error_message->{'line_nr'}, '$line'],\n";
     }
     $error_idx++;
   }
@@ -91,11 +98,13 @@ in chapter
 @listoffloats type
 
 @bye
-', 'long example', [[4, 'warning: @setfilename after the first element'],
-                    [24, 'column fraction not a number: a'],
-                    [24, 'column fraction not a number: b'],
-                    [24, '@columnfractions only meaningful on a @multitable 
line'],
-]]
+', 'long example',
+   [[4, 'warning: @setfilename after the first element'],
+   [24, 'column fraction not a number: a'],
+   [24, 'column fraction not a number: b'],
+   [24, '@columnfractions only meaningful on a @multitable line'],
+   ],
+]
 );
 
 foreach my $test_string_explanation (@tests) {
diff --git a/tp/t/test_protect_hashchar_at_line_beginning.t 
b/tp/t/test_protect_hashchar_at_line_beginning.t
index 454014b182..03a353dac4 100644
--- a/tp/t/test_protect_hashchar_at_line_beginning.t
+++ b/tp/t/test_protect_hashchar_at_line_beginning.t
@@ -5,78 +5,82 @@ use Texinfo::ModulePath (undef, undef, undef, 'updirs' => 2);
 
 use Test::More;
 
-BEGIN { plan tests => 9; }
+# 1 + 2 * number of tests + 2 * number of errors
+BEGIN { plan tests => 1 + 2 * 6 + 2 * 1; }
 
+#use Data::Dumper;
+
+use Texinfo::XSLoader;
+use Texinfo::Convert::Texinfo;
+use Texinfo::Document;
 use Texinfo::Parser;
 use Texinfo::Transformations;
-use Texinfo::Document;
-use Texinfo::Convert::Texinfo;
 
-use Data::Dumper;
+my $XS_structuring = Texinfo::XSLoader::XS_structuring_enabled();
+my $XS_convert = Texinfo::XSLoader::XS_convert_enabled();
 
 # For consistent error message, use the C locale
 $ENV{LC_ALL} = 'C';
 # also needed for consistent error message
 $ENV{LANGUAGE} = 'C';
 
+# modules loaded
 ok(1);
 
-my $with_XS = ((not defined($ENV{TEXINFO_XS})
-                or $ENV{TEXINFO_XS} ne 'omit')
-               and (!defined $ENV{TEXINFO_XS_PARSER}
-                    or $ENV{TEXINFO_XS_PARSER} eq '1'));
-
-
 sub run_test($$$;$)
 {
   my $in = shift;
   my $out = shift;
-  my $name = shift;
-  my $error_message = shift;
+  my $test_name = shift;
+  my $errors_references = shift;
 
   my $parser = Texinfo::Parser::parser();
   my $document = $parser->parse_texi_piece($in, 1);
-  my $tree = $document->tree();
+  my $tree = $document->tree($XS_structuring);
 
-  my $corrected_tree =
-    Texinfo::Transformations::protect_hashchar_at_line_beginning($tree,
-                                       $document->registrar(), $document);
+  Texinfo::Transformations::protect_hashchar_at_line_beginning($tree,
+                                    $document->registrar(), $document);
+  # rebuild tree if structuring with XS but conversion in pure Perl.
+  my $corrected_tree = $document->tree($XS_convert);
 
-  #Texinfo::Document::rebuild_document($document);
-  $corrected_tree = $document->tree();
+  my $reference_error_nrs = 0;
+  if (defined($errors_references)) {
+    $reference_error_nrs = scalar(@$errors_references);
+  }
 
-  if (defined($error_message)) {
-    my ($errors, $errors_count) = $parser->errors();
-    my ($document_errors, $document_errors_count)
+  my ($error_warnings_list, $parser_errors_count) = $parser->errors();
+  my ($document_errors, $document_errors_count)
       = $document->errors();
-    $errors_count += $document_errors_count if ($document_errors_count);
-    push @$errors, @$document_errors;
-
-    my ($error_line_nr_reference, $error_line_reference) = @$error_message;
-    if (!$error_line_reference) {
-      if ($errors and scalar(@$errors)) {
-        print STDERR " --error-> $errors->[0]->{'error_line'}";
-      } else {
-        print STDERR "No message\n";
-      }
+  push @$error_warnings_list, @$document_errors;
+
+  is(scalar(@$error_warnings_list), $reference_error_nrs,
+    "error nr $test_name");
+
+  my $error_idx = 0;
+  foreach my $error_message (@$error_warnings_list) {
+    if (defined($errors_references)
+        and $error_idx < scalar(@$errors_references)) {
+      my ($error_line_nr_reference, $error_line_reference)
+        = @{$errors_references->[$error_idx]};
+      is($error_message->{'line_nr'}, $error_line_nr_reference,
+         "$test_name error line $error_idx");
+      is($error_message->{'error_line'}, $error_line_reference."\n",
+         "$test_name error message $error_idx");
     } else {
-      if ($errors and scalar(@$errors)) {
-        is($error_line_nr_reference, $errors->[0]->{'line_nr'},
-          "error line: $name");
-        is($error_line_reference, $errors->[0]->{'error_line'},
-          "error message: $name");
-      } else {
-        ok(0, "error message: $name");
-      }
+      my $line = $error_message->{'error_line'};
+      chomp($line);
+      warn "not caught: [$error_message->{'line_nr'}, '$line'],\n";
     }
+    $error_idx++;
   }
 
-  my $texi_result = 
Texinfo::Convert::Texinfo::convert_to_texinfo($corrected_tree);
+  my $texi_result
+    = Texinfo::Convert::Texinfo::convert_to_texinfo($corrected_tree);
 
   if (!defined($out)) {
-    print STDERR " --> $name:\n$texi_result";
+    print STDERR " --> $test_name:\n$texi_result";
   } else {
-    is ($texi_result, $out, $name);
+    is($texi_result, $out, $test_name);
   }
 }
 
@@ -154,8 +158,10 @@ run_test('
 @macro mymacro {}
 # line 20 "ff"
 @end macro
-', 'in raw command', [2, 'warning: could not protect hash character in @macro
-']);
+', 'in raw command',
+   [[2, 'warning: could not protect hash character in @macro'],
+   ],
+);
 
 run_test('
 @example



reply via email to

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