From 54b9c2015194b68135098c4eae564a122a4bccf6 Mon Sep 17 00:00:00 2001 From: Alex Brainman Date: Tue, 20 Nov 2012 16:24:12 +1100 Subject: [PATCH] net/http/cgi: another attempt to fix windows tests Also enables TestDirWindows test on windows. Fixes #4401. R=golang-dev, bradfitz CC=golang-dev, krautz https://golang.org/cl/6847072 --- src/pkg/net/http/cgi/host_test.go | 5 +- src/pkg/net/http/cgi/testdata/test.cgi | 77 +++++++------------------- 2 files changed, 25 insertions(+), 57 deletions(-) diff --git a/src/pkg/net/http/cgi/host_test.go b/src/pkg/net/http/cgi/host_test.go index 4db3d850c5..0dc16c2990 100644 --- a/src/pkg/net/http/cgi/host_test.go +++ b/src/pkg/net/http/cgi/host_test.go @@ -404,7 +404,8 @@ func TestDirUnix(t *testing.T) { } func TestDirWindows(t *testing.T) { - if skipTest(t) || runtime.GOOS != "windows" { + if runtime.GOOS != "windows" { + t.Logf("Skipping windows specific test.") return } @@ -414,6 +415,7 @@ func TestDirWindows(t *testing.T) { var err error perl, err = exec.LookPath("perl") if err != nil { + t.Logf("Skipping test: perl not found.") return } perl, _ = filepath.Abs(perl) @@ -456,6 +458,7 @@ func TestEnvOverride(t *testing.T) { var err error perl, err = exec.LookPath("perl") if err != nil { + t.Logf("Skipping test: perl not found.") return } perl, _ = filepath.Abs(perl) diff --git a/src/pkg/net/http/cgi/testdata/test.cgi b/src/pkg/net/http/cgi/testdata/test.cgi index dcefe4e7af..1b25bc2999 100755 --- a/src/pkg/net/http/cgi/testdata/test.cgi +++ b/src/pkg/net/http/cgi/testdata/test.cgi @@ -10,23 +10,6 @@ use Cwd; binmode STDOUT; -sub on_windows { - return $^O eq 'MSWin32' || $^O eq 'msys'; -} - -# normalize_windows_path normalizes the various Windows Perl path -# formats into Go's format. -sub normalize_windows_path { - my $dir = shift; - return $dir unless on_windows(); - $dir =~ s!^[a-z]:!uc($&)!e; - if ($dir =~ s!^/([a-zA-Z])/!!) { - $dir = uc($1) . ":\\$dir"; - } - $dir =~ s!/!\\!g; - return $dir; -} - my $q = MiniCGI->new; my $params = $q->Vars; @@ -35,40 +18,43 @@ if ($params->{"loc"}) { exit(0); } -my $NL = "\r\n"; -$NL = "\n" if $params->{mode} eq "NL"; - -my $p = sub { - print "$_[0]$NL"; -}; - -# With carriage returns -$p->("Content-Type: text/html"); -$p->("X-CGI-Pid: $$"); -$p->("X-Test-Header: X-Test-Value"); -$p->(""); +print "Content-Type: text/html\r\n"; +print "X-CGI-Pid: $$\r\n"; +print "X-Test-Header: X-Test-Value\r\n"; +print "\r\n"; if ($params->{"bigresponse"}) { for (1..1024) { - print "A" x 1024, "\n"; + print "A" x 1024, "\r\n"; } exit 0; } -print "test=Hello CGI\n"; +print "test=Hello CGI\r\n"; foreach my $k (sort keys %$params) { - print "param-$k=$params->{$k}\n"; + print "param-$k=$params->{$k}\r\n"; } foreach my $k (sort keys %ENV) { my $clean_env = $ENV{$k}; $clean_env =~ s/[\n\r]//g; - print "env-$k=$clean_env\n"; + print "env-$k=$clean_env\r\n"; } -my $dir = normalize_windows_path(getcwd()); -print "cwd=$dir\n"; +# NOTE: msys perl returns /c/go/src/... not C:\go\.... +my $dir = getcwd(); +if ($^O eq 'MSWin32' || $^O eq 'msys') { + if ($dir =~ /^.:/) { + $dir =~ s!/!\\!g; + } else { + my $cmd = $ENV{'COMSPEC'} || 'c:\\windows\\system32\\cmd.exe'; + $cmd =~ s!\\!/!g; + $dir = `$cmd /c cd`; + chomp $dir; + } +} +print "cwd=$dir\r\n"; # A minimal version of CGI.pm, for people without the perl-modules # package installed. (CGI.pm used to be part of the Perl core, but @@ -102,24 +88,3 @@ sub _urldecode { $v =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; return $v; } - -package Tests; - -sub test_normalize_windows_paths { - my @tests = ( - {in => "C:\\foo\\bar", want => "C:\\foo\\bar"}, - {in => "C:/foo/bar", want => "C:\\foo\\bar"}, - {in => "c:/foo/bar", want => "C:\\foo\\bar"}, - {in => "/c/foo/bar", want => "C:\\foo\\bar"}, - ); - foreach my $tt (@tests) { - my $got = ::normalize_windows_path($tt->{in}); - unless ($got eq $tt->{want}) { - die "For path $tt->{in}, normalize = $got; want $tt->{want}\n"; - } - } -} - -BEGIN { - test_normalize_windows_paths() if ::on_windows(); -} -- 2.48.1