Skip to content

Commit 2e4be23

Browse files
rodotheory
authored andcommitted
Added name, name composite assertion functions
Add `has_composite(name, name)` and `hasnt_composite(name, name)`, which allow users to test composites without having to write descriptions. Resolves #234.
1 parent 224f5b3 commit 2e4be23

9 files changed

+905
-833
lines changed

Changes

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ Revision history for pgTAP
77
* Fixed the upgrade from v1.2.0 to v1.3.0. Thanks to @runqitian for the pull
88
request (#338).
99

10+
* Added `name, name` variants for `has_composite` and `hasnt_composite` Thanks
11+
to Jim Nasby for reporting the issue (#234) Rodolphe Quiédeville for for the
12+
pull request (#339).
13+
1014
1.3.3 2024-04-08T13:44:11Z
1115
--------------------------
1216

@@ -278,7 +282,7 @@ Revision history for pgTAP
278282
Quiédeville (PR #106).
279283
* Add `has_extension()` and `hasnt_extension()`. Thanks to Rodolphe Quiédeville
280284
(PR #101).
281-
285+
282286
0.96.0 2016-05-16T20:53:57Z
283287
---------------------------
284288
* Added an optional `:exclude_pattern` parameter to `findfuncs()` to prevent

compat/install-9.1.patch

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
RETURN ok( FALSE, descr ) || E'\n' || diag(
1212
' died: ' || _error_diag(SQLSTATE, SQLERRM, detail, hint, context, schname, tabname, colname, chkname, typname)
1313
);
14-
@@ -6698,10 +6694,6 @@
14+
@@ -6732,10 +6728,6 @@
1515
-- Something went wrong. Record that fact.
1616
errstate := SQLSTATE;
1717
errmsg := SQLERRM;
@@ -22,15 +22,15 @@
2222
END;
2323

2424
-- Always raise an exception to rollback any changes.
25-
@@ -7169,7 +7161,6 @@
25+
@@ -7203,7 +7195,6 @@
2626
RETURN ok( true, $3 );
2727
EXCEPTION
2828
WHEN datatype_mismatch THEN
2929
- GET STACKED DIAGNOSTICS err_msg = MESSAGE_TEXT;
3030
RETURN ok( false, $3 ) || E'\n' || diag(
3131
E' Number of columns or their types differ between the queries' ||
3232
CASE WHEN have_rec::TEXT = want_rec::text THEN '' ELSE E':\n' ||
33-
@@ -7323,7 +7314,6 @@
33+
@@ -7357,7 +7348,6 @@
3434
RETURN ok( false, $3 );
3535
EXCEPTION
3636
WHEN datatype_mismatch THEN

compat/install-9.2.patch

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
RETURN ok( FALSE, descr ) || E'\n' || diag(
1515
' died: ' || _error_diag(SQLSTATE, SQLERRM, detail, hint, context, schname, tabname, colname, chkname, typname)
1616
);
17-
@@ -6706,12 +6701,7 @@
17+
@@ -6740,12 +6735,7 @@
1818
GET STACKED DIAGNOSTICS
1919
detail = PG_EXCEPTION_DETAIL,
2020
hint = PG_EXCEPTION_HINT,

compat/install-9.4.patch

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
-- There should have been no exception.
1919
GET STACKED DIAGNOSTICS
2020
detail = PG_EXCEPTION_DETAIL,
21-
@@ -10250,233 +10250,6 @@
21+
@@ -10284,233 +10284,6 @@
2222
), $2);
2323
$$ LANGUAGE SQL immutable;
2424

compat/install-9.6.patch

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
--- sql/pgtap.sql
22
+++ sql/pgtap.sql
3-
@@ -10232,136 +10232,6 @@
3+
@@ -10266,136 +10266,6 @@
44
);
55
$$ LANGUAGE sql;
66

sql/pgtap--1.3.3--1.3.4.sql

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,17 @@
1-
-- TBD
1+
-- has_composite( schema, type )
2+
CREATE OR REPLACE FUNCTION has_composite ( NAME, NAME )
3+
RETURNS TEXT AS $$
4+
SELECT has_composite(
5+
$1, $2,
6+
'Composite type ' || quote_ident($1) || '.' || quote_ident($2) || ' should exist'
7+
);
8+
$$ LANGUAGE SQL;
9+
10+
-- hasnt_composite( schema, type )
11+
CREATE OR REPLACE FUNCTION hasnt_composite ( NAME, NAME )
12+
RETURNS TEXT AS $$
13+
SELECT hasnt_composite(
14+
$1, $2,
15+
'Composite type ' || quote_ident($1) || '.' || quote_ident($2) || ' should not exist'
16+
);
17+
$$ LANGUAGE SQL;

sql/pgtap.sql.in

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1223,6 +1223,14 @@ RETURNS TEXT AS $$
12231223
SELECT ok( _rexists( 'c', $1, $2 ), $3 );
12241224
$$ LANGUAGE SQL;
12251225

1226+
-- has_composite( schema, type )
1227+
CREATE OR REPLACE FUNCTION has_composite ( NAME, NAME )
1228+
RETURNS TEXT AS $$
1229+
SELECT has_composite($1, $2,
1230+
'Composite type ' || quote_ident($1) || '.' || quote_ident($2) || ' should exist'
1231+
);
1232+
$$ LANGUAGE SQL;
1233+
12261234
-- has_composite( type, description )
12271235
CREATE OR REPLACE FUNCTION has_composite ( NAME, TEXT )
12281236
RETURNS TEXT AS $$
@@ -1241,6 +1249,15 @@ RETURNS TEXT AS $$
12411249
SELECT ok( NOT _rexists( 'c', $1, $2 ), $3 );
12421250
$$ LANGUAGE SQL;
12431251

1252+
-- hasnt_composite( schema, type )
1253+
CREATE OR REPLACE FUNCTION hasnt_composite ( NAME, NAME )
1254+
RETURNS TEXT AS $$
1255+
SELECT hasnt_composite(
1256+
$1, $2,
1257+
'Composite type ' || quote_ident($1) || '.' || quote_ident($2) || ' should not exist'
1258+
);
1259+
$$ LANGUAGE SQL;
1260+
12441261
-- hasnt_composite( type, description )
12451262
CREATE OR REPLACE FUNCTION hasnt_composite ( NAME, TEXT )
12461263
RETURNS TEXT AS $$

test/expected/hastap.out

Lines changed: 826 additions & 817 deletions
Large diffs are not rendered by default.

test/sql/hastap.sql

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
\i test/setup.sql
33
-- \i sql/pgtap.sql
44

5-
SELECT plan(1004);
5+
SELECT plan(1013);
66
--SELECT * FROM no_plan();
77

88
-- This will be rolled back. :-)
@@ -579,6 +579,23 @@ SELECT * FROM check_test(
579579
''
580580
);
581581

582+
SELECT * FROM check_test(
583+
has_composite( 'public'::name, '__SDFSDFD__'::name ),
584+
false,
585+
'has_composite(schema, type)',
586+
'Composite type public."__SDFSDFD__" should exist',
587+
''
588+
);
589+
590+
SELECT * FROM check_test(
591+
has_composite( 'public'::name, 'sometype'::name ),
592+
true,
593+
'has_composite(schema, type)',
594+
'Composite type public.sometype should exist',
595+
''
596+
);
597+
598+
582599
SELECT * FROM check_test(
583600
has_composite( 'public', 'sometype', 'desc' ),
584601
true,
@@ -638,6 +655,15 @@ SELECT * FROM check_test(
638655
''
639656
);
640657

658+
SELECT * FROM check_test(
659+
hasnt_composite( 'public'::name, '__SDFSDFD__'::name ),
660+
true,
661+
'hasnt_composite(schema, non-existent type',
662+
'Composite type public."__SDFSDFD__" should not exist',
663+
''
664+
);
665+
666+
641667
SELECT * FROM check_test(
642668
hasnt_composite( 'public', 'sometype', 'desc' ),
643669
false,
@@ -665,7 +691,7 @@ SELECT * FROM check_test(
665691
SELECT * FROM check_test(
666692
has_type( 'public'::name, 'sometype'::name ),
667693
true,
668-
'has_type(scheam, type)',
694+
'has_type(schema, type)',
669695
'Type public.sometype should exist',
670696
''
671697
);
@@ -2305,7 +2331,7 @@ SELECT * FROM check_test(
23052331
domain_type_is( 'public'::name, 'us_postal_code', 'text'),
23062332
true,
23072333
'domain_type_is(schema, domain, type)',
2308-
'Domain public.us_postal_code should extend type text',
2334+
'Domain public.us_postal_code should extend type text',
23092335
''
23102336
);
23112337

@@ -2346,7 +2372,7 @@ SELECT * FROM check_test(
23462372
domain_type_is( 'us_postal_code', 'text'),
23472373
true,
23482374
'domain_type_is(domain, type)',
2349-
'Domain us_postal_code should extend type text',
2375+
'Domain us_postal_code should extend type text',
23502376
''
23512377
);
23522378

@@ -2428,7 +2454,7 @@ SELECT * FROM check_test(
24282454
domain_type_isnt( 'public'::name, 'us_postal_code', 'int'),
24292455
true,
24302456
'domain_type_isnt(schema, domain, type)',
2431-
'Domain public.us_postal_code should not extend type int',
2457+
'Domain public.us_postal_code should not extend type int',
24322458
''
24332459
);
24342460

@@ -2469,7 +2495,7 @@ SELECT * FROM check_test(
24692495
domain_type_isnt( 'us_postal_code', 'int'),
24702496
true,
24712497
'domain_type_isnt(domain, type)',
2472-
'Domain us_postal_code should not extend type int',
2498+
'Domain us_postal_code should not extend type int',
24732499
''
24742500
);
24752501

@@ -2503,7 +2529,7 @@ SELECT * FROM check_test(
25032529
CREATE FUNCTION test_fdw() RETURNS SETOF TEXT AS $$
25042530
DECLARE
25052531
tap record;
2506-
BEGIN
2532+
BEGIN
25072533
IF pg_version_num() >= 90100 THEN
25082534
EXECUTE $E$
25092535
CREATE FOREIGN DATA WRAPPER dummy;
@@ -3272,7 +3298,7 @@ BEGIN
32723298
) AS b LOOP
32733299
RETURN NEXT tap.b;
32743300
END LOOP;
3275-
3301+
32763302
FOR tap IN SELECT * FROM check_test(
32773303
has_view( 'pg_tables' ),
32783304
true,

0 commit comments

Comments
 (0)