Permalink
Browse files

updates to tests for provider patches

git-svn-id: svn://svn.tt2.org/tt/Template2/trunk@1064 d5a88997-0a34-4036-9ed2-92fb5d660d91
  • Loading branch information...
abw committed Apr 27, 2007
1 parent 730dffa commit 93e861c86b26cca93b77248495736581579b67b2
Showing with 51 additions and 3 deletions.
  1. +11 −3 t/compile2.t
  2. +11 −0 t/compile5.t
  3. +29 −0 t/provider.t
View
@@ -30,8 +30,10 @@ my $ttcfg = {
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 @@ ok( $out =~ /^name: baz/ );
# 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);
View
@@ -51,6 +51,8 @@ ok( -f $blam );
# 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 @@ open(FOO, "> $foo") || die "$foo: $!\n";
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 @@ open(BLAM, "> $blam") || die "$blam: $!\n";
print BLAM $content;
close(BLAM);
+# and set back
+utime( @blam_times, $blam );
+
test_expect(\*DATA, $ttcfg, { root => abs_path($dir) } );
# cleanup cache directory
View
@@ -146,6 +146,35 @@ sub denied {
return ($error == Template::Constants::STATUS_ERROR);
}
+#------------------------------------------------------------------------
+# 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

0 comments on commit 93e861c

Please sign in to comment.