"Fossies" - the Fresh Open Source Software Archive

Member "Module-Build-0.4224/t/ext.t" (30 May 2017, 6596 Bytes) of package /linux/privat/Module-Build-0.4224.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Perl source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. See also the last Fossies "Diffs" side-by-side code changes report for "ext.t": 0.4216_vs_0.4218.

    1 #!/usr/bin/perl -w
    2 
    3 use strict;
    4 use lib 't/lib';
    5 use MBTest;
    6 
    7 my @unix_splits =
    8   (
    9    { q{one t'wo th'ree f"o\"ur " "five" } => [ 'one', 'two three', 'fo"ur ', 'five' ] },
   10    { q{ foo bar }                         => [ 'foo', 'bar'                         ] },
   11    { q{ D\'oh f\{g\'h\"i\]\* }            => [ "D'oh", "f{g'h\"i]*"                 ] },
   12    { q{ D\$foo }                          => [ 'D$foo'                              ] },
   13    { qq{one\\\ntwo}                       => [ "one\ntwo"                           ] },  # TODO
   14   );
   15 
   16 my @win_splits =
   17   (
   18    { 'a" "b\\c" "d'         => [ 'a b\c d'       ] },
   19    { '"a b\\c d"'           => [ 'a b\c d'       ] },
   20    { '"a b"\\"c d"'         => [ 'a b"c', 'd'    ] },
   21    { '"a b"\\\\"c d"'       => [ 'a b\c d'       ] },
   22    { '"a"\\"b" "a\\"b"'     => [ 'a"b a"b'       ] },
   23    { '"a"\\\\"b" "a\\\\"b"' => [ 'a\b', 'a\b'    ] },
   24    { '"a"\\"b a\\"b"'       => [ 'a"b', 'a"b'    ] },
   25    { 'a"\\"b" "a\\"b'       => [ 'a"b', 'a"b'    ] },
   26    { 'a"\\"b"  "a\\"b'      => [ 'a"b', 'a"b'    ] },
   27    { 'a           b'        => [ 'a', 'b'        ] },
   28    { 'a"\\"b a\\"b'         => [ 'a"b a"b'       ] },
   29    { '"a""b" "a"b"'         => [ 'a"b ab'        ] },
   30    { '\\"a\\"'              => [ '"a"'           ] },
   31    { '"a"" "b"'             => [ 'a"', 'b'       ] },
   32    { 'a"b'                  => [ 'ab'            ] },
   33    { 'a""b'                 => [ 'ab'            ] },
   34    { 'a"""b'                => [ 'a"b'           ] },
   35    { 'a""""b'               => [ 'a"b'           ] },
   36    { 'a"""""b'              => [ 'a"b'           ] },
   37    { 'a""""""b'             => [ 'a""b'          ] },
   38    { '"a"b"'                => [ 'ab'            ] },
   39    { '"a""b"'               => [ 'a"b'           ] },
   40    { '"a"""b"'              => [ 'a"b'           ] },
   41    { '"a""""b"'             => [ 'a"b'           ] },
   42    { '"a"""""b"'            => [ 'a""b'          ] },
   43    { '"a""""""b"'           => [ 'a""b'          ] },
   44    { ''                     => [                 ] },
   45    { ' '                    => [                 ] },
   46    { '""'                   => [ ''              ] },
   47    { '" "'                  => [ ' '             ] },
   48    { '""a'                  => [ 'a'             ] },
   49    { '""a b'                => [ 'a', 'b'        ] },
   50    { 'a""'                  => [ 'a'             ] },
   51    { 'a"" b'                => [ 'a', 'b'        ] },
   52    { '"" a'                 => [ '', 'a'         ] },
   53    { 'a ""'                 => [ 'a', ''         ] },
   54    { 'a "" b'               => [ 'a', '', 'b'    ] },
   55    { 'a " " b'              => [ 'a', ' ', 'b'   ] },
   56    { 'a " b " c'            => [ 'a', ' b ', 'c' ] },
   57    { 'a "0" c'              => [ 'a', '0', 'c'   ] },
   58    { '"a\\b"'               => [ 'a\\b'          ] },
   59    { '"a\\\\b"'             => [ 'a\\\\b'        ] },
   60    { '"a\\\\\\b"'           => [ 'a\\\\\\b'      ] },
   61    { '"a\\\\\\\\b"'         => [ 'a\\\\\\\\b'    ] },
   62    { '"a\\"'                => [ 'a"'            ] },
   63    { '"a\\\\"'              => [ 'a\\'           ] },
   64    { '"a\\\\\\"'            => [ 'a\\"'          ] },
   65    { '"a\\\\\\\\"'          => [ 'a\\\\'         ] },
   66    { '"a\\\\\\""'           => [ 'a\\"'          ] },
   67 );
   68 
   69 plan tests => 9 + 4*@unix_splits + 4*@win_splits;
   70 
   71 blib_load('Module::Build');
   72 blib_load('Module::Build::Platform::Unix');
   73 blib_load('Module::Build::Platform::Windows');
   74 
   75 #########################
   76 
   77 # Should always return an array unscathed
   78 foreach my $platform ('', '::Platform::Unix', '::Platform::Windows') {
   79   my $pkg = "Module::Build$platform";
   80   my @result = $pkg->split_like_shell(['foo', 'bar', 'baz']);
   81   is @result, 3, "Split using $pkg";
   82   is "@result", "foo bar baz", "Split using $pkg";
   83 }
   84 
   85 # I think 3.24 isn't actually the majik version, my 3.23 seems to pass...
   86 my $low_TPW_version = Text::ParseWords->VERSION < 3.24;
   87 foreach my $test (@unix_splits) {
   88   # Text::ParseWords bug:
   89   local $TODO = $low_TPW_version && ((keys %$test)[0] =~ m{\\\n});
   90 
   91   do_split_tests('Module::Build::Platform::Unix', $test);
   92 }
   93 
   94 foreach my $test (@win_splits) {
   95   do_split_tests('Module::Build::Platform::Windows', $test);
   96 }
   97 
   98 
   99 {
  100   # Make sure read_args() functions properly as a class method
  101   my @args = qw(foo=bar --food bard --foods=bards);
  102   my ($args) = Module::Build->read_args(@args);
  103   is_deeply($args, {foo => 'bar', food => 'bard', foods => 'bards', ARGV => []});
  104 }
  105 
  106 {
  107   # Make sure data can make a round-trip through unparse_args() and read_args()
  108   my %args = (foo => 'bar', food => 'bard', config => {a => 1, b => 2}, ARGV => []);
  109   my ($args) = Module::Build->read_args( Module::Build->unparse_args(\%args) );
  110   is_deeply($args, \%args);
  111 }
  112 
  113 {
  114   # Make sure data can make a round-trip through an external perl
  115   # process, which can involve the shell command line
  116 
  117   # silence the printing for easier matching
  118   local *Module::Build::log_info = sub {};
  119 
  120   my @data = map values(%$_), @unix_splits, @win_splits;
  121   for my $d (@data) {
  122     my $out = stdout_of
  123       ( sub {
  124       Module::Build->run_perl_script('-le', [], ['print join " ", map "{$_}", @ARGV', @$d]);
  125     } );
  126     chomp $out;
  127     is($out, join(' ', map "{$_}", @$d), "perl round trip for ".join('',map "{$_}", @$d));
  128   }
  129 }
  130 
  131 {
  132   # Make sure data can make a round-trip through an external backtick
  133   # process, which can involve the shell command line
  134 
  135   # silence the printing for easier matching
  136   local *Module::Build::log_info = sub {};
  137 
  138   my @data = map values(%$_), @unix_splits, @win_splits;
  139   for my $d (@data) {
  140     chomp(my $out = Module::Build->_backticks($^X, '-le', 'print join " ", map "{$_}", @ARGV', @$d));
  141     is($out, join(' ', map "{$_}", @$d), "backticks round trip for ".join('',map "{$_}", @$d));
  142   }
  143 }
  144 
  145 {
  146   # Make sure run_perl_script() propagates @INC
  147   my $dir = MBTest->tmpdir;
  148   if ($^O eq 'VMS') {
  149       # VMS can store INC paths in Unix format with out the trailing
  150       # directory delimiter.
  151       $dir = VMS::Filespec::unixify($dir);
  152       $dir =~ s#/$##;
  153   }
  154   local @INC = ($dir, @INC);
  155   my $output = stdout_of( sub { Module::Build->run_perl_script('-le', [], ['print for @INC']) } );
  156   like $output, qr{^\Q$dir\E}m;
  157 }
  158 
  159 ##################################################################
  160 sub do_split_tests {
  161   my ($package, $test) = @_;
  162 
  163   my ($string, $expected) = %$test;
  164   my @result = $package->split_like_shell($string);
  165   is( 0 + grep( !defined(), @result ), # all defined
  166       0,
  167       "'$string' result all defined" );
  168   is_deeply(\@result, $expected) or
  169     diag("$package split_like_shell error \n" .
  170       ">$string< is not splitting as >" . join("|", @$expected) . '<');
  171 }