Skip to content

Commit 7d2a20e

Browse files
committed
Update introductory documentation.
A lot has changed over the years!
1 parent 0c31b33 commit 7d2a20e

File tree

2 files changed

+52
-62
lines changed

2 files changed

+52
-62
lines changed

Changes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ Revision history for pgTAP
33

44
0.99.0
55
---------------------------
6+
* Updated introductory documentation. A lot has changed over the years!
67

78
0.98.0 2017-11-06T22:30:54Z
89
---------------------------

doc/pgtap.mmd

Lines changed: 51 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ used in the xUnit testing style.
1010
Synopsis
1111
========
1212

13+
CREATE EXTENSION IF NOT EXISTS pgtap;
14+
1315
SELECT plan( 23 );
1416
-- or SELECT * from no_plan();
1517

@@ -96,28 +98,6 @@ You need to run the test suite using a super user, such as the default
9698

9799
make installcheck PGUSER=postgres
98100

99-
Once pgTAP is installed, you can add it to a database. If you're running
100-
PostgreSQL 9.1.0 or greater, it's a simple as connecting to a database as a
101-
super user and running:
102-
103-
CREATE EXTENSION pgtap;
104-
105-
If you've upgraded your cluster to PostgreSQL 9.1 and already had pgTAP
106-
installed, you can upgrade it to a properly packaged extension with:
107-
108-
CREATE EXTENSION pgtap FROM unpackaged;
109-
110-
For versions of PostgreSQL less than 9.1.0, you'll need to run the
111-
installation script:
112-
113-
psql -d mydb -f /path/to/pgsql/share/contrib/pgtap.sql
114-
115-
If you want to install pgTAP and all of its supporting objects into a
116-
specific schema, use the `PGOPTIONS` environment variable to specify the
117-
schema, like so:
118-
119-
PGOPTIONS=--search_path=tap psql -d mydb -f pgTAP.sql
120-
121101
Testing pgTAP with pgTAP
122102
------------------------
123103

@@ -142,15 +122,36 @@ You can use it to run the test suite as a database super user like so:
142122
Adding pgTAP to a Database
143123
--------------------------
144124

145-
Once pgTAP has been built and tested, you can install it into a
146-
PL/pgSQL-enabled database:
125+
Once pgTAP is installed, you can add it to a database. If you're running
126+
PostgreSQL 9.1.0 or greater, it's a simple as connecting to a database as a
127+
super user and running:
128+
129+
CREATE EXTENSION IF NOT EXISTS pgtap;
147130

148-
psql -d dbname -f pgtap.sql
131+
If you've upgraded your cluster to PostgreSQL 9.1 and already had pgTAP
132+
installed, you can upgrade it to a properly packaged extension with:
133+
134+
CREATE EXTENSION pgtap FROM unpackaged;
149135

150136
If you want pgTAP to be available to all new databases, install it into the
151137
"template1" database:
152138

153-
psql -d template1 -f pgtap.sql
139+
psql -d template1 -C "CREATE EXTENSION pgtap"
140+
141+
To uninstall pgTAP, use `DROP EXTENSION`:
142+
143+
DROP EXTENSION IF EXISTS pgtap;
144+
145+
For versions of PostgreSQL less than 9.1.0, you'll need to run the
146+
installation script:
147+
148+
psql -d mydb -f /path/to/pgsql/share/contrib/pgtap.sql
149+
150+
If you want to install pgTAP and all of its supporting objects into a
151+
specific schema, use the `PGOPTIONS` environment variable to specify the
152+
schema, like so:
153+
154+
PGOPTIONS=--search_path=tap psql -d mydb -f pgTAP.sql
154155

155156
If you want to remove pgTAP from a database, run the `uninstall_pgtap.sql`
156157
script:
@@ -175,23 +176,22 @@ variables to keep the tests quiet, start a transaction, load the functions in
175176
your test script, and then rollback the transaction at the end of the script.
176177
Here's an example:
177178

178-
\set ECHO
179+
\unset ECHO
179180
\set QUIET 1
180181
-- Turn off echo and keep things quiet.
181182

182183
-- Format the output for nice TAP.
183184
\pset format unaligned
184185
\pset tuples_only true
185-
\pset pager
186+
\pset pager off
186187

187188
-- Revert all changes on failure.
188189
\set ON_ERROR_ROLLBACK 1
189190
\set ON_ERROR_STOP true
190-
\set QUIET 1
191191

192192
-- Load the TAP functions.
193193
BEGIN;
194-
\i pgtap.sql
194+
\i pgtap.sql
195195

