Changeset 6 for trunk/epic

Show
Ignore:
Timestamp:
08/16/08 17:57:42 (4 years ago)
Author:
fumanchu
Message:

Made run_test return a record just like the other run_* functions.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/epic/epic.sql

    r5 r6  
    210210 
    211211 
    212 CREATE OR REPLACE FUNCTION test.run_test(testname text) RETURNS boolean AS $$ 
    213 -- Runs the named test, stores in test.results, and returns success. 
    214 BEGIN 
    215   DELETE FROM test.results WHERE name = testname; 
    216    
    217   BEGIN 
    218     EXECUTE 'SELECT * FROM test.' || testname || '();'; 
    219   EXCEPTION WHEN OTHERS THEN 
    220     IF SQLERRM = '[OK]' THEN 
    221       INSERT INTO test.results (name, ok) VALUES (testname, TRUE); 
    222       RETURN TRUE; 
    223     ELSE 
    224       INSERT INTO test.results (name, ok, errcode, errmsg) 
    225            VALUES (testname, FALSE, SQLSTATE, SQLERRM); 
    226       RETURN FALSE; 
    227     END IF; 
    228   END; 
    229    
    230   RAISE EXCEPTION 'Test % did not raise an exception as it should have. Exceptions must ALWAYS be raised in test procedures for rollback.', testname; 
    231 END; 
    232 $$ LANGUAGE plpgsql; 
    233  
    234  
    235212CREATE OR REPLACE VIEW test.testnames AS 
    236213  SELECT pg_proc.proname AS name, 
     
    242219 
    243220 
     221CREATE OR REPLACE FUNCTION test.run_test(testname text) RETURNS test.suite_results AS $$ 
     222-- Runs the named test, stores in test.results, and returns success. 
     223DECLARE 
     224  modulename      text; 
     225  output_record   test.suite_results%ROWTYPE; 
     226BEGIN 
     227  SELECT module INTO modulename FROM test.testnames WHERE name = testname; 
     228  DELETE FROM test.results WHERE name = testname; 
     229   
     230  BEGIN 
     231    EXECUTE 'SELECT * FROM test.' || testname || '();'; 
     232  EXCEPTION WHEN OTHERS THEN 
     233    IF SQLERRM = '[OK]' THEN 
     234      INSERT INTO test.results (name, module, ok) 
     235        VALUES (testname, modulename, TRUE) 
     236        RETURNING name, module, CASE WHEN ok=true THEN '[OK]' ELSE '[FAIL]' END, errcode, errmsg 
     237        INTO output_record; 
     238      RETURN output_record; 
     239    ELSE 
     240      INSERT INTO test.results (name, module, ok, errcode, errmsg) 
     241        VALUES (testname, modulename, FALSE, SQLSTATE, SQLERRM) 
     242        RETURNING name, module, CASE WHEN ok=true THEN '[OK]' ELSE '[FAIL]' END, errcode, errmsg 
     243        INTO output_record; 
     244      RETURN output_record; 
     245    END IF; 
     246  END; 
     247   
     248  RAISE EXCEPTION 'Test % did not raise an exception as it should have. Exceptions must ALWAYS be raised in test procedures for rollback.', testname; 
     249END; 
     250$$ LANGUAGE plpgsql; 
     251 
     252 
    244253CREATE OR REPLACE FUNCTION test.run_module(modulename text) RETURNS SETOF test.suite_results AS $$ 
    245254-- Runs all tests in the given module, stores in test.results, and returns results. 
     
    248257  output_record   test.suite_results%ROWTYPE; 
    249258BEGIN 
    250   FOR testname IN SELECT name, module FROM test.testnames WHERE module = modulename 
     259  FOR testname IN SELECT name FROM test.testnames WHERE module = modulename 
    251260  LOOP 
    252     PERFORM test.run_test(testname); 
    253     UPDATE test.results SET module = modulename WHERE name = testname; 
    254   END LOOP; 
    255    
    256   FOR output_record in 
    257     SELECT name, module, CASE WHEN ok=true THEN '[OK]' ELSE '[FAIL]' END, 
    258            errcode, errmsg 
    259     FROM test.results 
    260     WHERE module = modulename 
    261   LOOP 
     261    SELECT INTO output_record * FROM test.run_test(testname); 
    262262    RETURN NEXT output_record; 
    263263  END LOOP; 
     
    277277    FOR testname IN SELECT name FROM test.testnames WHERE module = modulename 
    278278    LOOP 
    279       PERFORM test.run_test(testname); 
    280       UPDATE test.results SET module = modulename WHERE name = testname; 
     279      SELECT INTO output_record * FROM test.run_test(testname); 
     280      RETURN NEXT output_record; 
    281281    END LOOP; 
    282   END LOOP; 
    283    
    284   FOR output_record in 
    285     SELECT name, module, CASE WHEN ok=true THEN '[OK]' ELSE '[FAIL]' END, errcode, errmsg 
    286     FROM test.results 
    287   LOOP 
    288     RETURN NEXT output_record; 
    289282  END LOOP; 
    290283END;