Skip to content

Switch plan(int) to plan(bigint) #348

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ Revision history for pgTAP
to Jim Nasby for reporting the issue (#234) Rodolphe Quiédeville for for the
pull request (#339).
* Added `index_is_partial()`, thanks to Rodolphe Quiédeville (#342).
* Change plan() to accept bigint. While only an insane person would need more
than 2^31 tests, the bigint version makes calling plan with the count(*) of
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't it just as easy to use plan(COUNT(*)::int)?

rows in a table of tests easier.

1.3.3 2024-04-08T13:44:11Z
--------------------------
Expand Down
40 changes: 40 additions & 0 deletions sql/pgtap--1.3.3--1.3.4.sql
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,43 @@ BEGIN
);
END;
$$ LANGUAGE plpgsql;

DROP FUNCTION plan( integer );
CREATE OR REPLACE FUNCTION plan( bigint )
RETURNS TEXT AS $$
DECLARE
rcount INTEGER;
BEGIN
BEGIN
EXECUTE '
CREATE TEMP SEQUENCE __tcache___id_seq;
CREATE TEMP TABLE __tcache__ (
id INTEGER NOT NULL DEFAULT nextval(''__tcache___id_seq''),
label TEXT NOT NULL,
value INTEGER NOT NULL,
note TEXT NOT NULL DEFAULT ''''
);
CREATE UNIQUE INDEX __tcache___key ON __tcache__(id);
GRANT ALL ON TABLE __tcache__ TO PUBLIC;
GRANT ALL ON TABLE __tcache___id_seq TO PUBLIC;

CREATE TEMP SEQUENCE __tresults___numb_seq;
GRANT ALL ON TABLE __tresults___numb_seq TO PUBLIC;
';

EXCEPTION WHEN duplicate_table THEN
-- Raise an exception if there's already a plan.
EXECUTE 'SELECT TRUE FROM __tcache__ WHERE label = ''plan''';
GET DIAGNOSTICS rcount = ROW_COUNT;
IF rcount > 0 THEN
RAISE EXCEPTION 'You tried to plan twice!';
END IF;
END;

-- Save the plan and return.
PERFORM _set('plan', $1::int );
PERFORM _set('failed', 0 );
RETURN '1..' || $1;
END;
$$ LANGUAGE plpgsql strict;

4 changes: 2 additions & 2 deletions sql/pgtap.sql.in
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ CREATE OR REPLACE FUNCTION pgtap_version()
RETURNS NUMERIC AS 'SELECT __VERSION__;'
LANGUAGE SQL IMMUTABLE;

CREATE OR REPLACE FUNCTION plan( integer )
CREATE OR REPLACE FUNCTION plan( bigint )
RETURNS TEXT AS $$
DECLARE
rcount INTEGER;
Expand Down Expand Up @@ -54,7 +54,7 @@ BEGIN
END;

-- Save the plan and return.
PERFORM _set('plan', $1 );
PERFORM _set('plan', $1::int );
PERFORM _set('failed', 0 );
RETURN '1..' || $1;
END;
Expand Down