@@ -242,6 +242,51 @@ sub taptest
242
242
exit $status if $status ;
243
243
}
244
244
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
+
245
290
sub plcheck
246
291
{
247
292
chdir " ../../pl" ;
@@ -252,7 +297,8 @@ sub plcheck
252
297
my $lang = $pl eq ' tcl' ? ' pltcl' : $pl ;
253
298
if ($lang eq ' plpython' )
254
299
{
255
- next unless -d " ../../$Config /plpython2" ;
300
+ next unless -d " $topdir /$Config /plpython2" ||
301
+ -d " $topdir /$Config /plpython3" ;
256
302
$lang = ' plpythonu' ;
257
303
}
258
304 else
@@ -262,6 +308,8 @@ sub plcheck
262
308
my @lang_args = (" --load-extension=$lang " );
263
309
chdir $pl ;
264
310
my @tests = fetchTests();
311
+ @tests = mangle_plpython3(\@tests )
312
+ if $lang eq ' plpythonu' && -d " $topdir /$Config /plpython3" ;
265
313
if ($lang eq ' plperl' )
266
314
{
267
315
@@ -277,6 +325,10 @@ sub plcheck
277
325
push (@tests , ' plperl_plperlu' );
278
326
}
279
327
}
328
+ elsif ($lang eq ' plpythonu' && -d " $topdir /$Config /plpython3" )
329
+ {
330
+ @lang_args = ();
331
+ }
280
332
print
281
333
" ============================================================\n " ;
282
334
print " Checking $lang \n " ;
@@ -295,7 +347,6 @@ sub plcheck
295
347
296
348
sub subdircheck
297
349
{
298
- my $subdir = shift ;
299
350
my $module = shift ;
300
351
301
352
if ( !-d " $module /sql"
@@ -309,43 +360,35 @@ sub subdircheck
309
360
my @tests = fetchTests();
310
361
my @opts = fetchRegressOpts();
311
362
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
314
365
# dependencies.
315
- if ( $module eq " hstore_plpython"
316
- || $module eq " ltree_plpython" )
366
+ if ( $module =~ / _plpython$ / )
317
367
{
318
368
die " Python not enabled in configuration"
319
369
if !defined ($config -> {python });
320
370
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" )
329
374
{
330
375
push @opts , " --load-extension=plpythonu" ;
331
376
push @opts , ' --load-extension=' . $module . ' u' ;
332
377
}
333
378
else
334
379
{
335
-
336
- # disable tests on python3 for now.
337
- chdir " .." ;
338
- return ;
380
+ # must be python 3
381
+ @tests = mangle_plpython3(\@tests );
339
382
}
340
383
}
341
384
342
-
343
385
print " ============================================================\n " ;
344
386
print " Checking $module \n " ;
345
387
my @args = (
346
388
" $topdir /$Config /pg_regress/pg_regress" ,
347
389
" --bindir=${topdir} /${Config} /psql" ,
348
390
" --dbname=contrib_regression" , @opts , @tests );
391
+ print join (' ' ,@args )," \n " ;
349
392
system (@args );
350
393
chdir " .." ;
351
394
}
@@ -360,12 +403,11 @@ sub contribcheck
360
403
next if ($module eq " uuid-ossp" && !defined ($config -> {uuid }));
361
404
next if ($module eq " sslinfo" && !defined ($config -> {openssl }));
362
405
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 }));
366
408
next if ($module eq " sepgsql" );
367
409
368
- subdircheck(" $topdir /contrib " , $module );
410
+ subdircheck($module );
369
411
my $status = $? >> 8;
370
412
$mstat ||= $status ;
371
413
}
@@ -378,7 +420,7 @@ sub modulescheck
378
420
my $mstat = 0;
379
421
foreach my $module (glob (" *" ))
380
422
{
381
- subdircheck(" $topdir /src/test/modules " , $module );
423
+ subdircheck($module );
382
424
my $status = $? >> 8;
383
425
$mstat ||= $status ;
384
426
}
0 commit comments