Show
Ignore:
Timestamp:
09/07/08 23:57:57 (4 years ago)
Author:
fumanchu
Message:

Lots of changes:

  1. Changed global to return the TEMP tablename instead of a record. Use the new test.get function to obtain a record.
  2. Added a 'name' arg to global to re-use the TEMP table.
  3. New test.get(call, rownum).
  4. Moved the few public functions into the test schema.
  5. Moved the under-under attributes to new functions: constructor, len, iter.
  6. Made run_test prepend the test schema to search_path.
Files:
1 modified

Legend:

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

    r22 r23  
    44CREATE OR REPLACE FUNCTION test._test_global() RETURNS VOID AS $$ 
    55DECLARE 
     6  g      text; 
     7  g2     text; 
    68  rec    record; 
    79  trec   record; 
    810BEGIN 
    9   rec := global('pg_namespace WHERE nspname = ''test'';'); 
     11  g := global('pg_namespace WHERE nspname = ''test'';'); 
    1012   
    11   -- The result of global() should be a normal record. 
     13  -- The returned string MUST be the name of the TEMP table. 
     14  PERFORM test.assert(g LIKE E'\_global\_%', g || ' not like _global'); 
     15   
     16  rec := get(g); 
     17   
     18  -- The result of get() should be a normal record. 
    1219  PERFORM test.assert_equal(rec.nspname, 'test'); 
    1320   
     
    1522  PERFORM test.assert(rec.__name__ LIKE E'\_global\_%', rec.__name__ || ' not like _global'); 
    1623   
    17   -- The .__name__ MUST reference a temporary table with the same fields. 
    18   EXECUTE 'SELECT * FROM ' || rec.__name__ INTO trec; 
     24  -- The global MUST reference a temporary table with the same fields. 
     25  EXECUTE 'SELECT * FROM ' || g INTO trec; 
    1926  PERFORM test.assert_equal(trec.nspname, 'test'); 
    2027  PERFORM test.assert_equal(trec.nspowner, rec.nspowner); 
    2128  PERFORM test.assert_equal(trec.nspacl, rec.nspacl); 
    2229   
    23   -- The returned record MUST possess a .__create__ attribute. 
    24   PERFORM test.assert_equal(rec.__create__, 'SELECT * FROM pg_namespace WHERE nspname = ''test'''); 
     30  -- The TEMP table MUST possess its own constructor SQL string in a COMMENT 
     31  PERFORM test.assert_equal(constructor(g), 'SELECT * FROM pg_namespace WHERE nspname = ''test'''); 
    2532   
    26   -- The returned record MUST possess a .__record__ attribute. 
    27   PERFORM test.assert_equal(rec.__record__, 
    28     'SELECT * FROM _global_record(''' || rec.__name__ || ''', ''' || rec.__create__ || ''')'); 
     33  -- Test the iter() function. 
     34  g2 := global('iter(''' || g || ''')'); 
     35  PERFORM test.assert_not_empty(g2); 
    2936   
    30   -- The returned record MUST possess an .__iter__ attribute. 
    31   PERFORM test.assert_equal(rec.__iter__, 'SELECT * FROM ' || rec.__name__); 
    32   PERFORM test.assert_not_empty(rec.__iter__); 
     37  -- Test the attributes() function. 
     38  PERFORM test.assert_column('SELECT attname FROM attributes(''' || g || ''')', 
     39                             ARRAY['nspname', 'nspowner', 'nspacl']); 
    3340   
    34   -- The returned record MUST possess an .__attributes__ attribute. 
    35   PERFORM test.assert_equal(rec.__attributes__, 'SELECT attname FROM test.attributes(''' || rec.__name__ || ''')'); 
    36   PERFORM test.assert_column(rec.__attributes__, ARRAY['nspname', 'nspowner', 'nspacl']); 
    37    
    38   -- The returned record MUST possess a .__len__ attribute. 
    39   PERFORM test.assert_equal(rec.__len__, 1); 
     41  -- Test the len() function. 
     42  PERFORM test.assert_equal(len(g), 1); 
    4043   
    4144  -- Raise an exception to test deletion of the TEMP table ON COMMIT 
    42   RAISE EXCEPTION '%', rec.__name__; 
     45  RAISE EXCEPTION '%', g; 
    4346END; 
    4447$$ LANGUAGE plpgsql;