theory/pgtap

pg_prove: using --ext makes tests fail

K-Kielak opened this issue · 3 comments

I have a test called tests/unit/index.sql with the following code:

BEGIN;
SELECT plan(1);

SELECT pass("hello");

SELECT * FROM finish();
ROLLBACK;

When I run pg_prove -U postgres -h localhost -d try tests/unit/*.sql I get:

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

But when I run pg_prove -U postgres -h localhost -d try --ext sql tests/unit/ I get:

tests/unit/index.sql .. Can't locate object method "SELECT" via package "plan" (perhaps you forgot to load "plan"?) at tests/unit/index.sql line 2.
tests/unit/index.sql .. Dubious, test returned 255 (wstat 65280, 0xff00)
No subtests run 

Test Summary Report
-------------------
tests/unit/index.sql (Wstat: 65280 Tests: 0 Failed: 0)
  Non-zero exit status: 255
  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

Why is the --ext sql option important even though just *.sql works? Because --recurse option only allows --ext sql option to specify that sql files should be run from what I understood.

pgtap version: 1.2.0
pg_prove version: 3.35
postgres version: 13.6
OS: Ubuntu 20.04

Interestingly, it's literally --ext sql option that causes errors. If I rename the file to tests/unit/index.pg and run pg_prove -U postgres -h localhost -d try tests/unit/, it succeeds but pg_prove -U postgres -h localhost -d try --ext pg tests/unit/ fails.

Try --ext .sql --- with the dot.

🤦

ok, it is actually quite clear from the docs, it works, my bad, thanks @theory!