| | 424 | |
| | 425 | |
| | 426 | CREATE 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 |
| | 429 | DECLARE |
| | 430 | failed bool; |
| | 431 | BEGIN |
| | 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]'; |
| | 458 | END; |
| | 459 | $$ LANGUAGE plpgsql; |