This repository has been archived by the owner on Jul 18, 2018. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Test _expand_filenames, requiring subtests
- Loading branch information
Showing
3 changed files
with
81 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
#!/usr/bin/perl | ||
package App::Cpan; | ||
use Test::More 0.95; | ||
|
||
BEGIN { | ||
local $^W = 0; | ||
|
||
our $class = 'App::Cpan'; | ||
our $method = '_expand_filename'; | ||
|
||
use_ok( $class ); | ||
can_ok( $class, $method ); | ||
|
||
$class->_init_logger; | ||
} | ||
|
||
{ | ||
no warnings 'redefine'; | ||
*_home_of = sub { | ||
my( $user ) = @_; | ||
$user = 'Buster' unless defined $user; | ||
$user = 'Buster' if $user =~ /\A\d+\z/; # not the UID | ||
"/Users/$user" | ||
}; | ||
} | ||
|
||
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # | ||
# Test with bad data | ||
subtest 'bad_input' => sub { | ||
foreach my $input ( undef, 0, '' ) { | ||
my $result = _expand_filename( $input ); | ||
no warnings 'uninitialized'; | ||
is( $result, $input, "For bad data [$input], output is same as input" ); | ||
} | ||
}; | ||
|
||
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # | ||
# Test with no leading tilde | ||
subtest 'no_leading_tilde' => sub { | ||
foreach my $input ( 'Buster', 'Mimi/Roscoe', 'Ros~coe' ) { | ||
my $result = _expand_filename( $input ); | ||
is( $result, $input, "For no leading tilde [$input], output is same as input" ); | ||
} | ||
}; | ||
|
||
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # | ||
# Test with only tilde | ||
subtest 'tilde_only' => sub { | ||
my $result = _expand_filename( '~' ); | ||
is( $result, _home_of(), 'For tilde only, output is _home_of' ); | ||
}; | ||
|
||
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # | ||
# Test with only tilde and one dir | ||
subtest 'tilde_with_name' => sub { | ||
my $result = _expand_filename( '~foo' ); | ||
is( $result, "/Users/foo", 'For tilde with name, output has that name' ); | ||
}; | ||
|
||
|
||
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # | ||
# Test with only tilde and two dirs | ||
subtest 'tilde_name_dir' => sub { | ||
my $result = _expand_filename( '~foo/bar' ); | ||
is( $result, "/Users/foo/bar", 'For tilde with name and dir, output has name and dir' ); | ||
}; | ||
|
||
done_testing; | ||
|
||
__END__ | ||
sub _expand_filename | ||
{ | ||
my( $path )= @_; | ||
$logger->debug( "Expanding path $path\n" ); | ||
$path =~ s{\A~([^/]+)?}{ | ||
_home_of( $1 || $> ) || "~$1" | ||
}e; | ||
return $path; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,3 +6,4 @@ install_hack.t | |
process_options.t | ||
return_values.t | ||
cpanpm_output_hook.t | ||
expand_filenames.t |