Refactor regression tests for more extensibility

Regression tests are still managed with scripts, except that now commands
are kicked by a psql client. This has the advantage to move output diff
evaluation outside the existing script and let pg_regress manage it.

Patch by Haishan Du, with some editorialization and tweaks by me.