Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Function request: diag_query( :sql, :description ) #228

Open
floratmin opened this issue Nov 26, 2019 · 2 comments
Open

Function request: diag_query( :sql, :description ) #228

floratmin opened this issue Nov 26, 2019 · 2 comments

Comments

@floratmin
Copy link

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

@theory
Copy link
Owner

theory commented Dec 6, 2019

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

@floratmin
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants