summaryrefslogtreecommitdiff
path: root/mysql-test/lib
diff options
context:
space:
mode:
authorunknown <msvensson@pilot.mysql.com>2008-02-20 14:55:30 +0100
committerunknown <msvensson@pilot.mysql.com>2008-02-20 14:55:30 +0100
commit0d01221c176da491ec96b803c3981e9432a2cfde (patch)
treeabea8679a6fbc88f4b168a528803167c9af64b31 /mysql-test/lib
parent6f26028287968970f911adf3a47cf644d80b1002 (diff)
downloadmariadb-git-0d01221c176da491ec96b803c3981e9432a2cfde.tar.gz
Use My::Platform
Put all path conversions in one file Convert the --tmpdir passed to "mysqld --verbose --help" mysql-test/lib/My/Find.pm: Use My::Platform mysql-test/lib/My/SafeProcess.pm: use My::Platform mysql-test/lib/mtr_cases.pm: Use My::Platform mysql-test/lib/mtr_misc.pl: Move 'mtr_native_path' to My::Platform mysql-test/lib/My/Platform.pm: New BitKeeper file ``mysql-test/lib/My/Platform.pm'' mysql-test/lib/t/Platform.t: New BitKeeper file ``mysql-test/lib/t/Platform.t''
Diffstat (limited to 'mysql-test/lib')
-rw-r--r--mysql-test/lib/My/Find.pm8
-rw-r--r--mysql-test/lib/My/Platform.pm95
-rw-r--r--mysql-test/lib/My/SafeProcess.pm37
-rw-r--r--mysql-test/lib/mtr_cases.pm5
-rw-r--r--mysql-test/lib/mtr_misc.pl34
-rw-r--r--mysql-test/lib/t/Platform.t18
6 files changed, 132 insertions, 65 deletions
diff --git a/mysql-test/lib/My/Find.pm b/mysql-test/lib/My/Find.pm
index 36a08dd6b58..6b4d5732c36 100644
--- a/mysql-test/lib/My/Find.pm
+++ b/mysql-test/lib/My/Find.pm
@@ -23,14 +23,14 @@ package My::Find;
use strict;
use Carp;
+use My::Platform;
use base qw(Exporter);
our @EXPORT= qw(my_find_bin my_find_dir);
our $vs_config_dir;
-my $is_win= ($^O eq "MSWin32" or $^O eq "cygwin");
-my $bin_extension= ".exe" if $is_win;
+my $bin_extension= ".exe" if IS_WINDOWS;
#
# my_find_bin - find an executable with "name_1...name_n" in
@@ -56,7 +56,7 @@ sub my_find_bin {
# Find and return the first executable
# -------------------------------------------------------
foreach my $path (my_find_paths($base, $paths, $names, $bin_extension)) {
- return $path if ( -x $path or ($is_win and -f $path) );
+ return $path if ( -x $path or (IS_WINDOWS and -f $path) );
}
find_error($base, $paths, $names);
}
@@ -120,7 +120,7 @@ sub my_find_paths {
# -------------------------------------------------------
# Windows specific
# -------------------------------------------------------
- if ($is_win) {
+ if (IS_WINDOWS) {
# Add the default extra build dirs unless a specific one has
# already been selected
push(@extra_dirs,
diff --git a/mysql-test/lib/My/Platform.pm b/mysql-test/lib/My/Platform.pm
new file mode 100644
index 00000000000..27543d55adf
--- /dev/null
+++ b/mysql-test/lib/My/Platform.pm
@@ -0,0 +1,95 @@
+# -*- cperl -*-
+# Copyright (C) 2004-2006 MySQL AB
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; version 2 of the License.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+
+package My::Platform;
+
+use strict;
+
+use base qw(Exporter);
+our @EXPORT= qw(IS_CYGWIN IS_WINDOWS IS_WIN32PERL
+ native_path posix_path mixed_path);
+
+BEGIN {
+ if ($^O eq "cygwin") {
+ # Make sure cygpath works
+ if ((system("cygpath > /dev/null 2>&1") >> 8) != 1){
+ die "Could not execute 'cygpath': $!";
+ }
+ eval 'sub IS_CYGWIN { 1 }';
+ }
+ else {
+ eval 'sub IS_CYGWIN { 0 }';
+ }
+ if ($^O eq "MSWin32") {
+ eval 'sub IS_WIN32PERL { 1 }';
+ }
+ else {
+ eval 'sub IS_WIN32PERL { 0 }';
+ }
+}
+
+BEGIN {
+ if (IS_CYGWIN or IS_WIN32PERL) {
+ eval 'sub IS_WINDOWS { 1 }';
+ }
+ else {
+ eval 'sub IS_WINDOWS { 0 }';
+ }
+}
+
+
+#
+# native_path
+# Convert from path format used by perl to the underlying
+# operating systems format
+#
+# NOTE
+# Used when running windows binaries (that expect windows paths)
+# in cygwin perl (that uses unix paths)
+#
+
+sub mixed_path {
+ my ($path)= @_;
+ if (IS_CYGWIN){
+ return unless defined $path;
+ $path= `cygpath -m $path`;
+ chomp $path;
+ }
+ return $path;
+}
+
+
+sub native_path {
+ my ($path)= @_;
+ $path=~ s/\//\\/g
+ if (IS_CYGWIN or IS_WIN32PERL);
+ return $path;
+}
+
+
+sub posix_path {
+ my ($path)= @_;
+ if (IS_CYGWIN){
+ return unless defined $path;
+ $path= `cygpath $path`;
+ chomp $path;
+ }
+ return $path;
+}
+
+
+
+1;
diff --git a/mysql-test/lib/My/SafeProcess.pm b/mysql-test/lib/My/SafeProcess.pm
index 8dffe66ea03..d4c3d29520a 100644
--- a/mysql-test/lib/My/SafeProcess.pm
+++ b/mysql-test/lib/My/SafeProcess.pm
@@ -56,35 +56,10 @@ use My::SafeProcess::Base;
use base 'My::SafeProcess::Base';
use My::Find;
+use My::Platform;
my %running;
-BEGIN {
- if ($^O eq "MSWin32") {
- eval 'sub IS_WIN32PERL () { 1 }';
- }
- else {
- eval 'sub IS_WIN32PERL () { 0 }';
- }
- if ($^O eq "cygwin") {
- eval 'sub IS_CYGWIN () { 1 }';
- # Make sure cygpath works
- if ((system("cygpath > /dev/null 2>&1") >> 8) != 1){
- die "Could not execute 'cygpath': $!";
- }
- eval 'sub fixpath {
- my ($path)= @_;
- return unless defined $path;
- $path= `cygpath -w $path`;
- chomp $path;
- return $path;
- }';
- }
- else {
- eval 'sub IS_CYGWIN () { 0 }';
- }
-}
-
END {
# Kill any children still running
for my $proc (values %running){
@@ -163,12 +138,10 @@ sub new {
# }
if (IS_CYGWIN){
- # safe_procss is a windows program and need
- # windows paths
- $path= fixpath($path);
- $input= fixpath($input);
- $output= fixpath($output);
- $error= fixpath($error);
+ $path= native_path($path);
+ $input= native_path($input);
+ $output= native_path($output);
+ $error= native_path($error);
}
my @safe_args;
diff --git a/mysql-test/lib/mtr_cases.pm b/mysql-test/lib/mtr_cases.pm
index 7bc3aad4b47..488ff21dabb 100644
--- a/mysql-test/lib/mtr_cases.pm
+++ b/mysql-test/lib/mtr_cases.pm
@@ -53,6 +53,7 @@ sub collect_option {
use File::Basename;
use IO::File();
use My::Config;
+use My::Platform;
require "mtr_match.pl";
require "mtr_misc.pl";
@@ -744,7 +745,7 @@ sub collect_one_test_case {
my $master_sh= "$testdir/$tname-master.sh";
if ( -f $master_sh )
{
- if ( $main::is_win32_perl )
+ if ( IS_WIN32PERL )
{
$tinfo->{'skip'}= 1;
$tinfo->{'comment'}= "No tests with sh scripts on Windows";
@@ -762,7 +763,7 @@ sub collect_one_test_case {
my $slave_sh= "$testdir/$tname-slave.sh";
if ( -f $slave_sh )
{
- if ( $main::is_win32_perl )
+ if ( IS_WIN32PERL )
{
$tinfo->{'skip'}= 1;
$tinfo->{'comment'}= "No tests with sh scripts on Windows";
diff --git a/mysql-test/lib/mtr_misc.pl b/mysql-test/lib/mtr_misc.pl
index 759ad6da3bc..658eb270535 100644
--- a/mysql-test/lib/mtr_misc.pl
+++ b/mysql-test/lib/mtr_misc.pl
@@ -20,7 +20,8 @@
use strict;
-sub mtr_native_path($);
+use My::Platform;
+
sub mtr_init_args ($);
sub mtr_add_arg ($$@);
sub mtr_args2str($@);
@@ -30,27 +31,6 @@ sub mtr_file_exists(@);
sub mtr_exe_exists(@);
sub mtr_exe_maybe_exists(@);
-##############################################################################
-#
-# Misc
-#
-##############################################################################
-
-# Convert path to OS native format
-sub mtr_native_path($)
-{
- my $path= shift;
-
- # MySQL version before 5.0 still use cygwin, no need
- # to convert path
- return $path
- if ($::mysql_version_id < 50000);
-
- $path=~ s/\//\\/g
- if ($::is_win32);
- return $path;
-}
-
##############################################################################
#
@@ -70,14 +50,14 @@ sub mtr_add_arg ($$@) {
# Quote args if args contain space
$format= "\"$format\""
- if ($::is_win32 and grep(/\s/, @fargs));
+ if (IS_WINDOWS and grep(/\s/, @fargs));
push(@$args, sprintf($format, @fargs));
}
sub mtr_args2str($@) {
my $exe= shift or die;
- return join(" ", mtr_native_path($exe), @_);
+ return join(" ", native_path($exe), @_);
}
##############################################################################
@@ -109,7 +89,7 @@ sub mtr_path_exists (@) {
sub mtr_script_exists (@) {
foreach my $path ( @_ )
{
- if($::is_win32)
+ if(IS_WINDOWS)
{
return $path if -f $path;
}
@@ -149,10 +129,10 @@ sub mtr_file_exists (@) {
sub mtr_exe_maybe_exists (@) {
my @path= @_;
- map {$_.= ".exe"} @path if $::is_win32;
+ map {$_.= ".exe"} @path if IS_WINDOWS;
foreach my $path ( @path )
{
- if($::is_win32)
+ if(IS_WINDOWS)
{
return $path if -f $path;
}
diff --git a/mysql-test/lib/t/Platform.t b/mysql-test/lib/t/Platform.t
new file mode 100644
index 00000000000..a8cb7751925
--- /dev/null
+++ b/mysql-test/lib/t/Platform.t
@@ -0,0 +1,18 @@
+# -*- cperl -*-
+use Test::More qw(no_plan);
+use strict;
+
+use_ok ("My::Platform");
+use My::Platform;
+
+use File::Temp qw / tempdir /;
+my $dir = tempdir( CLEANUP => 1 );
+
+print "Running on Windows\n" if (IS_WINDOWS);
+print "Using ActiveState perl\n" if (IS_WIN32PERL);
+print "Using cygwin perl\n" if (IS_CYGWIN);
+
+print "dir: '$dir'\n";
+print "native: '".native_path($dir)."'\n";
+print "mixed: '".mixed_path($dir)."'\n";
+print "posix: '".posix_path($dir)."'\n";