Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit a9fbf55

Browse files
committed
Provide for testing on python3 modules when under MSVC
This should have been done some years ago as promised in commit c4dcdd0. However, better late than never. Along the way do a little housekeeping, including using a simpler test for the python version being tested, and removing a redundant subroutine parameter. These changes only apply back to release 9.5. Backpatch to all live releases.
1 parent 679b074 commit a9fbf55

File tree

2 files changed

+68
-29
lines changed

2 files changed

+68
-29
lines changed

src/tools/msvc/Install.pm

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -458,14 +458,12 @@ sub CopyContribFiles
458458
opendir($D, $subdir) || croak "Could not opendir on $subdir!\n";
459459
while (my $d = readdir($D))
460460
{
461-
462461
# These configuration-based exclusions must match vcregress.pl
463462
next if ($d eq "uuid-ossp" && !defined($config->{uuid}));
464463
next if ($d eq "sslinfo" && !defined($config->{openssl}));
465464
next if ($d eq "xml2" && !defined($config->{xml}));
466-
next if ($d eq "hstore_plperl" && !defined($config->{perl}));
467-
next if ($d eq "hstore_plpython" && !defined($config->{python}));
468-
next if ($d eq "ltree_plpython" && !defined($config->{python}));
465+
next if ($d =~ /_plperl$/ && !defined($config->{perl}));
466+
next if ($d =~ /_plpython$/ && !defined($config->{python}));
469467
next if ($d eq "sepgsql");
470468

471469
CopySubdirFiles($subdir, $d, $config, $target);

src/tools/msvc/vcregress.pl

Lines changed: 66 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,51 @@ sub taptest
243243
exit $status if $status;
244244
}
245245

