Changeset 18
- Timestamp:
- 08/27/08 01:19:15 (4 years ago)
- Location:
- trunk/epic
- Files:
-
- 2 modified
-
epic.sql (modified) (5 diffs)
-
test/test_asserts.sql (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/epic/epic.sql
r17 r18 108 108 Raises an exception if the SELECT statement row_1 != the SELECT statement row_2. 109 109 * test.assert_column(call text, expected anyarray[, colname text]): 110 Raises an exception if SELECT colname FROM call != expected .110 Raises an exception if SELECT colname FROM call != expected (in order). 111 111 112 112 * test.assert_raises(call text, errm text, state text): … … 649 649 650 650 CREATE OR REPLACE FUNCTION test.assert_column(call text, expected anyarray, colname text) RETURNS VOID AS $$ 651 -- Raises an exception if SELECT colname FROM call != expected .651 -- Raises an exception if SELECT colname FROM call != expected (in order). 652 652 -- 653 653 -- If colname is NULL or omitted, the first column of call's output will be used. 654 654 -- 655 655 -- 'call' can be any table, view, or procedure that returns records. 656 --657 656 -- 'expected' MUST be an array of the same type as colname. 658 -- Neither call nor expected need to be sorted.659 657 -- 660 658 -- Example: … … 665 663 DECLARE 666 664 i integer; 667 record record; 665 record1 record; 666 record2 record; 667 curs_base refcursor; 668 curs_expected refcursor; 668 669 firstname text; 670 found_1 boolean; 669 671 BEGIN 670 672 -- Dump the call output into a temp table … … 701 703 END LOOP; 702 704 703 -- Compare the two tables in setwise fashion.705 -- Compare the two tables in order. 704 706 <<TRY>> 705 707 BEGIN 706 FOR record IN EXECUTE '(SELECT * FROM _test_assert_column_base EXCEPT ALL707 SELECT * FROM _test_assert_column_expected)'708 OPEN curs_base FOR EXECUTE 'SELECT * FROM _test_assert_column_base'; 709 OPEN curs_expected FOR EXECUTE 'SELECT * FROM _test_assert_column_expected'; 708 710 LOOP 709 RAISE EXCEPTION 'result: % not in array: %', record._assert_column_result, expected; 710 END LOOP; 711 712 FOR record IN EXECUTE '(SELECT * FROM _test_assert_column_expected EXCEPT ALL 713 SELECT * FROM _test_assert_column_base)' 714 LOOP 715 RAISE EXCEPTION 'element: % not in call: %', record._assert_column_result, call; 711 FETCH curs_base INTO record1; 712 found_1 := FOUND; 713 FETCH curs_expected INTO record2; 714 IF FOUND THEN 715 IF NOT found_1 THEN 716 PERFORM test.fail('element: ' || record2._assert_column_result || ' not found in call: ' || call); 717 END IF; 718 ELSE 719 IF NOT found_1 THEN 720 EXIT; 721 ELSE 722 PERFORM test.fail('record: ' || record1._assert_column_result || ' not found in array: ' || array_to_string(expected)); 723 END IF; 724 END IF; 725 PERFORM test.assert_equal(record1._assert_column_result, record2._assert_column_result); 716 726 END LOOP; 717 727 EXCEPTION WHEN OTHERS THEN … … 721 731 END TRY; 722 732 733 CLOSE curs_base; 734 CLOSE curs_expected; 723 735 DROP TABLE _test_assert_column_base; 724 736 EXECUTE 'DROP TABLE _test_assert_column_expected'; -
trunk/epic/test/test_asserts.sql
r17 r18 374 374 EXCEPTION WHEN OTHERS THEN 375 375 failed := true; 376 IF SQLERRM = ' result: 3 not in array: {1,2}' THEN376 IF SQLERRM = '[FAIL] record: 3 not found in array: 1,2' THEN 377 377 NULL; 378 378 ELSE
