texinfo-commits
[Top][All Lists]
Advanced

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

texinfo/tp/t 06columnfractions.t test_utils.pl ...


From: Patrice Dumas
Subject: texinfo/tp/t 06columnfractions.t test_utils.pl ...
Date: Mon, 20 Sep 2010 21:07:59 +0000

CVSROOT:        /sources/texinfo
Module name:    texinfo
Changes by:     Patrice Dumas <pertusus>        10/09/20 21:07:59

Modified files:
        tp/t           : 06columnfractions.t 
Added files:
        tp/t           : test_utils.pl 
        tp/t/results   : columnfractions.pl 

Log message:
        Code for systematic tests.

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/texinfo/tp/t/06columnfractions.t?cvsroot=texinfo&r1=1.3&r2=1.4
http://cvs.savannah.gnu.org/viewcvs/texinfo/tp/t/test_utils.pl?cvsroot=texinfo&rev=1.1
http://cvs.savannah.gnu.org/viewcvs/texinfo/tp/t/results/columnfractions.pl?cvsroot=texinfo&rev=1.1

Patches:
Index: 06columnfractions.t
===================================================================
RCS file: /sources/texinfo/texinfo/tp/t/06columnfractions.t,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -b -r1.3 -r1.4
--- 06columnfractions.t 20 Sep 2010 19:57:46 -0000      1.3
+++ 06columnfractions.t 20 Sep 2010 21:07:58 -0000      1.4
@@ -1,65 +1,45 @@
 #use strict;
 
 use Test::More;
-BEGIN { plan tests => 8 };
-use Texinfo::Parser qw(:all);
-use Data::Dumper;
-use Data::Compare;
+#BEGIN { plan tests => 8 };
 
-ok(1);
+require 't/test_utils.pl';
 
 my $generate;
