Navigation Menu

Skip to content

Commit

Permalink
Added function_returns().
Browse files Browse the repository at this point in the history
* 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`.
  • Loading branch information
theory committed May 27, 2009
1 parent 59f8c1d commit 0c610aa
Show file tree
Hide file tree
Showing 5 changed files with 603 additions and 207 deletions.
2 changes: 1 addition & 1 deletion Changes
Expand Up @@ -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
-------------------------
Expand Down
50 changes: 49 additions & 1 deletion README.pgtap
Expand Up @@ -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 )` ###
Expand Down Expand Up @@ -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()`
Expand Down
206 changes: 139 additions & 67 deletions 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
Expand Down Expand Up @@ -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

0 comments on commit 0c610aa

Please sign in to comment.