Show
Ignore:
Timestamp:
08/28/08 16:50:51 (4 years ago)
Author:
fumanchu
Message:

Made assert_empty more generic; now takes call(s) not just tablename(s). Also ordered the output of run_module and run_all, and added a test for assert_not_empty.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/epic/test/test_asserts.sql

    r19 r20  
    400400  -- array version 
    401401  CREATE TEMP TABLE testtemp2 (a int); 
    402   PERFORM test.assert_empty('testtemp, testtemp2'); 
     402  PERFORM test.assert_empty('{testtemp, testtemp2}'::text[]); 
    403403  PERFORM test.assert_empty(ARRAY['testtemp', 'testtemp2']); 
    404404   
     
    406406  failed := false; 
    407407  BEGIN 
    408     PERFORM test.assert_empty('pg_type,pg_proc'); 
     408    PERFORM test.assert_empty('{pg_type,pg_proc}'::text[]); 
    409409  EXCEPTION WHEN OTHERS THEN 
    410410    failed := true; 
    411     IF SQLERRM = '[FAIL] The tables "pg_type", "pg_proc" are not empty.' THEN 
     411    IF SQLERRM = '[FAIL] The calls "pg_type", "pg_proc" are not empty.' THEN 
    412412      NULL; 
    413413    ELSE 
     
    422422END; 
    423423$$ LANGUAGE plpgsql; 
     424 
     425 
     426CREATE 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 
     429DECLARE 
     430  failed     bool; 
     431BEGIN 
     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]'; 
     458END; 
     459$$ LANGUAGE plpgsql;