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