196196
-- Plan the tests.
197197
SELECT plan(1);
@@ -203,16 +203,6 @@ Here's an example:
203203
SELECT * FROM finish();
204204
ROLLBACK;
205205

206-
Of course, if you already have the pgTAP functions in your testing database,
207-
you should skip `\i pgtap.sql` at the beginning of the script.
208-
209-
The only other limitation is that the `pg_typeof()` function, which is
210-
written in C, will not be available in 8.3 and lower. You'll want to
211-
comment out its declaration in the bundled copy of `pgtap.sql` and then avoid
212-
using `cmp_ok()`, since that function relies on `pg_typeof()`. Note that
213-
`pg_typeof()` is included in PostgreSQL 8.4, so you won't need to avoid it on
214-
that version or higher.
215-
216206
Now you're ready to run your test script!
217207

218208
% psql -d try -Xf test.sql
@@ -270,12 +260,12 @@ Using pgTAP
270260
===========
271261

272262
The purpose of pgTAP is to provide a wide range of testing utilities that
273-
output TAP. TAP, or the "Test Anything Protocol", is an emerging standard for
274-
representing the output from unit tests. It owes its success to its format as
275-
a simple text-based interface that allows for practical machine parsing and
276-
high legibility for humans. TAP started life as part of the test harness for
277-
Perl but now has implementations in C/C++, Python, PHP, JavaScript, Perl, and
278-
now PostgreSQL.
263+
output TAP. TAP, or the "Test Anything Protocol", is a standard for
264+
representing the output from unit tests. It owes its success to its format as a
265+
simple text-based interface that allows for practical machine parsing and high
266+
legibility for humans. TAP started life as part of the test harness for Perl
267+
but now has implementations in C/C++, Python, PHP, JavaScript, Perl, and, of
268+
course, PostgreSQL.
279269

280270
There are two ways to use pgTAP: 1) In simple test scripts that use a plan to
281271
describe the tests in the script; or 2) In xUnit-style test functions that you
@@ -291,7 +281,7 @@ many tests your script is going to run to protect against premature failure.
291281
The preferred way to do this is to declare a plan by calling the `plan()`
292282
function:
293283

294-
SELECT plan( 42 );
284+
SELECT plan(42);
295285

296286
There are rare cases when you will not know beforehand how many tests your
297287
script is going to run. In this case, you can declare that you have no plan.
@@ -344,12 +334,12 @@ Each test function will run within its own transaction, and rolled back when
344334
the function completes (or after any teardown functions have run). The TAP
345335
results will be sent to your client.
346336

347-
Test names
348-
----------
337+
Test Descriptions
338+
-----------------
349339

350340
By convention, each test is assigned a number in order. This is largely done
351-
automatically for you. However, it's often very useful to assign a name to
352-
each test. Would you rather see this?
341+
automatically for you. However, it's often very useful to deascribe each test.
342+
Would you rather see this?
353343

354344
ok 4
355345
not ok 5
@@ -364,32 +354,31 @@ Or this?
364354
The latter gives you some idea of what failed. It also makes it easier to find
365355
the test in your script, simply search for "simple exponential".
366356

367-
All test functions take a name argument. It's optional, but highly suggested
368-
that you use it.
357+
All test functions take a description argument. It's optional, but highly
358+
suggested that you use it.
369359

370-
Sometimes it's useful to extract test function names from pgtap output, especially when using xUnit style with Continuous Integration Server like Hudson or TeamCity.
371-
By default pgTAP displays this names as "comment", but you're able to change this behavior by overriding function `diag_test_name`:
360+
### xUnit Function Names ###
372361

373-
### `diag_test_name()` ###
362+
Sometimes it's useful to extract xUnit test function names from TAP output,
363+
especially when using xUnit style with Continuous Integration Server like
364+
Hudson or TeamCity. By default pgTAP displays these names as comments, but
365+
you're able to change this behavior by overriding the function `diag_test_name`.
366+
For example:
374367

375368
CREATE OR REPLACE FUNCTION diag_test_name(TEXT)
376369
RETURNS TEXT AS $$
377370
SELECT diag('test: ' || $1 );
378371
$$ LANGUAGE SQL;
379372

380-
**Parameters**
381-
382-
`:test_name`
383-
: A test name.
384-
385373
This will show
386374

387375
# test: my_example_test_function_name
376+
388377
instead of
389378

390379
# my_example_test_function_name()
391380

392-
This makes easy handling test name and differing test names from comments.
381+
This simplifies parsing test names from TAP comments.
393382

394383
I'm ok, you're not ok
395384
---------------------

0 commit comments

Comments
 (0)