1# -*- mode: perl; -*- 2 3use strict; 4use warnings; 5 6use Test::More tests => 5; 7 8############################################################################### 9# Read and load configuration file and backend library. 10 11use Config::Tiny (); 12 13my $config_file = 'xt/author/lib.ini'; 14my $config = Config::Tiny -> read('xt/author/lib.ini') 15 or die Config::Tiny -> errstr(); 16 17# Read the library to test. 18 19our $LIB = $config->{_}->{lib}; 20 21die "No library defined in file '$config_file'" 22 unless defined $LIB; 23die "Invalid library name '$LIB' in file '$config_file'" 24 unless $LIB =~ /^[A-Za-z]\w*(::\w+)*\z/; 25 26# Read the reference type(s) the library uses. 27 28our $REF = $config->{_}->{ref}; 29 30die "No reference type defined in file '$config_file'" 31 unless defined $REF; 32die "Invalid reference type '$REF' in file '$config_file'" 33 unless $REF =~ /^[A-Za-z]\w*(::\w+)*\z/; 34 35# Load the library. 36 37eval "require $LIB"; 38die $@ if $@; 39 40############################################################################### 41 42can_ok($LIB, '_one'); 43 44my $out0 = '1'; 45 46# List context. 47 48{ 49 my @got; 50 51 my $test = qq|\@got = $LIB->_one(); |; 52 53 diag("\n$test\n\n") if $ENV{AUTHOR_DEBUGGING}; 54 55 eval $test; 56 is($@, "", "'$test' gives emtpy \$\@"); 57 58 subtest "_one() in list context: $test", sub { 59 plan tests => 4, 60 61 cmp_ok(scalar @got, '==', 1, 62 "'$test' gives one output arg"); 63 64 is(ref($got[0]), $REF, 65 "'$test' output arg is a $REF"); 66 67 is($LIB->_check($got[0]), 0, 68 "'$test' output is valid"); 69 70 is($LIB->_str($got[0]), $out0, 71 "'$test' output arg has the right value"); 72 }; 73} 74 75# Scalar context. 76 77{ 78 my $got; 79 80 my $test = qq|\$got = $LIB->_one(); |; 81 82 diag("\n$test\n\n") if $ENV{AUTHOR_DEBUGGING}; 83 84 eval $test; 85 is($@, "", "'$test' gives emtpy \$\@"); 86 87 subtest "_one() in scalar context: $test", sub { 88 plan tests => 3, 89 90 is(ref($got), $REF, 91 "'$test' output arg is a $REF"); 92 93 is($LIB->_check($got), 0, 94 "'$test' output is valid"); 95 96 is($LIB->_str($got), $out0, 97 "'$test' output arg has the right value"); 98 }; 99} 100