From 0c610aa40d1f2a19c29812ee7f98011217dc2489 Mon Sep 17 00:00:00 2001 From: "David E. Wheeler" Date: Tue, 26 May 2009 22:25:08 -0700 Subject: [PATCH] Added `function_returns()`. * Added `function_returns()`. * Refactored all of the function-related tests to use a new view, `tap_funky`, to make them all quite a bit simpler. There was too much redundant code! * Added some notes for some other function-testing assertions to add. I've already added the necessary code to `tap_funky` to make them work. * Eliminated some extra spaces in the test descriptions in `sql/functap.sql`. --- Changes | 2 +- README.pgtap | 50 ++++++- expected/functap.out | 206 ++++++++++++++++++---------- pgtap.sql.in | 310 +++++++++++++++++++++++++++---------------- sql/functap.sql | 242 +++++++++++++++++++++++++++++---- 5 files changed, 603 insertions(+), 207 deletions(-) diff --git a/Changes b/Changes index 7cbe51318..831e1988b 100644 --- a/Changes +++ b/Changes @@ -23,7 +23,7 @@ Revision history for pgTAP `can_ok()` function is still available as an alias, but it emits a warning and will be removed in a future version of pgTAP. * Added `hasnt_trigger()`, `hasnt_index()`, and `hasnt_function()`. -* Added `function_lang_is()`. +* Added `function_lang_is()` and `function_returns()`. 0.20 2009-03-29T19:05:40 ------------------------- diff --git a/README.pgtap b/README.pgtap index 062b6ace0..357b04155 100644 --- a/README.pgtap +++ b/README.pgtap @@ -2344,6 +2344,51 @@ If the function does not exist, you'll be told that, too. But then you check with `has_function()` first, right? +### `function_returns( schema, function, args[], type, description )` ### +### `function_returns( schema, function, args[], type )` ### +### `function_returns( schema, function, type, description )` ### +### `function_returns( schema, function, type )` ### +### `function_returns( function, args[], type, description )` ### +### `function_returns( function, args[], type )` ### +### `function_returns( function, type, description )` ### +### `function_returns( function, type )` ### + + SELECT function_returns( + 'myschema', + 'foo', + ARRAY['integer', 'text'], + 'integer', + 'The myschema.foo() function should return an integer' + ); + + + SELECT function_returns( 'do_something', 'setof bool' ); + SELECT function_returns( 'do_something', ARRAY['integer'], 'bool' ); + SELECT function_returns( 'do_something', ARRAY['numeric'], 'numeric' ); + +Tests that a particular function returns a particular data type. For set +returning functions, the `:type` argument should start with "setof " (yes, +lowercase). If the `:schema` argument is omitted, then the function must be +visible in the search path. If the `:args[]` argument is passed, then the +function with that argument signature will be the one tested; otherwise, a +function with any signature will be checked (pass an empty array to specify a +function with an empty signature). If the `:description` is omitted, a +reasonable substitute will be created. + +In the event of a failure, you'll useful diagnostics will tell you what went +wrong, for example: + + # Failed test 283: "Function oww(integer, text) should return integer" + # have: bool + # want: integer + +If the function does not exist, you'll be told that, too. + + # Failed test 284: "Function oui(integer, text) should return integer" + # Function oui(integer, text) does not exist + +But then you check with `has_function()` first, right? + ### `enum_has_labels( schema, enum, labels, desc )` ### ### `enum_has_labels( schema, enum, labels )` ### ### `enum_has_labels( enum, labels, desc )` ### @@ -3122,7 +3167,10 @@ To Do ----- * Useful schema testing functions to consider adding: - * `function_returns()` + * `function_is_definer()` + * `function_is_agg()` + * `function_is_strict()` + * `function_is_volatile()` * `sequence_has_range()` * `sequence_increments_by()` * `sequence_starts_at()` diff --git a/expected/functap.out b/expected/functap.out index 0b1615cca..f8ffef01e 100644 --- a/expected/functap.out +++ b/expected/functap.out @@ -1,5 +1,5 @@ \unset ECHO -1..210 +1..282 ok 1 - simple function should pass ok 2 - simple function should have the proper description ok 3 - simple function should have the proper diagnostics @@ -144,69 +144,141 @@ ok 141 - can(schema) should have the proper diagnostics ok 142 - fail can() with desc should fail ok 143 - fail can() with desc should have the proper description ok 144 - fail can() with desc should have the proper diagnostics -ok 145 - function_lang_is(schema, func, 0 args, sql, desc ) should pass -ok 146 - function_lang_is(schema, func, 0 args, sql, desc ) should have the proper description -ok 147 - function_lang_is(schema, func, 0 args, sql, desc ) should have the proper diagnostics -ok 148 - function_lang_is(schema, func, 0 args, sql ) should pass -ok 149 - function_lang_is(schema, func, 0 args, sql ) should have the proper description -ok 150 - function_lang_is(schema, func, 0 args, sql ) should have the proper diagnostics -ok 151 - function_lang_is(schema, func, args, plpgsql, desc ) should pass -ok 152 - function_lang_is(schema, func, args, plpgsql, desc ) should have the proper description -ok 153 - function_lang_is(schema, func, args, plpgsql, desc ) should have the proper diagnostics -ok 154 - function_lang_is(schema, func, args, plpgsql ) should pass -ok 155 - function_lang_is(schema, func, args, plpgsql ) should have the proper description -ok 156 - function_lang_is(schema, func, args, plpgsql ) should have the proper diagnostics -ok 157 - function_lang_is(schema, func, 0 args, perl, desc ) should fail -ok 158 - function_lang_is(schema, func, 0 args, perl, desc ) should have the proper description -ok 159 - function_lang_is(schema, func, 0 args, perl, desc ) should have the proper diagnostics -ok 160 - function_lang_is(schema, non-func, 0 args, sql, desc ) should fail -ok 161 - function_lang_is(schema, non-func, 0 args, sql, desc ) should have the proper description -ok 162 - function_lang_is(schema, non-func, 0 args, sql, desc ) should have the proper diagnostics -ok 163 - function_lang_is(schema, func, args, plpgsql ) should fail -ok 164 - function_lang_is(schema, func, args, plpgsql ) should have the proper description -ok 165 - function_lang_is(schema, func, args, plpgsql ) should have the proper diagnostics -ok 166 - function_lang_is(schema, func, sql, desc ) should pass -ok 167 - function_lang_is(schema, func, sql, desc ) should have the proper description -ok 168 - function_lang_is(schema, func, sql, desc ) should have the proper diagnostics -ok 169 - function_lang_is(schema, func, sql ) should pass -ok 170 - function_lang_is(schema, func, sql ) should have the proper description -ok 171 - function_lang_is(schema, func, sql ) should have the proper diagnostics -ok 172 - function_lang_is(schema, func, perl, desc ) should fail -ok 173 - function_lang_is(schema, func, perl, desc ) should have the proper description -ok 174 - function_lang_is(schema, func, perl, desc ) should have the proper diagnostics -ok 175 - function_lang_is(schema, non-func, sql, desc ) should fail -ok 176 - function_lang_is(schema, non-func, sql, desc ) should have the proper description -ok 177 - function_lang_is(schema, non-func, sql, desc ) should have the proper diagnostics -ok 178 - function_lang_is(func, 0 args, sql, desc ) should pass -ok 179 - function_lang_is(func, 0 args, sql, desc ) should have the proper description -ok 180 - function_lang_is(func, 0 args, sql, desc ) should have the proper diagnostics -ok 181 - function_lang_is(func, 0 args, sql ) should pass -ok 182 - function_lang_is(func, 0 args, sql ) should have the proper description -ok 183 - function_lang_is(func, 0 args, sql ) should have the proper diagnostics -ok 184 - function_lang_is(func, args, plpgsql, desc ) should pass -ok 185 - function_lang_is(func, args, plpgsql, desc ) should have the proper description -ok 186 - function_lang_is(func, args, plpgsql, desc ) should have the proper diagnostics -ok 187 - function_lang_is(func, args, plpgsql ) should pass -ok 188 - function_lang_is(func, args, plpgsql ) should have the proper description -ok 189 - function_lang_is(func, args, plpgsql ) should have the proper diagnostics -ok 190 - function_lang_is(func, 0 args, perl, desc ) should fail -ok 191 - function_lang_is(func, 0 args, perl, desc ) should have the proper description -ok 192 - function_lang_is(func, 0 args, perl, desc ) should have the proper diagnostics -ok 193 - function_lang_is(non-func, 0 args, sql, desc ) should fail -ok 194 - function_lang_is(non-func, 0 args, sql, desc ) should have the proper description -ok 195 - function_lang_is(non-func, 0 args, sql, desc ) should have the proper diagnostics -ok 196 - function_lang_is(func, args, plpgsql ) should fail -ok 197 - function_lang_is(func, args, plpgsql ) should have the proper description -ok 198 - function_lang_is(func, args, plpgsql ) should have the proper diagnostics -ok 199 - function_lang_is(func, sql, desc ) should pass -ok 200 - function_lang_is(func, sql, desc ) should have the proper description -ok 201 - function_lang_is(func, sql, desc ) should have the proper diagnostics -ok 202 - function_lang_is(func, sql ) should pass -ok 203 - function_lang_is(func, sql ) should have the proper description -ok 204 - function_lang_is(func, sql ) should have the proper diagnostics -ok 205 - function_lang_is(func, perl, desc ) should fail -ok 206 - function_lang_is(func, perl, desc ) should have the proper description -ok 207 - function_lang_is(func, perl, desc ) should have the proper diagnostics -ok 208 - function_lang_is(non-func, sql, desc ) should fail -ok 209 - function_lang_is(non-func, sql, desc ) should have the proper description -ok 210 - function_lang_is(non-func, sql, desc ) should have the proper diagnostics +ok 145 - function_lang_is(schema, func, 0 args, sql, desc) should pass +ok 146 - function_lang_is(schema, func, 0 args, sql, desc) should have the proper description +ok 147 - function_lang_is(schema, func, 0 args, sql, desc) should have the proper diagnostics +ok 148 - function_lang_is(schema, func, 0 args, sql) should pass +ok 149 - function_lang_is(schema, func, 0 args, sql) should have the proper description +ok 150 - function_lang_is(schema, func, 0 args, sql) should have the proper diagnostics +ok 151 - function_lang_is(schema, func, args, plpgsql, desc) should pass +ok 152 - function_lang_is(schema, func, args, plpgsql, desc) should have the proper description +ok 153 - function_lang_is(schema, func, args, plpgsql, desc) should have the proper diagnostics +ok 154 - function_lang_is(schema, func, args, plpgsql) should pass +ok 155 - function_lang_is(schema, func, args, plpgsql) should have the proper description +ok 156 - function_lang_is(schema, func, args, plpgsql) should have the proper diagnostics +ok 157 - function_lang_is(schema, func, 0 args, perl, desc) should fail +ok 158 - function_lang_is(schema, func, 0 args, perl, desc) should have the proper description +ok 159 - function_lang_is(schema, func, 0 args, perl, desc) should have the proper diagnostics +ok 160 - function_lang_is(schema, non-func, 0 args, sql, desc) should fail +ok 161 - function_lang_is(schema, non-func, 0 args, sql, desc) should have the proper description +ok 162 - function_lang_is(schema, non-func, 0 args, sql, desc) should have the proper diagnostics +ok 163 - function_lang_is(schema, func, args, plpgsql) should fail +ok 164 - function_lang_is(schema, func, args, plpgsql) should have the proper description +ok 165 - function_lang_is(schema, func, args, plpgsql) should have the proper diagnostics +ok 166 - function_lang_is(schema, func, sql, desc) should pass +ok 167 - function_lang_is(schema, func, sql, desc) should have the proper description +ok 168 - function_lang_is(schema, func, sql, desc) should have the proper diagnostics +ok 169 - function_lang_is(schema, func, sql) should pass +ok 170 - function_lang_is(schema, func, sql) should have the proper description +ok 171 - function_lang_is(schema, func, sql) should have the proper diagnostics +ok 172 - function_lang_is(schema, func, perl, desc) should fail +ok 173 - function_lang_is(schema, func, perl, desc) should have the proper description +ok 174 - function_lang_is(schema, func, perl, desc) should have the proper diagnostics +ok 175 - function_lang_is(schema, non-func, sql, desc) should fail +ok 176 - function_lang_is(schema, non-func, sql, desc) should have the proper description +ok 177 - function_lang_is(schema, non-func, sql, desc) should have the proper diagnostics +ok 178 - function_lang_is(func, 0 args, sql, desc) should pass +ok 179 - function_lang_is(func, 0 args, sql, desc) should have the proper description +ok 180 - function_lang_is(func, 0 args, sql, desc) should have the proper diagnostics +ok 181 - function_lang_is(func, 0 args, sql) should pass +ok 182 - function_lang_is(func, 0 args, sql) should have the proper description +ok 183 - function_lang_is(func, 0 args, sql) should have the proper diagnostics +ok 184 - function_lang_is(func, args, plpgsql, desc) should pass +ok 185 - function_lang_is(func, args, plpgsql, desc) should have the proper description +ok 186 - function_lang_is(func, args, plpgsql, desc) should have the proper diagnostics +ok 187 - function_lang_is(func, args, plpgsql) should pass +ok 188 - function_lang_is(func, args, plpgsql) should have the proper description +ok 189 - function_lang_is(func, args, plpgsql) should have the proper diagnostics +ok 190 - function_lang_is(func, 0 args, perl, desc) should fail +ok 191 - function_lang_is(func, 0 args, perl, desc) should have the proper description +ok 192 - function_lang_is(func, 0 args, perl, desc) should have the proper diagnostics +ok 193 - function_lang_is(non-func, 0 args, sql, desc) should fail +ok 194 - function_lang_is(non-func, 0 args, sql, desc) should have the proper description +ok 195 - function_lang_is(non-func, 0 args, sql, desc) should have the proper diagnostics +ok 196 - function_lang_is(func, args, plpgsql) should fail +ok 197 - function_lang_is(func, args, plpgsql) should have the proper description +ok 198 - function_lang_is(func, args, plpgsql) should have the proper diagnostics +ok 199 - function_lang_is(func, sql, desc) should pass +ok 200 - function_lang_is(func, sql, desc) should have the proper description +ok 201 - function_lang_is(func, sql, desc) should have the proper diagnostics +ok 202 - function_lang_is(func, sql) should pass +ok 203 - function_lang_is(func, sql) should have the proper description +ok 204 - function_lang_is(func, sql) should have the proper diagnostics +ok 205 - function_lang_is(func, perl, desc) should fail +ok 206 - function_lang_is(func, perl, desc) should have the proper description +ok 207 - function_lang_is(func, perl, desc) should have the proper diagnostics +ok 208 - function_lang_is(non-func, sql, desc) should fail +ok 209 - function_lang_is(non-func, sql, desc) should have the proper description +ok 210 - function_lang_is(non-func, sql, desc) should have the proper diagnostics +ok 211 - function_returns(schema, func, 0 args, bool, desc) should pass +ok 212 - function_returns(schema, func, 0 args, bool, desc) should have the proper description +ok 213 - function_returns(schema, func, 0 args, bool, desc) should have the proper diagnostics +ok 214 - function_returns(schema, func, 0 args, bool) should pass +ok 215 - function_returns(schema, func, 0 args, bool) should have the proper description +ok 216 - function_returns(schema, func, 0 args, bool) should have the proper diagnostics +ok 217 - function_returns(schema, func, args, bool, false) should pass +ok 218 - function_returns(schema, func, args, bool, false) should have the proper description +ok 219 - function_returns(schema, func, args, bool, false) should have the proper diagnostics +ok 220 - function_returns(schema, func, args, bool) should pass +ok 221 - function_returns(schema, func, args, bool) should have the proper description +ok 222 - function_returns(schema, func, args, bool) should have the proper diagnostics +ok 223 - function_returns(schema, func, 0 args, setof bool, desc) should pass +ok 224 - function_returns(schema, func, 0 args, setof bool, desc) should have the proper description +ok 225 - function_returns(schema, func, 0 args, setof bool, desc) should have the proper diagnostics +ok 226 - function_returns(schema, func, 0 args, setof bool) should pass +ok 227 - function_returns(schema, func, 0 args, setof bool) should have the proper description +ok 228 - function_returns(schema, func, 0 args, setof bool) should have the proper diagnostics +ok 229 - function_returns(schema, func, bool, desc) should pass +ok 230 - function_returns(schema, func, bool, desc) should have the proper description +ok 231 - function_returns(schema, func, bool, desc) should have the proper diagnostics +ok 232 - function_returns(schema, func, bool) should pass +ok 233 - function_returns(schema, func, bool) should have the proper description +ok 234 - function_returns(schema, func, bool) should have the proper diagnostics +ok 235 - function_returns(schema, other func, bool, false) should pass +ok 236 - function_returns(schema, other func, bool, false) should have the proper description +ok 237 - function_returns(schema, other func, bool, false) should have the proper diagnostics +ok 238 - function_returns(schema, other func, bool) should pass +ok 239 - function_returns(schema, other func, bool) should have the proper description +ok 240 - function_returns(schema, other func, bool) should have the proper diagnostics +ok 241 - function_returns(schema, func, setof bool, desc) should pass +ok 242 - function_returns(schema, func, setof bool, desc) should have the proper description +ok 243 - function_returns(schema, func, setof bool, desc) should have the proper diagnostics +ok 244 - function_returns(schema, func, setof bool) should pass +ok 245 - function_returns(schema, func, setof bool) should have the proper description +ok 246 - function_returns(schema, func, setof bool) should have the proper diagnostics +ok 247 - function_returns(func, 0 args, bool, desc) should pass +ok 248 - function_returns(func, 0 args, bool, desc) should have the proper description +ok 249 - function_returns(func, 0 args, bool, desc) should have the proper diagnostics +ok 250 - function_returns(func, 0 args, bool) should pass +ok 251 - function_returns(func, 0 args, bool) should have the proper description +ok 252 - function_returns(func, 0 args, bool) should have the proper diagnostics +ok 253 - function_returns(func, args, bool, false) should pass +ok 254 - function_returns(func, args, bool, false) should have the proper description +ok 255 - function_returns(func, args, bool, false) should have the proper diagnostics +ok 256 - function_returns(func, args, bool) should pass +ok 257 - function_returns(func, args, bool) should have the proper description +ok 258 - function_returns(func, args, bool) should have the proper diagnostics +ok 259 - function_returns(func, 0 args, setof bool, desc) should pass +ok 260 - function_returns(func, 0 args, setof bool, desc) should have the proper description +ok 261 - function_returns(func, 0 args, setof bool, desc) should have the proper diagnostics +ok 262 - function_returns(func, 0 args, setof bool) should pass +ok 263 - function_returns(func, 0 args, setof bool) should have the proper description +ok 264 - function_returns(func, 0 args, setof bool) should have the proper diagnostics +ok 265 - function_returns(func, bool, desc) should pass +ok 266 - function_returns(func, bool, desc) should have the proper description +ok 267 - function_returns(func, bool, desc) should have the proper diagnostics +ok 268 - function_returns(func, bool) should pass +ok 269 - function_returns(func, bool) should have the proper description +ok 270 - function_returns(func, bool) should have the proper diagnostics +ok 271 - function_returns(other func, bool, false) should pass +ok 272 - function_returns(other func, bool, false) should have the proper description +ok 273 - function_returns(other func, bool, false) should have the proper diagnostics +ok 274 - function_returns(other func, bool) should pass +ok 275 - function_returns(other func, bool) should have the proper description +ok 276 - function_returns(other func, bool) should have the proper diagnostics +ok 277 - function_returns(func, setof bool, desc) should pass +ok 278 - function_returns(func, setof bool, desc) should have the proper description +ok 279 - function_returns(func, setof bool, desc) should have the proper diagnostics +ok 280 - function_returns(func, setof bool) should pass +ok 281 - function_returns(func, setof bool) should have the proper description +ok 282 - function_returns(func, setof bool) should have the proper diagnostics diff --git a/pgtap.sql.in b/pgtap.sql.in index f504806d6..ce1b1d278 100644 --- a/pgtap.sql.in +++ b/pgtap.sql.in @@ -2011,48 +2011,54 @@ RETURNS TEXT AS $$ SELECT fk_ok( $1, ARRAY[$2], $3, ARRAY[$4] ); $$ LANGUAGE sql; +CREATE OR REPLACE VIEW tap_funky AS + SELECT p.oid AS oid, + n.nspname AS schema, + p.proname AS name, + array_to_string(p.proargtypes::regtype[], ',') AS args, + CASE p.proretset WHEN TRUE THEN 'setof ' ELSE '' END || t.typname AS returns, + p.prolang AS langoid, + p.proisstrict AS is_strict, + p.proisagg AS is_agg, + p.prosecdef AS is_definer, + p.proretset AS returns_set, + p.provolatile AS is_volatile, + pg_catalog.pg_function_is_visible(p.oid) AS is_visible + FROM pg_catalog.pg_proc p + JOIN pg_catalog.pg_namespace n ON p.pronamespace = n.oid + JOIN pg_catalog.pg_type t ON p.prorettype = t.oid +; + CREATE OR REPLACE FUNCTION _got_func ( NAME, NAME, NAME[] ) RETURNS BOOLEAN AS $$ - SELECT EXISTS( - SELECT TRUE - FROM pg_catalog.pg_proc p - JOIN pg_catalog.pg_namespace n ON p.pronamespace = n.oid - WHERE n.nspname = $1 - AND p.proname = $2 - AND array_to_string(p.proargtypes::regtype[], ',') = array_to_string($3, ',') - ); + SELECT EXISTS( + SELECT TRUE + FROM tap_funky + WHERE schema = $1 + AND name = $2 + AND args = array_to_string($3, ',') + ); $$ LANGUAGE SQL; CREATE OR REPLACE FUNCTION _got_func ( NAME, NAME ) RETURNS BOOLEAN AS $$ - SELECT EXISTS( - SELECT TRUE - FROM pg_catalog.pg_proc p - JOIN pg_catalog.pg_namespace n ON p.pronamespace = n.oid - WHERE n.nspname = $1 - AND p.proname = $2 - ); + SELECT EXISTS( SELECT TRUE FROM tap_funky WHERE schema = $1 AND name = $2 ); $$ LANGUAGE SQL; CREATE OR REPLACE FUNCTION _got_func ( NAME, NAME[] ) RETURNS BOOLEAN AS $$ - SELECT EXISTS( - SELECT TRUE - FROM pg_catalog.pg_proc p - WHERE p.proname = $1 - AND pg_catalog.pg_function_is_visible(p.oid) - AND array_to_string(p.proargtypes::regtype[], ',') = array_to_string($2, ',') - ); + SELECT EXISTS( + SELECT TRUE + FROM tap_funky + WHERE name = $1 + AND args = array_to_string($2, ',') + AND is_visible + ); $$ LANGUAGE SQL; CREATE OR REPLACE FUNCTION _got_func ( NAME ) RETURNS BOOLEAN AS $$ - SELECT EXISTS( - SELECT TRUE - FROM pg_catalog.pg_proc p - WHERE p.proname = $1 - AND pg_catalog.pg_function_is_visible(p.oid) - ); + SELECT EXISTS( SELECT TRUE FROM tap_funky WHERE name = $1 AND is_visible); $$ LANGUAGE SQL; -- has_function( schema, function, args[], description ) @@ -2256,14 +2262,8 @@ BEGIN SELECT ARRAY( SELECT quote_ident($2[i]) FROM generate_series(1, array_upper($2, 1)) s(i) - LEFT JOIN pg_catalog.pg_proc p - ON p.proname = $2[i] - AND p.pronamespace = ( - SELECT oid - FROM pg_catalog.pg_namespace - WHERE nspname = $1 - ) - WHERE p.oid IS NULL + LEFT JOIN tap_funky ON name = $2[i] AND schema = $1 + WHERE oid IS NULL GROUP BY $2[i], s.i ORDER BY MIN(s.i) ) INTO missing; @@ -4014,7 +4014,7 @@ RETURNS NAME[] AS $$ JOIN pg_catalog.pg_class c ON n.oid = c.relnamespace WHERE c.relkind = $1 AND n.nspname = $2 - AND c.relname <> 'pg_all_foreign_keys' + AND c.relname NOT IN('pg_all_foreign_keys', 'tap_funky') EXCEPT SELECT $3[i] FROM generate_series(1, array_upper($3, 1)) s(i) @@ -4030,7 +4030,7 @@ RETURNS NAME[] AS $$ WHERE pg_catalog.pg_table_is_visible(c.oid) AND n.nspname <> 'pg_catalog' AND c.relkind = $1 - AND c.relname NOT IN ('__tcache__', '__tresults__', 'pg_all_foreign_keys', '__tresults___numb_seq', '__tcache___id_seq') + AND c.relname NOT IN ('__tcache__', '__tresults__', 'pg_all_foreign_keys', 'tap_funky', '__tresults___numb_seq', '__tcache___id_seq') EXCEPT SELECT $2[i] FROM generate_series(1, array_upper($2, 1)) s(i) @@ -4162,10 +4162,7 @@ RETURNS TEXT AS $$ SELECT _are( 'functions', ARRAY( - SELECT p.proname - FROM pg_catalog.pg_namespace n - JOIN pg_catalog.pg_proc p ON n.oid = p.pronamespace - WHERE n.nspname = $1 + SELECT name FROM tap_funky WHERE schema = $1 EXCEPT SELECT $2[i] FROM generate_series(1, array_upper($2, 1)) s(i) @@ -4174,10 +4171,7 @@ RETURNS TEXT AS $$ SELECT $2[i] FROM generate_series(1, array_upper($2, 1)) s(i) EXCEPT - SELECT p.proname - FROM pg_catalog.pg_namespace n - JOIN pg_catalog.pg_proc p ON n.oid = p.pronamespace - WHERE n.nspname = $1 + SELECT name FROM tap_funky WHERE schema = $1 ), $3 ); @@ -4195,11 +4189,7 @@ RETURNS TEXT AS $$ SELECT _are( 'functions', ARRAY( - SELECT p.proname - FROM pg_catalog.pg_namespace n - JOIN pg_catalog.pg_proc p ON n.oid = p.pronamespace - WHERE pg_catalog.pg_function_is_visible(p.oid) - AND n.nspname <> 'pg_catalog' + SELECT name FROM tap_funky WHERE is_visible AND schema <> 'pg_catalog' EXCEPT SELECT $1[i] FROM generate_series(1, array_upper($1, 1)) s(i) @@ -4208,11 +4198,7 @@ RETURNS TEXT AS $$ SELECT $1[i] FROM generate_series(1, array_upper($1, 1)) s(i) EXCEPT - SELECT p.proname - FROM pg_catalog.pg_namespace n - JOIN pg_catalog.pg_proc p ON n.oid = p.pronamespace - WHERE pg_catalog.pg_function_is_visible(p.oid) - AND n.nspname <> 'pg_catalog' + SELECT name FROM tap_funky WHERE is_visible AND schema <> 'pg_catalog' ), $2 ); @@ -4846,58 +4832,87 @@ $$ LANGUAGE SQL; CREATE OR REPLACE FUNCTION _lang ( NAME, NAME, NAME[] ) RETURNS NAME AS $$ SELECT l.lanname - FROM pg_catalog.pg_proc p - JOIN pg_catalog.pg_namespace n ON p.pronamespace = n.oid - JOIN pg_catalog.pg_language l ON p.prolang = l.oid - WHERE n.nspname = $1 - AND p.proname = $2 - AND array_to_string(p.proargtypes::regtype[], ',') = array_to_string($3, ','); + FROM tap_funky f + JOIN pg_catalog.pg_language l ON f.langoid = l.oid + WHERE f.schema = $1 + and f.name = $2 + AND f.args = array_to_string($3, ',') $$ LANGUAGE SQL; CREATE OR REPLACE FUNCTION _lang ( NAME, NAME ) RETURNS NAME AS $$ SELECT l.lanname - FROM pg_catalog.pg_proc p - JOIN pg_catalog.pg_namespace n ON p.pronamespace = n.oid - JOIN pg_catalog.pg_language l ON p.prolang = l.oid - WHERE n.nspname = $1 - AND p.proname = $2 + FROM tap_funky f + JOIN pg_catalog.pg_language l ON f.langoid = l.oid + WHERE f.schema = $1 + and f.name = $2 $$ LANGUAGE SQL; CREATE OR REPLACE FUNCTION _lang ( NAME, NAME[] ) RETURNS NAME AS $$ SELECT l.lanname - FROM pg_catalog.pg_proc p - JOIN pg_catalog.pg_language l ON p.prolang = l.oid - WHERE p.proname = $1 - AND array_to_string(p.proargtypes::regtype[], ',') = array_to_string($2, ',') - AND pg_catalog.pg_function_is_visible(p.oid); + FROM tap_funky f + JOIN pg_catalog.pg_language l ON f.langoid = l.oid + WHERE f.name = $1 + AND f.args = array_to_string($2, ',') + AND f.is_visible; $$ LANGUAGE SQL; CREATE OR REPLACE FUNCTION _lang ( NAME ) RETURNS NAME AS $$ SELECT l.lanname - FROM pg_catalog.pg_proc p - JOIN pg_catalog.pg_language l ON p.prolang = l.oid - WHERE p.proname = $1 - AND pg_catalog.pg_function_is_visible(p.oid); + FROM tap_funky f + JOIN pg_catalog.pg_language l ON f.langoid = l.oid + WHERE f.name = $1 + AND f.is_visible; $$ LANGUAGE SQL; --- function_lang_is( schema, function, args[], language, description ) -CREATE OR REPLACE FUNCTION function_lang_is( NAME, NAME, NAME[], NAME, TEXT ) +CREATE OR REPLACE FUNCTION _func_compare( NAME, NAME, NAME[], anyelement, anyelement, TEXT) RETURNS TEXT AS $$ DECLARE - have name := _lang($1, $2, $3); + schema ALIAS FOR $1; + name ALIAS FOR $2; + args ALIAS FOR $3; + have ALIAS FOR $4; + want ALIAS FOR $5; + descr ALIAS FOR $6; BEGIN - IF have IS NOT NULL THEN RETURN is( have, $4, $5 ); END IF; + IF have IS NOT NULL THEN RETURN is( have, want, descr ); END IF; - RETURN ok( FALSE, $5 ) || E'\n' || diag( - ' Function ' || quote_ident($1) || '.' || quote_ident($2) || '(' || - array_to_string($3, ', ') || ') does not exist' + RETURN ok( FALSE, descr ) || E'\n' || diag( + ' Function ' + || CASE WHEN schema IS NOT NULL THEN quote_ident(schema) || '.' ELSE '' END + || quote_ident(name) || '(' + || array_to_string(args, ', ') || ') does not exist' ); END; $$ LANGUAGE plpgsql; +CREATE OR REPLACE FUNCTION _func_compare( NAME, NAME, anyelement, anyelement, TEXT) +RETURNS TEXT AS $$ +DECLARE + schema ALIAS FOR $1; + name ALIAS FOR $2; + have ALIAS FOR $3; + want ALIAS FOR $4; + descr ALIAS FOR $5; +BEGIN + IF have IS NOT NULL THEN RETURN is( have, want, descr ); END IF; + + RETURN ok( FALSE, descr ) || E'\n' || diag( + ' Function ' + || CASE WHEN schema IS NOT NULL THEN quote_ident(schema) || '.' ELSE '' END + || quote_ident(name) || '() does not exist' + ); +END; +$$ LANGUAGE plpgsql; + +-- function_lang_is( schema, function, args[], language, description ) +CREATE OR REPLACE FUNCTION function_lang_is( NAME, NAME, NAME[], NAME, TEXT ) +RETURNS TEXT AS $$ + SELECT _func_compare($1, $2, $3, _lang($1, $2, $3), $4, $5 ); +$$ LANGUAGE SQL; + -- function_lang_is( schema, function, args[], language ) CREATE OR REPLACE FUNCTION function_lang_is( NAME, NAME, NAME[], NAME ) RETURNS TEXT AS $$ @@ -4911,17 +4926,8 @@ $$ LANGUAGE SQL; -- function_lang_is( schema, function, language, description ) CREATE OR REPLACE FUNCTION function_lang_is( NAME, NAME, NAME, TEXT ) RETURNS TEXT AS $$ -DECLARE - have name := _lang($1, $2); -BEGIN - IF have IS NOT NULL THEN RETURN is( have, $3, $4 ); END IF; - - RETURN ok( FALSE, $4 ) || E'\n' || diag( - ' Function ' || quote_ident($1) || '.' || quote_ident($2) - || '() does not exist' - ); -END; -$$ LANGUAGE plpgsql; + SELECT _func_compare($1, $2, _lang($1, $2), $3, $4 ); +$$ LANGUAGE SQL; -- function_lang_is( schema, function, language ) CREATE OR REPLACE FUNCTION function_lang_is( NAME, NAME, NAME ) @@ -4936,17 +4942,8 @@ $$ LANGUAGE SQL; -- function_lang_is( function, args[], language, description ) CREATE OR REPLACE FUNCTION function_lang_is( NAME, NAME[], NAME, TEXT ) RETURNS TEXT AS $$ -DECLARE - have name := _lang($1, $2); -BEGIN - IF have IS NOT NULL THEN RETURN is( have, $3, $4 ); END IF; - - RETURN ok( FALSE, $4 ) || E'\n' || diag( - ' Function ' || quote_ident($1) || '(' || - array_to_string($2, ', ') || ') does not exist' - ); -END; -$$ LANGUAGE plpgsql; + SELECT _func_compare(NULL, $1, $2, _lang($1, $2), $3, $4 ); +$$ LANGUAGE SQL; -- function_lang_is( function, args[], language ) CREATE OR REPLACE FUNCTION function_lang_is( NAME, NAME[], NAME ) @@ -4961,16 +4958,8 @@ $$ LANGUAGE SQL; -- function_lang_is( function, language, description ) CREATE OR REPLACE FUNCTION function_lang_is( NAME, NAME, TEXT ) RETURNS TEXT AS $$ -DECLARE - have name := _lang($1); -BEGIN - IF have IS NOT NULL THEN RETURN is( have, $2, $3 ); END IF; - - RETURN ok( FALSE, $3 ) || E'\n' || diag( - ' Function ' || quote_ident($1) || '() does not exist' - ); -END; -$$ LANGUAGE plpgsql; + SELECT _func_compare(NULL, $1, _lang($1), $2, $3 ); +$$ LANGUAGE SQL; -- function_lang_is( function, language ) CREATE OR REPLACE FUNCTION function_lang_is( NAME, NAME ) @@ -4982,6 +4971,97 @@ RETURNS TEXT AS $$ ); $$ LANGUAGE SQL; +CREATE OR REPLACE FUNCTION _returns ( NAME, NAME, NAME[] ) +RETURNS TEXT AS $$ + SELECT returns + FROM tap_funky + WHERE schema = $1 + AND name = $2 + AND args = array_to_string($3, ',') +$$ LANGUAGE SQL; + +CREATE OR REPLACE FUNCTION _returns ( NAME, NAME ) +RETURNS TEXT AS $$ + SELECT returns FROM tap_funky WHERE schema = $1 AND name = $2 +$$ LANGUAGE SQL; + +CREATE OR REPLACE FUNCTION _returns ( NAME, NAME[] ) +RETURNS TEXT AS $$ + SELECT returns + FROM tap_funky + WHERE name = $1 + AND args = array_to_string($2, ',') + AND is_visible; +$$ LANGUAGE SQL; + +CREATE OR REPLACE FUNCTION _returns ( NAME ) +RETURNS TEXT AS $$ + SELECT returns FROM tap_funky WHERE name = $1 AND is_visible; +$$ LANGUAGE SQL; + +-- function_returns( schema, function, args[], type, description ) +CREATE OR REPLACE FUNCTION function_returns( NAME, NAME, NAME[], TEXT, TEXT ) +RETURNS TEXT AS $$ + SELECT _func_compare($1, $2, $3, _returns($1, $2, $3), $4, $5 ); +$$ LANGUAGE SQL; + +-- function_returns( schema, function, args[], type ) +CREATE OR REPLACE FUNCTION function_returns( NAME, NAME, NAME[], TEXT ) +RETURNS TEXT AS $$ + SELECT function_returns( + $1, $2, $3, $4, + 'Function ' || quote_ident($1) || '.' || quote_ident($2) || '(' || + array_to_string($3, ', ') || ') should return ' || $4 + ); +$$ LANGUAGE SQL; + +-- function_returns( schema, function, type, description ) +CREATE OR REPLACE FUNCTION function_returns( NAME, NAME, TEXT, TEXT ) +RETURNS TEXT AS $$ + SELECT _func_compare($1, $2, _returns($1, $2), $3, $4 ); +$$ LANGUAGE SQL; + +-- function_returns( schema, function, type ) +CREATE OR REPLACE FUNCTION function_returns( NAME, NAME, TEXT ) +RETURNS TEXT AS $$ + SELECT function_returns( + $1, $2, $3, + 'Function ' || quote_ident($1) || '.' || quote_ident($2) + || '() should return ' || $3 + ); +$$ LANGUAGE SQL; + +-- function_returns( function, args[], type, description ) +CREATE OR REPLACE FUNCTION function_returns( NAME, NAME[], TEXT, TEXT ) +RETURNS TEXT AS $$ + SELECT _func_compare(NULL, $1, $2, _returns($1, $2), $3, $4 ); +$$ LANGUAGE SQL; + +-- function_returns( function, args[], type ) +CREATE OR REPLACE FUNCTION function_returns( NAME, NAME[], TEXT ) +RETURNS TEXT AS $$ + SELECT function_returns( + $1, $2, $3, + 'Function ' || quote_ident($1) || '(' || + array_to_string($2, ', ') || ') should return ' || $3 + ); +$$ LANGUAGE SQL; + +-- function_returns( function, type, description ) +CREATE OR REPLACE FUNCTION function_returns( NAME, TEXT, TEXT ) +RETURNS TEXT AS $$ + SELECT _func_compare(NULL, $1, _returns($1), $2, $3 ); +$$ LANGUAGE SQL; + +-- function_returns( function, type ) +CREATE OR REPLACE FUNCTION function_returns( NAME, TEXT ) +RETURNS TEXT AS $$ + SELECT function_returns( + $1, $2, + 'Function ' || quote_ident($1) || '() should return ' || $2 + ); +$$ LANGUAGE SQL; + -- check_test( test_output, pass, name, description, diag, match_diag ) CREATE OR REPLACE FUNCTION check_test( TEXT, BOOLEAN, TEXT, TEXT, TEXT, BOOLEAN ) RETURNS SETOF TEXT AS $$ diff --git a/sql/functap.sql b/sql/functap.sql index 71098dd2b..5f7f35c6f 100644 --- a/sql/functap.sql +++ b/sql/functap.sql @@ -1,7 +1,7 @@ \unset ECHO \i test_setup.sql -SELECT plan(210); +SELECT plan(282); --SELECT * FROM no_plan(); CREATE SCHEMA someschema; @@ -12,6 +12,8 @@ AS 'BEGIN RETURN TRUE; END;' LANGUAGE plpgsql; CREATE FUNCTION public.yay () RETURNS BOOL AS 'SELECT TRUE' LANGUAGE SQL; CREATE FUNCTION public.oww (int, text) RETURNS BOOL AS 'BEGIN RETURN TRUE; END;' LANGUAGE plpgsql; +CREATE FUNCTION public.set () RETURNS SETOF BOOL +AS 'BEGIN RETURN NEXT TRUE; RETURN; END;' LANGUAGE plpgsql; -- XXX Delete when can_ok() is removed. SET client_min_messages = error; @@ -428,7 +430,7 @@ SELECT * FROM check_test( SELECT * FROM check_test( function_lang_is( 'someschema', 'huh', '{}'::name[], 'sql', 'whatever' ), true, - 'function_lang_is(schema, func, 0 args, sql, desc )', + 'function_lang_is(schema, func, 0 args, sql, desc)', 'whatever', '' ); @@ -436,7 +438,7 @@ SELECT * FROM check_test( SELECT * FROM check_test( function_lang_is( 'someschema', 'huh', '{}'::name[], 'sql' ), true, - 'function_lang_is(schema, func, 0 args, sql )', + 'function_lang_is(schema, func, 0 args, sql)', 'Function someschema.huh() should be written in sql', '' ); @@ -444,7 +446,7 @@ SELECT * FROM check_test( SELECT * FROM check_test( function_lang_is( 'someschema', 'bah', '{"integer", "text"}'::name[], 'plpgsql', 'whatever' ), true, - 'function_lang_is(schema, func, args, plpgsql, desc )', + 'function_lang_is(schema, func, args, plpgsql, desc)', 'whatever', '' ); @@ -452,7 +454,7 @@ SELECT * FROM check_test( SELECT * FROM check_test( function_lang_is( 'someschema', 'bah', '{"integer", "text"}'::name[], 'plpgsql' ), true, - 'function_lang_is(schema, func, args, plpgsql )', + 'function_lang_is(schema, func, args, plpgsql)', 'Function someschema.bah(integer, text) should be written in plpgsql', '' ); @@ -460,7 +462,7 @@ SELECT * FROM check_test( SELECT * FROM check_test( function_lang_is( 'someschema', 'huh', '{}'::name[], 'perl', 'whatever' ), false, - 'function_lang_is(schema, func, 0 args, perl, desc )', + 'function_lang_is(schema, func, 0 args, perl, desc)', 'whatever', ' have: sql want: perl' @@ -469,7 +471,7 @@ SELECT * FROM check_test( SELECT * FROM check_test( function_lang_is( 'someschema', 'why', '{}'::name[], 'sql', 'whatever' ), false, - 'function_lang_is(schema, non-func, 0 args, sql, desc )', + 'function_lang_is(schema, non-func, 0 args, sql, desc)', 'whatever', ' Function someschema.why() does not exist' ); @@ -477,7 +479,7 @@ SELECT * FROM check_test( SELECT * FROM check_test( function_lang_is( 'someschema', 'why', '{"integer", "text"}'::name[], 'plpgsql' ), false, - 'function_lang_is(schema, func, args, plpgsql )', + 'function_lang_is(schema, func, args, plpgsql)', 'Function someschema.why(integer, text) should be written in plpgsql', ' Function someschema.why(integer, text) does not exist' ); @@ -485,7 +487,7 @@ SELECT * FROM check_test( SELECT * FROM check_test( function_lang_is( 'someschema', 'huh', 'sql', 'whatever' ), true, - 'function_lang_is(schema, func, sql, desc )', + 'function_lang_is(schema, func, sql, desc)', 'whatever', '' ); @@ -493,7 +495,7 @@ SELECT * FROM check_test( SELECT * FROM check_test( function_lang_is( 'someschema', 'huh', 'sql'::name ), true, - 'function_lang_is(schema, func, sql )', + 'function_lang_is(schema, func, sql)', 'Function someschema.huh() should be written in sql', '' ); @@ -501,7 +503,7 @@ SELECT * FROM check_test( SELECT * FROM check_test( function_lang_is( 'someschema', 'huh', 'perl', 'whatever' ), false, - 'function_lang_is(schema, func, perl, desc )', + 'function_lang_is(schema, func, perl, desc)', 'whatever', ' have: sql want: perl' @@ -510,7 +512,7 @@ SELECT * FROM check_test( SELECT * FROM check_test( function_lang_is( 'someschema', 'why', 'sql', 'whatever' ), false, - 'function_lang_is(schema, non-func, sql, desc )', + 'function_lang_is(schema, non-func, sql, desc)', 'whatever', ' Function someschema.why() does not exist' ); @@ -518,7 +520,7 @@ SELECT * FROM check_test( SELECT * FROM check_test( function_lang_is( 'yay', '{}'::name[], 'sql', 'whatever' ), true, - 'function_lang_is(func, 0 args, sql, desc )', + 'function_lang_is(func, 0 args, sql, desc)', 'whatever', '' ); @@ -526,7 +528,7 @@ SELECT * FROM check_test( SELECT * FROM check_test( function_lang_is( 'yay', '{}'::name[], 'sql' ), true, - 'function_lang_is(func, 0 args, sql )', + 'function_lang_is(func, 0 args, sql)', 'Function yay() should be written in sql', '' ); @@ -534,7 +536,7 @@ SELECT * FROM check_test( SELECT * FROM check_test( function_lang_is( 'oww', '{"integer", "text"}'::name[], 'plpgsql', 'whatever' ), true, - 'function_lang_is(func, args, plpgsql, desc )', + 'function_lang_is(func, args, plpgsql, desc)', 'whatever', '' ); @@ -542,7 +544,7 @@ SELECT * FROM check_test( SELECT * FROM check_test( function_lang_is( 'oww', '{"integer", "text"}'::name[], 'plpgsql' ), true, - 'function_lang_is(func, args, plpgsql )', + 'function_lang_is(func, args, plpgsql)', 'Function oww(integer, text) should be written in plpgsql', '' ); @@ -550,7 +552,7 @@ SELECT * FROM check_test( SELECT * FROM check_test( function_lang_is( 'yay', '{}'::name[], 'perl', 'whatever' ), false, - 'function_lang_is(func, 0 args, perl, desc )', + 'function_lang_is(func, 0 args, perl, desc)', 'whatever', ' have: sql want: perl' @@ -559,7 +561,7 @@ SELECT * FROM check_test( SELECT * FROM check_test( function_lang_is( 'why', '{}'::name[], 'sql', 'whatever' ), false, - 'function_lang_is(non-func, 0 args, sql, desc )', + 'function_lang_is(non-func, 0 args, sql, desc)', 'whatever', ' Function why() does not exist' ); @@ -567,7 +569,7 @@ SELECT * FROM check_test( SELECT * FROM check_test( function_lang_is( 'why', '{"integer", "text"}'::name[], 'plpgsql' ), false, - 'function_lang_is(func, args, plpgsql )', + 'function_lang_is(func, args, plpgsql)', 'Function why(integer, text) should be written in plpgsql', ' Function why(integer, text) does not exist' ); @@ -575,7 +577,7 @@ SELECT * FROM check_test( SELECT * FROM check_test( function_lang_is( 'yay', 'sql', 'whatever' ), true, - 'function_lang_is(func, sql, desc )', + 'function_lang_is(func, sql, desc)', 'whatever', '' ); @@ -583,7 +585,7 @@ SELECT * FROM check_test( SELECT * FROM check_test( function_lang_is( 'yay', 'sql' ), true, - 'function_lang_is(func, sql )', + 'function_lang_is(func, sql)', 'Function yay() should be written in sql', '' ); @@ -591,7 +593,7 @@ SELECT * FROM check_test( SELECT * FROM check_test( function_lang_is( 'yay', 'perl', 'whatever' ), false, - 'function_lang_is(func, perl, desc )', + 'function_lang_is(func, perl, desc)', 'whatever', ' have: sql want: perl' @@ -600,11 +602,205 @@ SELECT * FROM check_test( SELECT * FROM check_test( function_lang_is( 'why', 'sql', 'whatever' ), false, - 'function_lang_is(non-func, sql, desc )', + 'function_lang_is(non-func, sql, desc)', 'whatever', ' Function why() does not exist' ); +/****************************************************************************/ +-- Test function_returns(). +SELECT * FROM check_test( + function_returns( 'someschema', 'huh', '{}'::name[], 'bool', 'whatever' ), + true, + 'function_returns(schema, func, 0 args, bool, desc)', + 'whatever', + '' +); + +SELECT * FROM check_test( + function_returns( 'someschema', 'huh', '{}'::name[], 'bool' ), + true, + 'function_returns(schema, func, 0 args, bool)', + 'Function someschema.huh() should return bool', + '' +); + +SELECT * FROM check_test( + function_returns( 'someschema', 'bah', ARRAY['integer', 'text'], 'bool', 'whatever' ), + true, + 'function_returns(schema, func, args, bool, false)', + 'whatever', + '' +); + +SELECT * FROM check_test( + function_returns( 'someschema', 'bah', ARRAY['integer', 'text'], 'bool' ), + true, + 'function_returns(schema, func, args, bool)', + 'Function someschema.bah(integer, text) should return bool', + '' +); + +SELECT * FROM check_test( + function_returns( 'public', 'set', '{}'::name[], 'setof bool', 'whatever' ), + true, + 'function_returns(schema, func, 0 args, setof bool, desc)', + 'whatever', + '' +); + +SELECT * FROM check_test( + function_returns( 'public', 'set', '{}'::name[], 'setof bool' ), + true, + 'function_returns(schema, func, 0 args, setof bool)', + 'Function public.set() should return setof bool', + '' +); + +SELECT * FROM check_test( + function_returns( 'someschema', 'huh', 'bool', 'whatever' ), + true, + 'function_returns(schema, func, bool, desc)', + 'whatever', + '' +); + +SELECT * FROM check_test( + function_returns( 'someschema', 'huh'::name, 'bool' ), + true, + 'function_returns(schema, func, bool)', + 'Function someschema.huh() should return bool', + '' +); + +SELECT * FROM check_test( + function_returns( 'someschema', 'bah', 'bool', 'whatever' ), + true, + 'function_returns(schema, other func, bool, false)', + 'whatever', + '' +); + +SELECT * FROM check_test( + function_returns( 'someschema', 'bah'::name, 'bool' ), + true, + 'function_returns(schema, other func, bool)', + 'Function someschema.bah() should return bool', + '' +); + +SELECT * FROM check_test( + function_returns( 'public', 'set', 'setof bool', 'whatever' ), + true, + 'function_returns(schema, func, setof bool, desc)', + 'whatever', + '' +); + +SELECT * FROM check_test( + function_returns( 'public', 'set'::name, 'setof bool' ), + true, + 'function_returns(schema, func, setof bool)', + 'Function public.set() should return setof bool', + '' +); + +SELECT * FROM check_test( + function_returns( 'yay', '{}'::name[], 'bool', 'whatever' ), + true, + 'function_returns(func, 0 args, bool, desc)', + 'whatever', + '' +); + +SELECT * FROM check_test( + function_returns( 'yay', '{}'::name[], 'bool' ), + true, + 'function_returns(func, 0 args, bool)', + 'Function yay() should return bool', + '' +); + +SELECT * FROM check_test( + function_returns( 'oww', ARRAY['integer', 'text'], 'bool', 'whatever' ), + true, + 'function_returns(func, args, bool, false)', + 'whatever', + '' +); + +SELECT * FROM check_test( + function_returns( 'oww', ARRAY['integer', 'text'], 'bool' ), + true, + 'function_returns(func, args, bool)', + 'Function oww(integer, text) should return bool', + '' +); + +SELECT * FROM check_test( + function_returns( 'set', '{}'::name[], 'setof bool', 'whatever' ), + true, + 'function_returns(func, 0 args, setof bool, desc)', + 'whatever', + '' +); + +SELECT * FROM check_test( + function_returns( 'set', '{}'::name[], 'setof bool' ), + true, + 'function_returns(func, 0 args, setof bool)', + 'Function set() should return setof bool', + '' +); + +SELECT * FROM check_test( + function_returns( 'yay', 'bool', 'whatever' ), + true, + 'function_returns(func, bool, desc)', + 'whatever', + '' +); + +SELECT * FROM check_test( + function_returns( 'yay', 'bool' ), + true, + 'function_returns(func, bool)', + 'Function yay() should return bool', + '' +); + +SELECT * FROM check_test( + function_returns( 'oww', 'bool', 'whatever' ), + true, + 'function_returns(other func, bool, false)', + 'whatever', + '' +); + +SELECT * FROM check_test( + function_returns( 'oww', 'bool' ), + true, + 'function_returns(other func, bool)', + 'Function oww() should return bool', + '' +); + +SELECT * FROM check_test( + function_returns( 'set', 'setof bool', 'whatever' ), + true, + 'function_returns(func, setof bool, desc)', + 'whatever', + '' +); + +SELECT * FROM check_test( + function_returns( 'set', 'setof bool' ), + true, + 'function_returns(func, setof bool)', + 'Function set() should return setof bool', + '' +); + /****************************************************************************/ -- Finish the tests and clean up. SELECT * FROM finish();