pgtap icon indicating copy to clipboard operation
pgtap copied to clipboard

Function request: diag_query( :sql, :description )

Open floratmin opened this issue 5 years ago • 2 comments

Hello, i started to use tap and for my testing scenarios i need to pretty print queries before and after i run a function. But when i raise a notice it is not printed together with the test output, but before. I thought maybe this could be a valuable feature for using pgTap.

I was thinking about something like:

create function schema.pretty_print_sql() returns setof text as $$ begin return next diag_query('select a as "fieldA", b from tables where conditions', 'Explanation'); return next is(1, 1, 'test explanation); end; $$ language plpgsql;

and with runtests('schema'::name);

should yield something like

          runtests
----------------------------
# |-----------------------|
# | Explanation           |
# |-----------------------|
# | fieldA | b            |
# |=======================|
# | 1      | someText     |
# | 2      | someMoreText |
# |=======================|
ok 1 - test explanation
1..1

ok 1 - schema.pretty_print_sql 1..1

Best Florian

floratmin avatar Nov 26 '19 07:11 floratmin

Looks nice, but the simple case always will. What about very long or complicated queries? How would one go about formatting them?

theory avatar Dec 06 '19 01:12 theory

Up to now I have only few columns per test case which are affected by the tests and displayed as before/after. I use it already with raise notice and one small function. But the test cases and the test results are not at the same place.

floratmin avatar Dec 11 '19 15:12 floratmin