You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If you want to remove pgTAP from a database, run the `uninstall_pgtap.sql`
156
157
script:
@@ -175,23 +176,22 @@ variables to keep the tests quiet, start a transaction, load the functions in
175
176
your test script, and then rollback the transaction at the end of the script.
176
177
Here's an example:
177
178
178
-
\set ECHO
179
+
\unset ECHO
179
180
\set QUIET 1
180
181
-- Turn off echo and keep things quiet.
181
182
182
183
-- Format the output for nice TAP.
183
184
\pset format unaligned
184
185
\pset tuples_only true
185
-
\pset pager
186
+
\pset pager off
186
187
187
188
-- Revert all changes on failure.
188
189
\set ON_ERROR_ROLLBACK 1
189
190
\set ON_ERROR_STOP true
190
-
\set QUIET 1
191
191
192
192
-- Load the TAP functions.
193
193
BEGIN;
194
-
\i pgtap.sql
194
+
\i pgtap.sql
195
195
196
196
-- Plan the tests.
197
197
SELECT plan(1);
@@ -203,16 +203,6 @@ Here's an example:
203
203
SELECT * FROM finish();
204
204
ROLLBACK;
205
205
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
-
216
206
Now you're ready to run your test script!
217
207
218
208
% psql -d try -Xf test.sql
@@ -270,12 +260,12 @@ Using pgTAP
270
260
===========
271
261
272
262
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.
279
269
280
270
There are two ways to use pgTAP: 1) In simple test scripts that use a plan to
281
271
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.
291
281
The preferred way to do this is to declare a plan by calling the `plan()`
292
282
function:
293
283
294
-
SELECT plan( 42 );
284
+
SELECT plan(42);
295
285
296
286
There are rare cases when you will not know beforehand how many tests your
297
287
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
344
334
the function completes (or after any teardown functions have run). The TAP
345
335
results will be sent to your client.
346
336
347
-
Test names
348
-
----------
337
+
Test Descriptions
338
+
-----------------
349
339
350
340
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?
353
343
354
344
ok 4
355
345
not ok 5
@@ -364,32 +354,31 @@ Or this?
364
354
The latter gives you some idea of what failed. It also makes it easier to find
365
355
the test in your script, simply search for "simple exponential".
366
356
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.
369
359
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 ###
372
361
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:
374
367
375
368
CREATE OR REPLACE FUNCTION diag_test_name(TEXT)
376
369
RETURNS TEXT AS $$
377
370
SELECT diag('test: ' || $1 );
378
371
$$ LANGUAGE SQL;
379
372
380
-
**Parameters**
381
-
382
-
`:test_name`
383
-
: A test name.
384
-
385
373
This will show
386
374
387
375
# test: my_example_test_function_name
376
+
388
377
instead of
389
378
390
379
# my_example_test_function_name()
391
380
392
-
This makes easy handling test name and differing test names from comments.
381
+
This simplifies parsing test names from TAP comments.
0 commit comments