tests with do-end blocks

49 views
Skip to first unread message

Yauheni Tsiarokhin

unread,
Oct 26, 2021, 9:53:01 AM10/26/21
to pgTAP Users
Hi all. I am new with pgTAP and i just can't get why it works this way.

So this test works fine
begin;
  select plan(1);
  select pass('ok');
  select * from finish();
rollback;

tests/sql/example2.sql .. ok   
All tests successful.
Files=1, Tests=1,  0 wallclock secs ( 0.01 usr +  0.00 sys =  0.01 CPU)
Result: PASS

Meanwhile the following two fail like they just don't see what's inside the do-end block

begin;
do $$
begin
  perform plan(1);
  perform pass('ok');
  perform * from finish();
end; $$;
rollback;

tests/sql/example.sql .. No subtests run 
Test Summary Report
-------------------
tests/sql/example.sql (Wstat: 0 Tests: 0 Failed: 0)
  Parse errors: No plan found in TAP output
Files=1, Tests=0,  0 wallclock secs ( 0.01 usr +  0.00 sys =  0.01 CPU)
Result: FAIL

begin;
select plan(1);
do $$
begin
  perform pass('ok');
end; $$;
select * from finish();
rollback;

tests/sql/example3.sql .. Failed 1/1 subtests 
Test Summary Report
-------------------
tests/sql/example3.sql (Wstat: 0 Tests: 0 Failed: 0)
  Parse errors: Bad plan.  You planned 1 tests but ran 0.
Files=1, Tests=0,  0 wallclock secs ( 0.01 usr +  0.00 sys =  0.01 CPU)
Result: FAIL

P.S I want to use do-end block because it offers declare block
where i can do some initializations like id uuid := uuid_generate_v4()

David E. Wheeler

unread,
Oct 26, 2021, 9:46:55 PM10/26/21
to Yauheni Tsiarokhin, pgTAP Users
On Oct 26, 2021, at 09:53, Yauheni Tsiarokhin <hihih...@gmail.com> wrote:

> begin;
> do $$
> begin
> perform plan(1);
> perform pass('ok');
> perform * from finish();
> end; $$;
> rollback;
>
> tests/sql/example.sql .. No subtests run
> Test Summary Report
> -------------------
> tests/sql/example.sql (Wstat: 0 Tests: 0 Failed: 0)
> Parse errors: No plan found in TAP output
> Files=1, Tests=0, 0 wallclock secs ( 0.01 usr + 0.00 sys = 0.01 CPU)
> Result: FAIL

DO blocks don’t return records, so psql prints nothing for the test harness to parse and report on.

Best,

David
signature.asc
Reply all
Reply to author
Forward
0 new messages