-#$generate = 1;
+# $generate = 1;
+
+my @test_cases = (
+[ 'good', '@multitable @columnfractions 0.4 .6 5.
address@hidden multitable' ],
+[ 'good_comment', '@multitable @columnfractions 0.4 .6 address@hidden comment
address@hidden multitable' ],
+[ 'good_space_comment', '@multitable @columnfractions 0 1  @c space comment
address@hidden multitable' ],
+[ 'not_fraction','@multitable @columnfractions aaa
address@hidden multitable' ],
+[ 'empty', '@multitable @columnfractions 
address@hidden multitable' ],
+[ 'empty_comment', '@multitable @columnfractions @c
address@hidden multitable' ],
+[ 'wrong_command', '@multitable @columnfractions @b{3.4} 
address@hidden multitable' ]
+);
+
+# following may be cut and paste.
+
 if ($generate) {
-  open (RES, ">t/columnfractions_results.pl") or die;
-  print RES 'use vars qw(%result_texts);'."\n\n";
+  plan tests => 1;
 }
 else {
-  require 't/columnfractions_results.pl';
+  plan tests => (1 + scalar(@test_cases) * 2);
 }
 
-sub try_test($$$) 
-{
-  my $test_text = shift;
-  my $test_name = shift;
-  my $check = shift;
-  my $parser = Texinfo::Parser->parser({'test' => 1});
-  #my $parser = Texinfo::Parser->parser({'test' => 1, 'debug' => 1});
-  my $result =  $parser->parse_texi_text($test_text, 1);
-  #ok (Data::Compare::Compare($result, $check), $test_name);
-  if ($generate) {
-    local $Data::Dumper::Purity = 1;
-    print RES 'use vars qw($result_'.$test_name.");\n";
-    print RES "".Data::Dumper->Dump([$result], ['$result_'.$test_name]);
-    print RES "\n".'$result_texts{\''.$test_name.'\'} = 
\''.tree_to_texi($result)."';\n\n";
-    print STDERR "--> $test_name\n".tree_to_texi($result)."\n";
-  }
-  else {
-    ok (Data::Compare::Compare($result, $check, { 'ignore_hash_keys' => 
[qw(parent)] }), $test_name);
-  }
-  #exit;
-}
+ok(1);
 
-foreach my $test (
-[ '@multitable @columnfractions 0.4 .6 5.
address@hidden multitable', 'good', $result_good ],
-[ '@multitable @columnfractions 0.4 .6 address@hidden comment
address@hidden multitable', 'good_comment', $result_good_comment ],
-[ '@multitable @columnfractions 0 1  @c space comment
address@hidden multitable', 'good_space_comment', $result_good_space_comment ],
-[ '@multitable @columnfractions aaa
address@hidden multitable', 'not_fraction', $result_not_fraction ],
-[ '@multitable @columnfractions 
address@hidden multitable', 'empty', $result_empty ],
-[ '@multitable @columnfractions @c
address@hidden multitable', 'empty_comment', $result_empty_comment ],
-[ '@multitable @columnfractions @b{3.4} 
address@hidden multitable', 'wrong_command', $result_wrong_command ]
-) {
-  try_test($test->[0], $test->[1], $test->[2])
-}
+my $test = new_test('columnfractions', $generate);
 
-if ($generate) {
-  print RES "\n1;\n";
-  close (RES);
+foreach my $test_case (@test_cases) {
+  $test->test($test_case);
 }
+
+$test->end_test();

Index: test_utils.pl
===================================================================
RCS file: test_utils.pl
diff -N test_utils.pl
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ test_utils.pl       20 Sep 2010 21:07:58 -0000      1.1
@@ -0,0 +1,65 @@
+use strict;
+
+use Texinfo::Parser qw(:all);
+use Data::Dumper;
+use Data::Compare;
+
+use vars qw(%result_texts %result_trees);
+
+sub new_test ($;$) {
+  my $name = shift;
+  my $generate = shift;
+  my $file = "t/results/$name.pl";
+  my $test = {'name' => $name, 'generate' => $generate, 'file' => $file};
+  
+  if ($generate) {
+    local *FH;
+    open (*FH, ">$file") or die "Open $file: $!\n";
+    $test->{'fh'} = *FH;
+    my $FH = $test->{'fh'};
+    print $FH 'use vars qw(%result_texts);'."\n\n";
+    print $FH 'use vars qw(%result_trees);'."\n\n";
+  }
+  else {
+    require "$file";
+  }
+  bless $test;
+  return $test;
+}
+
+sub test($$$$) 
+{
+  my $self = shift;
+  my $test_case = shift;
+  my $test_name = shift @$test_case;
+  my $test_text = shift @$test_case;
+
+  my $parser = Texinfo::Parser->parser({'test' => 1});
+  #my $parser = Texinfo::Parser->parser({'test' => 1, 'debug' => 1});
+  my $result =  $parser->parse_texi_text($test_text, 1);
+
+  if ($self->{'generate'}) {
+    local $Data::Dumper::Purity = 1;
+    $Data::Dumper::Sortkeys = 1;
+    my $FH = $self->{'fh'};
+    print $FH "".Data::Dumper->Dump([$result], 
['$result_trees{\''.$test_name.'\'}']);
+    print $FH "\n".'$result_texts{\''.$test_name.'\'} = 
\''.tree_to_texi($result)."';\n\n";
+    print STDERR "--> $test_name\n".tree_to_texi($result)."\n";
+  }
+  else {
+    ok (Data::Compare::Compare($result, $result_trees{$test_name}, { 
'ignore_hash_keys' => [qw(parent)] }), $test_name.' tree' );
+    is (tree_to_texi($result), $result_texts{$test_name}, $test_name.' text' );
+  }
+  #exit;
+}
+
+sub end_test($) {
+  my $self = shift;
+  if ($self->{'generate'}) {
+    my $FH = $self->{'fh'};
+    print $FH "\n1;\n";
+    close ($self->{'fh'});
+  }
+}
+
+1;

Index: results/columnfractions.pl
===================================================================
RCS file: results/columnfractions.pl
diff -N results/columnfractions.pl
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ results/columnfractions.pl  20 Sep 2010 21:07:59 -0000      1.1
@@ -0,0 +1,280 @@
+use vars qw(%result_texts);
+
+use vars qw(%result_trees);
+
+$result_trees{'good'} = {
+                          'contents' => [
+                                          {
+                                            'args' => [
+                                                        {
+                                                          'args' => [
+                                                                      {
+                                                                        
'parent' => {},
+                                                                        'text' 
=> '0.4',
+                                                                        'type' 
=> 'fraction'
+                                                                      },
+                                                                      {
+                                                                        
'parent' => {},
+                                                                        'text' 
=> '.6',
+                                                                        'type' 
=> 'fraction'
+                                                                      },
+                                                                      {
+                                                                        
'parent' => {},
+                                                                        'text' 
=> '5.',
+                                                                        'type' 
=> 'fraction'
+                                                                      }
+                                                                    ],
+                                                          'cmdname' => 
'columnfractions',
+                                                          'parent' => {}
+                                                        }
+                                                      ],
+                                            'cmdname' => 'multitable',
+                                            'parent' => {}
+                                          }
+                                        ]
+                        };
+$result_trees{'good'}{'contents'}[0]{'args'}[0]{'args'}[0]{'parent'} = 
$result_trees{'good'}{'contents'}[0]{'args'}[0];
+$result_trees{'good'}{'contents'}[0]{'args'}[0]{'args'}[1]{'parent'} = 
$result_trees{'good'}{'contents'}[0]{'args'}[0];
+$result_trees{'good'}{'contents'}[0]{'args'}[0]{'args'}[2]{'parent'} = 
$result_trees{'good'}{'contents'}[0]{'args'}[0];
+$result_trees{'good'}{'contents'}[0]{'args'}[0]{'parent'} = 
$result_trees{'good'}{'contents'}[0];
+$result_trees{'good'}{'contents'}[0]{'parent'} = $result_trees{'good'};
+
+$result_texts{'good'} = '@multitable @columnfractions 0.4 .6 5.
address@hidden multitable
+';
+
+$result_trees{'good_comment'} = {
+                                  'contents' => [
+                                                  {
+                                                    'args' => [
+                                                                {
+                                                                  'args' => [
+                                                                              {
+                                                                               
 'parent' => {},
+                                                                               
 'text' => '0.4',
+                                                                               
 'type' => 'fraction'
+                                                                              
},
+                                                                              {
+                                                                               
 'parent' => {},
+                                                                               
 'text' => '.6',
+                                                                               
 'type' => 'fraction'
+                                                                              
},
+                                                                              {
+                                                                               
 'parent' => {},
+                                                                               
 'text' => '5.',
+                                                                               
 'type' => 'fraction'
+                                                                              }
+                                                                            ],
+                                                                  'cmdname' => 
'columnfractions',
+                                                                  'parent' => 
{}
+                                                                },
+                                                                {
+                                                                  'args' => [
+                                                                              {
+                                                                               
 'parent' => {},
+                                                                               
 'text' => ' comment
+',
+                                                                               
 'type' => 'misc_arg'
+                                                                              }
+                                                                            ],
+                                                                  'cmdname' => 
'c',
+                                                                  'parent' => 
{}
+                                                                }
+                                                              ],
+                                                    'cmdname' => 'multitable',
+                                                    'parent' => {}
+                                                  }
+                                                ]
+                                };
+$result_trees{'good_comment'}{'contents'}[0]{'args'}[0]{'args'}[0]{'parent'} = 
$result_trees{'good_comment'}{'contents'}[0]{'args'}[0];
+$result_trees{'good_comment'}{'contents'}[0]{'args'}[0]{'args'}[1]{'parent'} = 
$result_trees{'good_comment'}{'contents'}[0]{'args'}[0];
+$result_trees{'good_comment'}{'contents'}[0]{'args'}[0]{'args'}[2]{'parent'} = 
$result_trees{'good_comment'}{'contents'}[0]{'args'}[0];
+$result_trees{'good_comment'}{'contents'}[0]{'args'}[0]{'parent'} = 
$result_trees{'good_comment'}{'contents'}[0];
+$result_trees{'good_comment'}{'contents'}[0]{'args'}[1]{'args'}[0]{'parent'} = 
$result_trees{'good_comment'}{'contents'}[0]{'args'}[1];
+$result_trees{'good_comment'}{'contents'}[0]{'args'}[1]{'parent'} = 
$result_trees{'good_comment'}{'contents'}[0];
+$result_trees{'good_comment'}{'contents'}[0]{'parent'} = 
$result_trees{'good_comment'};
+
+$result_texts{'good_comment'} = '@multitable @columnfractions 0.4 .6 5. @c 
comment
address@hidden multitable
+';
+
+$result_trees{'good_space_comment'} = {
+                                        'contents' => [
+                                                        {
+                                                          'args' => [
+                                                                      {
+                                                                        'args' 
=> [
+                                                                               
     {
+                                                                               
       'parent' => {},
+                                                                               
       'text' => '0',
+                                                                               
       'type' => 'fraction'
+                                                                               
     },
+                                                                               
     {
+                                                                               
       'parent' => {},
+                                                                               
       'text' => '1',
+                                                                               
       'type' => 'fraction'
+                                                                               
     }
+                                                                               
   ],
+                                                                        
'cmdname' => 'columnfractions',
+                                                                        
'parent' => {}
+                                                                      },
+                                                                      {
+                                                                        'args' 
=> [
+                                                                               
     {
+                                                                               
       'parent' => {},
+                                                                               
       'text' => ' space comment
+',
+                                                                               
       'type' => 'misc_arg'
+                                                                               
     }
+                                                                               
   ],
+                                                                        
'cmdname' => 'c',
+                                                                        
'parent' => {}
+                                                                      }
+                                                                    ],
+                                                          'cmdname' => 
'multitable',
+                                                          'parent' => {}
+                                                        }
+                                                      ]
+                                      };
+$result_trees{'good_space_comment'}{'contents'}[0]{'args'}[0]{'args'}[0]{'parent'}
 = $result_trees{'good_space_comment'}{'contents'}[0]{'args'}[0];
+$result_trees{'good_space_comment'}{'contents'}[0]{'args'}[0]{'args'}[1]{'parent'}
 = $result_trees{'good_space_comment'}{'contents'}[0]{'args'}[0];
+$result_trees{'good_space_comment'}{'contents'}[0]{'args'}[0]{'parent'} = 
$result_trees{'good_space_comment'}{'contents'}[0];
+$result_trees{'good_space_comment'}{'contents'}[0]{'args'}[1]{'args'}[0]{'parent'}
 = $result_trees{'good_space_comment'}{'contents'}[0]{'args'}[1];
+$result_trees{'good_space_comment'}{'contents'}[0]{'args'}[1]{'parent'} = 
$result_trees{'good_space_comment'}{'contents'}[0];
+$result_trees{'good_space_comment'}{'contents'}[0]{'parent'} = 
$result_trees{'good_space_comment'};
+
+$result_texts{'good_space_comment'} = '@multitable @columnfractions 0 1 @c 
space comment
address@hidden multitable
+';
+
+$result_trees{'not_fraction'} = {
+                                  'contents' => [
+                                                  {
+                                                    'args' => [
+                                                                {
+                                                                  'cmdname' => 
'columnfractions',
+                                                                  'parent' => 
{}
+                                                                }
+                                                              ],
+                                                    'cmdname' => 'multitable',
+                                                    'parent' => {}
+                                                  }
+                                                ]
+                                };
+$result_trees{'not_fraction'}{'contents'}[0]{'args'}[0]{'parent'} = 
$result_trees{'not_fraction'}{'contents'}[0];
+$result_trees{'not_fraction'}{'contents'}[0]{'parent'} = 
$result_trees{'not_fraction'};
+
+$result_texts{'not_fraction'} = '@multitable @columnfractions
address@hidden multitable
+';
+
+$result_trees{'empty'} = {
+                           'contents' => [
+                                           {
+                                             'args' => [
+                                                         {
+                                                           'cmdname' => 
'columnfractions',
+                                                           'parent' => {}
+                                                         }
+                                                       ],
+                                             'cmdname' => 'multitable',
+                                             'parent' => {}
+                                           }
+                                         ]
+                         };
+$result_trees{'empty'}{'contents'}[0]{'args'}[0]{'parent'} = 
$result_trees{'empty'}{'contents'}[0];
+$result_trees{'empty'}{'contents'}[0]{'parent'} = $result_trees{'empty'};
+
+$result_texts{'empty'} = '@multitable @columnfractions
address@hidden multitable
+';
+
+$result_trees{'empty_comment'} = {
+                                   'contents' => [
+                                                   {
+                                                     'args' => [
+                                                                 {
+                                                                   'cmdname' 
=> 'columnfractions',
+                                                                   'parent' => 
{}
+                                                                 },
+                                                                 {
+                                                                   'args' => [
+                                                                               
{
+                                                                               
  'parent' => {},
+                                                                               
  'text' => '
+',
+                                                                               
  'type' => 'misc_arg'
+                                                                               
}
+                                                                             ],
+                                                                   'cmdname' 
=> 'c',
+                                                                   'parent' => 
{}
+                                                                 }
+                                                               ],
+                                                     'cmdname' => 'multitable',
+                                                     'parent' => {}
+                                                   }
+                                                 ]
+                                 };
+$result_trees{'empty_comment'}{'contents'}[0]{'args'}[0]{'parent'} = 
$result_trees{'empty_comment'}{'contents'}[0];
+$result_trees{'empty_comment'}{'contents'}[0]{'args'}[1]{'args'}[0]{'parent'} 
= $result_trees{'empty_comment'}{'contents'}[0]{'args'}[1];
+$result_trees{'empty_comment'}{'contents'}[0]{'args'}[1]{'parent'} = 
$result_trees{'empty_comment'}{'contents'}[0];
+$result_trees{'empty_comment'}{'contents'}[0]{'parent'} = 
$result_trees{'empty_comment'};
+
+$result_texts{'empty_comment'} = '@multitable @columnfractions @c
address@hidden multitable
+';
+
+$result_trees{'wrong_command'} = {
+                                   'contents' => [
+                                                   {
+                                                     'args' => [
+                                                                 {
+                                                                   'cmdname' 
=> 'columnfractions',
+                                                                   'contents' 
=> [
+                                                                               
    {
+                                                                               
      'args' => [
+                                                                               
                  {
+                                                                               
                    'contents' => [
+                                                                               
                                    {
+                                                                               
                                      'parent' => {},
+                                                                               
                                      'text' => '3.4'
+                                                                               
                                    }
+                                                                               
                                  ],
+                                                                               
                    'parent' => {},
+                                                                               
                    'type' => 'brace_command_arg'
+                                                                               
                  }
+                                                                               
                ],
+                                                                               
      'cmdname' => 'b',
+                                                                               
      'contents' => [
+                                                                               
                      {
+                                                                               
                        'parent' => {},
+                                                                               
                        'text' => ' 
+'
+                                                                               
                      }
+                                                                               
                    ],
+                                                                               
      'parent' => {},
+                                                                               
      'remaining_args' => 0
+                                                                               
    }
+                                                                               
  ],
+                                                                   'parent' => 
{},
+                                                                   'type' => 
'block_line_arg'
+                                                                 }
+                                                               ],
+                                                     'cmdname' => 'multitable',
+                                                     'parent' => {}
+                                                   }
+                                                 ]
+                                 };
+$result_trees{'wrong_command'}{'contents'}[0]{'args'}[0]{'contents'}[0]{'args'}[0]{'contents'}[0]{'parent'}
 = 
$result_trees{'wrong_command'}{'contents'}[0]{'args'}[0]{'contents'}[0]{'args'}[0];
+$result_trees{'wrong_command'}{'contents'}[0]{'args'}[0]{'contents'}[0]{'args'}[0]{'parent'}
 = $result_trees{'wrong_command'}{'contents'}[0]{'args'}[0]{'contents'}[0];
+$result_trees{'wrong_command'}{'contents'}[0]{'args'}[0]{'contents'}[0]{'contents'}[0]{'parent'}
 = $result_trees{'wrong_command'}{'contents'}[0]{'args'}[0]{'contents'}[0];
+$result_trees{'wrong_command'}{'contents'}[0]{'args'}[0]{'contents'}[0]{'parent'}
 = $result_trees{'wrong_command'}{'contents'}[0]{'args'}[0];
+$result_trees{'wrong_command'}{'contents'}[0]{'args'}[0]{'parent'} = 
$result_trees{'wrong_command'}{'contents'}[0];
+$result_trees{'wrong_command'}{'contents'}[0]{'parent'} = 
$result_trees{'wrong_command'};
+
+$result_texts{'wrong_command'} = '@multitable @address@hidden 
address@hidden multitable
+';
+
+
+1;



reply via email to

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