Skip to content

Commit

Permalink
For #115, cp has case problems on Windows.
Browse files Browse the repository at this point in the history
Squashed commit of the following:

commit b3a0f1e
Author: brian d foy <brian.d.foy@gmail.com>
Date:   Wed Jun 21 09:49:15 2023 -0400

    Turn off case sensitive tracking in bin/cp (#115)

commit e937650
Author: brian d foy <briandfoy@pobox.com>
Date:   Wed Jun 21 09:36:01 2023 -0400

    Initial cp test for #115
  • Loading branch information
briandfoy committed Jun 21, 2023
1 parent 0c6cb24 commit d62f527
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 9 deletions.
9 changes: 0 additions & 9 deletions bin/cp
Expand Up @@ -64,16 +64,7 @@ if ($^O =~ /Win32/i)
# $cp::BINMODE = 0;
#}

## default is that OS is case sensitive (file a.txt ne A.txt)
if ($^O =~ /(Win32|VMS|OS2)/i) ## OS is not case sensitive.. normalize path
{
$cp::CASE_SENSITIVE = 0;
$cp::CWD = uc $cp::CWD;
}
else
{
$cp::CASE_SENSITIVE = 1;
}
$cp::CWD =~ s|\\|/|g; ## normalize for compares

####### C H E C K P A T H S & C L E A N U P I F N E E D E D ######
Expand Down
66 changes: 66 additions & 0 deletions t/cp/gh-115-copy-into-dir.t
@@ -0,0 +1,66 @@
use strict;
use warnings;

use Test::More;
use Cwd;
use File::Spec::Functions qw(catfile);
use File::Temp qw(tempdir);
use File::Path qw(make_path);

require './t/lib/common.pl';

my $Program = program_name();

sanity_test($Program);

my $starting_dir = getcwd();
my $program_path = catfile( $starting_dir, $Program );
diag( "Starting working dir is $starting_dir" );
diag( "Program path is $program_path" );

my $test_file = 'a.txt';
my $dir = tempdir( CLEANUP => 1 );
ok( chdir $dir, 'Was able to change into temporary directory' );
diag( "Current working dir is " . getcwd() );

my $subdir = 'child';
make_path $subdir;
ok( -d $subdir, 'Subdirectory is there' );

my $filename = 'a.txt';
open my $fh, '>', $filename;
print {$fh} "a\nb\nc\n";
close $fh;

my $second_filename = 'b.txt';

subtest 'starting files' => sub {
ok -e $filename, "$filename exists";
ok ! -e $second_filename, "$second_filename does not exist";
};

=pod
On Windows, cp a.txt b.txt fails at line 252 with message "cp: can not access B.TXT ... skipping".
=cut

subtest 'same directory' => sub {
my $rc = system $^X, $program_path, $filename, $second_filename;
is $rc, 0, 'system exited with 0';
ok -e $second_filename, "$second_filename exists";
};

=pod
Overall, this script has problems with case sensitivity, for example cp a.txt dir will create dir/A.TXT.
=cut

subtest 'into directory' => sub {
my $rc = system $^X, $program_path, $filename, $subdir;
is $rc, 0, 'system exited with 0';
ok -e catfile( $subdir, $filename ), "$subdir/$second_filename exists";
};

done_testing();

0 comments on commit d62f527

Please sign in to comment.