From a276db189a656a4cc5881a2ebc4cad3113685030 Mon Sep 17 00:00:00 2001 From: Lorry Tar Creator Date: Tue, 21 Jul 2015 13:23:57 +0000 Subject: File-Which-1.19 --- t/00_diag.t | 91 ++++++++++++++++++++++++++++++++++++++++++++++++ t/00_diag.txt | 2 ++ t/01_compile.t | 5 +++ t/02_all.t | 34 ++++++++++++++++++ t/03_simple.t | 85 ++++++++++++++++++++++++++++++++++++++++++++ t/04_pwhich.t | 13 +++++++ t/test-bin/README.txt | 5 +++ t/test-bin/all | 2 ++ t/test-bin/all.bat | 0 t/test-bin/all.exe | 0 t/test-bin/test1.exe | 2 ++ t/test-bin/test2.bat | 3 ++ t/test-bin/test3 | 5 +++ t/test-bin/test4/foo.txt | 1 + 14 files changed, 248 insertions(+) create mode 100644 t/00_diag.t create mode 100644 t/00_diag.txt create mode 100644 t/01_compile.t create mode 100644 t/02_all.t create mode 100644 t/03_simple.t create mode 100644 t/04_pwhich.t create mode 100644 t/test-bin/README.txt create mode 100755 t/test-bin/all create mode 100755 t/test-bin/all.bat create mode 100755 t/test-bin/all.exe create mode 100755 t/test-bin/test1.exe create mode 100755 t/test-bin/test2.bat create mode 100755 t/test-bin/test3 create mode 100644 t/test-bin/test4/foo.txt (limited to 't') diff --git a/t/00_diag.t b/t/00_diag.t new file mode 100644 index 0000000..f913073 --- /dev/null +++ b/t/00_diag.t @@ -0,0 +1,91 @@ +use strict; +use warnings; +use Config; +use Test::More tests => 1; +BEGIN { + my @modules; + eval q{ + require FindBin; + require File::Spec; + 1; + } || die $@; + do { + my $fh; + if(open($fh, '<', File::Spec->catfile($FindBin::Bin, '00_diag.pre.txt'))) + { + @modules = <$fh>; + close $fh; + chomp @modules; + } + }; + eval qq{ require $_ } for @modules; +}; + +sub spacer () +{ + diag ''; + diag ''; + diag ''; +} + +pass 'okay'; + +my @modules; +do { + my $fh; + open($fh, '<', File::Spec->catfile($FindBin::Bin, '00_diag.txt')); + @modules = <$fh>; + close $fh; + chomp @modules; +}; + +my $max = 1; +$max = $_ > $max ? $_ : $max for map { length $_ } @modules; +our $format = "%-${max}s %s"; + +spacer; + +my @keys = sort grep /(MOJO|PERL|\A(LC|HARNESS)_|\A(SHELL|LANG)\Z)/i, keys %ENV; + +if(@keys > 0) +{ + diag "$_=$ENV{$_}" for @keys; + + if($ENV{PERL5LIB}) + { + spacer; + diag "PERL5LIB path"; + diag $_ for split $Config{path_sep}, $ENV{PERL5LIB}; + + } + elsif($ENV{PERLLIB}) + { + spacer; + diag "PERLLIB path"; + diag $_ for split $Config{path_sep}, $ENV{PERLLIB}; + } + + spacer; +} + +diag sprintf $format, 'perl ', $^V; + +require(File::Spec->catfile($FindBin::Bin, '00_diag.pl')) + if -e File::Spec->catfile($FindBin::Bin, '00_diag.pl'); + +foreach my $module (@modules) +{ + if(eval qq{ require $module; 1 }) + { + my $ver = eval qq{ \$$module\::VERSION }; + $ver = 'undef' unless defined $ver; + diag sprintf $format, $module, $ver; + } + else + { + diag sprintf $format, $module, '-'; + } +} + +spacer; + diff --git a/t/00_diag.txt b/t/00_diag.txt new file mode 100644 index 0000000..187dd73 --- /dev/null +++ b/t/00_diag.txt @@ -0,0 +1,2 @@ +ExtUtils::MakeMaker +Test::More diff --git a/t/01_compile.t b/t/01_compile.t new file mode 100644 index 0000000..342ab47 --- /dev/null +++ b/t/01_compile.t @@ -0,0 +1,5 @@ +use strict; +use warnings; +use Test::More tests => 1; + +use_ok( 'File::Which' ); diff --git a/t/02_all.t b/t/02_all.t new file mode 100644 index 0000000..379df36 --- /dev/null +++ b/t/02_all.t @@ -0,0 +1,34 @@ +use strict; +use warnings; + +use Test::More tests => 4; +use File::Spec (); +use File::Which qw(which where); + +# Where is the test application +my $test_bin = File::Spec->catdir( 't', 'test-bin' ); +ok( -d $test_bin, 'Found test-bin' ); + +# Set up for running the test application +local $ENV{PATH} = $test_bin; +unless ( + File::Which::IS_VMS + or + File::Which::IS_MAC + or + File::Which::IS_DOS +) { + my $all = File::Spec->catfile( $test_bin, 'all' ); + chmod 0755, $all; +} + +my @result = which('all'); +like( $result[0], qr/all/i, 'Found all' ); +ok( scalar(@result), 'Found at least one result' ); + +# Should have as many elements. +is( + scalar(@result), + scalar(where('all')), + 'Scalar which result matches where result', +); diff --git a/t/03_simple.t b/t/03_simple.t new file mode 100644 index 0000000..efea5ea --- /dev/null +++ b/t/03_simple.t @@ -0,0 +1,85 @@ +use strict; +use warnings; +use Test::More tests => 10; +use File::Spec (); +use File::Which qw{which where}; + +use constant IS_VMS => ($^O eq 'VMS'); +use constant IS_MAC => ($^O eq 'MacOS'); +use constant IS_DOS => ($^O eq 'MSWin32' or $^O eq 'dos' or $^O eq 'os2'); +use constant IS_CYGWIN => ($^O eq 'cygwin'); + +# Check that it returns undef if no file is passed +is( + scalar(which('')), undef, + 'Null-length false result', +); +is( + scalar(which('non_existent_very_unlinkely_thingy_executable')), undef, + 'Positive length false result', +); + +# Where is the test application +my $test_bin = File::Spec->catdir( 't', 'test-bin' ); +ok( -d $test_bin, 'Found test-bin' ); + +# Set up for running the test application +local $ENV{PATH} = $test_bin; +unless ( + File::Which::IS_VMS + or + File::Which::IS_MAC + or + File::Which::IS_DOS +) { + my $test3 = File::Spec->catfile( $test_bin, 'test3' ); + chmod 0755, $test3; +} + +SKIP: { + skip("Not on DOS-like filesystem", 3) unless IS_DOS; + is( lc scalar which('test1'), 't\test-bin\test1.exe', 'Looking for test1.exe' ); + is( lc scalar which('test2'), 't\test-bin\test2.bat', 'Looking for test2.bat' ); + is( scalar which('test3'), undef, 'test3 returns undef' ); +} + +SKIP: { + skip("Not on a UNIX filesystem", 1) if IS_DOS; + skip("Not on a UNIX filesystem", 1) if IS_MAC; + skip("Not on a UNIX filesystem", 1) if IS_VMS; + is( + scalar(which('test3')), + File::Spec->catfile( $test_bin, 'test3'), + 'Check test3 for Unix', + ); +} + +SKIP: { + skip("Not on a cygwin filesystem", 2) unless IS_CYGWIN; + + # Cygwin: should make test1.exe transparent + is( + scalar(which('test1')), + File::Spec->catfile( $test_bin, 'test1' ), + 'Looking for test1 on Cygwin: transparent to test1.exe', + ); + is( + scalar(which('test4')), + undef, + 'Make sure that which() doesn\'t return a directory', + ); +} + +# Make sure that .\ stuff works on DOSish, VMS, MacOS (. is in PATH implicitly). +SKIP: { + unless ( IS_DOS or IS_VMS ) { + skip("Not on a DOS or VMS filesystem", 1); + } + + chdir( $test_bin ); + is( + lc scalar which('test1'), + File::Spec->catfile(File::Spec->curdir(), 'test1.exe'), + 'Looking for test1.exe in curdir', + ); +} diff --git a/t/04_pwhich.t b/t/04_pwhich.t new file mode 100644 index 0000000..c73fd3f --- /dev/null +++ b/t/04_pwhich.t @@ -0,0 +1,13 @@ +use strict; +use warnings; + +use Test::More tests => 3; +use File::Which; + +# Look for a very common program +my $tool = 'perl'; +my $path = which($tool); +ok( defined $path, "Found path to $tool" ); +ok( $path, "Found path to $tool" ); +ok( -f $path, "$tool exists" ); + diff --git a/t/test-bin/README.txt b/t/test-bin/README.txt new file mode 100644 index 0000000..f7b062a --- /dev/null +++ b/t/test-bin/README.txt @@ -0,0 +1,5 @@ +The files included in this directory are only used for testing: they +should not be executed: especially the *.exe files which aren't really +compiled programs, only empty files with special filenames (as +File::Which only cares about special attributes). Do NOT try to run +them. diff --git a/t/test-bin/all b/t/test-bin/all new file mode 100755 index 0000000..b76df2e --- /dev/null +++ b/t/test-bin/all @@ -0,0 +1,2 @@ +#!bash +# above shebang needed so Cygwin treats it as -x \ No newline at end of file diff --git a/t/test-bin/all.bat b/t/test-bin/all.bat new file mode 100755 index 0000000..e69de29 diff --git a/t/test-bin/all.exe b/t/test-bin/all.exe new file mode 100755 index 0000000..e69de29 diff --git a/t/test-bin/test1.exe b/t/test-bin/test1.exe new file mode 100755 index 0000000..3cb13a5 --- /dev/null +++ b/t/test-bin/test1.exe @@ -0,0 +1,2 @@ +DO NOT RUN THIS PROGRAM +IT IS ONLY TO TEST File::Which diff --git a/t/test-bin/test2.bat b/t/test-bin/test2.bat new file mode 100755 index 0000000..fdaae7c --- /dev/null +++ b/t/test-bin/test2.bat @@ -0,0 +1,3 @@ +@echo off +echo This is for testing File::Which +echo Nothing interesting here! \ No newline at end of file diff --git a/t/test-bin/test3 b/t/test-bin/test3 new file mode 100755 index 0000000..ef252be --- /dev/null +++ b/t/test-bin/test3 @@ -0,0 +1,5 @@ +#!sh + +# ^ above shebang is needed for Cygwin +echo "Just testing File::Which" +echo "Nothing interesting here" diff --git a/t/test-bin/test4/foo.txt b/t/test-bin/test4/foo.txt new file mode 100644 index 0000000..7e34287 --- /dev/null +++ b/t/test-bin/test4/foo.txt @@ -0,0 +1 @@ +This file only needs to be here to test4 dir is copied over. \ No newline at end of file -- cgit v1.2.1