- Timestamp:
- 08/28/08 16:50:51 (4 years ago)
- Location:
- trunk/epic
- Files:
-
- 2 modified
-
epic.sql (modified) (9 diffs)
-
test/test_asserts.sql (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/epic/epic.sql
r19 r20 346 346 output_record test.results%ROWTYPE; 347 347 BEGIN 348 FOR testname IN SELECT name FROM test.testnames WHERE module = modulename 348 FOR testname IN SELECT name FROM test.testnames WHERE module = modulename ORDER BY name ASC 349 349 LOOP 350 350 SELECT INTO output_record * FROM test.run_test(testname); … … 364 364 FOR modulename in SELECT DISTINCT module FROM test.testnames ORDER BY module ASC 365 365 LOOP 366 FOR testname IN SELECT name FROM test.testnames WHERE module = modulename 366 FOR testname IN SELECT name FROM test.testnames WHERE module = modulename ORDER BY name ASC 367 367 LOOP 368 368 SELECT INTO output_record * FROM test.run_test(testname); … … 763 763 764 764 765 CREATE OR REPLACE FUNCTION test.assert_empty( tablenames text[]) RETURNS VOID AS $$766 -- Raises an exception if the given tables have any rows.765 CREATE OR REPLACE FUNCTION test.assert_empty(calls text[]) RETURNS VOID AS $$ 766 -- Raises an exception if the given calls have any rows. 767 767 DECLARE 768 768 result bool; … … 770 770 failed_len int; 771 771 BEGIN 772 IF array_lower( tablenames, 1) IS NOT NULL THEN773 FOR i in array_lower( tablenames, 1)..array_upper(tablenames, 1)772 IF array_lower(calls, 1) IS NOT NULL THEN 773 FOR i in array_lower(calls, 1)..array_upper(calls, 1) 774 774 LOOP 775 EXECUTE 'SELECT (EXISTS (SELECT 1 FROM ' || tablenames[i] || '));' INTO result;775 EXECUTE 'SELECT EXISTS (' || test.statement(calls[i]) || ');' INTO result; 776 776 IF result THEN 777 failed := failed || ('"' || btrim( tablenames[i]) || '"');777 failed := failed || ('"' || btrim(calls[i]) || '"'); 778 778 END IF; 779 779 END LOOP; … … 783 783 failed_len := (array_upper(failed, 1) - array_lower(failed, 1)) + 1; 784 784 IF failed_len = 1 THEN 785 PERFORM test.fail('The table' || array_to_string(failed, ', ') || ' is not empty.');785 PERFORM test.fail('The call ' || array_to_string(failed, ', ') || ' is not empty.'); 786 786 ELSEIF failed_len > 1 THEN 787 PERFORM test.fail('The tables ' || array_to_string(failed, ', ') || ' are not empty.');787 PERFORM test.fail('The calls ' || array_to_string(failed, ', ') || ' are not empty.'); 788 788 END IF; 789 789 END IF; … … 791 791 $$ LANGUAGE plpgsql; 792 792 793 CREATE OR REPLACE FUNCTION test.assert_empty( tablenametext) RETURNS VOID AS $$794 -- Raises an exception if the given table has any rows.793 CREATE OR REPLACE FUNCTION test.assert_empty(call text) RETURNS VOID AS $$ 794 -- Raises an exception if the given call returns any rows. 795 795 DECLARE 796 796 result bool; 797 797 BEGIN 798 IF tablename LIKE '%,%' THEN 799 PERFORM test.assert_empty(string_to_array(tablename, ',')); 800 RETURN; 801 END IF; 802 803 EXECUTE 'SELECT (EXISTS (SELECT 1 FROM ' || tablename || '));' INTO result; 798 EXECUTE 'SELECT EXISTS (' || test.statement(call) || ');' INTO result; 804 799 IF result THEN 805 PERFORM test.fail('The table "' || tablename|| '" is not empty.');806 END IF; 807 END; 808 $$ LANGUAGE plpgsql; 809 810 811 CREATE OR REPLACE FUNCTION test.assert_not_empty( tablenames text[]) RETURNS VOID AS $$812 -- Raises an exception if the given tables have no rows.800 PERFORM test.fail('The call "' || call || '" is not empty.'); 801 END IF; 802 END; 803 $$ LANGUAGE plpgsql; 804 805 806 CREATE OR REPLACE FUNCTION test.assert_not_empty(calls text[]) RETURNS VOID AS $$ 807 -- Raises an exception if the given calls have no rows. 813 808 DECLARE 814 809 result bool; … … 816 811 failed_len int; 817 812 BEGIN 818 IF array_lower( tablenames, 1) IS NOT NULL THEN819 FOR i in array_lower( tablenames, 1)..array_upper(tablenames, 1)813 IF array_lower(calls, 1) IS NOT NULL THEN 814 FOR i in array_lower(calls, 1)..array_upper(calls, 1) 820 815 LOOP 821 EXECUTE 'SELECT (EXISTS (SELECT 1 FROM ' || tablenames[i] || '));' INTO result;816 EXECUTE 'SELECT EXISTS (' || test.statement(calls[i]) || ');' INTO result; 822 817 IF NOT result THEN 823 failed := failed || ('"' || btrim( tablenames[i]) || '"');818 failed := failed || ('"' || btrim(calls[i]) || '"'); 824 819 END IF; 825 820 END LOOP; … … 832 827 failed_len := (array_upper(failed, 1) - array_lower(failed, 1)) + 1; 833 828 IF failed_len = 1 THEN 834 PERFORM test.fail('The table' || array_to_string(failed, ', ') || ' is empty.');829 PERFORM test.fail('The call ' || array_to_string(failed, ', ') || ' is empty.'); 835 830 ELSEIF failed_len > 1 THEN 836 PERFORM test.fail('The tables ' || array_to_string(failed, ', ') || ' are empty.');831 PERFORM test.fail('The calls ' || array_to_string(failed, ', ') || ' are empty.'); 837 832 END IF; 838 833 END IF; … … 840 835 $$ LANGUAGE plpgsql; 841 836 842 CREATE OR REPLACE FUNCTION test.assert_not_empty( tablenametext) RETURNS VOID AS $$837 CREATE OR REPLACE FUNCTION test.assert_not_empty(call text) RETURNS VOID AS $$ 843 838 -- Raises an exception if the given table has no rows. 844 839 DECLARE 845 840 result bool; 846 841 BEGIN 847 IF tablename LIKE '%,%' THEN 848 PERFORM test.assert_not_empty(string_to_array(tablename, ',')); 849 RETURN; 850 END IF; 851 852 EXECUTE 'SELECT (EXISTS (SELECT 1 FROM ' || tablename || '));' INTO result; 842 EXECUTE 'SELECT EXISTS (' || test.statement(call) || ');' INTO result; 853 843 IF NOT result THEN 854 PERFORM test.fail('The table "' || tablename|| '" is empty.');855 END IF; 856 END; 857 $$ LANGUAGE plpgsql; 858 844 PERFORM test.fail('The call "' || call || '" is empty.'); 845 END IF; 846 END; 847 $$ LANGUAGE plpgsql; 848 -
trunk/epic/test/test_asserts.sql
r19 r20 400 400 -- array version 401 401 CREATE TEMP TABLE testtemp2 (a int); 402 PERFORM test.assert_empty(' testtemp, testtemp2');402 PERFORM test.assert_empty('{testtemp, testtemp2}'::text[]); 403 403 PERFORM test.assert_empty(ARRAY['testtemp', 'testtemp2']); 404 404 … … 406 406 failed := false; 407 407 BEGIN 408 PERFORM test.assert_empty(' pg_type,pg_proc');408 PERFORM test.assert_empty('{pg_type,pg_proc}'::text[]); 409 409 EXCEPTION WHEN OTHERS THEN 410 410 failed := true; 411 IF SQLERRM = '[FAIL] The tables "pg_type", "pg_proc" are not empty.' THEN411 IF SQLERRM = '[FAIL] The calls "pg_type", "pg_proc" are not empty.' THEN 412 412 NULL; 413 413 ELSE … … 422 422 END; 423 423 $$ LANGUAGE plpgsql; 424 425 426 CREATE OR REPLACE FUNCTION test.test_assert_not_empty() RETURNS VOID AS $$ 427 -- Assert the correct operation of test.assert_not_empty 428 -- module: test_asserts 429 DECLARE 430 failed bool; 431 BEGIN 432 -- Test an assertion that should pass 433 CREATE TEMP TABLE testtemp AS SELECT * FROM generate_series(1, 10); 434 PERFORM test.assert_not_empty('testtemp'); 435 -- array version 436 CREATE TEMP TABLE testtemp2 AS SELECT * FROM generate_series(1, 5); 437 PERFORM test.assert_not_empty('{testtemp, testtemp2}'::text[]); 438 PERFORM test.assert_not_empty(ARRAY['testtemp', 'testtemp2']); 439 440 -- ...and an assertion that should fail 441 CREATE TEMP TABLE testtemp3 (a int); 442 failed := false; 443 BEGIN 444 PERFORM test.assert_not_empty('testtemp3'); 445 EXCEPTION WHEN OTHERS THEN 446 failed := true; 447 IF SQLERRM = '[FAIL] The call "testtemp3" is empty.' THEN 448 NULL; 449 ELSE 450 RAISE EXCEPTION 'test.assert_not_empty() did not raise the correct error. Raised: %', SQLERRM; 451 END IF; 452 END; 453 IF NOT failed THEN 454 PERFORM test.fail('test.assert_not_empty() did not fail.'); 455 END IF; 456 457 RAISE EXCEPTION '[OK]'; 458 END; 459 $$ LANGUAGE plpgsql;
