| 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 | | |
| | 221 | CREATE 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. |
| | 223 | DECLARE |
| | 224 | modulename text; |
| | 225 | output_record test.suite_results%ROWTYPE; |
| | 226 | BEGIN |
| | 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; |
| | 249 | END; |
| | 250 | $$ LANGUAGE plpgsql; |
| | 251 | |
| | 252 | |