@@ -246,6 +246,51 @@ sub taptest
246246 exit $status if $status ;
247247}
248248
249+ sub mangle_plpython3
250+ {
251+ my $tests = shift ;
252+ mkdir " results" unless -d " results" ;
253+ mkdir " sql/python3" ;
254+ mkdir " results/python3" ;
255+ mkdir " expected/python3" ;
256+
257+ foreach my $test (@$tests )
258+ {
259+ local $/ = undef ;
260+ foreach my $dir (' sql' ,' expected' )
261+ {
262+ my $extension = ($dir eq ' sql' ? ' sql' : ' out' );
263+
264+ my @files = glob (" $dir /$test .$extension $dir /${test} _[0-9].$extension " );
265+ foreach my $file (@files )
266+ {
267+ open (my $handle , " $file " ) || die " test file $file not found" ;
268+ my $contents = <$handle >;
269+ close ($handle );
270+ map
271+ {
272+ s / except ([[:alpha:]][[:alpha:].]*), *([[:alpha:]][[:alpha:]]*):/ except $1 as $2 :/ g ;
273+ s / <type 'exceptions\. ([[:alpha:]]*)'>/ <class '$1 '>/ g ;
274+ s / <type 'long'>/ <class 'int'>/ g ;
275+ s / ([0-9][0-9]*)L/ $1 / g ;
276+ s / ([ [{])u"/ $1 "/ g ;
277+ s / ([ [{])u'/ $1 '/ g ;
278+ s / def next/ def __next__/ g ;
279+ s / LANGUAGE plpython2?u/ LANGUAGE plpython3u/ g ;
280+ s / EXTENSION ([^ ]*_)*plpython2?u/ EXTENSION $1plpython3u/ g ;
281+ s / installing required extension "plpython2u"/ installing required extension "plpython3u"/ g ;
282+ } $contents ;
283+ my $base = basename $file ;
284+ open ($handle , " >$dir /python3/$base " ) || die " opening python 3 file for $file " ;
285+ print $handle $contents ;
286+ close ($handle );
287+ }
288+ }
289+ }
290+ map { $_ =~ s ! ^! python3/! ; } @$tests ;
291+ return @$tests ;
292+ }
293+
249294sub plcheck
250295{
251296 chdir " $topdir /src/pl" ;
@@ -268,7 +313,8 @@ sub plcheck
268313 }
269314 if ($lang eq ' plpython' )
270315 {
271- next unless -d " $topdir /$Config /plpython2" ;
316+ next unless -d " $topdir /$Config /plpython2" ||
317+ -d " $topdir /$Config /plpython3" ;
272318 $lang = ' plpythonu' ;
273319 }
274320 else
@@ -278,6 +324,8 @@ sub plcheck
278324 my @lang_args = (" --load-extension=$lang " );
279325 chdir $dir ;
280326 my @tests = fetchTests();
327+ @tests = mangle_plpython3(\@tests )
328+ if $lang eq ' plpythonu' && -d " $topdir /$Config /plpython3" ;
281329 if ($lang eq ' plperl' )
282330 {
283331
@@ -293,6 +341,10 @@ sub plcheck
293341 push (@tests , ' plperl_plperlu' );
294342 }
295343 }
344+ elsif ($lang eq ' plpythonu' && -d " $topdir /$Config /plpython3" )
345+ {
346+ @lang_args = ();
347+ }
296348 print
297349 " ============================================================\n " ;
298350 print " Checking $lang \n " ;
@@ -311,7 +363,6 @@ sub plcheck
311363
312364sub subdircheck
313365{
314- my $subdir = shift ;
315366 my $module = shift ;
316367
317368 if ( !-d " $module /sql"
@@ -325,44 +376,35 @@ sub subdircheck
325376 my @tests = fetchTests();
326377 my @opts = fetchRegressOpts();
327378
328- # Add some options for transform modules, see their respective
329- # Makefile for more details regarding Python-version specific
379+ # Special processing for python transform modules, see their respective
380+ # Makefiles for more details regarding Python-version specific
330381 # dependencies.
331- if ( $module eq " hstore_plpython"
332- || $module eq " jsonb_plpython"
333- || $module eq " ltree_plpython" )
382+ if ( $module =~ / _plpython$ / )
334383 {
335384 die " Python not enabled in configuration"
336385 if !defined ($config -> {python });
337386
338- # Attempt to get python version and location.
339- # Assume python.exe in specified dir.
340- my $pythonprog = " import sys;" . " print(str(sys.version_info[0]))" ;
341- my $prefixcmd = $config -> {python } . " \\ python -c \" $pythonprog \" " ;
342- my $pyver = ` $prefixcmd ` ;
343- die " Could not query for python version!\n " if $? ;
344- chomp ($pyver );
345- if ($pyver eq " 2" )
387+ @opts = grep { $_ !~ / plpythonu/ } @opts ;
388+
389+ if (-d " $topdir /$Config /plpython2" )
346390 {
347391 push @opts , " --load-extension=plpythonu" ;
348392 push @opts , ' --load-extension=' . $module . ' u' ;
349393 }
350394 else
351395 {
352-
353- # disable tests on python3 for now.
354- chdir " .." ;
355- return ;
396+ # must be python 3
397+ @tests = mangle_plpython3(\@tests );
356398 }
357399 }
358400
359-
360401 print " ============================================================\n " ;
361402 print " Checking $module \n " ;
362403 my @args = (
363404 " $topdir /$Config /pg_regress/pg_regress" ,
364405 " --bindir=${topdir} /${Config} /psql" ,
365406 " --dbname=contrib_regression" , @opts , @tests );
407+ print join (' ' ,@args )," \n " ;
366408 system (@args );
367409 chdir " .." ;
368410}
@@ -373,19 +415,15 @@ sub contribcheck
373415 my $mstat = 0;
374416 foreach my $module (glob (" *" ))
375417 {
376-
377418 # these configuration-based exclusions must match Install.pm
378419 next if ($module eq " uuid-ossp" && !defined ($config -> {uuid }));
379420 next if ($module eq " sslinfo" && !defined ($config -> {openssl }));
380421 next if ($module eq " xml2" && !defined ($config -> {xml }));
381- next if ($module eq " hstore_plperl" && !defined ($config -> {perl }));
382- next if ($module eq " jsonb_plperl" && !defined ($config -> {perl }));
383- next if ($module eq " hstore_plpython" && !defined ($config -> {python }));
384- next if ($module eq " jsonb_plpython" && !defined ($config -> {python }));
385- next if ($module eq " ltree_plpython" && !defined ($config -> {python }));
422+ next if ($module =~ / _plperl$ / && !defined ($config -> {perl }));
423+ next if ($module =~ / _plpython$ / && !defined ($config -> {python }));
386424 next if ($module eq " sepgsql" );
387425
388- subdircheck(" $topdir /contrib " , $module );
426+ subdircheck($module );
389427 my $status = $? >> 8;
390428 $mstat ||= $status ;
391429 }
@@ -398,7 +436,7 @@ sub modulescheck
398436 my $mstat = 0;
399437 foreach my $module (glob (" *" ))
400438 {
401- subdircheck(" $topdir /src/test/modules " , $module );
439+ subdircheck($module );
402440 my $status = $? >> 8;
403441 $mstat ||= $status ;
404442 }
0 commit comments