1ifeq ($(python_majorversion),3)
2# Adjust regression tests for Python 3 compatibility
3#
4# Mention those regression test files that need to be mangled in the
5# variable REGRESS_PLPYTHON3_MANGLE.  They will be copied to a
6# subdirectory python3/ and have their Python syntax and other bits
7# adjusted to work with Python 3.
8
9# Note that the order of the tests needs to be preserved in this
10# expression.
11REGRESS := $(foreach test,$(REGRESS),$(if $(filter $(test),$(REGRESS_PLPYTHON3_MANGLE)),python3/$(test),$(test)))
12
13.PHONY: pgregress-python3-mangle
14pgregress-python3-mangle:
15	$(MKDIR_P) sql/python3 expected/python3 results/python3
16	for file in $(patsubst %,$(srcdir)/sql/%.sql,$(REGRESS_PLPYTHON3_MANGLE)) $(patsubst %,$(srcdir)/expected/%*.out,$(REGRESS_PLPYTHON3_MANGLE)); do \
17	  sed -e 's/except \([[:alpha:]][[:alpha:].]*\), *\([[:alpha:]][[:alpha:]]*\):/except \1 as \2:/g' \
18	      -e "s/<type 'exceptions\.\([[:alpha:]]*\)'>/<class '\1'>/g" \
19	      -e "s/<type 'long'>/<class 'int'>/g" \
20	      -e "s/\([0-9][0-9]*\)L/\1/g" \
21	      -e 's/\([ [{]\)u"/\1"/g' \
22	      -e "s/\([ [{]\)u'/\1'/g" \
23	      -e "s/def next/def __next__/g" \
24	      -e "s/LANGUAGE plpythonu/LANGUAGE plpython3u/g" \
25	      -e "s/LANGUAGE plpython2u/LANGUAGE plpython3u/g" \
26	      -e "s/EXTENSION plpythonu/EXTENSION plpython3u/g" \
27	      -e "s/EXTENSION plpython2u/EXTENSION plpython3u/g" \
28	      -e "s/EXTENSION \([^ ]*\)_plpythonu/EXTENSION \1_plpython3u/g" \
29	      -e "s/EXTENSION \([^ ]*\)_plpython2u/EXTENSION \1_plpython3u/g" \
30	      -e 's/installing required extension "plpython2u"/installing required extension "plpython3u"/g' \
31	    $$file >`echo $$file | sed 's,^.*/\([^/][^/]*/\)\([^/][^/]*\)$$,\1python3/\2,'` || exit; \
32	done
33
34check installcheck: pgregress-python3-mangle
35
36pg_regress_clean_files += sql/python3/ expected/python3/ results/python3/
37
38endif # Python 3
39