Skip to content

Commit 25fcfdf

Browse files
committed
The beginnings of a regression test for plperl. Right now it only
covers return value processing, but that was the most broken stuff...
1 parent f520626 commit 25fcfdf

File tree

3 files changed

+386
-0
lines changed

3 files changed

+386
-0
lines changed

src/pl/plperl/test/runtest

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/bin/sh
2+
3+
DBNAME=plperl_test
4+
export DBNAME
5+
6+
echo "**** Destroy old database $DBNAME ****"
7+
dropdb $DBNAME
8+
9+
sleep 1
10+
11+
echo "**** Create test database $DBNAME ****"
12+
createdb $DBNAME
13+
14+
echo "**** Create procedural language plperl ****"
15+
createlang plperl $DBNAME
16+
17+
echo "**** Running test queries ****"
18+
psql -q -n -e $DBNAME <test_queries.sql > test.out 2>&1
19+
20+
if diff test.expected test.out >/dev/null 2>&1 ; then
21+
echo " Tests passed O.K."
22+
rm test.out
23+
else
24+
echo " Tests failed - look at diffs between"
25+
echo " test.expected and test.out"
26+
fi

src/pl/plperl/test/test.expected

Lines changed: 224 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,224 @@
1+
checkpoint;
2+
CREATE OR REPLACE FUNCTION perl_int(int) RETURNS INTEGER AS $$
3+
return undef;
4+
$$ LANGUAGE plperl;
5+
SELECT perl_int(11);
6+
perl_int
7+
----------
8+
9+
(1 row)
10+
11+
SELECT * FROM perl_int(42);
12+
perl_int
13+
----------
14+
15+
(1 row)
16+
17+
CREATE OR REPLACE FUNCTION perl_int(int) RETURNS INTEGER AS $$
18+
return $_[0] + 1;
19+
$$ LANGUAGE plperl;
20+
SELECT perl_int(11);
21+
perl_int
22+
----------
23+
12
24+
(1 row)
25+
26+
SELECT * FROM perl_int(42);
27+
perl_int
28+
----------
29+
43
30+
(1 row)
31+
32+
CREATE OR REPLACE FUNCTION perl_set_int(int) RETURNS SETOF INTEGER AS $$
33+
return undef;
34+
$$ LANGUAGE plperl;
35+
SELECT perl_set_int(5);
36+
perl_set_int
37+
--------------
38+
(0 rows)
39+
40+
SELECT * FROM perl_set_int(5);
41+
perl_set_int
42+
--------------
43+
(0 rows)
44+
45+
CREATE OR REPLACE FUNCTION perl_set_int(int) RETURNS SETOF INTEGER AS $$
46+
return [0..$_[0]];
47+
$$ LANGUAGE plperl;
48+
SELECT perl_set_int(5);
49+
perl_set_int
50+
--------------
51+
0
52+
1
53+
2
54+
3
55+
4
56+
5
57+
(6 rows)
58+
59+
SELECT * FROM perl_set_int(5);
60+
perl_set_int
61+
--------------
62+
0
63+
1
64+
2
65+
3
66+
4
67+
5
68+
(6 rows)
69+
70+
CREATE TYPE testrowperl AS (f1 integer, f2 text, f3 text);
71+
CREATE OR REPLACE FUNCTION perl_row() RETURNS testrowperl AS $$
72+
return undef;
73+
$$ LANGUAGE plperl;
74+
SELECT perl_row();
75+
perl_row
76+
----------
77+
78+
(1 row)
79+
80+
SELECT * FROM perl_row();
81+
f1 | f2 | f3
82+
----+----+----
83+
| |
84+
(1 row)
85+
86+
CREATE OR REPLACE FUNCTION perl_row() RETURNS testrowperl AS $$
87+
return {f2 => 'hello', f1 => 1, f3 => 'world'};
88+
$$ LANGUAGE plperl;
89+
SELECT perl_row();
90+
perl_row
91+
-----------------
92+
(1,hello,world)
93+
(1 row)
94+
95+
SELECT * FROM perl_row();
96+
f1 | f2 | f3
97+
----+-------+-------
98+
1 | hello | world
99+
(1 row)
100+
101+
CREATE OR REPLACE FUNCTION perl_set() RETURNS SETOF testrowperl AS $$
102+
return undef;
103+
$$ LANGUAGE plperl;
104+
SELECT perl_set();
105+
perl_set
106+
----------
107+
(0 rows)
108+
109+
SELECT * FROM perl_set();
110+
f1 | f2 | f3
111+
----+----+----
112+
(0 rows)
113+
114+
CREATE OR REPLACE FUNCTION perl_set() RETURNS SETOF testrowperl AS $$
115+
return [
116+
{ f1 => 1, f2 => 'Hello', f3 => 'World' },
117+
undef,
118+
{ f1 => 3, f2 => 'Hello', f3 => 'PL/Perl' }
119+
];
120+
$$ LANGUAGE plperl;
121+
SELECT perl_set();
122+
ERROR: plperl: check your return value structure
123+
SELECT * FROM perl_set();
124+
ERROR: plperl: check your return value structure
125+
CREATE OR REPLACE FUNCTION perl_set() RETURNS SETOF testrowperl AS $$
126+
return [
127+
{ f1 => 1, f2 => 'Hello', f3 => 'World' },
128+
{ f1 => 2, f2 => 'Hello', f3 => 'PostgreSQL' },
129+
{ f1 => 3, f2 => 'Hello', f3 => 'PL/Perl' }
130+
];
131+
$$ LANGUAGE plperl;
132+
SELECT perl_set();
133+
perl_set
134+
----------------------
135+
(1,Hello,World)
136+
(2,Hello,PostgreSQL)
137+
(3,Hello,PL/Perl)
138+
(3 rows)
139+
140+
SELECT * FROM perl_set();
141+
f1 | f2 | f3
142+
----+-------+------------
143+
1 | Hello | World
144+
2 | Hello | PostgreSQL
145+
3 | Hello | PL/Perl
146+
(3 rows)
147+
148+
CREATE OR REPLACE FUNCTION perl_record() RETURNS record AS $$
149+
return undef;
150+
$$ LANGUAGE plperl;
151+
SELECT perl_record();
152+
perl_record
153+
-------------
154+
155+
(1 row)
156+
157+
SELECT * FROM perl_record();
158+
ERROR: a column definition list is required for functions returning "record"
159+
SELECT * FROM perl_record() AS (f1 integer, f2 text, f3 text);
160+
f1 | f2 | f3
161+
----+----+----
162+
| |
163+
(1 row)
164+
165+
CREATE OR REPLACE FUNCTION perl_record() RETURNS record AS $$
166+
return {f2 => 'hello', f1 => 1, f3 => 'world'};
167+
$$ LANGUAGE plperl;
168+
SELECT perl_record();
169+
ERROR: could not determine row description for function returning record
170+
SELECT * FROM perl_record();
171+
ERROR: a column definition list is required for functions returning "record"
172+
SELECT * FROM perl_record() AS (f1 integer, f2 text, f3 text);
173+
f1 | f2 | f3
174+
----+-------+-------
175+
1 | hello | world
176+
(1 row)
177+
178+
CREATE OR REPLACE FUNCTION perl_record_set() RETURNS SETOF record AS $$
179+
return undef;
180+
$$ LANGUAGE plperl;
181+
SELECT perl_record_set();
182+
perl_record_set
183+
-----------------
184+
(0 rows)
185+
186+
SELECT * FROM perl_record_set();
187+
ERROR: a column definition list is required for functions returning "record"
188+
SELECT * FROM perl_record_set() AS (f1 integer, f2 text, f3 text);
189+
f1 | f2 | f3
190+
----+----+----
191+
(0 rows)
192+
193+
CREATE OR REPLACE FUNCTION perl_record_set() RETURNS SETOF record AS $$
194+
return [
195+
{ f1 => 1, f2 => 'Hello', f3 => 'World' },
196+
undef,
197+
{ f1 => 3, f2 => 'Hello', f3 => 'PL/Perl' }
198+
];
199+
$$ LANGUAGE plperl;
200+
SELECT perl_record_set();
201+
ERROR: could not determine row description for function returning record
202+
SELECT * FROM perl_record_set();
203+
ERROR: a column definition list is required for functions returning "record"
204+
SELECT * FROM perl_record_set() AS (f1 integer, f2 text, f3 text);
205+
ERROR: plperl: check your return value structure
206+
CREATE OR REPLACE FUNCTION perl_record_set() RETURNS SETOF record AS $$
207+
return [
208+
{ f1 => 1, f2 => 'Hello', f3 => 'World' },
209+
{ f1 => 2, f2 => 'Hello', f3 => 'PostgreSQL' },
210+
{ f1 => 3, f2 => 'Hello', f3 => 'PL/Perl' }
211+
];
212+
$$ LANGUAGE plperl;
213+
SELECT perl_record_set();
214+
ERROR: could not determine row description for function returning record
215+
SELECT * FROM perl_record_set();
216+
ERROR: a column definition list is required for functions returning "record"
217+
SELECT * FROM perl_record_set() AS (f1 integer, f2 text, f3 text);
218+
f1 | f2 | f3
219+
----+-------+------------
220+
1 | Hello | World
221+
2 | Hello | PostgreSQL
222+
3 | Hello | PL/Perl
223+
(3 rows)
224+

