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