diff options
Diffstat (limited to 't')
-rw-r--r-- | t/00-compile.t | 51 | ||||
-rw-r--r-- | t/author-split_like_shell.t | 89 | ||||
-rw-r--r-- | t/make_executable.t | 34 | ||||
-rw-r--r-- | t/man_pagename.t | 24 | ||||
-rw-r--r-- | t/release-pod-coverage.t | 22 | ||||
-rw-r--r-- | t/release-pod-syntax.t | 16 | ||||
-rw-r--r-- | t/split_like_shell.t | 83 | ||||
-rw-r--r-- | t/tilde.t | 66 |
8 files changed, 385 insertions, 0 deletions
diff --git a/t/00-compile.t b/t/00-compile.t new file mode 100644 index 0000000..8efa30d --- /dev/null +++ b/t/00-compile.t @@ -0,0 +1,51 @@ +use strict; +use warnings; + +# this test was generated with Dist::Zilla::Plugin::Test::Compile 2.036 + +use Test::More tests => 4 + ($ENV{AUTHOR_TESTING} ? 1 : 0); + + + +my @module_files = ( + 'ExtUtils/Helpers.pm', + 'ExtUtils/Helpers/Unix.pm', + 'ExtUtils/Helpers/VMS.pm', + 'ExtUtils/Helpers/Windows.pm' +); + + + +# no fake home requested + +my $inc_switch = q[-Mblib]; + +use File::Spec; +use IPC::Open3; +use IO::Handle; + +my @warnings; +for my $lib (@module_files) +{ + # see L<perlfaq8/How can I capture STDERR from an external command?> + open my $stdin, '<', File::Spec->devnull or die "can't open devnull: $!"; + my $stderr = IO::Handle->new; + + my $pid = open3($stdin, '>&STDERR', $stderr, $^X, $inc_switch, '-e', "require q[$lib]"); + binmode $stderr, ':crlf' if $^O eq 'MSWin32'; + my @_warnings = <$stderr>; + waitpid($pid, 0); + is($?, 0, "$lib loaded ok"); + + if (@_warnings) + { + warn @_warnings; + push @warnings, @_warnings; + } +} + + + +is(scalar(@warnings), 0, 'no warnings found') if $ENV{AUTHOR_TESTING}; + + diff --git a/t/author-split_like_shell.t b/t/author-split_like_shell.t new file mode 100644 index 0000000..92ab2a3 --- /dev/null +++ b/t/author-split_like_shell.t @@ -0,0 +1,89 @@ +#!/usr/bin/perl + +BEGIN { + unless ($ENV{AUTHOR_TESTING}) { + require Test::More; + Test::More::plan(skip_all => 'these tests are for testing by the author'); + } +} + + +use strict; +use warnings FATAL => 'all'; +use Test::More; +use ExtUtils::Helpers::Unix (); +use ExtUtils::Helpers::Windows (); + +plan(skip_all => 'Author only tests') unless $ENV{AUTHOR_TESTING}; + +my @unix_splits = + ( + { q{one t'wo th'ree f"o\"ur " "five" } => [ 'one', 'two three', 'fo"ur ', 'five' ] }, + { q{ foo bar } => [ 'foo', 'bar' ] }, + { q{ D\'oh f\{g\'h\"i\]\* } => [ "D'oh", "f{g'h\"i]*" ] }, + { q{ D\$foo } => [ 'D$foo' ] }, + { qq{one\\\ntwo} => [ "one\ntwo" ] }, # TODO + ); + +my @win_splits = + ( + { 'a" "b\\c" "d' => [ 'a b\c d' ] }, + { '"a b\\c d"' => [ 'a b\c d' ] }, + { '"a b"\\"c d"' => [ 'a b"c', 'd' ] }, + { '"a b"\\\\"c d"' => [ 'a b\c d' ] }, + { '"a"\\"b" "a\\"b"' => [ 'a"b a"b' ] }, + { '"a"\\\\"b" "a\\\\"b"' => [ 'a\b', 'a\b' ] }, + { '"a"\\"b a\\"b"' => [ 'a"b', 'a"b' ] }, + { 'a"\\"b" "a\\"b' => [ 'a"b', 'a"b' ] }, + { 'a"\\"b" "a\\"b' => [ 'a"b', 'a"b' ] }, + { 'a b' => [ 'a', 'b' ] }, + { "a\nb" => [ 'a', 'b' ] }, + { 'a"\\"b a\\"b' => [ 'a"b a"b' ] }, + { '"a""b" "a"b"' => [ 'a"b ab' ] }, + { '\\"a\\"' => [ '"a"' ] }, + { '"a"" "b"' => [ 'a"', 'b' ] }, + { 'a"b' => [ 'ab' ] }, + { 'a""b' => [ 'ab' ] }, + { 'a"""b' => [ 'a"b' ] }, + { 'a""""b' => [ 'a"b' ] }, + { 'a"""""b' => [ 'a"b' ] }, + { 'a""""""b' => [ 'a""b' ] }, + { '"a"b"' => [ 'ab' ] }, + { '"a""b"' => [ 'a"b' ] }, + { '"a"""b"' => [ 'a"b' ] }, + { '"a""""b"' => [ 'a"b' ] }, + { '"a"""""b"' => [ 'a""b' ] }, + { '"a""""""b"' => [ 'a""b' ] }, + { '' => [ ] }, + { ' ' => [ ] }, + { '""' => [ '' ] }, + { '" "' => [ ' ' ] }, + { '""a' => [ 'a' ] }, + { '""a b' => [ 'a', 'b' ] }, + { 'a""' => [ 'a' ] }, + { 'a"" b' => [ 'a', 'b' ] }, + { '"" a' => [ '', 'a' ] }, + { 'a ""' => [ 'a', '' ] }, + { 'a "" b' => [ 'a', '', 'b' ] }, + { 'a " " b' => [ 'a', ' ', 'b' ] }, + { 'a " b " c' => [ 'a', ' b ', 'c' ] }, +); + +foreach my $test (@win_splits) { + my ($string, $expected) = %$test; + my @result = ExtUtils::Helpers::Windows::split_like_shell($string); + $string =~ s/\n/\\n/g; + is(grep( !defined(), @result ), 0, "\"$string\" result all defined"); + is_deeply(\@result, $expected) or + diag("split_like_shell error \n>$string< is not splitting as >" . join("|", @$expected) . '<'); +} +foreach my $test (@unix_splits) { + my ($string, $expected) = %$test; + my @result = ExtUtils::Helpers::Unix::split_like_shell($string); + $string =~ s/\n/\\n/g; + is(grep( !defined(), @result ), 0, "\"$string\" result all defined"); + is_deeply(\@result, $expected) or + diag("split_like_shell error \n>$string< is not splitting as >" . join("|", @$expected) . '<'); +} + +done_testing; diff --git a/t/make_executable.t b/t/make_executable.t new file mode 100644 index 0000000..330c8ea --- /dev/null +++ b/t/make_executable.t @@ -0,0 +1,34 @@ +#!/usr/bin/perl + +use strict; +use warnings FATAL => 'all'; + +use Config; +use Test::More tests => 7; +use ExtUtils::Helpers qw/make_executable/; +use Cwd qw/cwd/; + +my $filename = 'test_exec'; +my @files; + +open my $out, '>', $filename or die "Couldn't create $filename: $!"; +print $out "#! perl -w\nexit \$ARGV[0];\n"; +close $out; + +make_executable($filename); + +foreach my $i (42, 51, 0) { + my $cwd = cwd; + local $ENV{PATH} = join $Config{path_sep}, $cwd, $ENV{PATH}; + my $ret = system $filename, $i; + is $ret & 0xff, 0, 'test_exec executed successfully'; + is $ret >> 8, $i, "test_exec $i return value ok"; +} + +SKIP: { + skip 'No batch file on non-windows', 1 if $^O ne 'MSWin32'; + push @files, grep { -f } map { $filename.$_ } split / $Config{path_sep} /x, $ENV{PATHEXT}; + is scalar(@files), 1, "Executable file exists"; +} + +unlink $filename, @files; diff --git a/t/man_pagename.t b/t/man_pagename.t new file mode 100644 index 0000000..91d1020 --- /dev/null +++ b/t/man_pagename.t @@ -0,0 +1,24 @@ +#!/usr/bin/perl + +use strict; +use warnings FATAL => 'all'; +use Test::More; +use Config; +use File::Spec::Functions qw/catfile/; +use ExtUtils::Helpers qw/man1_pagename man3_pagename/; + +my %separator = ( + MSWin32 => '.', + VMS => '__', + os2 => '.', + cygwin => '.', +); +my $sep = $separator{$^O} || '::'; + +is man1_pagename('script/foo'), "foo.$Config{man1ext}", 'man1_pagename'; + +is man3_pagename(catfile(qw/lib ExtUtils.pm/)), "ExtUtils.$Config{man3ext}", 'man3_pagename 1'; +is man3_pagename(catfile(qw/lib ExtUtils Helpers.pm/)), join($sep, qw/ExtUtils Helpers./).$Config{man3ext}, 'man3_pagename 2'; +is man3_pagename(catfile(qw/lib ExtUtils Helpers Unix.pm/)), join($sep, qw/ExtUtils Helpers Unix./).$Config{man3ext}, 'man3_pagename 3'; + +done_testing; diff --git a/t/release-pod-coverage.t b/t/release-pod-coverage.t new file mode 100644 index 0000000..6f7a96e --- /dev/null +++ b/t/release-pod-coverage.t @@ -0,0 +1,22 @@ +#!perl + +BEGIN { + unless ($ENV{RELEASE_TESTING}) { + require Test::More; + Test::More::plan(skip_all => 'these tests are for release candidate testing'); + } +} + +# This file was automatically generated by Dist::Zilla::Plugin::PodCoverageTests. + +use Test::More; + +eval "use Test::Pod::Coverage 1.08"; +plan skip_all => "Test::Pod::Coverage 1.08 required for testing POD coverage" + if $@; + +eval "use Pod::Coverage::TrustPod"; +plan skip_all => "Pod::Coverage::TrustPod required for testing POD coverage" + if $@; + +all_pod_coverage_ok({ coverage_class => 'Pod::Coverage::TrustPod' }); diff --git a/t/release-pod-syntax.t b/t/release-pod-syntax.t new file mode 100644 index 0000000..dddaea4 --- /dev/null +++ b/t/release-pod-syntax.t @@ -0,0 +1,16 @@ +#!perl + +BEGIN { + unless ($ENV{RELEASE_TESTING}) { + require Test::More; + Test::More::plan(skip_all => 'these tests are for release candidate testing'); + } +} + +# This file was automatically generated by Dist::Zilla::Plugin::PodSyntaxTests. +use Test::More; + +eval "use Test::Pod 1.41"; +plan skip_all => "Test::Pod 1.41 required for testing POD" if $@; + +all_pod_files_ok(); diff --git a/t/split_like_shell.t b/t/split_like_shell.t new file mode 100644 index 0000000..df2d2bc --- /dev/null +++ b/t/split_like_shell.t @@ -0,0 +1,83 @@ +#!/usr/bin/perl + +use strict; +use warnings FATAL => 'all'; +use Test::More; +use ExtUtils::Helpers qw/split_like_shell/; + +my @unix_splits = + ( + { q{one t'wo th'ree f"o\"ur " "five" } => [ 'one', 'two three', 'fo"ur ', 'five' ] }, + { q{ foo bar } => [ 'foo', 'bar' ] }, + { q{ D\'oh f\{g\'h\"i\]\* } => [ "D'oh", "f{g'h\"i]*" ] }, + { q{ D\$foo } => [ 'D$foo' ] }, + { qq{one\\\ntwo} => [ "one\ntwo" ] }, # TODO + ); + +my @win_splits = + ( + { 'a" "b\\c" "d' => [ 'a b\c d' ] }, + { '"a b\\c d"' => [ 'a b\c d' ] }, + { '"a b"\\"c d"' => [ 'a b"c', 'd' ] }, + { '"a b"\\\\"c d"' => [ 'a b\c d' ] }, + { '"a"\\"b" "a\\"b"' => [ 'a"b a"b' ] }, + { '"a"\\\\"b" "a\\\\"b"' => [ 'a\b', 'a\b' ] }, + { '"a"\\"b a\\"b"' => [ 'a"b', 'a"b' ] }, + { 'a"\\"b" "a\\"b' => [ 'a"b', 'a"b' ] }, + { 'a"\\"b" "a\\"b' => [ 'a"b', 'a"b' ] }, + { 'a b' => [ 'a', 'b' ] }, + { "a\nb" => [ 'a', 'b' ] }, + { 'a"\\"b a\\"b' => [ 'a"b a"b' ] }, + { '"a""b" "a"b"' => [ 'a"b ab' ] }, + { '\\"a\\"' => [ '"a"' ] }, + { '"a"" "b"' => [ 'a"', 'b' ] }, + { 'a"b' => [ 'ab' ] }, + { 'a""b' => [ 'ab' ] }, + { 'a"""b' => [ 'a"b' ] }, + { 'a""""b' => [ 'a"b' ] }, + { 'a"""""b' => [ 'a"b' ] }, + { 'a""""""b' => [ 'a""b' ] }, + { '"a"b"' => [ 'ab' ] }, + { '"a""b"' => [ 'a"b' ] }, + { '"a"""b"' => [ 'a"b' ] }, + { '"a""""b"' => [ 'a"b' ] }, + { '"a"""""b"' => [ 'a""b' ] }, + { '"a""""""b"' => [ 'a""b' ] }, + { '' => [ ] }, + { ' ' => [ ] }, + { '""' => [ '' ] }, + { '" "' => [ ' ' ] }, + { '""a' => [ 'a' ] }, + { '""a b' => [ 'a', 'b' ] }, + { 'a""' => [ 'a' ] }, + { 'a"" b' => [ 'a', 'b' ] }, + { '"" a' => [ '', 'a' ] }, + { 'a ""' => [ 'a', '' ] }, + { 'a "" b' => [ 'a', '', 'b' ] }, + { 'a " " b' => [ 'a', ' ', 'b' ] }, + { 'a " b " c' => [ 'a', ' b ', 'c' ] }, +); + +if ($^O eq 'MSWin32') { + plan tests => 2 * @win_splits; + foreach my $test (@win_splits) { + do_split_tests($test); + } +} +else { + plan tests => 2 * @unix_splits; + foreach my $test (@unix_splits) { + do_split_tests($test); + } +} + +sub do_split_tests { + my ($test) = @_; + + my ($string, $expected) = %$test; + my @result = split_like_shell($string); + $string =~ s/\n/\\n/g; + is(grep( !defined(), @result ), 0, "\"$string\" result all defined"); + is_deeply(\@result, $expected) or + diag("split_like_shell error \n>$string< is not splitting as >" . join("|", @$expected) . '<'); +} diff --git a/t/tilde.t b/t/tilde.t new file mode 100644 index 0000000..784ca4a --- /dev/null +++ b/t/tilde.t @@ -0,0 +1,66 @@ +#!/usr/bin/perl -w + +# Test ~ expansion from command line arguments. + +use strict; +use lib 't/lib'; +use Test::More tests => 9; + +use ExtUtils::Helpers 'detildefy'; + +SKIP: { + my $env_name = $^O eq 'MSWin32' ? 'USERPROFILE' : 'HOME'; + my $home = $ENV{$env_name}; + + if ($^O eq 'VMS') { + # Convert the path to UNIX format, trim off the trailing slash + $home = VMS::Filespec::unixify($home); + $home =~ s#/$##; + } + + unless (defined $home) { + my @info = eval { getpwuid $> }; + skip "No home directory for tilde-expansion tests", 8 if $@ or !defined $info[7]; + $home = $info[7]; + } + + is( detildefy('~'), $home); + + is( detildefy('~/fooxzy'), "$home/fooxzy"); + + is( detildefy('~/ fooxzy'), "$home/ fooxzy"); + + is( detildefy('~/fo o'), "$home/fo o"); + + is( detildefy('fooxzy~'), 'fooxzy~'); + + # Test when HOME is different from getpwuid(), as in sudo. + { + local $ENV{HOME} = '/wibble/whomp'; + local $ENV{USERPROFILE} = $ENV{HOME}; + + is( detildefy('~'), "/wibble/whomp"); + } + + skip "On OS/2 EMX all users are equal", 2 if $^O eq 'os2'; + is( detildefy('~~'), '~~' ); + is( detildefy('~ fooxzy'), '~ fooxzy' ); +} + +# Again, with named users +SKIP: { + my @info = eval { getpwuid $> }; + skip "No home directory for tilde-expansion tests", 1 if $@ or !defined $info[7] or !defined $info[0]; + my ($me, $home) = @info[0,7]; + + my $expected = "$home/fooxzy"; + + if ($^O eq 'VMS') { + # Convert the path to UNIX format and trim off the trailing slash + $home = VMS::Filespec::unixify($home); + $home =~ s#/$##; + $expected = $home . '/../[^/]+' . '/fooxzy'; + } + like( detildefy("~$me/fooxzy"), qr(\Q$expected\E)i ); +} + |