src/pl/plperl/test/test_queries.sql

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
--
2+
-- checkpoint so that if we have a crash in the tests, replay of the
3+
-- just-completed CREATE DATABASE won't discard the core dump file
4+
--
5+
checkpoint;
6+
7+
--
8+
-- Test result value processing
9+
--
10+
11+
CREATE OR REPLACE FUNCTION perl_int(int) RETURNS INTEGER AS $$
12+
return undef;
13+
$$ LANGUAGE plperl;
14+
15+
SELECT perl_int(11);
16+
SELECT * FROM perl_int(42);
17+
18+
CREATE OR REPLACE FUNCTION perl_int(int) RETURNS INTEGER AS $$
19+
return $_[0] + 1;
20+
$$ LANGUAGE plperl;
21+
22+
SELECT perl_int(11);
23+
SELECT * FROM perl_int(42);
24+
25+
26+
CREATE OR REPLACE FUNCTION perl_set_int(int) RETURNS SETOF INTEGER AS $$
27+
return undef;
28+
$$ LANGUAGE plperl;
29+
30+
SELECT perl_set_int(5);
31+
SELECT * FROM perl_set_int(5);
32+
33+
CREATE OR REPLACE FUNCTION perl_set_int(int) RETURNS SETOF INTEGER AS $$
34+
return [0..$_[0]];
35+
$$ LANGUAGE plperl;
36+
37+
SELECT perl_set_int(5);
38+
SELECT * FROM perl_set_int(5);
39+
40+
41+
CREATE TYPE testrowperl AS (f1 integer, f2 text, f3 text);
42+
43+
CREATE OR REPLACE FUNCTION perl_row() RETURNS testrowperl AS $$
44+
return undef;
45+
$$ LANGUAGE plperl;
46+
47+
SELECT perl_row();
48+
SELECT * FROM perl_row();
49+
50+
CREATE OR REPLACE FUNCTION perl_row() RETURNS testrowperl AS $$
51+
return {f2 => 'hello', f1 => 1, f3 => 'world'};
52+
$$ LANGUAGE plperl;
53+
54+
SELECT perl_row();
55+
SELECT * FROM perl_row();
56+
57+
58+
CREATE OR REPLACE FUNCTION perl_set() RETURNS SETOF testrowperl AS $$
59+
return undef;
60+
$$ LANGUAGE plperl;
61+
62+
SELECT perl_set();
63+
SELECT * FROM perl_set();
64+
65+
CREATE OR REPLACE FUNCTION perl_set() RETURNS SETOF testrowperl AS $$
66+
return [
67+
{ f1 => 1, f2 => 'Hello', f3 => 'World' },
68+
undef,
69+
{ f1 => 3, f2 => 'Hello', f3 => 'PL/Perl' }
70+
];
71+
$$ LANGUAGE plperl;
72+
73+
SELECT perl_set();
74+
SELECT * FROM perl_set();
75+
76+
CREATE OR REPLACE FUNCTION perl_set() RETURNS SETOF testrowperl AS $$
77+
return [
78+
{ f1 => 1, f2 => 'Hello', f3 => 'World' },
79+
{ f1 => 2, f2 => 'Hello', f3 => 'PostgreSQL' },
80+
{ f1 => 3, f2 => 'Hello', f3 => 'PL/Perl' }
81+
];
82+
$$ LANGUAGE plperl;
83+
84+
SELECT perl_set();
85+
SELECT * FROM perl_set();
86+
87+
88+
89+
CREATE OR REPLACE FUNCTION perl_record() RETURNS record AS $$
90+
return undef;
91+
$$ LANGUAGE plperl;
92+
93+
SELECT perl_record();
94+
SELECT * FROM perl_record();
95+
SELECT * FROM perl_record() AS (f1 integer, f2 text, f3 text);
96+
97+
CREATE OR REPLACE FUNCTION perl_record() RETURNS record AS $$
98+
return {f2 => 'hello', f1 => 1, f3 => 'world'};
99+
$$ LANGUAGE plperl;
100+
101+
SELECT perl_record();
102+
SELECT * FROM perl_record();
103+
SELECT * FROM perl_record() AS (f1 integer, f2 text, f3 text);
104+
105+
106+
CREATE OR REPLACE FUNCTION perl_record_set() RETURNS SETOF record AS $$
107+
return undef;
108+
$$ LANGUAGE plperl;
109+
110+
SELECT perl_record_set();
111+
SELECT * FROM perl_record_set();
112+
SELECT * FROM perl_record_set() AS (f1 integer, f2 text, f3 text);
113+
114+
CREATE OR REPLACE FUNCTION perl_record_set() RETURNS SETOF record AS $$
115+
return [
116+
{ f1 => 1, f2 => 'Hello', f3 => 'World' },
117+
undef,
118+
{ f1 => 3, f2 => 'Hello', f3 => 'PL/Perl' }
119+
];
120+
$$ LANGUAGE plperl;
121+
122+
SELECT perl_record_set();
123+
SELECT * FROM perl_record_set();
124+
SELECT * FROM perl_record_set() AS (f1 integer, f2 text, f3 text);
125+
126+
CREATE OR REPLACE FUNCTION perl_record_set() RETURNS SETOF record AS $$
127+
return [
128+
{ f1 => 1, f2 => 'Hello', f3 => 'World' },
129+
{ f1 => 2, f2 => 'Hello', f3 => 'PostgreSQL' },
130+
{ f1 => 3, f2 => 'Hello', f3 => 'PL/Perl' }
131+
];
132+
$$ LANGUAGE plperl;
133+
134+
SELECT perl_record_set();
135+
SELECT * FROM perl_record_set();
136+
SELECT * FROM perl_record_set() AS (f1 integer, f2 text, f3 text);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy