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