@@ -37,16 +37,16 @@ $test_socket = $::test_socket;
37
37
Getopt::Long::GetOptions(
38
38
$opt ,
39
39
" 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" ,
50
50
) || die Usage();
51
51
52
52
$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
103
103
Configure($opt , $source , $key );
104
104
}
105
105
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 ) {
107
107
$opt -> {testsocket } = $test_socket ;
108
108
$source -> {testsocket } = " User's choice" ;
109
- if ($test_host && $test_host eq ' localhost' ) {
110
- $opt -> {testhost } = ' localhost' ;
111
- $source -> {testhost } = " User's choice" ;
112
- }
113
109
}
114
110
115
111
if (!$opt -> {testsocket }) {
116
- if (!$opt -> {testhost } && $test_host ) {
112
+ if (!defined $opt -> {testhost } && $test_host && (! $opt -> { testport } || $test_host ne ' localhost ' ) ) {
117
113
$opt -> {testhost } = $test_host ;
118
114
$source -> {testhost } = " User's choice" ;
119
115
}
120
- if (!$opt -> {testport } && $test_port ) {
116
+ if (!defined $opt -> {testport } && $test_port && (! $opt -> { testhost } || $opt -> { testhost } ne ' localhost ' ) ) {
121
117
$opt -> {testport } = $test_port ;
122
118
$source -> {testport } = " User's choice" ;
123
119
}
120
+ } else {
121
+ if (!defined $opt -> {testhost } && $test_host && $test_host eq ' localhost' ) {
122
+ $opt -> {testhost } = ' localhost' ;
123
+ $source -> {testhost } = " User's choice" ;
124
+ }
124
125
}
125
126
126
127
# if we have a testport but no host, assume 127.0.0.1
@@ -129,13 +130,33 @@ if ( $opt->{testport} && !$opt->{testhost} ) {
129
130
$source -> {testhost } = ' guessed' ;
130
131
}
131
132
133
+ foreach (qw( testhost testport testsocket) ) {
134
+ next if defined $opt -> {$_ };
135
+ $opt -> {$_ } = ' ' ;
136
+ $source -> {$_ } = ' default' ;
137
+ }
138
+
132
139
# testsocket makes sense only when testhost is localhost
133
140
if ($opt -> {testsocket } && $opt -> {testhost } && $opt -> {testhost } ne ' localhost' ) {
134
141
die << "MSG" ;
135
142
Option --testport or --testhost different from localhost cannot be specified together with option --testsocket.
136
143
MSG
137
144
}
138
145
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
+
139
160
# Separate libs and libdirs from ldflags
140
161
# When linking libdirs must be specified before libs due to runtime linking problems
141
162
my ($main_lib , @libs , @libdirs , @ldflags );
@@ -524,7 +545,7 @@ sub ParseMySQLConfig {
524
545
525
546
sub Configure {
526
547
my ($opt , $source , $param ) = @_ ;
527
- if (defined ($opt -> {$param }) and length ( $opt -> { $param }) ) {
548
+ if (defined ($opt -> {$param })) {
528
549
$source -> {$param } = " User's choice" ;
529
550
return ;
530
551
}
@@ -643,8 +664,7 @@ perl Makefile.PL --testuser=username
643
664
$source -> {$param } = " default" ;
644
665
$opt -> {$param } = $TESTDB ;
645
666
}
646
- elsif ($param eq " testhost" || $param eq " testport" ||
647
- $param eq " testpassword" || $param eq " testsocket" ) {
667
+ elsif ($param eq " testpassword" ) {
648
668
$source -> {$param } = " default" ;
649
669
$opt -> {$param } = " " ;
650
670
}
@@ -690,6 +710,9 @@ section "Linker flags" or type
690
710
perl Makefile.PL --help
691
711
MSG
692
712
}
713
+ elsif ($param eq " testhost" || $param eq " testport" || $param eq " testsocket" ) {
714
+ # known parameter, but do nothing
715
+ }
693
716
else {
694
717
die " Unknown configuration parameter: $param " ;
695
718
}
0 commit comments