[Templates-svn] r1064 - trunk/t
svn@template-toolkit.org
svn@template-toolkit.org
Author: abw
Date: 2007-04-27 14:20:21 +0100 (Fri, 27 Apr 2007)
New Revision: 1064
Modified:
trunk/t/compile2.t
trunk/t/compile5.t
trunk/t/provider.t
Log:
updates to tests for provider patches
Modified: trunk/t/compile2.t
===================================================================
--- trunk/t/compile2.t 2007-04-27 13:19:05 UTC (rev 1063)
+++ trunk/t/compile2.t 2007-04-27 13:20:21 UTC (rev 1064)
@@ -30,8 +30,10 @@
COMPILE_EXT => '.ttc',
};
+my $compiled = "$dir/foo.ttc";
+
# check compiled template files exist
-ok( -f "$dir/foo.ttc" );
+ok( -f $compiled );
ok( -f "$dir/complex.ttc" );
# ensure template metadata is saved in compiled file (bug fixed in v2.00)
@@ -44,16 +46,22 @@
# this way we can tell that the template was loaded from the compiled
# version and not the source.
-open(FOO, "$dir/foo.ttc") || die "$dir/foo.ttc: $!\n";
+
+my @current_times = (stat $compiled)[8,9];
+
+open(FOO, $compiled) || die "$compiled: $!\n";
local $/ = undef;
my $foo = <FOO>;
close(FOO);
$foo =~ s/the foo file/the hacked foo file/;
-open(FOO, "> $dir/foo.ttc") || die "$dir/foo.ttc: $!\n";
+open(FOO, "> $compiled") || die "$compiled: $!\n";
print FOO $foo;
close(FOO);
+# Set mtime back to what it was
+utime( @current_times, $compiled );
+
test_expect(\*DATA, $ttcfg);
Modified: trunk/t/compile5.t
===================================================================
--- trunk/t/compile5.t 2007-04-27 13:19:05 UTC (rev 1063)
+++ trunk/t/compile5.t 2007-04-27 13:20:21 UTC (rev 1064)
@@ -51,6 +51,8 @@
# this way we can tell that the template was loaded from the compiled
# version and not the source.
+my @foo_times = (stat $foo)[8,9];
+
open(FOO, $foo) || die "$foo: $!\n";
local $/ = undef;
my $content = <FOO>;
@@ -61,8 +63,14 @@
print FOO $content;
close(FOO);
+# and set back
+utime( @foo_times, $foo );
+
# same again for 'blam'
+
+my @blam_times = (stat $blam)[8,9];
+
open(BLAM, $blam) || die "$blam: $!\n";
local $/ = undef;
$content = <BLAM>;
@@ -72,6 +80,9 @@
print BLAM $content;
close(BLAM);
+# and set back
+utime( @blam_times, $blam );
+
test_expect(\*DATA, $ttcfg, { root => abs_path($dir) } );
# cleanup cache directory
Modified: trunk/t/provider.t
===================================================================
--- trunk/t/provider.t 2007-04-27 13:19:05 UTC (rev 1063)
+++ trunk/t/provider.t 2007-04-27 13:20:21 UTC (rev 1064)
@@ -147,6 +147,35 @@
}
#------------------------------------------------------------------------
+# Test if can fetch from a file handle
+#------------------------------------------------------------------------
+
+my $ttglob = Template->new || die "$Template::ERROR\n";
+ok( $ttglob, 'Created template for glob test' );
+
+# Make sure we have a multi-line template file so $/ is tested.
+my $glob_file = abs_path($dir) . '/baz';
+
+open GLOBFILE, $glob_file or die "Failed to open '$absfile': $!";
+my $outstr = '';
+
+$ttglob->process( \*GLOBFILE, { a => 'globtest' }, \$outstr ) || die $ttglob->error;
+
+close GLOBFILE;
+
+my $glob_expect = "This is the baz file, a: globtest\n";
+
+my $ok = $glob_expect eq $outstr;
+
+ok( $ok, $ok ? 'Fetch template from file handle' : <<EOF );
+template text did not match template from file handle
+MATCH FAILED
+expect: $glob_expect
+output: $outstr
+EOF
+
+
+#------------------------------------------------------------------------
# now we'll fold those providers up into some Template objects that
# we can pass to text_expect() to do some template driven testing
#------------------------------------------------------------------------