Skip to content

Commit f647999

Browse files
committed
Merge pull request #115
Fix propagation and logic for Makefile.PL --testhost and --testport
2 parents 4c54a2a + fa4e732 commit f647999

File tree

1 file changed

+43
-20
lines changed

1 file changed

+43
-20
lines changed

Makefile.PL

Lines changed: 43 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,16 @@ $test_socket = $::test_socket;
3737
Getopt::Long::GetOptions(
3838
$opt,
3939
"help",
40-
"testdb=s",
41-
"testhost=s",
42-
"testport=s",
43-
"testuser=s",
44-
"testpassword=s",
45-
"testsocket=s",
46-
"cflags=s",
47-
"libs=s",
48-
"mysql_config=s",
49-
"mariadb_config=s",
40+
"testdb:s",
41+
"testhost:s",
42+
"testport:s",
43+
"testuser:s",
44+
"testpassword:s",
45+
"testsocket:s",
46+
"cflags:s",
47+
"libs:s",
48+
"mysql_config:s",
49+
"mariadb_config:s",
5050
) || die Usage();
5151

5252
$opt->{mysql_config} = delete $opt->{mariadb_config} if exists $opt->{mariadb_config};
@@ -103,24 +103,25 @@ for my $key (qw(testdb testhost testuser testpassword testsocket testport cflags
103103
Configure($opt, $source, $key);
104104
}
105105

106-
if (!$opt->{testport} && (!$opt->{testhost} || $opt->{testhost} eq 'localhost') && !$opt->{testsocket} && $test_socket) {
106+
if (!$opt->{testport} && (!$opt->{testhost} || $opt->{testhost} eq 'localhost') && !defined $opt->{testsocket} && $test_socket) {
107107
$opt->{testsocket} = $test_socket;
108108
$source->{testsocket} = "User's choice";
109-
if ($test_host && $test_host eq 'localhost') {
110-
$opt->{testhost} = 'localhost';
111-
$source->{testhost} = "User's choice";
112-
}
113109
}
114110

115111
if (!$opt->{testsocket}) {
116-
if (!$opt->{testhost} && $test_host) {
112+
if (!defined $opt->{testhost} && $test_host && (!$opt->{testport} || $test_host ne 'localhost')) {
117113
$opt->{testhost} = $test_host;
118114
$source->{testhost} = "User's choice";
119115
}
120-
if (!$opt->{testport} && $test_port) {
116+
if (!defined $opt->{testport} && $test_port && (!$opt->{testhost} || $opt->{testhost} ne 'localhost')) {
121117
$opt->{testport} = $test_port;
122118
$source->{testport} = "User's choice";
123119
}
120+
} else {
121+
if (!defined $opt->{testhost} && $test_host && $test_host eq 'localhost') {
122+
$opt->{testhost} = 'localhost';
123+
$source->{testhost} = "User's choice";
124+
}
124125
}
125126

126127
#if we have a testport but no host, assume 127.0.0.1
@@ -129,13 +130,33 @@ if ( $opt->{testport} && !$opt->{testhost} ) {
129130
$source->{testhost} = 'guessed';
130131
}
131132

133+
foreach (qw(testhost testport testsocket)) {
134+
next if defined $opt->{$_};
135+
$opt->{$_} = '';
136+
$source->{$_} = 'default';
137+
}
138+
132139
# testsocket makes sense only when testhost is localhost
133140
if ($opt->{testsocket} && $opt->{testhost} && $opt->{testhost} ne 'localhost') {
134141
die << "MSG";
135142
Option --testport or --testhost different from localhost cannot be specified together with option --testsocket.
136143
MSG
137144
}
138145

146+
# testport cannot be specified when host is localhost
147+
if ($opt->{testport} && $opt->{testhost} && $opt->{testhost} eq 'localhost') {
148+
die << "MSG";
149+
Option --testport cannot be specified when --testhost is localhost.
150+
MSG
151+
}
152+
153+
# testhost cannot be embedded
154+
if ($opt->{testhost} && $opt->{testhost} eq 'embedded') {
155+
die << "MSG";
156+
Option --testhost cannot be embedded.
157+
MSG
158+
}
159+
139160
# Separate libs and libdirs from ldflags
140161
# When linking libdirs must be specified before libs due to runtime linking problems
141162
my ($main_lib, @libs, @libdirs, @ldflags);
@@ -524,7 +545,7 @@ sub ParseMySQLConfig {
524545

525546
sub Configure {
526547
my($opt, $source, $param) = @_;
527-
if (defined($opt->{$param}) and length($opt->{$param})) {
548+
if (defined($opt->{$param})) {
528549
$source->{$param} = "User's choice";
529550
return;
530551
}
@@ -643,8 +664,7 @@ perl Makefile.PL --testuser=username
643664
$source->{$param} = "default";
644665
$opt->{$param} = $TESTDB;
645666
}
646-
elsif ($param eq "testhost" || $param eq "testport" ||
647-
$param eq "testpassword" || $param eq "testsocket" ) {
667+
elsif ($param eq "testpassword") {
648668
$source->{$param} = "default";
649669
$opt->{$param} = "";
650670
}
@@ -690,6 +710,9 @@ section "Linker flags" or type
690710
perl Makefile.PL --help
691711
MSG
692712
}
713+
elsif ($param eq "testhost" || $param eq "testport" || $param eq "testsocket") {
714+
# known parameter, but do nothing
715+
}
693716
else {
694717
die "Unknown configuration parameter: $param";
695718
}

0 commit comments

Comments
 (0)