Changeset 18

Show
Ignore:
Timestamp:
08/27/08 01:19:15 (4 years ago)
Author:
fumanchu
Message:

Made assert_column compare the call and expected array in order.

Location:
trunk/epic
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • trunk/epic/epic.sql

    r17 r18  
    108108        Raises an exception if the SELECT statement row_1 != the SELECT statement row_2. 
    109109    * 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). 
    111111     
    112112    * test.assert_raises(call text, errm text, state text):  
     
    649649 
    650650CREATE 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). 
    652652-- 
    653653-- If colname is NULL or omitted, the first column of call's output will be used. 
    654654-- 
    655655-- 'call' can be any table, view, or procedure that returns records. 
    656 --  
    657656-- 'expected' MUST be an array of the same type as colname. 
    658 -- Neither call nor expected need to be sorted. 
    659657--  
    660658-- Example: 
     
    665663DECLARE 
    666664  i             integer; 
    667   record        record; 
     665  record1       record; 
     666  record2       record; 
     667  curs_base     refcursor; 
     668  curs_expected refcursor; 
    668669  firstname     text; 
     670  found_1       boolean; 
    669671BEGIN 
    670672  -- Dump the call output into a temp table 
     
    701703  END LOOP; 
    702704   
    703   -- Compare the two tables in setwise fashion. 
     705  -- Compare the two tables in order. 
    704706  <<TRY>> 
    705707  BEGIN 
    706     FOR record IN EXECUTE '(SELECT * FROM _test_assert_column_base EXCEPT ALL 
    707                             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'; 
    708710    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); 
    716726    END LOOP; 
    717727  EXCEPTION WHEN OTHERS THEN 
     
    721731  END TRY; 
    722732   
     733  CLOSE curs_base; 
     734  CLOSE curs_expected; 
    723735  DROP TABLE _test_assert_column_base; 
    724736  EXECUTE 'DROP TABLE _test_assert_column_expected'; 
  • trunk/epic/test/test_asserts.sql

    r17 r18  
    374374  EXCEPTION WHEN OTHERS THEN 
    375375    failed := true; 
    376     IF SQLERRM = 'result: 3 not in array: {1,2}' THEN 
     376    IF SQLERRM = '[FAIL] record: 3 not found in array: 1,2' THEN 
    377377      NULL; 
    378378    ELSE