]> granicus.if.org Git - postgresql/commitdiff
Improve regression test coverage of regress.c.
authorTom Lane <tgl@sss.pgh.pa.us>
Tue, 27 Feb 2018 17:13:14 +0000 (12:13 -0500)
committerTom Lane <tgl@sss.pgh.pa.us>
Tue, 27 Feb 2018 17:13:14 +0000 (12:13 -0500)
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/29322.1519701006@sss.pgh.pa.us

src/test/regress/expected/create_misc.out
src/test/regress/expected/create_operator.out
src/test/regress/expected/create_type.out
src/test/regress/input/create_function_1.source
src/test/regress/output/create_function_1.source
src/test/regress/regress.c
src/test/regress/sql/create_misc.sql
src/test/regress/sql/create_operator.sql
src/test/regress/sql/create_type.sql

index 45125fedfd47962e86827d00e6f6ed28d513d768..8366841ff0455dbdc26b782874e24c552c0afeca 100644 (file)
@@ -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
index 3c4ccae1e7aff17e782014b8cb66da9e52275359..e35eb092505b279d658efbf07b74af1dab83349a 100644 (file)
@@ -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 ######
index 4eef32bf4d100f97b63d913b4a89ca6d1924c014..96093477b65c68b20ee255cf72bdc3096ffc5b99 100644 (file)
@@ -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)
+
index b4479e44f6b0de6f0c84f7c20efcd357473f5ca0..825974d2ac1ae6268c0ab5f5fa726c1a77c3da79 100644 (file)
@@ -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;
index 1d8c170df861cfc104f0dad2a064f940e0ab2240..6c3f5e9c64bbcb9ad60a1d8c10e0fb47df68bd28 100644 (file)
@@ -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;
index 200ce5064fd2f9272b60df59e1a0eaabc13b372a..064351f7b07d80060e4752a865754cb723cd531f 100644 (file)
@@ -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();
 }
index 705a7e55b1ae92baaa95e47b9770390c03b73e96..d4a63b7aed2c645f6b7c03c11663e1a429fad905 100644 (file)
@@ -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
index bb9907b3ed9c4ba914214fd1baf19aa2152a4710..c71765f9be5e88e77e34fb0e038253bb16f8d85c 100644 (file)
@@ -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';
 
index 2123d63e2efd8d64c27862f83c154eb8e631c2ec..9a5b5bbadd220577adca5810d99806f39c660bac 100644 (file)
@@ -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;