- Timestamp:
- 08/20/08 11:39:29 (4 years ago)
- Location:
- trunk/epic
- Files:
-
- 2 modified
-
epic.sql (modified) (13 diffs)
-
test/test_results.sql (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/epic/epic.sql
r10 r12 49 49 1. ALWAYS RAISE EXCEPTION at the end of test procs to rollback! Even if 50 50 the test passes, RAISE EXCEPTION '[OK]'. You may instead PERFORM the 51 Epic functions test.pass(), test.fail( errmsg), test.todo(msg) and51 Epic functions test.pass(), test.fail(msg), test.todo(msg) and 52 52 test.skip(msg). 53 53 2. Put your test in the "test" schema. … … 104 104 * test.assert_less_than(elem_1 anyelement, elem_2 anyelement) 105 105 * test.assert_less_than_or_equal(elem_1 anyelement, elem_2 anyelement) 106 106 107 * test.assert_rows(row_1 text, row_2 text): 107 108 Raises an exception if the SELECT statement row_1 != the SELECT statement row_2. … … 208 209 WHERE pg_namespace.nspname = 'test' 209 210 AND pg_proc.proname LIKE E'test\_%'; 211 212 213 ------------------------------ Runners ------------------------------ 210 214 211 215 … … 278 282 279 283 280 CREATE OR REPLACE FUNCTION test.finish(result text, errmsg text) RETURNS VOID AS $$ 284 ------------------------------ Pass/fail ------------------------------ 285 286 287 CREATE OR REPLACE FUNCTION test.finish(result text, msg text) RETURNS VOID AS $$ 281 288 -- Use this to finish a test. Raises the given result as an exception (for rollback). 282 289 DECLARE 283 msg text;284 BEGIN 285 msg := '[' || result || ']';286 IF errmsg IS NOT NULL THEN287 msg := msg || ' ' || errmsg;288 END IF; 289 RAISE EXCEPTION '%', msg;290 END; 291 $$ LANGUAGE plpgsql ;290 fullmsg text; 291 BEGIN 292 fullmsg := '[' || result || ']'; 293 IF msg IS NOT NULL THEN 294 fullmsg := fullmsg || ' ' || msg; 295 END IF; 296 RAISE EXCEPTION '%', fullmsg; 297 END; 298 $$ LANGUAGE plpgsql IMMUTABLE; 292 299 293 300 … … 297 304 PERFORM test.finish('OK', msg); 298 305 END; 299 $$ LANGUAGE plpgsql ;306 $$ LANGUAGE plpgsql IMMUTABLE; 300 307 CREATE OR REPLACE FUNCTION test.pass() RETURNS VOID AS $$ 301 308 -- Use this to finish a successful test. Raises exception '[OK]'. … … 303 310 PERFORM test.finish('OK', NULL); 304 311 END; 305 $$ LANGUAGE plpgsql ;312 $$ LANGUAGE plpgsql IMMUTABLE; 306 313 307 314 … … 311 318 PERFORM test.finish('FAIL', msg); 312 319 END; 313 $$ LANGUAGE plpgsql ;320 $$ LANGUAGE plpgsql IMMUTABLE; 314 321 CREATE OR REPLACE FUNCTION test.fail() RETURNS VOID AS $$ 315 322 -- Use this to finish a failed test. Raises exception '[FAIL]'. … … 317 324 PERFORM test.finish('FAIL', NULL); 318 325 END; 319 $$ LANGUAGE plpgsql ;326 $$ LANGUAGE plpgsql IMMUTABLE; 320 327 321 328 … … 325 332 PERFORM test.finish('TODO', msg); 326 333 END; 327 $$ LANGUAGE plpgsql ;334 $$ LANGUAGE plpgsql IMMUTABLE; 328 335 CREATE OR REPLACE FUNCTION test.todo() RETURNS VOID AS $$ 329 336 -- Use this to abort a test as 'todo'. Raises exception '[TODO]'. … … 331 338 PERFORM test.finish('TODO', NULL); 332 339 END; 333 $$ LANGUAGE plpgsql ;340 $$ LANGUAGE plpgsql IMMUTABLE; 334 341 335 342 … … 339 346 PERFORM test.finish('SKIP', msg); 340 347 END; 341 $$ LANGUAGE plpgsql ;348 $$ LANGUAGE plpgsql IMMUTABLE; 342 349 CREATE OR REPLACE FUNCTION test.skip() RETURNS VOID AS $$ 343 350 -- Use this to skip a test. Raises exception '[SKIP]'. … … 345 352 PERFORM test.finish('SKIP', NULL); 346 353 END; 347 $$ LANGUAGE plpgsql ;348 349 350 ------------------------------ Test helpers ------------------------------354 $$ LANGUAGE plpgsql IMMUTABLE; 355 356 357 ------------------------------ Assertions ------------------------------ 351 358 352 359 … … 520 527 -- 521 528 -- Both arguments should be SELECT statements yielding a single row or a set of rows. 529 -- It is common for the 'expected' arg to be sans a FROM clause, and simply SELECT values. 522 530 -- Neither source nor expected need to be sorted. Either may include a trailing semicolon. 523 531 -- 524 532 -- Example: 525 533 -- 526 -- PERFORM test.assert_row ('SELECT first, last, city FROM table1',527 -- 'SELECT ROW(''Davy'', ''Crockett'', NULL)');534 -- PERFORM test.assert_rows('SELECT first, last, city FROM table1', 535 -- 'SELECT ''Davy'', ''Crockett'', NULL'; 528 536 DECLARE 529 537 rec record; -
trunk/epic/test/test_results.sql
r11 r12 20 20 PERFORM test.fail('test.pass() did not raise the ''[OK]'' exception.'); 21 21 END; 22 $$ LANGUAGE plpgsql ;22 $$ LANGUAGE plpgsql IMMUTABLE; 23 23 24 24
