From d4b9a41af9be3575f07fe96d77ede6b4caf8dee5 Mon Sep 17 00:00:00 2001
From: Marius Gavrilescu
Date: Thu, 25 Dec 2014 22:34:36 +0200
Subject: [PATCH] Fix tests
---
Makefile.PL | 3 +-
t/TestUtils.pm | 35 ----
t/crunch.t | 14 +-
t/defmap.t | 6 +-
t/dual_iter.t | 8 +-
t/fillinform.t | 7 +-
t/hashmap.t | 11 +-
t/highlander.t | 9 +-
t/highlander2.t | 8 +-
t/html/crunch/crunch.exp | 60 +++---
t/html/crunch/crunch.gen | 30 ---
t/html/defmap/defmap.gen | 5 -
t/html/dual_iter.gen | 15 --
t/html/fillinform/fillinform.exp | 10 +-
t/html/fillinform/fillinform.gen | 23 ---
t/html/fillinform/fillinform.initial | 10 +-
t/html/highlander-15.gen | 6 -
t/html/highlander-5.gen | 6 -
t/html/highlander-50.gen | 5 -
t/html/highlander2-15.gen | 6 -
t/html/highlander2-27.gen | 6 -
t/html/highlander2-5.gen | 6 -
t/html/highlander2-passover.gen | 6 -
t/html/iter.gen | 10 -
t/html/iter2.gen | 15 --
t/html/same_as/same_as.gen | 15 --
t/html/table-alt.gen | 42 -----
t/html/table.gen | 42 -----
t/html/table2-table_ld-arrayref.gen | 158 ----------------
t/html/table2-table_ld-arrayref.html | 78 --------
t/html/table2-table_ld-coderef.exp | 158 ----------------
t/html/table2-table_ld-coderef.gen | 158 ----------------
t/html/table2-table_ld-coderef.html | 78 --------
t/html/table2-table_ld-default.exp | 158 ----------------
t/html/table2-table_ld-default.gen | 158 ----------------
t/html/table2-table_ld-default.html | 78 --------
...le_ld-arrayref.exp => table2-table_ld.exp} | 8 +-
t/html/table2-tr_ld-arrayref.gen | 9 -
t/html/table2-tr_ld-arrayref.html | 61 +++---
t/html/table2-tr_ld-coderef.exp | 10 +-
t/html/table2-tr_ld-coderef.gen | 131 -------------
t/html/table2-tr_ld-default.gen | 160 ----------------
t/html/table2.exp | 10 +-
t/html/table2.gen | 176 ------------------
t/html/table2.html | 55 +++---
t/html/unroll_select.exp | 14 +-
t/html/unroll_select.gen | 54 ------
t/html/unroll_select.html | 16 +-
t/iter.t | 7 +-
t/iter2.t | 9 +-
t/m/TestUtils.pm | 31 ---
t/passover.t | 7 +-
t/table-alt.t | 6 +-
t/table.t | 6 +-
t/table2-table_ld.t | 18 +-
t/table2-tr_ld.t | 15 +-
t/table2.t | 7 +-
t/unroll_select.t | 6 +-
58 files changed, 169 insertions(+), 2090 deletions(-)
delete mode 100644 t/TestUtils.pm
delete mode 100644 t/html/crunch/crunch.gen
delete mode 100644 t/html/defmap/defmap.gen
delete mode 100644 t/html/dual_iter.gen
delete mode 100644 t/html/fillinform/fillinform.gen
delete mode 100644 t/html/highlander-15.gen
delete mode 100644 t/html/highlander-5.gen
delete mode 100644 t/html/highlander-50.gen
delete mode 100644 t/html/highlander2-15.gen
delete mode 100644 t/html/highlander2-27.gen
delete mode 100644 t/html/highlander2-5.gen
delete mode 100644 t/html/highlander2-passover.gen
delete mode 100644 t/html/iter.gen
delete mode 100644 t/html/iter2.gen
delete mode 100644 t/html/same_as/same_as.gen
delete mode 100644 t/html/table-alt.gen
delete mode 100644 t/html/table.gen
delete mode 100644 t/html/table2-table_ld-arrayref.gen
delete mode 100644 t/html/table2-table_ld-arrayref.html
delete mode 100644 t/html/table2-table_ld-coderef.exp
delete mode 100644 t/html/table2-table_ld-coderef.gen
delete mode 100644 t/html/table2-table_ld-coderef.html
delete mode 100644 t/html/table2-table_ld-default.exp
delete mode 100644 t/html/table2-table_ld-default.gen
delete mode 100644 t/html/table2-table_ld-default.html
rename t/html/{table2-table_ld-arrayref.exp => table2-table_ld.exp} (95%)
delete mode 100644 t/html/table2-tr_ld-arrayref.gen
delete mode 100644 t/html/table2-tr_ld-coderef.gen
delete mode 100644 t/html/table2-tr_ld-default.gen
delete mode 100644 t/html/table2.gen
delete mode 100644 t/html/unroll_select.gen
delete mode 100644 t/m/TestUtils.pm
diff --git a/Makefile.PL b/Makefile.PL
index 60d6ffe..7d2fdb4 100644
--- a/Makefile.PL
+++ b/Makefile.PL
@@ -17,7 +17,8 @@ WriteMakefile(
qw/File::Slurp 0
HTML::PrettyPrinter 0
HTML::TreeBuilder 0
- Test::More 0/,
+ Test::More 0
+ Test::XML 0/,
},
PREREQ_PM => {
qw/Array::Group 0
diff --git a/t/TestUtils.pm b/t/TestUtils.pm
deleted file mode 100644
index e4bb274..0000000
--- a/t/TestUtils.pm
+++ /dev/null
@@ -1,35 +0,0 @@
-package TestUtils;
-
-use HTML::PrettyPrinter;
-use FileHandle;
-use File::Slurp;
-
-require Exporter;
-@ISA=qw(Exporter);
-@EXPORT = qw(ptree html_dir strip_ws);
-
-sub html_dir {
- 't/html/'
-}
-
-sub ptree {
- my $tree = shift or die 'must supply tree';
- my $out = shift or die 'must supply outfile';
-
- my $hpp = HTML::PrettyPrinter->new
- (tabify => 0, allow_forced_nl => 1, quote_attr => 1);
- my $lines = $hpp->format($tree);
-
- write_file $out, @$lines;
- join '', @$lines;
-}
-
-sub strip_ws {
- my($str)=@_;
-
- $str =~ s/\s+//g;
- $str;
-}
-
-
-1;
diff --git a/t/crunch.t b/t/crunch.t
index 383d5ed..627ef2a 100644
--- a/t/crunch.t
+++ b/t/crunch.t
@@ -1,11 +1,9 @@
# This might look like shell script, but it's actually -*- perl -*-
use strict;use warnings;
-use lib qw(t/ t/m/);
-use File::Slurp;
+use File::Slurp qw/read_file/;
use Test::More;
-use TestUtils;
use HTML::TreeBuilder;
use HTML::Element::Library;
use Test::XML;
@@ -16,17 +14,9 @@ sub tage {
my $tree = HTML::TreeBuilder->new_from_file("$root.initial")->guts;
-
$tree->crunch(look_down => [ class => 'imageElement' ], leave => 1);
- my $generated_html = strip_ws ( ptree($tree, "$root.gen") );
- # must put read_file() in scalar context so that a string instead of first line is returned.
- my $expected_html = strip_ws(scalar File::Slurp::read_file("$root.exp"));
-
- #warn "g:$generated_html";
- #warn "e:$expected_html";
-
- is ($generated_html, $expected_html, "HTML for crunch");
+ is_xml $tree->as_XML, scalar read_file("$root.exp"), 'XML for crunch';
}
diff --git a/t/defmap.t b/t/defmap.t
index c26ab43..26eeeed 100644
--- a/t/defmap.t
+++ b/t/defmap.t
@@ -1,12 +1,10 @@
# This might look like shell script, but it's actually -*- perl -*-
use strict;use warnings;
-use lib qw(t/ t/m/);
use File::Slurp;
use Test::More qw(no_plan);
use Test::XML;
-use TestUtils;
use HTML::TreeBuilder;
use HTML::Element::Library;
@@ -22,11 +20,11 @@ sub tage {
$tree->defmap(smap => \%data, 1);
- my $g = ptree($tree, "$root.gen");
+ my $g = $tree->as_XML;
my $e = File::Slurp::read_file("$root.exp");
warn "generated:$g:\nexpected:$e:";
- is_xml ($g, $e, "HTML for defmap");
+ is_xml ($g, $e, "XML for defmap");
}
diff --git a/t/dual_iter.t b/t/dual_iter.t
index dfe5b2f..dbcfb28 100644
--- a/t/dual_iter.t
+++ b/t/dual_iter.t
@@ -1,13 +1,12 @@
# This might look like shell script, but it's actually -*- perl -*-
use strict;
-use lib qw(t/ t/m/);
use File::Slurp;
use Test::More qw(no_plan);
-use TestUtils;
use HTML::TreeBuilder;
use HTML::Element::Library;
+use Test::XML;
# this is a simpler call to iter2()
@@ -47,7 +46,6 @@ $tree->iter2(
);
- my $generated_html = ptree($tree, "$root.gen");
- is ($generated_html, File::Slurp::read_file("$root.exp"),
- "HTML for generated li");
+ is_xml ($tree->as_XML, scalar File::Slurp::read_file("$root.exp"),
+ "XML for generated li");
diff --git a/t/fillinform.t b/t/fillinform.t
index 3a6c0f2..d989f4e 100644
--- a/t/fillinform.t
+++ b/t/fillinform.t
@@ -1,13 +1,12 @@
# This might look like shell script, but it's actually -*- perl -*-
use strict;use warnings;
-use lib qw(t/ t/m/);
use File::Slurp;
use Test::More qw(no_plan);
-use TestUtils;
use HTML::TreeBuilder;
use HTML::Element::Library;
+use Test::XML;
sub tage {
@@ -19,9 +18,7 @@ sub tage {
my $new_tree = HTML::TreeBuilder->new_from_content( $tree->fillinform(\%data) ) ;
- my $generated_html = ptree($new_tree, "$root.gen");
-
- is ($generated_html, File::Slurp::read_file("$root.exp"), "HTML for fillinform");
+ is_xml ($new_tree->as_XML, scalar File::Slurp::read_file("$root.exp"), "HTML for fillinform");
}
diff --git a/t/hashmap.t b/t/hashmap.t
index 285f64c..9ed2864 100644
--- a/t/hashmap.t
+++ b/t/hashmap.t
@@ -1,13 +1,12 @@
# This might look like shell script, but it's actually -*- perl -*-
use strict;
-use lib qw(t/ t/m/);
use File::Slurp;
use Test::More qw(no_plan);
-use TestUtils;
use HTML::TreeBuilder;
use HTML::Element::Library;
+use Test::XML;
sub replace_age {
my $branch = shift;
@@ -29,15 +28,11 @@ sub tage {
$tree->hash_map
(hash => \%data,
to_attr => 'sid',
- excluding => [ 'email' ],
- debug => 1
+ excluding => [ 'email' ]
);
- my $generated_html = ptree($tree, "$root.gen");
-
- is ($generated_html, File::Slurp::read_file("$root.exp"), "HTML for same_as");
+ is_xml ($tree->as_XML, scalar File::Slurp::read_file("$root.exp"), "XML for same_as");
}
tage();
-
diff --git a/t/highlander.t b/t/highlander.t
index 061cc5f..e9f754c 100644
--- a/t/highlander.t
+++ b/t/highlander.t
@@ -1,14 +1,12 @@
# This might look like shell script, but it's actually -*- perl -*-
use strict;
-use lib qw(t/ t/m/);
use File::Slurp;
use Test::More qw(no_plan);
-use TestUtils;
use HTML::TreeBuilder;
use HTML::Element::Library;
-
+use Test::XML;
sub tage {
my $age = shift;
@@ -27,9 +25,8 @@ sub tage {
my $root = "t/html/highlander-$age";
- my $generated_html = ptree($tree, "$root.gen");
-
- is ($generated_html, File::Slurp::read_file("$root.exp"), "HTML for $age");
+ local $_; # XML::Parser does not like read-only $_ (RT #101129)
+ is_xml ($tree->as_XML, scalar File::Slurp::read_file("$root.exp"), "XML for $age");
}
diff --git a/t/highlander2.t b/t/highlander2.t
index 479553f..c145b68 100644
--- a/t/highlander2.t
+++ b/t/highlander2.t
@@ -1,13 +1,12 @@
# This might look like shell script, but it's actually -*- perl -*-
use strict;
-use lib qw(t/ t/m/);
use File::Slurp;
use Test::More qw(no_plan);
-use TestUtils;
use HTML::TreeBuilder;
use HTML::Element::Library;
+use Test::XML;
sub replace_age {
my $branch = shift;
@@ -41,9 +40,8 @@ sub tage {
my $root = "t/html/highlander2-$age";
- my $generated_html = ptree($tree, "$root.gen");
-
- is ($generated_html, File::Slurp::read_file("$root.exp"), "HTML for $age");
+ local $_; # XML::Parser does not like read-only $_ (RT #101129)
+ is_xml ($tree->as_XML, scalar File::Slurp::read_file("$root.exp"), "HTML for $age");
}
diff --git a/t/html/crunch/crunch.exp b/t/html/crunch/crunch.exp
index 5c5b118..272e334 100644
--- a/t/html/crunch/crunch.exp
+++ b/t/html/crunch/crunch.exp
@@ -1,30 +1,30 @@
-
-
-
-
-
-
-
-
-
-
-
-
Item 1 Title
-
Item 1 Description
-
-

-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
Item 1 Title
+
Item 1 Description
+
+

+
+
+
diff --git a/t/html/crunch/crunch.gen b/t/html/crunch/crunch.gen
deleted file mode 100644
index 5c5b118..0000000
--- a/t/html/crunch/crunch.gen
+++ /dev/null
@@ -1,30 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
Item 1 Title
-
Item 1 Description
-
-

-
-
-
diff --git a/t/html/defmap/defmap.gen b/t/html/defmap/defmap.gen
deleted file mode 100644
index f5aabd8..0000000
--- a/t/html/defmap/defmap.gen
+++ /dev/null
@@ -1,5 +0,0 @@
-
- Yes |
- arsenal rules |
- No |
-
diff --git a/t/html/dual_iter.gen b/t/html/dual_iter.gen
deleted file mode 100644
index 64c6c8f..0000000
--- a/t/html/dual_iter.gen
+++ /dev/null
@@ -1,15 +0,0 @@
-
-
-
-
- - the pros
- - never have to worry about service again
- - the cons
- - upfront extra charge on purchase
- - our choice
- - go with the extended service plan
- - sample header
- - sample data
-
-
-
diff --git a/t/html/fillinform/fillinform.exp b/t/html/fillinform/fillinform.exp
index ed123ac..bbe603e 100644
--- a/t/html/fillinform/fillinform.exp
+++ b/t/html/fillinform/fillinform.exp
@@ -5,18 +5,18 @@
Dialer
-
-
diff --git a/t/html/fillinform/fillinform.gen b/t/html/fillinform/fillinform.gen
deleted file mode 100644
index ed123ac..0000000
--- a/t/html/fillinform/fillinform.gen
+++ /dev/null
@@ -1,23 +0,0 @@
-
-