summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Lane2018-02-27 17:13:14 +0000
committerTom Lane2018-02-27 17:13:14 +0000
commitbe42eb9d624cc14a9326e21ec75fdc571a7cb188 (patch)
tree92da8ff7b0083dfcb1f3dcd606b78dacbf2916cd
parentdb3af9feb19f39827e916145f88fa5eca3130cb2 (diff)
Improve regression test coverage of regress.c.
It's a bit silly to have test functions that aren't tested, so test them. In passing, rename int44in/int44out to city_budget_in/_out so that they match how the regression tests use them. Also, fix city_budget_out so that it emits the format city_budget_in expects to read; otherwise we'd have dump/reload failures when testing pg_dump against the regression database. (We avoided that in the past only because no data of type city_budget was actually stored anywhere.) Discussion: https://postgr.es/m/[email protected]
-rw-r--r--src/test/regress/expected/create_misc.out10
-rw-r--r--src/test/regress/expected/create_operator.out8
-rw-r--r--src/test/regress/expected/create_type.out13
-rw-r--r--src/test/regress/input/create_function_1.source4
-rw-r--r--src/test/regress/output/create_function_1.source4
-rw-r--r--src/test/regress/regress.c34
-rw-r--r--src/test/regress/sql/create_misc.sql5
-rw-r--r--src/test/regress/sql/create_operator.sql4
-rw-r--r--src/test/regress/sql/create_type.sql8
9 files changed, 63 insertions, 27 deletions
diff --git a/src/test/regress/expected/create_misc.out b/src/test/regress/expected/create_misc.out
index 45125fedfd4..8366841ff04 100644
--- a/src/test/regress/expected/create_misc.out
+++ b/src/test/regress/expected/create_misc.out
@@ -24,6 +24,16 @@ INSERT INTO equipment_r (name, hobby) VALUES ('advil', 'posthacking');
INSERT INTO equipment_r (name, hobby) VALUES ('peet''s coffee', 'posthacking');
INSERT INTO equipment_r (name, hobby) VALUES ('hightops', 'basketball');
INSERT INTO equipment_r (name, hobby) VALUES ('guts', 'skywalking');
+INSERT INTO city VALUES
+('Podunk', '(1,2),(3,4)', '100,127,1000'),
+('Gotham', '(1000,34),(1100,334)', '123456,127,-1000,6789');
+TABLE city;
+ name | location | budget
+--------+----------------------+-----------------------
+ Podunk | (3,4),(1,2) | 100,127,1000,0
+ Gotham | (1100,334),(1000,34) | 123456,127,-1000,6789
+(2 rows)
+
SELECT *
INTO TABLE ramp
FROM road
diff --git a/src/test/regress/expected/create_operator.out b/src/test/regress/expected/create_operator.out
index 3c4ccae1e7a..e35eb092505 100644
--- a/src/test/regress/expected/create_operator.out
+++ b/src/test/regress/expected/create_operator.out
@@ -26,6 +26,14 @@ CREATE OPERATOR #%# (
leftarg = int8, -- right unary
procedure = numeric_fac
);
+-- Test operator created above
+SELECT point '(1,2)' <% widget '(0,0,3)' AS t,
+ point '(1,2)' <% widget '(0,0,1)' AS f;
+ t | f
+---+---
+ t | f
+(1 row)
+
-- Test comments
COMMENT ON OPERATOR ###### (int4, NONE) IS 'bad right unary';
ERROR: operator does not exist: integer ######
diff --git a/src/test/regress/expected/create_type.out b/src/test/regress/expected/create_type.out
index 4eef32bf4d1..96093477b65 100644
--- a/src/test/regress/expected/create_type.out
+++ b/src/test/regress/expected/create_type.out
@@ -16,8 +16,8 @@ CREATE TYPE widget (
);
CREATE TYPE city_budget (
internallength = 16,
- input = int44in,
- output = int44out,
+ input = city_budget_in,
+ output = city_budget_out,
element = int4,
category = 'x', -- just to verify the system will take it
preferred = true -- ditto
@@ -182,3 +182,12 @@ WHERE attrelid = 'mytab'::regclass AND attnum > 0;
widget(42,13)
(1 row)
+-- might as well exercise the widget type while we're here
+INSERT INTO mytab VALUES ('(1,2,3)'), ('(-44,5.5,12)');
+TABLE mytab;
+ foo
+--------------
+ (1,2,3)
+ (-44,5.5,12)
+(2 rows)
+
diff --git a/src/test/regress/input/create_function_1.source b/src/test/regress/input/create_function_1.source
index b4479e44f6b..825974d2ac1 100644
--- a/src/test/regress/input/create_function_1.source
+++ b/src/test/regress/input/create_function_1.source
@@ -12,12 +12,12 @@ CREATE FUNCTION widget_out(widget)
AS '@libdir@/regress@DLSUFFIX@'
LANGUAGE C STRICT IMMUTABLE;
-CREATE FUNCTION int44in(cstring)
+CREATE FUNCTION city_budget_in(cstring)
RETURNS city_budget
AS '@libdir@/regress@DLSUFFIX@'
LANGUAGE C STRICT IMMUTABLE;
-CREATE FUNCTION int44out(city_budget)
+CREATE FUNCTION city_budget_out(city_budget)
RETURNS cstring
AS '@libdir@/regress@DLSUFFIX@'
LANGUAGE C STRICT IMMUTABLE;
diff --git a/src/test/regress/output/create_function_1.source b/src/test/regress/output/create_function_1.source
index 1d8c170df86..6c3f5e9c64b 100644
--- a/src/test/regress/output/create_function_1.source
+++ b/src/test/regress/output/create_function_1.source
@@ -12,13 +12,13 @@ CREATE FUNCTION widget_out(widget)
AS '@libdir@/regress@DLSUFFIX@'
LANGUAGE C STRICT IMMUTABLE;
NOTICE: argument type widget is only a shell
-CREATE FUNCTION int44in(cstring)
+CREATE FUNCTION city_budget_in(cstring)
RETURNS city_budget
AS '@libdir@/regress@DLSUFFIX@'
LANGUAGE C STRICT IMMUTABLE;
NOTICE: type "city_budget" is not yet defined
DETAIL: Creating a shell type definition.
-CREATE FUNCTION int44out(city_budget)
+CREATE FUNCTION city_budget_out(city_budget)
RETURNS cstring
AS '@libdir@/regress@DLSUFFIX@'
LANGUAGE C STRICT IMMUTABLE;
diff --git a/src/test/regress/regress.c b/src/test/regress/regress.c
index 200ce5064fd..064351f7b07 100644
--- a/src/test/regress/regress.c
+++ b/src/test/regress/regress.c
@@ -427,19 +427,19 @@ set_ttdummy(PG_FUNCTION_ARGS)
/*
- * Type int44 has no real-world use, but the regression tests use it.
+ * Type city_budget has no real-world use, but the regression tests use it.
* It's a four-element vector of int4's.
*/
/*
- * int44in - converts "num num ..." to internal form
+ * city_budget_in - converts "num, num, ..." to internal form
*
* Note: Fills any missing positions with zeroes.
*/
-PG_FUNCTION_INFO_V1(int44in);
+PG_FUNCTION_INFO_V1(city_budget_in);
Datum
-int44in(PG_FUNCTION_ARGS)
+city_budget_in(PG_FUNCTION_ARGS)
{
char *input_string = PG_GETARG_CSTRING(0);
int32 *result = (int32 *) palloc(4 * sizeof(int32));
@@ -458,27 +458,22 @@ int44in(PG_FUNCTION_ARGS)
}
/*
- * int44out - converts internal form to "num num ..."
+ * city_budget_out - converts internal form to "num, num, ..."
*/
-PG_FUNCTION_INFO_V1(int44out);
+PG_FUNCTION_INFO_V1(city_budget_out);
Datum
-int44out(PG_FUNCTION_ARGS)
+city_budget_out(PG_FUNCTION_ARGS)
{
int32 *an_array = (int32 *) PG_GETARG_POINTER(0);
- char *result = (char *) palloc(16 * 4); /* Allow 14 digits + sign */
- int i;
- char *walk;
+ char *result = (char *) palloc(16 * 4);
+
+ snprintf(result, 16 * 4, "%d,%d,%d,%d",
+ an_array[0],
+ an_array[1],
+ an_array[2],
+ an_array[3]);
- walk = result;
- for (i = 0; i < 4; i++)
- {
- pg_ltoa(an_array[i], walk);
- while (*++walk != '\0')
- ;
- *walk++ = ' ';
- }
- *--walk = '\0';
PG_RETURN_CSTRING(result);
}
@@ -861,5 +856,6 @@ PG_FUNCTION_INFO_V1(test_fdw_handler);
Datum
test_fdw_handler(PG_FUNCTION_ARGS)
{
+ elog(ERROR, "test_fdw_handler is not implemented");
PG_RETURN_NULL();
}
diff --git a/src/test/regress/sql/create_misc.sql b/src/test/regress/sql/create_misc.sql
index 705a7e55b1a..d4a63b7aed2 100644
--- a/src/test/regress/sql/create_misc.sql
+++ b/src/test/regress/sql/create_misc.sql
@@ -37,6 +37,11 @@ INSERT INTO equipment_r (name, hobby) VALUES ('hightops', 'basketball');
INSERT INTO equipment_r (name, hobby) VALUES ('guts', 'skywalking');
+INSERT INTO city VALUES
+('Podunk', '(1,2),(3,4)', '100,127,1000'),
+('Gotham', '(1000,34),(1100,334)', '123456,127,-1000,6789');
+TABLE city;
+
SELECT *
INTO TABLE ramp
FROM road
diff --git a/src/test/regress/sql/create_operator.sql b/src/test/regress/sql/create_operator.sql
index bb9907b3ed9..c71765f9be5 100644
--- a/src/test/regress/sql/create_operator.sql
+++ b/src/test/regress/sql/create_operator.sql
@@ -32,6 +32,10 @@ CREATE OPERATOR #%# (
procedure = numeric_fac
);
+-- Test operator created above
+SELECT point '(1,2)' <% widget '(0,0,3)' AS t,
+ point '(1,2)' <% widget '(0,0,1)' AS f;
+
-- Test comments
COMMENT ON OPERATOR ###### (int4, NONE) IS 'bad right unary';
diff --git a/src/test/regress/sql/create_type.sql b/src/test/regress/sql/create_type.sql
index 2123d63e2ef..9a5b5bbadd2 100644
--- a/src/test/regress/sql/create_type.sql
+++ b/src/test/regress/sql/create_type.sql
@@ -18,8 +18,8 @@ CREATE TYPE widget (
CREATE TYPE city_budget (
internallength = 16,
- input = int44in,
- output = int44out,
+ input = city_budget_in,
+ output = city_budget_out,
element = int4,
category = 'x', -- just to verify the system will take it
preferred = true -- ditto
@@ -144,3 +144,7 @@ CREATE TEMP TABLE mytab (foo widget(42,13));
SELECT format_type(atttypid,atttypmod) FROM pg_attribute
WHERE attrelid = 'mytab'::regclass AND attnum > 0;
+
+-- might as well exercise the widget type while we're here
+INSERT INTO mytab VALUES ('(1,2,3)'), ('(-44,5.5,12)');
+TABLE mytab;