8000 Provide for testing on python3 modules when under MSVC · limezra/postgres@c1f3638 · GitHub
[go: up one dir, main page]

Skip to content
This repository was archived by the owner on Aug 17, 2020. It is now read-only.

Commit c1f3638

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 1fcb0df commit c1f3638

File tree

2 files changed

+68
-28
lines changed

2 files changed

+68
-28
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 & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,51 @@ sub taptest
242242
exit $status if $status;
243243
}
244244

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

@@ -277,6 +325,10 @@ sub plcheck
277325
push(@tests, 'plperl_plperlu');
278326
}
279327
}
328+
elsif ($lang eq 'plpythonu' && -d "$topdir/$Config/plpython3")
329+
{
330+
@lang_args = ();
331+
}
280332
print
281333
"============================================================\n";
282334
print "Checking $lang\n";
@@ -295,7 +347,6 @@ sub plcheck
295347

296348
sub subdircheck
297349
{
298-
my $subdir = shift;
299350
my $module = shift;
300351

301352
if ( !-d "$module/sql"
@@ -309,43 +360,35 @@ sub subdircheck
309360
my @tests = fetchTests();
310361
my @opts = fetchRegressOpts();
311362

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

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

342-
343385
print "============================================================\n";
344386
print "Checking $module\n";
345387
my @args = (
346388
"$topdir/$Config/pg_regress/pg_regress",
347389
"--bindir=${topdir}/${Config}/psql",
348390
"--dbname=contrib_regression", @opts, @tests);
391+
print join(' ',@args),"\n";
349392
system(@args);
350393
chdir "..";
351394
}
@@ -360,12 +403,11 @@ sub contribcheck
360403
next if ($module eq "uuid-ossp" && !defined($config->{uuid}));
361404
next if ($module eq "sslinfo" && !defined($config->{openssl}));
362405
next if ($module eq "xml2" && !defined($config->{xml}));
363-
next if ($module eq "hstore_plperl" && !defined($config->{perl}));
364-
next if ($module eq "hstore_plpython" && !defined($config->{python}));
365-
next if ($module eq "ltree_plpython" && !defined($config->{python}));
406+
next if ($module =~ /_plperl$/ && !defined($config->{perl}));
407+
next if ($module =~ /_plpython$/ && !defined($config->{python}));
366408
next if ($module eq "sepgsql");
367409

368-
subdircheck("$topdir/contrib", $module);
410+
subdircheck($module);
369411
my $status = $? >> 8;
370412
$mstat ||= $status;
371413
}
@@ -378,7 +420,7 @@ sub modulescheck
378420
my $mstat = 0;
379421
foreach my $module (glob("*"))
380422
{
381-
subdircheck("$topdir/src/test/modules", $module);
423+
subdircheck($module);
382424
my $status = $? >> 8;
383425
$mstat ||= $status;
384426
}

0 commit comments

Comments
 (0)
0