]> git.vpit.fr Git - perl/modules/LaTeX-TikZ.git/blobdiff - t/lib/LaTeX/TikZ/TestHelper.pm
Factor the check() test function in an helper test module
[perl/modules/LaTeX-TikZ.git] / t / lib / LaTeX / TikZ / TestHelper.pm
diff --git a/t/lib/LaTeX/TikZ/TestHelper.pm b/t/lib/LaTeX/TikZ/TestHelper.pm
new file mode 100644 (file)
index 0000000..deb1dff
--- /dev/null
@@ -0,0 +1,43 @@
+package LaTeX::TikZ::TestHelper;
+
+use strict;
+use warnings;
+
+use Test::More ();
+
+use Any::Moose 'Exporter';
+
+any_moose('Exporter')->setup_import_methods(
+ as_is => [ qw<using check> ],
+);
+
+my $tikz;
+
+sub using {
+ $tikz = $_[0] if defined $_[0];
+
+ return $tikz;
+}
+
+sub check {
+ my ($set, $desc, $exp) = @_;
+
+ local $Test::Builder::Level = $Test::Builder::Level + 1;
+
+ my ($head, $decl, $body) = eval {
+  $tikz->render(ref $set eq 'ARRAY' ? @$set : $set);
+ };
+ Test::More::is($@, '', "$desc: no error");
+
+ unless (ref $exp eq 'ARRAY') {
+  $exp = [ split /\n/, $exp ];
+ }
+ unshift @$exp, '\begin{tikzpicture}';
+ push    @$exp, '\end{tikzpicture}';
+
+ Test::More::is_deeply($body, $exp, "$desc: body");
+
+ return $head, $decl, $body;
+}
+
+1;