mirror of
https://github.com/postgres/postgres.git
synced 2025-05-01 01:04:50 +03:00
Another round of portability hacking on ECPG regression tests.
Removing the separate Windows expected-files in commit f1885386f turns out to have been too optimistic: on most (but not all!) of our Windows buildfarm members, the tests still print floats with three exponent digits, because they're invoking the native printf() not snprintf.c. But rather than put back the extra expected-files, let's hack the three tests in question so that they adjust float formatting the same way snprintf.c does. Discussion: https://postgr.es/m/18890.1539374107@sss.pgh.pa.us
This commit is contained in:
parent
13cd7209f7
commit
240cd6bc83
@ -15,6 +15,7 @@ ECPG = ../../preproc/ecpg --regression -I$(srcdir)/../../include -I$(srcdir)
|
||||
# Files that most or all ecpg preprocessor test outputs depend on
|
||||
ECPG_TEST_DEPENDENCIES = ../../preproc/ecpg$(X) \
|
||||
$(srcdir)/../regression.h \
|
||||
$(srcdir)/../printf_hack.h \
|
||||
$(srcdir)/../../include/sqlca.h \
|
||||
$(srcdir)/../../include/sqlda.h \
|
||||
$(srcdir)/../../include/sqltypes.h \
|
||||
|
@ -7,14 +7,7 @@
|
||||
|
||||
exec sql include ../regression;
|
||||
|
||||
|
||||
/*
|
||||
|
||||
NOTE: This file has a different expect file for regression tests on MinGW32
|
||||
|
||||
*/
|
||||
|
||||
|
||||
exec sql include ../printf_hack;
|
||||
|
||||
|
||||
/*
|
||||
@ -115,7 +108,9 @@ main(void)
|
||||
/* this is a libc problem since we only call strtod() */
|
||||
r = dectodbl(dec, &dbl);
|
||||
if (r) check_errno();
|
||||
printf("dec[%d,10]: %g (r: %d)\n", i, r?0.0:dbl, r);
|
||||
printf("dec[%d,10]: ", i);
|
||||
print_double(r ? 0.0 : dbl);
|
||||
printf(" (r: %d)\n", r);
|
||||
}
|
||||
|
||||
PGTYPESdecimal_free(din);
|
||||
|
@ -28,12 +28,38 @@
|
||||
|
||||
|
||||
|
||||
#line 1 "printf_hack.h"
|
||||
/*
|
||||
* print_double(x) has the same effect as printf("%g", x), but is intended
|
||||
* to produce the same formatting across all platforms.
|
||||
*/
|
||||
static void
|
||||
print_double(double x)
|
||||
{
|
||||
#ifdef WIN32
|
||||
/* Change Windows' 3-digit exponents to look like everyone else's */
|
||||
char convert[128];
|
||||
int vallen;
|
||||
|
||||
NOTE: This file has a different expect file for regression tests on MinGW32
|
||||
sprintf(convert, "%g", x);
|
||||
vallen = strlen(convert);
|
||||
|
||||
*/
|
||||
if (vallen >= 6 &&
|
||||
convert[vallen - 5] == 'e' &&
|
||||
convert[vallen - 3] == '0')
|
||||
{
|
||||
convert[vallen - 3] = convert[vallen - 2];
|
||||
convert[vallen - 2] = convert[vallen - 1];
|
||||
convert[vallen - 1] = '\0';
|
||||
}
|
||||
|
||||
printf("%s", convert);
|
||||
#else
|
||||
printf("%g", x);
|
||||
#endif
|
||||
}
|
||||
|
||||
#line 10 "dec_test.pgc"
|
||||
|
||||
|
||||
|
||||
@ -135,7 +161,9 @@ main(void)
|
||||
/* this is a libc problem since we only call strtod() */
|
||||
r = dectodbl(dec, &dbl);
|
||||
if (r) check_errno();
|
||||
printf("dec[%d,10]: %g (r: %d)\n", i, r?0.0:dbl, r);
|
||||
printf("dec[%d,10]: ", i);
|
||||
print_double(r ? 0.0 : dbl);
|
||||
printf(" (r: %d)\n", r);
|
||||
}
|
||||
|
||||
PGTYPESdecimal_free(din);
|
||||
|
@ -24,11 +24,39 @@
|
||||
|
||||
|
||||
|
||||
#line 1 "printf_hack.h"
|
||||
/*
|
||||
* print_double(x) has the same effect as printf("%g", x), but is intended
|
||||
* to produce the same formatting across all platforms.
|
||||
*/
|
||||
static void
|
||||
print_double(double x)
|
||||
{
|
||||
#ifdef WIN32
|
||||
/* Change Windows' 3-digit exponents to look like everyone else's */
|
||||
char convert[128];
|
||||
int vallen;
|
||||
|
||||
NOTE: This file has a different expect file for regression tests on MinGW32
|
||||
sprintf(convert, "%g", x);
|
||||
vallen = strlen(convert);
|
||||
|
||||
if (vallen >= 6 &&
|
||||
convert[vallen - 5] == 'e' &&
|
||||
convert[vallen - 3] == '0')
|
||||
{
|
||||
convert[vallen - 3] = convert[vallen - 2];
|
||||
convert[vallen - 2] = convert[vallen - 1];
|
||||
convert[vallen - 1] = '\0';
|
||||
}
|
||||
|
||||
printf("%s", convert);
|
||||
#else
|
||||
printf("%g", x);
|
||||
#endif
|
||||
}
|
||||
|
||||
#line 8 "num_test.pgc"
|
||||
|
||||
*/
|
||||
|
||||
|
||||
int
|
||||
@ -40,10 +68,10 @@ main(void)
|
||||
|
||||
/* = {0, 0, 0, 0, 0, NULL, NULL} ; */
|
||||
|
||||
#line 22 "num_test.pgc"
|
||||
#line 17 "num_test.pgc"
|
||||
numeric * des ;
|
||||
/* exec sql end declare section */
|
||||
#line 24 "num_test.pgc"
|
||||
#line 19 "num_test.pgc"
|
||||
|
||||
double d;
|
||||
long l1, l2;
|
||||
@ -51,27 +79,27 @@ main(void)
|
||||
|
||||
ECPGdebug(1, stderr);
|
||||
/* exec sql whenever sqlerror do sqlprint ( ) ; */
|
||||
#line 30 "num_test.pgc"
|
||||
#line 25 "num_test.pgc"
|
||||
|
||||
|
||||
{ ECPGconnect(__LINE__, 0, "ecpg1_regression" , NULL, NULL , NULL, 0);
|
||||
#line 32 "num_test.pgc"
|
||||
#line 27 "num_test.pgc"
|
||||
|
||||
if (sqlca.sqlcode < 0) sqlprint ( );}
|
||||
#line 32 "num_test.pgc"
|
||||
#line 27 "num_test.pgc"
|
||||
|
||||
|
||||
{ ECPGsetcommit(__LINE__, "off", NULL);
|
||||
#line 34 "num_test.pgc"
|
||||
#line 29 "num_test.pgc"
|
||||
|
||||
if (sqlca.sqlcode < 0) sqlprint ( );}
|
||||
#line 34 "num_test.pgc"
|
||||
#line 29 "num_test.pgc"
|
||||
|
||||
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "create table test ( text char ( 5 ) , num numeric ( 14 , 7 ) )", ECPGt_EOIT, ECPGt_EORT);
|
||||
#line 35 "num_test.pgc"
|
||||
#line 30 "num_test.pgc"
|
||||
|
||||
if (sqlca.sqlcode < 0) sqlprint ( );}
|
||||
#line 35 "num_test.pgc"
|
||||
#line 30 "num_test.pgc"
|
||||
|
||||
|
||||
value1 = PGTYPESnumeric_new();
|
||||
@ -100,10 +128,10 @@ if (sqlca.sqlcode < 0) sqlprint ( );}
|
||||
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "insert into test ( text , num ) values ( 'test' , $1 )",
|
||||
ECPGt_numeric,&(des),(long)1,(long)0,sizeof(numeric),
|
||||
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
|
||||
#line 60 "num_test.pgc"
|
||||
#line 55 "num_test.pgc"
|
||||
|
||||
if (sqlca.sqlcode < 0) sqlprint ( );}
|
||||
#line 60 "num_test.pgc"
|
||||
#line 55 "num_test.pgc"
|
||||
|
||||
|
||||
value2 = PGTYPESnumeric_from_asc("2369.7", NULL);
|
||||
@ -113,10 +141,10 @@ if (sqlca.sqlcode < 0) sqlprint ( );}
|
||||
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "select num from test where text = 'test'", ECPGt_EOIT,
|
||||
ECPGt_numeric,&(des),(long)1,(long)0,sizeof(numeric),
|
||||
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
|
||||
#line 66 "num_test.pgc"
|
||||
#line 61 "num_test.pgc"
|
||||
|
||||
if (sqlca.sqlcode < 0) sqlprint ( );}
|
||||
#line 66 "num_test.pgc"
|
||||
#line 61 "num_test.pgc"
|
||||
|
||||
|
||||
PGTYPESnumeric_mul(res, des, res);
|
||||
@ -129,7 +157,9 @@ if (sqlca.sqlcode < 0) sqlprint ( );}
|
||||
PGTYPESnumeric_div(res, value2, res);
|
||||
text = PGTYPESnumeric_to_asc(res, -1);
|
||||
PGTYPESnumeric_to_double(res, &d);
|
||||
printf("div = %s %e\n", text, d);
|
||||
printf("div = %s ", text);
|
||||
print_double(d);
|
||||
printf("\n");
|
||||
|
||||
PGTYPESnumeric_free(value1);
|
||||
PGTYPESnumeric_free(value2);
|
||||
@ -145,16 +175,16 @@ if (sqlca.sqlcode < 0) sqlprint ( );}
|
||||
PGTYPESnumeric_free(res);
|
||||
|
||||
{ ECPGtrans(__LINE__, NULL, "rollback");
|
||||
#line 93 "num_test.pgc"
|
||||
#line 90 "num_test.pgc"
|
||||
|
||||
if (sqlca.sqlcode < 0) sqlprint ( );}
|
||||
#line 93 "num_test.pgc"
|
||||
#line 90 "num_test.pgc"
|
||||
|
||||
{ ECPGdisconnect(__LINE__, "CURRENT");
|
||||
#line 94 "num_test.pgc"
|
||||
#line 91 "num_test.pgc"
|
||||
|
||||
if (sqlca.sqlcode < 0) sqlprint ( );}
|
||||
#line 94 "num_test.pgc"
|
||||
#line 91 "num_test.pgc"
|
||||
|
||||
|
||||
return 0;
|
||||
|
@ -2,31 +2,31 @@
|
||||
[NO_PID]: sqlca: code: 0, state: 00000
|
||||
[NO_PID]: ECPGconnect: opening database ecpg1_regression on <DEFAULT> port <DEFAULT>
|
||||
[NO_PID]: sqlca: code: 0, state: 00000
|
||||
[NO_PID]: ECPGsetcommit on line 34: action "off"; connection "ecpg1_regression"
|
||||
[NO_PID]: ECPGsetcommit on line 29: action "off"; connection "ecpg1_regression"
|
||||
[NO_PID]: sqlca: code: 0, state: 00000
|
||||
[NO_PID]: ecpg_execute on line 35: query: create table test ( text char ( 5 ) , num numeric ( 14 , 7 ) ); with 0 parameter(s) on connection ecpg1_regression
|
||||
[NO_PID]: ecpg_execute on line 30: query: create table test ( text char ( 5 ) , num numeric ( 14 , 7 ) ); with 0 parameter(s) on connection ecpg1_regression
|
||||
[NO_PID]: sqlca: code: 0, state: 00000
|
||||
[NO_PID]: ecpg_execute on line 35: using PQexec
|
||||
[NO_PID]: ecpg_execute on line 30: using PQexec
|
||||
[NO_PID]: sqlca: code: 0, state: 00000
|
||||
[NO_PID]: ecpg_process_output on line 35: OK: CREATE TABLE
|
||||
[NO_PID]: ecpg_process_output on line 30: OK: CREATE TABLE
|
||||
[NO_PID]: sqlca: code: 0, state: 00000
|
||||
[NO_PID]: ecpg_execute on line 60: query: insert into test ( text , num ) values ( 'test' , $1 ); with 1 parameter(s) on connection ecpg1_regression
|
||||
[NO_PID]: ecpg_execute on line 55: query: insert into test ( text , num ) values ( 'test' , $1 ); with 1 parameter(s) on connection ecpg1_regression
|
||||
[NO_PID]: sqlca: code: 0, state: 00000
|
||||
[NO_PID]: ecpg_execute on line 60: using PQexecParams
|
||||
[NO_PID]: ecpg_execute on line 55: using PQexecParams
|
||||
[NO_PID]: sqlca: code: 0, state: 00000
|
||||
[NO_PID]: ecpg_free_params on line 60: parameter 1 = 2369.7
|
||||
[NO_PID]: ecpg_free_params on line 55: parameter 1 = 2369.7
|
||||
[NO_PID]: sqlca: code: 0, state: 00000
|
||||
[NO_PID]: ecpg_process_output on line 60: OK: INSERT 0 1
|
||||
[NO_PID]: ecpg_process_output on line 55: OK: INSERT 0 1
|
||||
[NO_PID]: sqlca: code: 0, state: 00000
|
||||
[NO_PID]: ecpg_execute on line 66: query: select num from test where text = 'test'; with 0 parameter(s) on connection ecpg1_regression
|
||||
[NO_PID]: ecpg_execute on line 61: query: select num from test where text = 'test'; with 0 parameter(s) on connection ecpg1_regression
|
||||
[NO_PID]: sqlca: code: 0, state: 00000
|
||||
[NO_PID]: ecpg_execute on line 66: using PQexec
|
||||
[NO_PID]: ecpg_execute on line 61: using PQexec
|
||||
[NO_PID]: sqlca: code: 0, state: 00000
|
||||
[NO_PID]: ecpg_process_output on line 66: correctly got 1 tuples with 1 fields
|
||||
[NO_PID]: ecpg_process_output on line 61: correctly got 1 tuples with 1 fields
|
||||
[NO_PID]: sqlca: code: 0, state: 00000
|
||||
[NO_PID]: ecpg_get_data on line 66: RESULT: 2369.7000000 offset: -1; array: no
|
||||
[NO_PID]: ecpg_get_data on line 61: RESULT: 2369.7000000 offset: -1; array: no
|
||||
[NO_PID]: sqlca: code: 0, state: 00000
|
||||
[NO_PID]: ECPGtrans on line 93: action "rollback"; connection "ecpg1_regression"
|
||||
[NO_PID]: ECPGtrans on line 90: action "rollback"; connection "ecpg1_regression"
|
||||
[NO_PID]: sqlca: code: 0, state: 00000
|
||||
[NO_PID]: ecpg_finish: connection ecpg1_regression closed
|
||||
[NO_PID]: sqlca: code: 0, state: 00000
|
||||
|
@ -2,5 +2,5 @@ from int = 1407.0
|
||||
add = 2379.7
|
||||
sub = 2369.7
|
||||
mul = 13306998429.873000000
|
||||
div = 1330699.84298730000 1.330700e+06
|
||||
div = 1330699.84298730000 1.3307e+06
|
||||
to long(0) = 20000000 14
|
||||
|
@ -25,11 +25,39 @@
|
||||
|
||||
|
||||
|
||||
#line 1 "printf_hack.h"
|
||||
/*
|
||||
* print_double(x) has the same effect as printf("%g", x), but is intended
|
||||
* to produce the same formatting across all platforms.
|
||||
*/
|
||||
static void
|
||||
print_double(double x)
|
||||
{
|
||||
#ifdef WIN32
|
||||
/* Change Windows' 3-digit exponents to look like everyone else's */
|
||||
char convert[128];
|
||||
int vallen;
|
||||
|
||||
NOTE: This file has a different expect file for regression tests on MinGW32
|
||||
sprintf(convert, "%g", x);
|
||||
vallen = strlen(convert);
|
||||
|
||||
if (vallen >= 6 &&
|
||||
convert[vallen - 5] == 'e' &&
|
||||
convert[vallen - 3] == '0')
|
||||
{
|
||||
convert[vallen - 3] = convert[vallen - 2];
|
||||
convert[vallen - 2] = convert[vallen - 1];
|
||||
convert[vallen - 1] = '\0';
|
||||
}
|
||||
|
||||
printf("%s", convert);
|
||||
#else
|
||||
printf("%g", x);
|
||||
#endif
|
||||
}
|
||||
|
||||
#line 9 "num_test2.pgc"
|
||||
|
||||
*/
|
||||
|
||||
|
||||
char* nums[] = { "2E394", "-2", ".794", "3.44", "592.49E21", "-32.84e4",
|
||||
@ -126,7 +154,9 @@ main(void)
|
||||
|
||||
r = PGTYPESnumeric_to_double(num, &d);
|
||||
if (r) check_errno();
|
||||
printf("num[%d,10]: %g (r: %d)\n", i, r?0.0:d, r);
|
||||
printf("num[%d,10]: ", i);
|
||||
print_double(r ? 0.0 : d);
|
||||
printf(" (r: %d)\n", r);
|
||||
}
|
||||
|
||||
/* do not test double to numeric because
|
||||
|
@ -5,12 +5,7 @@
|
||||
|
||||
exec sql include ../regression;
|
||||
|
||||
|
||||
/*
|
||||
|
||||
NOTE: This file has a different expect file for regression tests on MinGW32
|
||||
|
||||
*/
|
||||
exec sql include ../printf_hack;
|
||||
|
||||
|
||||
int
|
||||
@ -75,7 +70,9 @@ main(void)
|
||||
PGTYPESnumeric_div(res, value2, res);
|
||||
text = PGTYPESnumeric_to_asc(res, -1);
|
||||
PGTYPESnumeric_to_double(res, &d);
|
||||
printf("div = %s %e\n", text, d);
|
||||
printf("div = %s ", text);
|
||||
print_double(d);
|
||||
printf("\n");
|
||||
|
||||
PGTYPESnumeric_free(value1);
|
||||
PGTYPESnumeric_free(value2);
|
||||
|
@ -6,12 +6,7 @@
|
||||
|
||||
exec sql include ../regression;
|
||||
|
||||
|
||||
/*
|
||||
|
||||
NOTE: This file has a different expect file for regression tests on MinGW32
|
||||
|
||||
*/
|
||||
exec sql include ../printf_hack;
|
||||
|
||||
|
||||
char* nums[] = { "2E394", "-2", ".794", "3.44", "592.49E21", "-32.84e4",
|
||||
@ -108,7 +103,9 @@ main(void)
|
||||
|
||||
r = PGTYPESnumeric_to_double(num, &d);
|
||||
if (r) check_errno();
|
||||
printf("num[%d,10]: %g (r: %d)\n", i, r?0.0:d, r);
|
||||
printf("num[%d,10]: ", i);
|
||||
print_double(r ? 0.0 : d);
|
||||
printf(" (r: %d)\n", r);
|
||||
}
|
||||
|
||||
/* do not test double to numeric because
|
||||
|
29
src/interfaces/ecpg/test/printf_hack.h
Normal file
29
src/interfaces/ecpg/test/printf_hack.h
Normal file
@ -0,0 +1,29 @@
|
||||
/*
|
||||
* print_double(x) has the same effect as printf("%g", x), but is intended
|
||||
* to produce the same formatting across all platforms.
|
||||
*/
|
||||
static void
|
||||
print_double(double x)
|
||||
{
|
||||
#ifdef WIN32
|
||||
/* Change Windows' 3-digit exponents to look like everyone else's */
|
||||
char convert[128];
|
||||
int vallen;
|
||||
|
||||
sprintf(convert, "%g", x);
|
||||
vallen = strlen(convert);
|
||||
|
||||
if (vallen >= 6 &&
|
||||
convert[vallen - 5] == 'e' &&
|
||||
convert[vallen - 3] == '0')
|
||||
{
|
||||
convert[vallen - 3] = convert[vallen - 2];
|
||||
convert[vallen - 2] = convert[vallen - 1];
|
||||
convert[vallen - 1] = '\0';
|
||||
}
|
||||
|
||||
printf("%s", convert);
|
||||
#else
|
||||
printf("%g", x);
|
||||
#endif
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user