This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Break out B::Debug into its own directory in ext.
[perl5.git] / t / lib / cygwin.t
1 #!perl
2
3 BEGIN {
4     chdir 't' if -d 't';
5     @INC = ('../lib');
6     unless ($^O eq "cygwin") {
7         print "1..0 # skipped: cygwin specific test\n";
8         exit 0;
9     }
10 }
11
12 use Test::More tests => 16;
13
14 is(Cygwin::winpid_to_pid(Cygwin::pid_to_winpid($$)), $$,
15    "perl pid translates to itself");
16
17 my $parent = getppid;
18 SKIP: {
19     skip "test not run from cygwin process", 1 if $parent <= 1;
20     is(Cygwin::winpid_to_pid(Cygwin::pid_to_winpid($parent)), $parent,
21        "parent pid translates to itself");
22 }
23
24 my $catpid = open my $cat, "|cat" or die "Couldn't cat: $!";
25 open my $ps, "ps|" or die "Couldn't do ps: $!";
26 my ($catwinpid) = map /^.\s+$catpid\s+\d+\s+\d+\s+(\d+)/, <$ps>;
27 close($ps);
28
29 is(Cygwin::winpid_to_pid($catwinpid), $catpid, "winpid to pid");
30 is(Cygwin::pid_to_winpid($catpid), $catwinpid, "pid to winpid");
31 close($cat);
32
33 is(Cygwin::win_to_posix_path("t\\lib"), "t/lib", "win to posix path: t/lib");
34 is(Cygwin::posix_to_win_path("t/lib"), "t\\lib", "posix to win path: t\\lib");
35
36 use Win32;
37 use Cwd;
38 my $pwd = getcwd();
39 chdir("/");
40 my $winpath = Win32::GetCwd();
41 is(Cygwin::posix_to_win_path("/", 1), $winpath, "posix to absolute win path");
42 chdir($pwd);
43 is(Cygwin::win_to_posix_path($winpath, 1), "/", "win to absolute posix path");
44
45 my $mount = join '', `/usr/bin/mount`;
46 $mount =~ m|on /usr/bin type .+ \((\w+mode)[,\)]|m;
47 my $binmode = $1 eq 'binmode';
48 is(Cygwin::is_binmount("/"),  $binmode ? 1 : '', "check / for binmount");
49
50 my $rootmnt = Cygwin::mount_flags("/");
51 ok($binmode ? ($rootmnt =~ /,binmode/) : ($rootmnt =~ /,textmode/), "check / mount_flags");
52 is(Cygwin::mount_flags("/cygdrive") =~ /,cygdrive/,  1, "check cygdrive mount_flags");
53
54 # Cygdrive mount prefix
55 my @flags = split(/,/, Cygwin::mount_flags('/cygdrive'));
56 my $prefix = pop(@flags);
57 ok($prefix, "cygdrive mount prefix = " . (($prefix) ? $prefix : '<none>'));
58 chomp(my $prefix2 = `df | grep -i '^c: ' | cut -d% -f2 | xargs`);
59 $prefix2 =~ s/\/c$//i;
60 if (! $prefix2) {
61     $prefix2 = '/';
62 }
63 is($prefix, $prefix2, 'cygdrive mount prefix');
64
65 my @mnttbl = Cygwin::mount_table();
66 ok(@mnttbl > 0, "non empty mount_table");
67 for $i (@mnttbl) {
68   if ($i->[0] eq '/') {
69     is($i->[2].",".$i->[3], $rootmnt, "same root mount flags");
70     last;
71   }
72 }
73
74 ok(Cwd->cwd(), "bug#38628 legacy");