8000 Provide for testing on python3 modules when under MSVC · limezra/postgres@56a4564 · 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 56a4564

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 d03cf45 commit 56a4564

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
< 6D40 td data-grid-cell-id="diff-a7ffdd71bd4ea2b5c69a971c666fbfe082620fb7e0408f0a92d7daee31802d63-257-303-0" data-selected="false" role="gridcell" style="background-color:var(--diffBlob-additionNum-bgColor, var(--diffBlob-addition-bgColor-num));text-align:center" tabindex="-1" valign="top" class="focusable-grid-cell diff-line-number position-relative left-side">
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,51 @@ sub taptest
244244
exit $status if $status;
245245
}
246246

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

@@ -279,6 +327,10 @@ sub plcheck
279327
push(@tests, 'plperl_plperlu');
280328
}
281329
}
330+
elsif ($lang eq 'plpythonu' && -d "$topdir/$Config/plpython3")
331+
{
332+
@lang_args = ();
333+
}
282334
print
283335
"============================================================\n";
284336
print "Checking $lang\n";
@@ -297,7 +349,6 @@ sub plcheck
297349

298350
sub subdircheck
299351
{
300-
my $subdir = shift;
301352
my $module = shift;
302353

303354
if ( !-d "$module/sql"
@@ -311,43 +362,35 @@ sub subdircheck
311362
my @tests = fetchTests();
312363
my @opts = fetchRegressOpts();
313364

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

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

344-
345387
print "============================================================\n";
346388
print "Checking $module\n";
347389
my @args = (
348390
"$topdir/$Config/pg_regress/pg_regress",
349391
"--bindir=${topdir}/${Config}/psql",
350392
"--dbname=contrib_regression", @opts, @tests);
393+
print join(' ',@args),"\n";
351394
system(@args);
352395
chdir "..";
353396
}
@@ -358,17 +401,15 @@ sub contribcheck
358401
my $mstat = 0;
359402
foreach my $module (glob("*"))
360403
{
361-
362404
# these configuration-based exclusions must match Install.pm
363405
next if ($module eq "uuid-ossp" && !defined($config->{uuid}));
364406
next if ($module eq "sslinfo" && !defined($config->{openssl}));
365407
next if ($module eq "xml2" && !defined($config->{xml}));
366-
next if ($module eq "hstore_plperl" && !defined($config->{perl}));
367-
next if ($module eq "hstore_plpython" && !defined($config->{python}));
368-
next if ($module eq "ltree_plpython" && !defined($config->{python}));
408+
next if ($module =~ /_plperl$/ && !defined($config->{perl}));
409+
next if ($module =~ /_plpython$/ && !defined($config->{python}));
369410
next if ($module eq "sepgsql");
370411

371-
subdircheck("$topdir/contrib", $module);
412+
subdircheck($module);
372413
my $status = $? >> 8;
373414
$mstat ||= $status;
374415
}
@@ -381,7 +422,7 @@ sub modulescheck
381422
my $mstat = 0;
382423
foreach my $module (glob("*"))
383424
{
384-
subdircheck("$topdir/src/test/modules", $module);
425+
subdircheck($module);
385426
my $status = $? >> 8;
386427
$mstat ||= $status;
387428
}

0 commit comments

Comments
 (0)
0