Skip to main content
  • Home
  • login
  • Browse the archive

    swh mirror partner logo
swh logo
SoftwareHeritage
Software
Heritage
Mirror
Features
  • Search

  • Downloads

  • Save code now

  • Add forge now

  • Help

  • f2023fb
  • /
  • external
  • /
  • perl
  • /
  • Text-Template-1.56
  • /
  • t
  • /
  • broken.t
Raw File
Permalinks

To reference or cite the objects present in the Software Heritage archive, permalinks based on SoftWare Hash IDentifiers (SWHIDs) must be used.
Select below a type of object currently browsed in order to display its associated SWHID and permalink.

  • content
  • directory
content badge Iframe embedding
swh:1:cnt:40e7b74650294fe3a1694f720647f31ecb32b7b8
directory badge Iframe embedding
swh:1:dir:7f3413dd469356106299d911badbf763182377dc
broken.t
#!perl
# test apparatus for Text::Template module

use strict;
use warnings;
use Test::More tests => 7;

use_ok 'Text::Template' or exit 1;

# (1) basic error delivery
{
    my $r = Text::Template->new(
        TYPE   => 'string',
        SOURCE => '{1/0}',)->fill_in();
    is $r, q{Program fragment delivered error ``Illegal division by zero at template line 1.''};
}

# (2) BROKEN sub called in ->new?
{
    my $r = Text::Template->new(
        TYPE   => 'string',
        SOURCE => '{1/0}',
        BROKEN => sub { '---' },)->fill_in();
    is $r, q{---};
}

# (3) BROKEN sub called in ->fill_in?
{
    my $r = Text::Template->new(
        TYPE   => 'string',
        SOURCE => '{1/0}',)->fill_in(BROKEN => sub { '---' });
    is $r, q{---};
}

# (4) BROKEN sub passed correct args when called in ->new?
{
    my $r = Text::Template->new(
        TYPE   => 'string',
        SOURCE => '{1/0}',
        BROKEN => sub {
            my %a = @_;
            qq{$a{lineno},$a{error},$a{text}};
        },)->fill_in();
    is $r, qq{1,Illegal division by zero at template line 1.\n,1/0};
}

# (5) BROKEN sub passed correct args when called in ->fill_in?
{
    my $r = Text::Template->new(
        TYPE   => 'string',
        SOURCE => '{1/0}',
        )->fill_in(
        BROKEN => sub {
            my %a = @_;
            qq{$a{lineno},$a{error},$a{text}};
        });
    is $r, qq{1,Illegal division by zero at template line 1.\n,1/0};
}

# BROKEN sub handles undef
{
    my $r = Text::Template->new(TYPE => 'string', SOURCE => 'abc{1/0}defg')
        ->fill_in(BROKEN => sub { undef });

    is $r, 'abc';
}

ENEA — Copyright (C), ENEA. License: GNU AGPLv3+.
Legal notes  ::  JavaScript license information ::  Web API

back to top