246+
sub mangle_plpython3
247+
{
248+
my $tests = shift;
249+
mkdir "results" unless -d "results";
250+
mkdir "sql/python3";
251+
mkdir "results/python3";
252+
mkdir "expected/python3";
253+
254+
foreach my $test (@$tests)
255+
{
256+
local $/ = undef;
257+
foreach my $dir ('sql','expected')
258+
{
259+
my $extension = ($dir eq 'sql' ? 'sql' : 'out');
260+
261+
my @files = glob("$dir/$test.$extension $dir/${test}_[0-9].$extension");
262+
foreach my $file (@files)
263+
{
264+
open(my $handle, "$file") || die "test file $file not found";
265+
my $contents = <$handle>;
266+
close($handle);
267+
map
268+
{
269+
s/except ([[:alpha:]][[:alpha:].]*), *([[:alpha:]][[:alpha:]]*):/except $1 as $2:/g;
270+
s/<type 'exceptions\.([[:alpha:]]*)'>/<class '$1'>/g;
271+
s/<type 'long'>/<class 'int'>/g;
272+
s/([0-9][0-9]*)L/$1/g;
273+
s/([ [{])u"/$1"/g;
274+
s/([ [{])u'/$1'/g;
275+
s/def next/def __next__/g;
276+
s/LANGUAGE plpython2?u/LANGUAGE plpython3u/g;
277+
s/EXTENSION ([^ ]*_)*plpython2?u/EXTENSION $1plpython3u/g;
278+
s/installing required extension "plpython2u"/installing required extension "plpython3u"/g;
279+
} $contents;
280+
my $base = basename $file;
281+
open($handle, ">$dir/python3/$base") || die "opening python 3 file for $file";
282+
print $handle $contents;
283+
close($handle);
284+
}
285+
}
286+
}
287+
map { $_ =~ s!^!python3/!; } @$tests;
288+
return @$tests;
289+
}
290+
246291
sub plcheck
247292
{
248293
chdir "../../pl";
@@ -253,7 +298,8 @@ sub plcheck
253298
my $lang = $pl eq 'tcl' ? 'pltcl' : $pl;
254299
if ($lang eq 'plpython')
255300
{
256-
next unless -d "../../$Config/plpython2";
301+
next unless -d "$topdir/$Config/plpython2" ||
302+
-d "$topdir/$Config/plpython3";
257303
$lang = 'plpythonu';
258304
}
259305
else
@@ -263,6 +309,8 @@ sub plcheck
263309
my @lang_args = ("--load-extension=$lang");
264310
chdir $pl;
265311
my @tests = fetchTests();
312+
@tests = mangle_plpython3(\@tests)
313+
if $lang eq 'plpythonu' && -d "$topdir/$Config/plpython3";
266314
if ($lang eq 'plperl')
267315
{
268316

@@ -278,6 +326,10 @@ sub plcheck
278326
push(@tests, 'plperl_plperlu');
279327
}
280328
}
329+
elsif ($lang eq 'plpythonu' && -d "$topdir/$Config/plpython3")
330+
{
331+
@lang_args = ();
332+
}
281333
print
282334
"============================================================\n";
283335
print "Checking $lang\n";
@@ -296,7 +348,6 @@ sub plcheck
296348

297349
sub subdircheck
298350
{
299-
my $subdir = shift;
300351
my $module = shift;
301352

302353
if ( !-d "$module/sql"
@@ -310,43 +361,35 @@ sub subdircheck
310361
my @tests = fetchTests();
311362
my @opts = fetchRegressOpts();
312363

313-
# Add some options for transform modules, see their respective
314-
# Makefile for more details regarding Python-version specific
364+
# Special processing for python transform modules, see their respective
365+
# Makefiles for more details regarding Python-version specific
315366
# dependencies.
316-
if ( $module eq "hstore_plpython"
317-
|| $module eq "ltree_plpython")
367+
if ( $module =~ /_plpython$/ )
318368
{
319369
die "Python not enabled in configuration"
320370
if !defined($config->{python});
321371

322-
# Attempt to get python version and location.
323-
# Assume python.exe in specified dir.
324-
my $pythonprog = "import sys;" . "print(str(sys.version_info[0]))";
325-
my $prefixcmd = $config->{python} . "\\python -c \"$pythonprog\"";
326-
my $pyver = `$prefixcmd`;
327-
die "Could not query for python version!\n" if $?;
328-
chomp($pyver);
329-
if ($pyver eq "2")
372+
@opts = grep { $_ !~ /plpythonu/ } @opts;
373+
374+
if (-d "$topdir/$Config/plpython2")
330375
{
331376
push @opts, "--load-extension=plpythonu";
332377
push @opts, '--load-extension=' . $module . 'u';
333378
}
334379
else
335380
{
336-
337-
# disable tests on python3 for now.
338-
chdir "..";
339-
return;
381+
# must be python 3
382+
@tests = mangle_plpython3(\@tests);
340383
}
341384
}
342385

343-
344386
print "============================================================\n";
345387
print "Checking $module\n";
346388
my @args = (
347389
"$topdir/$Config/pg_regress/pg_regress",
348390
"--bindir=${topdir}/${Config}/psql",
349391
"--dbname=contrib_regression", @opts, @tests);
392+
print join(' ',@args),"\n";
350393
system(@args);
351394
chdir "..";
352395
}
@@ -357,17 +400,15 @@ sub contribcheck
357400
my $mstat = 0;
358401
foreach my $module (glob("*"))
359402
{
360-
361403
# these configuration-based exclusions must match Install.pm
362404
next if ($module eq "uuid-ossp" && !defined($config->{uuid}));
363405
next if ($module eq "sslinfo" && !defined($config->{openssl}));
364406
next if ($module eq "xml2" && !defined($config->{xml}));
365-
next if ($module eq "hstore_plperl" && !defined($config->{perl}));
366-
next if ($module eq "hstore_plpython" && !defined($config->{python}));
367-
next if ($module eq "ltree_plpython" && !defined($config->{python}));
407+
next if ($module =~ /_plperl$/ && !defined($config->{perl}));
408+
next if ($module =~ /_plpython$/ && !defined($config->{python}));
368409
next if ($module eq "sepgsql");
369410

370-
subdircheck("$topdir/contrib", $module);
411+
subdircheck($module);
371412
my $status = $? >> 8;
372413
$mstat ||= $status;
373414
}
@@ -380,7 +421,7 @@ sub modulescheck
380421
my $mstat = 0;
381422
foreach my $module (glob("*"))
382423
{
383-
subdircheck("$topdir/src/test/modules", $module);
424+
subdircheck($module);
384425
my $status = $? >> 8;
385426
$mstat ||= $status;
386427
}

0 commit comments

Comments
 (0)