1# -*- mode: perl; -*- 2 3use strict; 4use warnings; 5 6use Test::More tests => 4001; 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# Load the library. 27 28eval "require $LIB"; 29die $@ if $@; 30 31############################################################################### 32 33can_ok($LIB, '_to_bytes'); 34 35my @data; 36 37# Add data in data file. 38 39(my $datafile = $0) =~ s/\.t/.dat/; 40open DATAFILE, $datafile or die "$datafile: can't open file for reading: $!"; 41while (<DATAFILE>) { 42 s/\s+\z//; 43 next if /^#/ || ! /\S/; 44 push @data, [ split /:/ ]; 45} 46close DATAFILE or die "$datafile: can't close file after reading: $!"; 47 48# List context. 49 50for (my $i = 0 ; $i <= $#data ; ++ $i) { 51 my ($in0, $out0) = @{ $data[$i] }; 52 $out0 = eval qq|"$out0"|; 53 54 my ($x, @got); 55 56 my $test = qq|\$x = $LIB->_new("$in0"); | 57 . qq|\@got = $LIB->_to_bytes(\$x)|; 58 59 diag("\n$test\n\n") if $ENV{AUTHOR_DEBUGGING}; 60 61 eval $test; 62 is($@, "", "'$test' gives emtpy \$\@"); 63 64 subtest "_to_bytes() in list context: $test", sub { 65 plan tests => 3, 66 67 cmp_ok(scalar @got, '==', 1, 68 "'$test' gives one output arg"); 69 70 is(ref($got[0]), "", 71 "'$test' output arg is a scalar"); 72 73 is($got[0], $out0, 74 "'$test' output arg has the right value"); 75 }; 76} 77 78# Scalar context. 79 80for (my $i = 0 ; $i <= $#data ; ++ $i) { 81 my ($in0, $out0) = @{ $data[$i] }; 82 $out0 = eval qq|"$out0"|; 83 84 my ($x, $got); 85 86 my $test = qq|\$x = $LIB->_new("$in0"); | 87 . qq|\$got = $LIB->_to_bytes(\$x)|; 88 89 diag("\n$test\n\n") if $ENV{AUTHOR_DEBUGGING}; 90 91 eval $test; 92 is($@, "", "'$test' gives emtpy \$\@"); 93 94 subtest "_to_bytes() in scalar context: $test", sub { 95 plan tests => 2, 96 97 is(ref($got), "", 98 "'$test' output arg is a scalar"); 99 100 is($got, $out0, 101 "'$test' output arg has the right value"); 102 }; 103} 104