@@ -244,6 +244,51 @@ sub taptest
244244exit $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+
247292sub plcheck
248293{
249294chdir " ../../pl" ;
@@ -254,7 +299,8 @@ sub plcheck
254299my $lang =$pl eq ' tcl' ?' pltcl' :$pl ;
255300if ($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}
260306else
@@ -264,6 +310,8 @@ sub plcheck
264310my @lang_args = (" --load-extension=$lang " );
265311chdir $pl ;
266312my @tests = fetchTests();
313+ @tests = mangle_plpython3(\@tests )
314+ if $lang eq ' plpythonu' &&-d " $topdir /$Config /plpython3" ;
267315if ($lang eq ' plperl' )
268316{
269317
@@ -279,6 +327,10 @@ sub plcheck
279327push (@tests ,' plperl_plperlu' );
280328}
281329}
330+ elsif ($lang eq ' plpythonu' &&-d " $topdir /$Config /plpython3" )
331+ {
332+ @lang_args = ();
333+ }
282334print
283335" ============================================================\n " ;
284336print " Checking$lang \n " ;
@@ -297,7 +349,6 @@ sub plcheck
297349
298350sub subdircheck
299351{
300- my $subdir =shift ;
301352my $module =shift ;
302353
303354if ( !-d " $module /sql"
@@ -311,43 +362,35 @@ sub subdircheck
311362my @tests = fetchTests();
312363my @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{
320370die " Python not enabled in configuration"
321371if !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{
332377push @opts ," --load-extension=plpythonu" ;
333378push @opts ,' --load-extension=' .$module .' u' ;
334379}
335380else
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-
345387print " ============================================================\n " ;
346388print " Checking$module \n " ;
347389my @args = (
348390" $topdir /$Config /pg_regress/pg_regress" ,
349391" --bindir=${topdir} /${Config} /psql" ,
350392" --dbname=contrib_regression" ,@opts ,@tests );
393+ print join (' ' ,@args )," \n " ;
351394system (@args );
352395chdir " .." ;
353396}
@@ -358,17 +401,15 @@ sub contribcheck
358401my $mstat = 0;
359402foreach my $module (glob (" *" ))
360403{
361-
362404# these configuration-based exclusions must match Install.pm
363405next if ($module eq " uuid-ossp" && !defined ($config -> {uuid }));
364406next if ($module eq " sslinfo" && !defined ($config -> {openssl }));
365407next 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 }));
369410next if ($module eq " sepgsql" );
370411
371- subdircheck(" $topdir /contrib " , $module );
412+ subdircheck($module );
372413my $status =$? >> 8;
373414$mstat ||=$status ;
374415}
@@ -381,7 +422,7 @@ sub modulescheck
381422my $mstat = 0;
382423foreach my $module (glob (" *" ))
383424{
384- subdircheck(" $topdir /src/test/modules " , $module );
425+ subdircheck($module );
385426my $status =$? >> 8;
386427$mstat ||=$status ;
387428}