Blame t/author-lib-boolean-_is_ten.t

Packit dcde0c
#!perl
Packit dcde0c
Packit dcde0c
BEGIN {
Packit dcde0c
    unless ($ENV{AUTHOR_TESTING}) {
Packit dcde0c
        require Test::More;
Packit dcde0c
        Test::More::plan(skip_all =>
Packit dcde0c
                         'these tests are for testing by the author');
Packit dcde0c
    }
Packit dcde0c
}
Packit dcde0c
Packit dcde0c
use strict;
Packit dcde0c
use warnings;
Packit dcde0c
Packit dcde0c
use Test::More tests => 81;
Packit dcde0c
Packit dcde0c
###############################################################################
Packit dcde0c
# Read and load configuration file and backend library.
Packit dcde0c
Packit dcde0c
use Config::Tiny ();
Packit dcde0c
Packit dcde0c
my $config_file = 't/author-lib.ini';
Packit dcde0c
my $config = Config::Tiny -> read('t/author-lib.ini')
Packit dcde0c
  or die Config::Tiny -> errstr();
Packit dcde0c
Packit dcde0c
# Read the library to test.
Packit dcde0c
Packit dcde0c
our $LIB = $config->{_}->{lib};
Packit dcde0c
Packit dcde0c
die "No library defined in file '$config_file'"
Packit dcde0c
  unless defined $LIB;
Packit dcde0c
die "Invalid library name '$LIB' in file '$config_file'"
Packit dcde0c
  unless $LIB =~ /^[A-Za-z]\w*(::\w+)*\z/;
Packit dcde0c
Packit dcde0c
# Load the library.
Packit dcde0c
Packit dcde0c
eval "require $LIB";
Packit dcde0c
die $@ if $@;
Packit dcde0c
Packit dcde0c
###############################################################################
Packit dcde0c
Packit dcde0c
can_ok($LIB, '_is_ten');
Packit dcde0c
Packit dcde0c
# Generate test data.
Packit dcde0c
Packit dcde0c
my @data;
Packit dcde0c
Packit dcde0c
for (my $x = 0 ; $x <= 10 ; ++ $x) {
Packit dcde0c
    push @data, [ $x, $x == 10 ];
Packit dcde0c
}
Packit dcde0c
Packit dcde0c
for (my $e = 2 ; $e <= 10 ; ++ $e) {
Packit dcde0c
    my $x = "1" . ("0" x $e);
Packit dcde0c
    push @data, [ $x, $x == 10 ];
Packit dcde0c
}
Packit dcde0c
Packit dcde0c
# List context.
Packit dcde0c
Packit dcde0c
for (my $i = 0 ; $i <= $#data ; ++ $i) {
Packit dcde0c
    my ($in0, $out0) = @{ $data[$i] };
Packit dcde0c
Packit dcde0c
    my ($x, @got);
Packit dcde0c
Packit dcde0c
    my $test = qq|\$x = $LIB->_new("$in0"); |
Packit dcde0c
             . qq|\@got = $LIB->_is_ten(\$x);|;
Packit dcde0c
Packit dcde0c
    diag("\n$test\n\n") if $ENV{AUTHOR_DEBUGGING};
Packit dcde0c
Packit dcde0c
    eval $test;
Packit dcde0c
    is($@, "", "'$test' gives emtpy \$\@");
Packit dcde0c
Packit dcde0c
    subtest "_is_ten() in list context: $test", sub {
Packit dcde0c
        plan tests => 3,
Packit dcde0c
Packit dcde0c
        cmp_ok(scalar @got, "==", 1,
Packit dcde0c
               "'$test' gives one output arg");
Packit dcde0c
Packit dcde0c
        is(ref($got[0]), "",
Packit dcde0c
           "'$test' output arg is a scalar");
Packit dcde0c
Packit dcde0c
        ok($got[0] && $out0 || !$got[0] && !$out0,
Packit dcde0c
           "'$test' output arg has the right value");
Packit dcde0c
    };
Packit dcde0c
}
Packit dcde0c
Packit dcde0c
# Scalar context.
Packit dcde0c
Packit dcde0c
for (my $i = 0 ; $i <= $#data ; ++ $i) {
Packit dcde0c
    my ($in0, $out0) = @{ $data[$i] };
Packit dcde0c
Packit dcde0c
    my ($x, $got);
Packit dcde0c
Packit dcde0c
    my $test = qq|\$x = $LIB->_new("$in0"); |
Packit dcde0c
             . qq|\$got = $LIB->_is_ten(\$x);|;
Packit dcde0c
Packit dcde0c
    diag("\n$test\n\n") if $ENV{AUTHOR_DEBUGGING};
Packit dcde0c
Packit dcde0c
    eval $test;
Packit dcde0c
    is($@, "", "'$test' gives emtpy \$\@");
Packit dcde0c
Packit dcde0c
    subtest "_is_ten() in scalar context: $test", sub {
Packit dcde0c
        plan tests => 2,
Packit dcde0c
Packit dcde0c
        is(ref($got), "",
Packit dcde0c
           "'$test' output arg is a scalar");
Packit dcde0c
Packit dcde0c
        ok($got && $out0 || !$got && !$out0,
Packit dcde0c
           "'$test' output arg has the right value");
Packit dcde0c
    };
Packit dcde0c
}