From 112fdeee1337b13065f96c340547bbb93aac3fcb Mon Sep 17 00:00:00 2001 From: "David E. Wheeler" Date: Mon, 2 Apr 2018 09:44:56 -0400 Subject: [PATCH] Add missing BEING/END to PL/pgSQL function. And add a comment about the hypothetical `users` table. Resolves #163. --- doc/pgtap.mmd | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/doc/pgtap.mmd b/doc/pgtap.mmd index f72bc403a..323f10e1b 100644 --- a/doc/pgtap.mmd +++ b/doc/pgtap.mmd @@ -305,17 +305,19 @@ What a sweet unit! If you're used to xUnit testing frameworks, you can collect all of your tests into database functions and run them all at once with `runtests()`. This is -similar to how [PGUnit](http://en.dklab.ru/lib/dklab_pgunit/)s. The +similar to how [PGUnit](http://en.dklab.ru/lib/dklab_pgunit/) works. The `runtests()` function does all the work of finding and running your test functions in individual transactions. It even supports setup and teardown functions. To use it, write your unit test functions so that they return a set of text results, and then use the pgTAP assertion functions to return TAP -values, like so: +values. Here's an example, testing a hypothetical `users` table: CREATE OR REPLACE FUNCTION setup_insert( ) RETURNS SETOF TEXT AS $$ + BEGIN RETURN NEXT is( MAX(nick), NULL, 'Should have no users') FROM users; INSERT INTO users (nick) VALUES ('theory'); + END; $$ LANGUAGE plpgsql; CREATE OR REPLACE FUNCTION test_user(