Skip to content

Commit

Permalink
Fixed compatibility with 8.3.
Browse files Browse the repository at this point in the history
  • Loading branch information
theory committed Jul 30, 2009
1 parent 0971f19 commit a64fffe
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 33 deletions.
2 changes: 1 addition & 1 deletion README.pgtap
Original file line number Diff line number Diff line change
Expand Up @@ -3770,7 +3770,7 @@ Supported Versions

pgTAP has been tested on the following builds of PostgreSQL:

* PostgreSQL 8.4beta2 on i386-apple-darwin9.7.0
* PostgreSQL 8.4.0 on i386-apple-darwin9.7.0
* PostgreSQL 8.3.7 on i386-apple-darwin9.6.0
* PostgreSQL 8.3.6 on i386-redhat-linux-gnu
* PostgreSQL 8.2.13 on i386-apple-darwin9.6.0
Expand Down
29 changes: 19 additions & 10 deletions compat/install-8.3.patch
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
--- pgtap.sql.orig 2009-07-01 10:24:04.000000000 -0700
+++ pgtap.sql 2009-07-01 10:35:45.000000000 -0700
@@ -5780,8 +5780,9 @@
--- pgtap.sql.orig 2009-07-29 17:03:30.000000000 -0700
+++ pgtap.sql 2009-07-29 17:05:34.000000000 -0700
@@ -5791,8 +5791,9 @@
SELECT pg_catalog.format_type(a.atttypid, a.atttypmod)
FROM pg_catalog.pg_attribute a
JOIN pg_catalog.pg_class c ON a.attrelid = c.oid
Expand All @@ -11,12 +11,21 @@
AND attnum > 0
AND CASE WHEN attisdropped THEN false ELSE pg_type_is_visible(a.atttypid) END
ORDER BY attnum
@@ -5885,7 +5886,7 @@
FETCH have INTO rec_have;
FETCH want INTO rec_want;
WHILE rec_have IS NOT NULL OR rec_want IS NOT NULL LOOP
- IF rec_have IS DISTINCT FROM rec_want THEN
+ IF rec_have::text IS DISTINCT FROM rec_want::text THEN
@@ -6140,7 +6141,7 @@
FETCH want INTO want_rec;
want_found := FOUND;
WHILE have_found OR want_found LOOP
- IF have_rec IS DISTINCT FROM want_rec OR have_found <> want_found THEN
+ IF have_rec::text IS DISTINCT FROM want_rec::text OR have_found <> want_found THEN
RETURN ok( false, $3 ) || E'\n' || diag(
' Results differ beginning at row ' || rownum || E':\n' ||
' have: ' || CASE WHEN rec_have IS NULL THEN '()' ELSE rec_have::text END || E'\n' ||
' have: ' || CASE WHEN have_found THEN have_rec::text ELSE 'NULL' END || E'\n' ||
@@ -6295,7 +6296,7 @@
FETCH want INTO want_rec;
want_found := FOUND;
WHILE have_found OR want_found LOOP
- IF have_rec IS DISTINCT FROM want_rec OR have_found <> want_found THEN
+ IF have_rec::text IS DISTINCT FROM want_rec::text OR have_found <> want_found THEN
RETURN ok( true, $3 );
ELSE
FETCH have INTO have_rec;
57 changes: 35 additions & 22 deletions sql/resultset.sql
Original file line number Diff line number Diff line change
Expand Up @@ -1995,29 +1995,38 @@ SELECT * FROM check_test(
''
);

-- Handle failure due to column mismatch.
SELECT * FROM check_test(
results_ne( 'VALUES (1, ''foo''), (2, ''bar'')', 'VALUES (''foo'', 1), (''bar'', 2)' ),
false,
'results_ne(values, values) mismatch',
'',
CASE WHEN pg_version_num() < 80400 THEN ' Results differ beginning at row 1:' ELSE ' Columns differ between queries:' END || '
have: (1,foo)
want: (foo,1)'
);

-- -- Handle failure due to more subtle column mismatch, valid only on 8.4.
-- Handle failure due to more subtle column mismatch, valid only on 8.4.
CREATE OR REPLACE FUNCTION subtlefail() RETURNS SETOF TEXT AS $$
DECLARE
tap record;
BEGIN
IF pg_version_num() < 80400 THEN
-- 8.3 and earlier cast records to text, so subtlety is out.
RETURN NEXT pass('results_ne(values, values) mismatch should fail');
RETURN NEXT pass('results_ne(values, values) mismatch should have the proper description');
RETURN NEXT pass('results_ne(values, values) mismatch should have the proper diagnostics');
RETURN NEXT pass('results_ne(values, values) subtle mismatch should fail');
RETURN NEXT pass('results_ne(values, values) subtle mismatch should have the proper description');
RETURN NEXT pass('results_ne(values, values) subtle mismatch should have the proper diagnostics');
RETURN NEXT pass('results_ne(values, values) fail column count should fail');
RETURN NEXT pass('results_ne(values, values) fail column count should have the proper description');
RETURN NEXT pass('results_ne(values, values) fail column count should have the proper diagnostics');
ELSE
-- 8.4 does true record comparisions, yay!
-- Handle failure due to column mismatch.
FOR tap IN SELECT * FROM check_test(
results_ne( 'VALUES (1, ''foo''), (2, ''bar'')', 'VALUES (''foo'', 1), (''bar'', 2)' ),
false,
'results_ne(values, values) mismatch',
'',
' Columns differ between queries:
have: (1,foo)
want: (foo,1)'
) AS a(b) LOOP
RETURN NEXT tap.b;
END LOOP;

-- Handle failure due to subtle column mismatch.
FOR tap IN SELECT * FROM check_test(
results_ne(
'VALUES (1, ''foo''::varchar), (2, ''bar''::varchar)',
Expand All @@ -2031,22 +2040,26 @@ BEGIN
want: (1,foo)' ) AS a(b) LOOP
RETURN NEXT tap.b;
END LOOP;

-- Handle failure due to column count mismatch.
FOR tap IN SELECT * FROM check_test(
results_ne( 'VALUES (1), (2)', 'VALUES (''foo'', 1), (''bar'', 2)' ),
false,
'results_ne(values, values) fail column count',
'',
' Columns differ between queries:
have: (1)
want: (foo,1)'
) AS a(b) LOOP
RETURN NEXT tap.b;
END LOOP;

END IF;
RETURN;
END;
$$ LANGUAGE plpgsql;
SELECT * FROM subtlefail();

-- Handle failure due to column count mismatch.
SELECT * FROM check_test(
results_ne( 'VALUES (1), (2)', 'VALUES (''foo'', 1), (''bar'', 2)' ),
false,
'results_ne(values, values) fail column count',
'',
CASE WHEN pg_version_num() < 80400 THEN ' Results differ beginning at row 1:' ELSE ' Columns differ between queries:' END || '
have: (1)
want: (foo,1)'
);

-- Compare with cursors.
CLOSE cwant;
Expand Down

0 comments on commit a64fffe

Please sign in to comment.