Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

* various minor updates to accomodate new DEBUG options

git-svn-id: svn://svn.tt2.org/tt/Template2/trunk@514 d5a88997-0a34-4036-9ed2-92fb5d660d91
  • Loading branch information...
commit 4e995837666f0d368034e4abe34fa1279f0067ec 1 parent a87e764
Andy Wardley authored
4 t/context.t
View
@@ -20,7 +20,9 @@
use strict;
use lib qw( ./lib ../lib );
use Template::Test;
+use Template::Constants qw( :debug );
+my $DEBUG = grep(/^--?d(debug)?$/, @ARGV);
#$Template::Test::DEBUG = 1;
ntests(54);
@@ -31,6 +33,7 @@ my $tt = Template->new({
INCLUDE_PATH => "$dir/src:$dir/lib",
TRIM => 1,
POST_CHOMP => 1,
+ DEBUG => $DEBUG ? DEBUG_CONTEXT : 0,
});
my $ttperl = Template->new({
@@ -38,6 +41,7 @@ my $ttperl = Template->new({
TRIM => 1,
EVAL_PERL => 1,
POST_CHOMP => 1,
+ DEBUG => $DEBUG ? DEBUG_CONTEXT : 0,
});
#------------------------------------------------------------------------
30 t/debug.t
View
@@ -20,10 +20,11 @@ use lib qw( ./lib ../lib );
use Template::Test qw( :all );
use Template::Parser;
use Template::Directive;
+use Template::Constants qw( :debug );
my $DEBUG = grep(/-d/, @ARGV);
-#$Template::Parser::DEBUG = $DEBUG;
-#$Template::Directive::Pretty = $DEBUG;
+#$Template::Parser::DEBUG = 1; #$DEBUG;
+$Template::Directive::Pretty = $DEBUG;
$Template::Test::PRESERVE = 1;
my $dir = -d 't' ? 't/test' : 'test';
@@ -37,22 +38,36 @@ my $vars = {
},
};
+my $dummy = Template::Base->new() || die Template::Base->error();
+ok( $dummy, 'created a dummy object' );
+my $flags = Template::Constants::debug_flags($dummy, 'dirs, stash');
+ok( $flags, 'created flags' );
+is( $flags, DEBUG_DIRS | DEBUG_STASH, "flags value is $flags" );
+$flags = Template::Constants::debug_flags($dummy, $flags)
+ || die $dummy->error();
+ok( $flags, 'got more flags back' );
+is( $flags, 'dirs, stash', 'dirs, stash' );
+
+$flags = Template::Constants::debug_flags($dummy, 'bad stupid');
+ok( ! $flags, 'bad flags' );
+is( $dummy->error(), 'unknown debug flag: bad', 'error correct' );
+
my $tt = Template->new( {
DEBUG => 0,
INCLUDE_PATH => "$dir/src:$dir/lib",
DEBUG_FORMAT => "<!-- \$file line \$line : [% \$text %] -->",
-} );
+} ) || die Template->error();
my $tt2 = Template->new( {
- DEBUG => 1,
+ DEBUG => DEBUG_DIRS,
INCLUDE_PATH => "$dir/src:$dir/lib",
-} );
+} ) || die Template->error();
my $ttd = Template->new( {
- DEBUG => 1,
+ DEBUG => 'dirs, vars',
INCLUDE_PATH => "$dir/src:$dir/lib",
DEBUG_FORMAT => "<!-- \$file line \$line : [% \$text %] -->",
-} );
+} ) || die Template->error();
test_expect(\*DATA, [ default => $tt, debug => $ttd, debug2 => $tt2 ], $vars);
#$tt->process(\*DATA, $vars) || die $tt->error();
@@ -103,6 +118,7 @@ Debugging enabled
foo: <!-- input text line 6 : [% foo %] -->10
-- test --
+-- name ping pong --
foo: [% foo %]
hello [% "$baz.ping/$baz.pong" %] world
[% DEBUG off %]
3  t/filter.t
View
@@ -22,8 +22,11 @@ use Template::Filters;
use Template qw( :status );
use Template::Parser;
use Template::Test;
+use Template::Constants qw( :debug );
$^W = 1;
+my $DEBUG = grep(/^--?d(debug)?$/, @ARGV);
+
$Template::Test::DEBUG = 0;
$Template::Test::EXTRA = 1; # ensure redirected file is created
#$Template::Context::DEBUG = 1;
6 t/plugins.t
View
@@ -19,9 +19,12 @@
use strict;
use lib qw( ./lib ../lib );
use Template::Test;
+use Template::Constants qw( :debug );
use Cwd qw( abs_path );
$^W = 1;
+my $DEBUG = grep(/^--?d(debug)?$/, @ARGV);
+
#$Template::Test::DEBUG = 0;
#$Template::Plugins::DEBUG = 0;
@@ -30,6 +33,7 @@ unshift(@INC, $dir);
my $tt1 = Template->new({
PLUGIN_BASE => 'MyPlugs',
+ DEBUG => $DEBUG ? DEBUG_PLUGINS : 0,
});
require "MyPlugs/Bar.pm";
@@ -41,10 +45,12 @@ my $tt2 = Template->new({
baz => 'MyPlugs::Foo',
cgi => 'MyPlugs::Bar',
},
+ DEBUG => $DEBUG ? DEBUG_PLUGINS : 0,
});
my $tt3 = Template->new({
LOAD_PERL => 1,
+ DEBUG => $DEBUG ? DEBUG_PLUGINS : 0,
});
my $tt = [
22 t/provider.t
View
@@ -24,8 +24,10 @@ use Template::Provider;
use Cwd 'abs_path';
$^W = 1;
+my $DEBUG = grep(/-d/, @ARGV);
$Template::Test::DEBUG = 0;
-#$Template::Provider::DEBUG = 0;
+use Template::Constants qw( :debug );
+$Template::Provider::DEBUG = $DEBUG ? DEBUG_PROVIDER | DEBUG_CALLER : 0;
#$Template::Parser::DEBUG = 1;
#$Template::Directive::PRETTY = 1;
@@ -33,8 +35,6 @@ $Template::Test::DEBUG = 0;
# the provider doesn't stat the file.
# $Template::Provider::STAT_TTL = 10;
-my $DEBUG = 0;
-
my $factory = 'Template::Config';
# script may be being run in distribution root or 't' directory
@@ -118,24 +118,28 @@ ok( delivered( $provrel, $relfile ) );
sub delivered {
my ($provider, $file) = @_;
my ($result, $error) = $provider->fetch($file);
- print STDERR "$provider->fetch($file) -> [$result] [$error]\n"
- if $DEBUG;
+ my $nice_result = defined $result ? $result : '<undef>';
+ my $nice_error = defined $error ? $error : '<undef>';
+# print STDERR "$provider->fetch($file) -> [$nice_result] [$nice_error]\n"
+# if $DEBUG;
return ! $error;
}
sub declined {
my ($provider, $file) = @_;
my ($result, $error) = $provider->fetch($file);
- print STDERR "$provider->fetch($file) -> [$result] [$error]\n"
- if $DEBUG;
+ my $nice_result = defined $result ? $result : '<undef>';
+ my $nice_error = defined $error ? $error : '<undef>';
+# print STDERR "$provider->fetch($file) -> [$nice_result] [$nice_error]\n"
+# if $DEBUG;
return ($error == Template::Constants::STATUS_DECLINED);
}
sub denied {
my ($provider, $file) = @_;
my ($result, $error) = $provider->fetch($file);
- print STDERR "$provider->fetch($file) -> [$result] [$error]\n"
- if $DEBUG;
+# print STDERR "$provider->fetch($file) -> [$result] [$error]\n"
+# if $DEBUG;
return ($error == Template::Constants::STATUS_ERROR);
}
4 t/service.t
View
@@ -21,6 +21,9 @@ use lib qw( ./lib ../lib );
use Template::Test;
use Template::Service;
use Template::Document;
+use Template::Constants qw( :debug );
+
+my $DEBUG = grep(/^--?d(debug)?$/, @ARGV);
my $dir = -d 't' ? 't/test' : 'test';
my $config = {
@@ -35,6 +38,7 @@ my $config = {
barf => 'barfed',
default => 'error',
},
+ DEBUG => $DEBUG ? DEBUG_SERVICE : 0,
};
my $tt1 = Template->new($config);
4 t/stash.t
View
@@ -18,7 +18,7 @@
use strict;
use lib qw( ./lib ../lib );
-use Template::Constants qw( :status );
+use Template::Constants qw( :status :debug );
use Template;
use Template::Stash;
use Template::Config;
@@ -64,7 +64,7 @@ match( $stash->get('bar.buz'), 100 );
my $ttlist = [
'default' => Template->new(),
- 'warn' => Template->new(DEBUG => 1, DEBUG_FORMAT => ''),
+ 'warn' => Template->new(DEBUG => DEBUG_UNDEF, DEBUG_FORMAT => ''),
];
test_expect(\*DATA, $ttlist, $data);
Please sign in to comment.
Something went wrong with that request. Please try again.