File: process_dir.t

package info (click to toggle)
libtemplate-perl 2.27-1
  • links: PTS
  • area: main
  • in suites: bookworm, bullseye, buster, forky, sid, trixie
  • size: 2,632 kB
  • sloc: perl: 14,750; makefile: 11; sh: 5
file content (80 lines) | stat: -rw-r--r-- 1,776 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#============================================================= -*-perl-*-
#
# t/process_dir.t
#
# Test the PROCESS option.
#
# Written by Andy Wardley <abw@wardley.org>
#
# Copyright (C) 1996-2000 Andy Wardley.  All Rights Reserved.
# Copyright (C) 1998-2000 Canon Research Centre Europe Ltd.
#
# This is free software; you can redistribute it and/or modify it
# under the same terms as Perl itself.
#
# $Id$
#
#========================================================================

use strict;
use lib qw( ./lib ../lib );

use Template;
use Test::More;

my $testdir  = 'testdir';
my $CACHEDIR = 'ttcache';

`rm -rf $CACHEDIR $testdir`;

my $config = {COMPILE_DIR  => $CACHEDIR};
my $tt1 = Template->new($config);

my $data = <<'EOF';
This is the first test
[% TRY; PROCESS "testdir"; CATCH e; "error: e"; END; %]
This is the end.
EOF

my $expected1 = "file error - $testdir: not found";

my $expected2 = "file error - ./$testdir: not a file";

my $expected3 = <<'EOF';
This is the first test

This is the end.
EOF

my $ret = undef;
$tt1->process(\$data, {}, \$ret);

is($tt1->error(), $expected1, 'Error on missing file');

mkdir($CACHEDIR, 0755);
is(-d $CACHEDIR, 1, "Made cache dir ($CACHEDIR)");

mkdir($testdir, 0755);
is(-d $testdir, 1, "Made test dir ($testdir)");

my $tt2 = Template->new($config);
undef $ret;
$tt2->process(\$data, {}, \$ret);
is($tt2->error(), $expected2, 'Error on PROCESSing directory');

-f "$CACHEDIR/$testdir"
  && fail("Erroneous creation of 0b file with name of folder '$testdir' in cache folder");

rmdir($testdir);

open(my $OUT, '>', $testdir);
close($OUT);

my $tt3 = Template->new($config);
undef $ret;
$tt3->process(\$data, {}, \$ret);
is($ret, $expected3, 'Correctly PROCESSed file');

done_testing();

`rm -rf $CACHEDIR $testdir`;