@@ -243,6 +243,51 @@ sub taptest
243243exit $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+
246291sub plcheck
247292{
248293chdir " ../../pl" ;
@@ -253,7 +298,8 @@ sub plcheck
253298my $lang =$pl eq ' tcl' ?' pltcl' :$pl ;
254299if ($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}
259305else
@@ -263,6 +309,8 @@ sub plcheck
263309my @lang_args = (" --load-extension=$lang " );
264310chdir $pl ;
265311my @tests = fetchTests();
312+ @tests = mangle_plpython3(\@tests )
313+ if $lang eq ' plpythonu' &&-d " $topdir /$Config /plpython3" ;
266314if ($lang eq ' plperl' )
267315{
268316
@@ -278,6 +326,10 @@ sub plcheck
278326push (@tests ,' plperl_plperlu' );
279327}
280328}
329+ elsif ($lang eq ' plpythonu' &&-d " $topdir /$Config /plpython3" )
330+ {
331+ @lang_args = ();
332+ }
281333print
282334" ============================================================\n " ;
283335print " Checking$lang \n " ;
@@ -296,7 +348,6 @@ sub plcheck
296348
297349sub subdircheck
298350{
299- my $subdir =shift ;
300351my $module =shift ;
301352
302353if ( !-d " $module /sql"
@@ -310,43 +361,35 @@ sub subdircheck
310361my @tests = fetchTests();
311362my @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{
319369die " Python not enabled in configuration"
320370if !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{
331376push @opts ," --load-extension=plpythonu" ;
332377push @opts ,' --load-extension=' .$module .' u' ;
333378}
334379else
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-
344386print " ============================================================\n " ;
345387print " Checking$module \n " ;
346388my @args = (
347389" $topdir /$Config /pg_regress/pg_regress" ,
348390" --bindir=${topdir} /${Config} /psql" ,
349391" --dbname=contrib_regression" ,@opts ,@tests );
392+ print join (' ' ,@args )," \n " ;
350393system (@args );
351394chdir " .." ;
352395}
@@ -357,17 +400,15 @@ sub contribcheck
357400my $mstat = 0;
358401foreach my $module (glob (" *" ))
359402{
360-
361403# these configuration-based exclusions must match Install.pm
362404next if ($module eq " uuid-ossp" && !defined ($config -> {uuid }));
363405next if ($module eq " sslinfo" && !defined ($config -> {openssl }));
364406next 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 }));
368409next if ($module eq " sepgsql" );
369410
370- subdircheck(" $topdir /contrib " , $module );
411+ subdircheck($module );
371412my $status =$? >> 8;
372413$mstat ||=$status ;
373414}
@@ -380,7 +421,7 @@ sub modulescheck
380421my $mstat = 0;
381422foreach my $module (glob (" *" ))
382423{
383- subdircheck(" $topdir /src/test/modules " , $module );
424+ subdircheck($module );
384425my $status =$? >> 8;
385426$mstat ||=$status ;
386427}