Changeset 4 for trunk/epic

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

More assert tests, plus a bunch of cleanups.

Location:
trunk/epic
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • trunk/epic/epic.sql

    r2 r4  
    442442--  
    443443-- Example: 
    444 --    PERFORM test.assert_values('user_id', 
     444--    PERFORM test.assert_values( 
    445445--      'get_favorite_user_ids(' || user_id || ');', 
    446 --      '{24, 10074, 87321}'); 
     446--      ARRAY[24, 10074, 87321], 'user_id'); 
    447447--  
    448448DECLARE 
     
    451451  firstname     text; 
    452452BEGIN 
     453  -- Dump the source into a temp table 
    453454  IF colname IS NULL THEN 
    454455    EXECUTE 'CREATE TEMPORARY TABLE _test_assert_values_base AS ' || 
     
    463464    EXECUTE 'ALTER TABLE _test_assert_values_base RENAME ' || firstname || ' TO result;'; 
    464465  ELSE 
    465     -- Dump the source into a temp table 
    466466    EXECUTE 'CREATE TEMPORARY TABLE _test_assert_values_base AS ' || 
    467467      'SELECT ' || colname || ' AS result FROM ' || source || ';'; 
     
    477477  END LOOP; 
    478478   
     479  -- Compare the two tables in setwise fashion. 
    479480  <<TRY>> 
    480481  BEGIN 
  • trunk/epic/test/test_asserts.sql

    r3 r4  
    3535 
    3636 
    37 CREATE OR REPLACE FUNCTION test.test_assert() RETURNS VOID AS $$ 
    38 -- Assert the correct operation of test.assert 
     37CREATE OR REPLACE FUNCTION test.test_assert_raises() RETURNS VOID AS $$ 
     38-- Assert the correct operation of test.assert_raises 
    3939-- module: test_asserts 
    4040DECLARE 
     
    4242  failed    bool; 
    4343BEGIN 
    44   -- assert() MUST return VOID if the given assertion holds. 
    45   SELECT INTO retval * FROM test.assert(true, 'truth is falsehood!'); 
    46   IF retval != '' THEN 
    47     RAISE EXCEPTION 'test.assert() did not return void.'; 
    48   END IF; 
    49    
    50   -- assert() MUST raise an exception if the given assertion does not hold. 
     44  -- assert_raises() MUST return VOID if an error is raised. 
     45  SELECT INTO retval * FROM test.assert_raises('unknown', 'relation "unknown" does not exist', '42P01'); 
     46  IF retval != '' THEN 
     47    RAISE EXCEPTION 'test.assert_raises() did not return void.'; 
     48  END IF; 
     49   
     50  -- assert_raises() MUST raise an exception if no error is raised. 
    5151  failed := false; 
    5252  BEGIN 
    53     SELECT INTO retval * FROM test.assert(false, 'falsehood is truth'); 
     53    SELECT INTO retval * FROM test.assert_raises('pg_namespace', '', ''); 
    5454  EXCEPTION WHEN OTHERS THEN 
    5555    failed := true; 
    56     IF SQLERRM = 'falsehood is truth' THEN 
     56    IF SQLERRM = 'Call: ''pg_namespace'' did not raise an error.' THEN 
    5757      NULL; 
    5858    ELSE 
    59       RAISE EXCEPTION 'test.assert(false) did not raise the given message on falsehood.'; 
     59      RAISE EXCEPTION 'test.assert_raises() did not raise the given message on falsehood. Raised: %', SQLERRM; 
    6060    END IF; 
    6161  END; 
    6262  IF NOT failed THEN 
    63     RAISE EXCEPTION 'test.assert(false) did not fail.'; 
    64   END IF; 
     63    RAISE EXCEPTION 'test.assert_raises() did not fail.'; 
     64  END IF; 
     65   
     66  RAISE EXCEPTION '[OK]'; 
     67END; 
     68$$ LANGUAGE plpgsql; 
     69 
     70 
     71CREATE OR REPLACE FUNCTION test.test_assert() RETURNS VOID AS $$ 
     72-- Assert the correct operation of test.assert 
     73-- module: test_asserts 
     74DECLARE 
     75  retval    text; 
     76BEGIN 
     77  -- assert() MUST return VOID if the given assertion holds. 
     78  SELECT INTO retval * FROM test.assert(true, 'truth is falsehood!'); 
     79  IF retval != '' THEN 
     80    RAISE EXCEPTION 'test.assert() did not return void.'; 
     81  END IF; 
     82   
     83  -- assert() MUST raise an exception if the given assertion does not hold. 
     84  PERFORM test.assert_raises('test.assert(false, ''falsehood is truth'')', 
     85                             'falsehood is truth', 'P0001'); 
    6586   
    6687  -- assert() MUST raise an exception if the given assertion is NULL. 
     88  PERFORM test.assert_raises('test.assert(null, ''null should choke'')', 
     89                             'Assertion test may not be NULL.', 'P0001'); 
     90   
     91  RAISE EXCEPTION '[OK]'; 
     92END; 
     93$$ LANGUAGE plpgsql; 
     94 
     95 
     96CREATE OR REPLACE FUNCTION test.test_assert_equal() RETURNS VOID AS $$ 
     97-- Assert the correct operation of test.assert_equal 
     98-- module: test_asserts 
     99DECLARE 
     100  retval    text; 
     101BEGIN 
     102  -- assert_equal() MUST return VOID if the given assertion holds. 
     103  SELECT INTO retval * FROM test.assert_equal(1, 1); 
     104  IF retval != '' THEN 
     105    RAISE EXCEPTION 'test.assert_equal() did not return void for (1, 1).'; 
     106  END IF; 
     107  SELECT INTO retval * FROM test.assert_equal('abc'::text, 'abc'); 
     108  IF retval != '' THEN 
     109    RAISE EXCEPTION 'test.assert_equal() did not return void for (''abc'', ''abc'').'; 
     110  END IF; 
     111   
     112  -- assert_equal() MUST raise an exception if the given assertion does not hold. 
     113  PERFORM test.assert_raises('test.assert_equal(1, 2)', '1 != 2', 'P0001'); 
     114   
     115  PERFORM test.assert_raises('test.assert_equal(''abc''::text, ''xyz'')', 'abc != xyz', 'P0001'); 
     116   
     117  -- assert_equal() MUST return VOID if both args are null. 
     118  SELECT INTO retval * FROM test.assert_equal(NULL::int, NULL); 
     119  IF retval != '' THEN 
     120    RAISE EXCEPTION 'test.assert_equal() did not return void for (null, null).'; 
     121  END IF; 
     122   
     123  -- assert_equal() MUST raise an exception if only one arg is NULL. 
     124  PERFORM test.assert_raises('test.assert_equal(8, NULL::int)', '8 != <NULL>', 'P0001'); 
     125  PERFORM test.assert_raises('test.assert_equal(NULL::int, 7)', '<NULL> != 7', 'P0001'); 
     126   
     127  -- assert_equal() will raise an undefined_function exception if the args have different types. 
     128  -- It would be nice to find a way around this (without writing M x N overloaded funcs). 
     129  PERFORM test.assert_raises('test.assert_equal(8, ''abc''::text)', 
     130    'function test.assert_equal(integer, text) does not exist', '42883'); 
     131   
     132  RAISE EXCEPTION '[OK]'; 
     133END; 
     134$$ LANGUAGE plpgsql; 
     135 
     136 
     137CREATE OR REPLACE FUNCTION test.test_assert_not_equal() RETURNS VOID AS $$ 
     138-- Assert the correct operation of test.assert_not_equal 
     139-- module: test_asserts 
     140DECLARE 
     141  retval    text; 
     142BEGIN 
     143  -- assert_not_equal() MUST return VOID if the given assertion does not hold. 
     144  SELECT INTO retval * FROM test.assert_not_equal(1, 2); 
     145  IF retval != '' THEN 
     146    RAISE EXCEPTION 'test.assert_not_equal() did not return void for (1, 2).'; 
     147  END IF; 
     148  SELECT INTO retval * FROM test.assert_not_equal('abc'::text, 'xyz'); 
     149  IF retval != '' THEN 
     150    RAISE EXCEPTION 'test.assert_not_equal() did not return void for (''abc'', ''xyz'').'; 
     151  END IF; 
     152   
     153  -- assert_not_equal() MUST raise an exception if the given assertion holds. 
     154  PERFORM test.assert_raises('test.assert_not_equal(1, 1)', '1 = 1', 'P0001'); 
     155  PERFORM test.assert_raises('test.assert_not_equal(''abc''::text, ''abc'')', 'abc = abc', 'P0001'); 
     156   
     157  -- assert_not_equal() MUST return VOID if only one arg is NULL. 
     158  SELECT INTO retval * FROM test.assert_not_equal(8, NULL); 
     159  IF retval != '' THEN 
     160    RAISE EXCEPTION 'test.assert_not_equal() did not return void for (8, null).'; 
     161  END IF; 
     162  SELECT INTO retval * FROM test.assert_not_equal(NULL, 7); 
     163  IF retval != '' THEN 
     164    RAISE EXCEPTION 'test.assert_not_equal() did not return void for (null, 7).'; 
     165  END IF; 
     166   
     167  -- assert_not_equal() MUST raise an exception if both args are NULL. 
     168  PERFORM test.assert_raises('test.assert_not_equal(NULL::int, NULL)', '<NULL> = <NULL>', 'P0001'); 
     169   
     170  -- assert_not_equal() will raise an undefined_function exception if the args have different types. 
     171  -- It would be nice to find a way around this (without writing M x N overloaded funcs). 
     172  PERFORM test.assert_raises('test.assert_not_equal(8, ''abc''::text)',  
     173    'function test.assert_not_equal(integer, text) does not exist', '42883'); 
     174   
     175  RAISE EXCEPTION '[OK]'; 
     176END; 
     177$$ LANGUAGE plpgsql; 
     178 
     179 
     180CREATE OR REPLACE FUNCTION test.test_assert_less_than_or_equal() RETURNS VOID AS $$ 
     181-- Assert the correct operation of test.assert_less_than_or_equal 
     182-- module: test_asserts 
     183DECLARE 
     184  retval    text; 
     185BEGIN 
     186  -- assert_less_than_or_equal() MUST return VOID if a <= b. 
     187  SELECT INTO retval * FROM test.assert_less_than_or_equal(1, 2); 
     188  IF retval != '' THEN 
     189    RAISE EXCEPTION 'test.assert_less_than_or_equal() did not return void for (1, 2).'; 
     190  END IF; 
     191  SELECT INTO retval * FROM test.assert_less_than_or_equal(1, 1); 
     192  IF retval != '' THEN 
     193    RAISE EXCEPTION 'test.assert_less_than_or_equal() did not return void for (1, 1).'; 
     194  END IF; 
     195  SELECT INTO retval * FROM test.assert_less_than_or_equal('abc'::text, 'xyz'); 
     196  IF retval != '' THEN 
     197    RAISE EXCEPTION 'test.assert_less_than_or_equal() did not return void for (''abc'', ''xyz'').'; 
     198  END IF; 
     199  SELECT INTO retval * FROM test.assert_less_than_or_equal('abc'::text, 'abc'); 
     200  IF retval != '' THEN 
     201    RAISE EXCEPTION 'test.assert_less_than_or_equal() did not return void for (''abc'', ''abc'').'; 
     202  END IF; 
     203   
     204  -- assert_less_than_or_equal() MUST raise an exception if a > b. 
     205  PERFORM test.assert_raises('test.assert_less_than_or_equal(2, 1)', '2 not <= 1', 'P0001'); 
     206  PERFORM test.assert_raises('test.assert_less_than_or_equal(''xyz''::text, ''abc'')',  
     207    'xyz not <= abc', 'P0001'); 
     208   
     209  -- assert_less_than_or_equal() MUST raise an exception if either arg is NULL. 
     210  PERFORM test.assert_raises('test.assert_less_than_or_equal(NULL::int, NULL)',  
     211    'Assertion arguments may not be NULL.', 'P0001'); 
     212   
     213  -- assert_less_than_or_equal() will raise an undefined_function exception if the args have different types. 
     214  -- It would be nice to find a way around this (without writing M x N overloaded funcs). 
     215  PERFORM test.assert_raises('test.assert_less_than_or_equal(8, ''abc''::text)',  
     216    'function test.assert_less_than_or_equal(integer, text) does not exist', '42883'); 
     217   
     218  RAISE EXCEPTION '[OK]'; 
     219END; 
     220$$ LANGUAGE plpgsql; 
     221 
     222 
     223CREATE OR REPLACE FUNCTION test.test_record_asserter() RETURNS VOID AS $$ 
     224-- Assert the correct operation of test.record_asserter 
     225-- module: test_asserts 
     226DECLARE 
     227  assertion    text; 
     228  assertions   text[]; 
     229  old          record; 
     230  new          record; 
     231BEGIN 
     232  FOR assertion in 
     233    SELECT * FROM test.record_asserter('old', 'new', 'first, last, city') 
     234  LOOP 
     235    assertions := assertions || assertion; 
     236  END LOOP; 
     237   
     238  IF assertions <> ARRAY['PERFORM test.assert_equal("old"."first", "new"."first");', 
     239                         'PERFORM test.assert_equal("old"."last", "new"."last");', 
     240                         'PERFORM test.assert_equal("old".city, "new".city);'] THEN 
     241    RAISE EXCEPTION 'record_asserter did not return the proper SQL. %', assertions; 
     242  END IF; 
     243   
     244  -- Now just for fun, execute the returned SQL. 
     245  CREATE TEMPORARY TABLE _test_user (first text, last text, city text); 
     246  INSERT INTO _test_user VALUES ('Michael', 'Stonebraker', 'New York'); 
     247  SELECT INTO old * FROM _test_user WHERE city = 'New York'; 
     248  SELECT INTO new * FROM _test_user WHERE city = 'New York'; 
     249  FOR i IN array_lower(assertions, 1)..array_upper(assertions, 1) 
     250  LOOP 
     251    PERFORM assertions[i]; 
     252  END LOOP; 
     253   
     254  RAISE EXCEPTION '[OK]'; 
     255END; 
     256$$ LANGUAGE plpgsql; 
     257 
     258 
     259CREATE OR REPLACE FUNCTION test.test_assert_values() RETURNS VOID AS $$ 
     260-- Assert the correct operation of test.assert_values 
     261-- module: test_asserts 
     262DECLARE 
     263  failed     bool; 
     264BEGIN 
     265  PERFORM test.assert_values( 
     266    'generate_series(1, 10);', 
     267    ARRAY[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]); 
     268   
    67269  failed := false; 
    68270  BEGIN 
    69     SELECT INTO retval * FROM test.assert(null, 'null should choke'); 
     271    PERFORM test.assert_values('generate_series(1, 10);', ARRAY[1, 2]); 
    70272  EXCEPTION WHEN OTHERS THEN 
    71273    failed := true; 
    72     IF SQLERRM = 'Assertion test may not be NULL.' THEN 
     274    IF SQLERRM = 'result: 3 not in array: {1,2}' THEN 
    73275      NULL; 
    74276    ELSE 
    75       RAISE EXCEPTION 'test.assert(null) did not raise the correct exception.'; 
     277      RAISE EXCEPTION 'test.assert_values() did not raise the correct error. Raised: %', SQLERRM; 
    76278    END IF; 
    77279  END; 
    78280  IF NOT failed THEN 
    79     RAISE EXCEPTION 'test.assert(null) did not fail.'; 
    80   END IF; 
    81    
    82   RAISE EXCEPTION '[OK]'; 
    83 END; 
    84 $$ LANGUAGE plpgsql; 
    85  
    86  
    87 CREATE OR REPLACE FUNCTION test.test_assert_equal() RETURNS VOID AS $$ 
    88 -- Assert the correct operation of test.assert_equal 
    89 -- module: test_asserts 
    90 DECLARE 
    91   retval    text; 
    92   dummy     int; 
    93   failed    bool; 
    94 BEGIN 
    95   -- assert_equal() MUST return VOID if the given assertion holds. 
    96   SELECT INTO retval * FROM test.assert_equal(1, 1); 
    97   IF retval != '' THEN 
    98     RAISE EXCEPTION 'test.assert_equal() did not return void for (1, 1).'; 
    99   END IF; 
    100   SELECT INTO retval * FROM test.assert_equal('abc'::text, 'abc'); 
    101   IF retval != '' THEN 
    102     RAISE EXCEPTION 'test.assert_equal() did not return void for (''abc'', ''abc'').'; 
    103   END IF; 
    104    
    105   -- assert_equal() MUST raise an exception if the given assertion does not hold. 
    106   failed := false; 
    107   BEGIN 
    108     SELECT INTO retval * FROM test.assert_equal(1, 2); 
    109   EXCEPTION WHEN OTHERS THEN 
    110     failed := true; 
    111     IF SQLERRM = '1 != 2' THEN 
    112       NULL; 
    113     ELSE 
    114       RAISE EXCEPTION 'test.assert_equal() did not raise the correct message on failure. Expected ''1 != 2'', received ''%''', SQLERRM; 
    115     END IF; 
    116   END; 
    117   IF NOT failed THEN 
    118     RAISE EXCEPTION 'test.assert_equal(1, 2) did not fail.'; 
    119   END IF; 
    120    
    121   failed := false; 
    122   BEGIN 
    123     SELECT INTO retval * FROM test.assert_equal('abc'::text, 'xyz'); 
    124   EXCEPTION WHEN OTHERS THEN 
    125     failed := true; 
    126     IF SQLERRM = 'abc != xyz' THEN 
    127       NULL; 
    128     ELSE 
    129       RAISE EXCEPTION 'test.assert_equal() did not raise the correct message on failure. Expected: ''abc != xyz'', received: %', SQLERRM; 
    130     END IF; 
    131   END; 
    132   IF NOT failed THEN 
    133     RAISE EXCEPTION 'test.assert(abc, xyz) did not fail.'; 
    134   END IF; 
    135    
    136   -- assert_equal() MUST return VOID if both args are null. 
    137   IF dummy IS NOT NULL THEN 
    138     RAISE EXCEPTION 'dummy must be NULL for this test to be valid.'; 
    139   END IF; 
    140   SELECT INTO retval * FROM test.assert_equal(dummy, dummy); 
    141   IF retval != '' THEN 
    142     RAISE EXCEPTION 'test.assert_equal() did not return void for (null, null).'; 
    143   END IF; 
    144    
    145   -- assert_equal() MUST raise an exception if only one arg is NULL. 
    146   failed := false; 
    147   BEGIN 
    148     SELECT INTO retval * FROM test.assert_equal(8, dummy); 
    149   EXCEPTION WHEN OTHERS THEN 
    150     failed := true; 
    151     IF SQLERRM = '8 != <NULL>' THEN 
    152       NULL; 
    153     ELSE 
    154       RAISE EXCEPTION 'test.assert_equal() did not raise the correct message on failure. Expected ''8 != <NULL>'', received ''%''', SQLERRM; 
    155     END IF; 
    156   END; 
    157   IF NOT failed THEN 
    158     RAISE EXCEPTION 'test.assert_equal(8, null) did not fail.'; 
    159   END IF; 
    160    
    161   failed := false; 
    162   BEGIN 
    163     SELECT INTO retval * FROM test.assert_equal(dummy, 7); 
    164   EXCEPTION WHEN OTHERS THEN 
    165     failed := true; 
    166     IF SQLERRM = '<NULL> != 7' THEN 
    167       NULL; 
    168     ELSE 
    169       RAISE EXCEPTION 'test.assert_equal() did not raise the correct message on failure. Expected ''<NULL> != 7'', received ''%''', SQLERRM; 
    170     END IF; 
    171   END; 
    172   IF NOT failed THEN 
    173     RAISE EXCEPTION 'test.assert_equal(null, 7) did not fail.'; 
    174   END IF; 
    175    
    176   -- assert_equal() will raise an undefined_function exception if the args have different types. 
    177   -- It would be nice to find a way around this (without writing M x N overloaded funcs). 
    178   failed := false; 
    179   BEGIN 
    180     SELECT INTO retval * FROM test.assert_equal(8, 'abc'::text); 
    181   EXCEPTION WHEN undefined_function THEN 
    182     failed := true; 
    183   END; 
    184   IF NOT failed THEN 
    185     RAISE EXCEPTION 'test.assert_equal(8, abc) did not fail.'; 
    186   END IF; 
    187    
    188   RAISE EXCEPTION '[OK]'; 
    189 END; 
    190 $$ LANGUAGE plpgsql; 
    191  
    192  
    193 CREATE OR REPLACE FUNCTION test.test_assert_not_equal() RETURNS VOID AS $$ 
    194 -- Assert the correct operation of test.assert_not_equal 
    195 -- module: test_asserts 
    196 DECLARE 
    197   retval    text; 
    198   dummy     int; 
    199   failed    bool; 
    200 BEGIN 
    201   -- assert_not_equal() MUST return VOID if the given assertion does not hold. 
    202   SELECT INTO retval * FROM test.assert_not_equal(1, 2); 
    203   IF retval != '' THEN 
    204     RAISE EXCEPTION 'test.assert_not_equal() did not return void for (1, 2).'; 
    205   END IF; 
    206   SELECT INTO retval * FROM test.assert_not_equal('abc'::text, 'xyz'); 
    207   IF retval != '' THEN 
    208     RAISE EXCEPTION 'test.assert_not_equal() did not return void for (''abc'', ''xyz'').'; 
    209   END IF; 
    210    
    211   -- assert_not_equal() MUST raise an exception if the given assertion holds. 
    212   failed := false; 
    213   BEGIN 
    214     SELECT INTO retval * FROM test.assert_not_equal(1, 1); 
    215   EXCEPTION WHEN OTHERS THEN 
    216     failed := true; 
    217     IF SQLERRM = '1 = 1' THEN 
    218       NULL; 
    219     ELSE 
    220       RAISE EXCEPTION 'test.assert_not_equal() did not raise the correct message on failure. Expected ''1 = 1'', received ''%''', SQLERRM; 
    221     END IF; 
    222   END; 
    223   IF NOT failed THEN 
    224     RAISE EXCEPTION 'test.assert_not_equal(1, 1) did not fail.'; 
    225   END IF; 
    226    
    227   failed := false; 
    228   BEGIN 
    229     SELECT INTO retval * FROM test.assert_not_equal('abc'::text, 'abc'); 
    230   EXCEPTION WHEN OTHERS THEN 
    231     failed := true; 
    232     IF SQLERRM = 'abc = abc' THEN 
    233       NULL; 
    234     ELSE 
    235       RAISE EXCEPTION 'test.assert_not_equal() did not raise the correct message on failure. Expected: ''abc = abc'', received: %', SQLERRM; 
    236     END IF; 
    237   END; 
    238   IF NOT failed THEN 
    239     RAISE EXCEPTION 'test.assert_not_equal(abc, abc) did not fail.'; 
    240   END IF; 
    241    
    242   -- assert_not_equal() MUST return VOID if only one arg is NULL. 
    243   IF dummy IS NOT NULL THEN 
    244     RAISE EXCEPTION 'dummy must be NULL for this test to be valid.'; 
    245   END IF; 
    246   SELECT INTO retval * FROM test.assert_not_equal(8, dummy); 
    247   IF retval != '' THEN 
    248     RAISE EXCEPTION 'test.assert_not_equal() did not return void for (8, null).'; 
    249   END IF; 
    250   SELECT INTO retval * FROM test.assert_not_equal(dummy, 7); 
    251   IF retval != '' THEN 
    252     RAISE EXCEPTION 'test.assert_not_equal() did not return void for (null, 7).'; 
    253   END IF; 
    254    
    255   -- assert_not_equal() MUST raise an exception if both args are NULL. 
    256   failed := false; 
    257   BEGIN 
    258     SELECT INTO retval * FROM test.assert_not_equal(dummy, dummy); 
    259   EXCEPTION WHEN OTHERS THEN 
    260     failed := true; 
    261     IF SQLERRM = '<NULL> = <NULL>' THEN 
    262       NULL; 
    263     ELSE 
    264       RAISE EXCEPTION 'test.assert_not_equal() did not raise the correct message on failure. Expected ''<NULL> = <NULL>'', received ''%''', SQLERRM; 
    265     END IF; 
    266   END; 
    267   IF NOT failed THEN 
    268     RAISE EXCEPTION 'test.assert_not_equal(null, null) did not fail.'; 
    269   END IF; 
    270    
    271   -- assert_not_equal() will raise an undefined_function exception if the args have different types. 
    272   -- It would be nice to find a way around this (without writing M x N overloaded funcs). 
    273   failed := false; 
    274   BEGIN 
    275     SELECT INTO retval * FROM test.assert_not_equal(8, 'abc'::text); 
    276   EXCEPTION WHEN undefined_function THEN 
    277     failed := true; 
    278   END; 
    279   IF NOT failed THEN 
    280     RAISE EXCEPTION 'test.assert_not_equal(8, abc) did not fail.'; 
    281   END IF; 
    282    
    283   RAISE EXCEPTION '[OK]'; 
    284 END; 
    285 $$ LANGUAGE plpgsql; 
    286  
    287  
    288 CREATE OR REPLACE FUNCTION test.test_assert_less_than_or_equal() RETURNS VOID AS $$ 
    289 -- Assert the correct operation of test.assert_less_than_or_equal 
    290 -- module: test_asserts 
    291 DECLARE 
    292   retval    text; 
    293   dummy     int; 
    294   failed    bool; 
    295 BEGIN 
    296   -- assert_less_than_or_equal() MUST return VOID if a <= b. 
    297   SELECT INTO retval * FROM test.assert_less_than_or_equal(1, 2); 
    298   IF retval != '' THEN 
    299     RAISE EXCEPTION 'test.assert_less_than_or_equal() did not return void for (1, 2).'; 
    300   END IF; 
    301   SELECT INTO retval * FROM test.assert_less_than_or_equal(1, 1); 
    302   IF retval != '' THEN 
    303     RAISE EXCEPTION 'test.assert_less_than_or_equal() did not return void for (1, 1).'; 
    304   END IF; 
    305   SELECT INTO retval * FROM test.assert_less_than_or_equal('abc'::text, 'xyz'); 
    306   IF retval != '' THEN 
    307     RAISE EXCEPTION 'test.assert_less_than_or_equal() did not return void for (''abc'', ''xyz'').'; 
    308   END IF; 
    309   SELECT INTO retval * FROM test.assert_less_than_or_equal('abc'::text, 'abc'); 
    310   IF retval != '' THEN 
    311     RAISE EXCEPTION 'test.assert_less_than_or_equal() did not return void for (''abc'', ''abc'').'; 
    312   END IF; 
    313    
    314   -- assert_less_than_or_equal() MUST raise an exception if a > b. 
    315   failed := false; 
    316   BEGIN 
    317     SELECT INTO retval * FROM test.assert_less_than_or_equal(2, 1); 
    318   EXCEPTION WHEN OTHERS THEN 
    319     failed := true; 
    320     IF SQLERRM = '2 not <= 1' THEN 
    321       NULL; 
    322     ELSE 
    323       RAISE EXCEPTION 'test.assert_less_than_or_equal() did not raise the correct message on failure. Expected ''2 not <= 1'', received ''%''', SQLERRM; 
    324     END IF; 
    325   END; 
    326   IF NOT failed THEN 
    327     RAISE EXCEPTION 'test.assert_less_than_or_equal(2, 1) did not fail.'; 
    328   END IF; 
    329    
    330   failed := false; 
    331   BEGIN 
    332     SELECT INTO retval * FROM test.assert_less_than_or_equal('xyz'::text, 'abc'); 
    333   EXCEPTION WHEN OTHERS THEN 
    334     failed := true; 
    335     IF SQLERRM = 'xyz not <= abc' THEN 
    336       NULL; 
    337     ELSE 
    338       RAISE EXCEPTION 'test.assert_less_than_or_equal() did not raise the correct message on failure. Expected: ''xyz not <= abc'', received: %', SQLERRM; 
    339     END IF; 
    340   END; 
    341   IF NOT failed THEN 
    342     RAISE EXCEPTION 'test.assert_less_than_or_equal(xyz, abc) did not fail.'; 
    343   END IF; 
    344    
    345   -- assert_less_than_or_equal() MUST raise an exception if either arg is NULL. 
    346   failed := false; 
    347   BEGIN 
    348     SELECT INTO retval * FROM test.assert_less_than_or_equal(dummy, dummy); 
    349   EXCEPTION WHEN OTHERS THEN 
    350     failed := true; 
    351     IF SQLERRM = 'Assertion arguments may not be NULL.' THEN 
    352       NULL; 
    353     ELSE 
    354       RAISE EXCEPTION 'test.assert_less_than_or_equal() did not raise the correct message on failure. Expected ''Assertion arguments may not be NULL.'', received ''%''', SQLERRM; 
    355     END IF; 
    356   END; 
    357   IF NOT failed THEN 
    358     RAISE EXCEPTION 'test.assert_less_than_or_equal(null, null) did not fail.'; 
    359   END IF; 
    360    
    361   -- assert_less_than_or_equal() will raise an undefined_function exception if the args have different types. 
    362   -- It would be nice to find a way around this (without writing M x N overloaded funcs). 
    363   failed := false; 
    364   BEGIN 
    365     SELECT INTO retval * FROM test.assert_less_than_or_equal(8, 'abc'::text); 
    366   EXCEPTION WHEN undefined_function THEN 
    367     failed := true; 
    368   END; 
    369   IF NOT failed THEN 
    370     RAISE EXCEPTION 'test.assert_less_than_or_equal(8, abc) did not fail.'; 
    371   END IF; 
    372    
    373   RAISE EXCEPTION '[OK]'; 
    374 END; 
    375 $$ LANGUAGE plpgsql; 
     281    RAISE EXCEPTION 'test.assert_values() did not fail.'; 
     282  END IF; 
     283   
     284  RAISE EXCEPTION '[OK]'; 
     285END; 
     286$$ LANGUAGE plpgsql;