Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit240cd6b

Browse files
committed
Another round of portability hacking on ECPG regression tests.
Removing the separate Windows expected-files in commitf188538turns out to have been too optimistic: on most (but not all!) of ourWindows buildfarm members, the tests still print floats with threeexponent digits, because they're invoking the native printf()not snprintf.c.But rather than put back the extra expected-files, let's hackthe three tests in question so that they adjust float formattingthe same way snprintf.c does.Discussion:https://postgr.es/m/18890.1539374107@sss.pgh.pa.us
1 parent13cd720 commit240cd6b

File tree

10 files changed

+170
-63
lines changed

10 files changed

+170
-63
lines changed

‎src/interfaces/ecpg/test/Makefile.regress

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ ECPG = ../../preproc/ecpg --regression -I$(srcdir)/../../include -I$(srcdir)
1515
# Files that most or all ecpg preprocessor test outputs depend on
1616
ECPG_TEST_DEPENDENCIES = ../../preproc/ecpg$(X) \
1717
$(srcdir)/../regression.h \
18+
$(srcdir)/../printf_hack.h \
1819
$(srcdir)/../../include/sqlca.h \
1920
$(srcdir)/../../include/sqlda.h \
2021
$(srcdir)/../../include/sqltypes.h \

‎src/interfaces/ecpg/test/compat_informix/dec_test.pgc

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,7 @@
77

88
exec sql include ../regression;
99

10-
11-
/*
12-
13-
NOTE: This file has a different expect file for regression tests on MinGW32
14-
15-
*/
16-
17-
10+
exec sql include ../printf_hack;
1811

1912

2013
/*
@@ -115,7 +108,9 @@ main(void)
115108
/* this is a libc problem since we only call strtod() */
116109
r = dectodbl(dec, &dbl);
117110
if (r) check_errno();
118-
printf("dec[%d,10]: %g (r: %d)\n", i, r?0.0:dbl, r);
111+
printf("dec[%d,10]: ", i);
112+
print_double(r ? 0.0 : dbl);
113+
printf(" (r: %d)\n", r);
119114
}
120115

121116
PGTYPESdecimal_free(din);

‎src/interfaces/ecpg/test/expected/compat_informix-dec_test.c

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,38 @@
2828

2929

3030

31+
#line 1 "printf_hack.h"
3132
/*
33+
* print_double(x) has the same effect as printf("%g", x), but is intended
34+
* to produce the same formatting across all platforms.
35+
*/
36+
staticvoid
37+
print_double(doublex)
38+
{
39+
#ifdefWIN32
40+
/* Change Windows' 3-digit exponents to look like everyone else's */
41+
charconvert[128];
42+
intvallen;
3243

33-
NOTE: This file has a different expect file for regression tests on MinGW32
44+
sprintf(convert,"%g",x);
45+
vallen=strlen(convert);
3446

35-
*/
47+
if (vallen >=6&&
48+
convert[vallen-5]=='e'&&
49+
convert[vallen-3]=='0')
50+
{
51+
convert[vallen-3]=convert[vallen-2];
52+
convert[vallen-2]=convert[vallen-1];
53+
convert[vallen-1]='\0';
54+
}
55+
56+
printf("%s",convert);
57+
#else
58+
printf("%g",x);
59+
#endif
60+
}
3661

62+
#line 10 "dec_test.pgc"
3763

3864

3965

@@ -135,7 +161,9 @@ main(void)
135161
/* this is a libc problem since we only call strtod() */
136162
r=dectodbl(dec,&dbl);
137163
if (r)check_errno();
138-
printf("dec[%d,10]: %g (r: %d)\n",i,r?0.0:dbl,r);
164+
printf("dec[%d,10]: ",i);
165+
print_double(r ?0.0 :dbl);
166+
printf(" (r: %d)\n",r);
139167
}
140168

141169
PGTYPESdecimal_free(din);

‎src/interfaces/ecpg/test/expected/pgtypeslib-num_test.c

Lines changed: 50 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,39 @@
2424

2525

2626

27+
#line 1 "printf_hack.h"
2728
/*
29+
* print_double(x) has the same effect as printf("%g", x), but is intended
30+
* to produce the same formatting across all platforms.
31+
*/
32+
staticvoid
33+
print_double(doublex)
34+
{
35+
#ifdefWIN32
36+
/* Change Windows' 3-digit exponents to look like everyone else's */
37+
charconvert[128];
38+
intvallen;
39+
40+
sprintf(convert,"%g",x);
41+
vallen=strlen(convert);
42+
43+
if (vallen >=6&&
44+
convert[vallen-5]=='e'&&
45+
convert[vallen-3]=='0')
46+
{
47+
convert[vallen-3]=convert[vallen-2];
48+
convert[vallen-2]=convert[vallen-1];
49+
convert[vallen-1]='\0';
50+
}
51+
52+
printf("%s",convert);
53+
#else
54+
printf("%g",x);
55+
#endif
56+
}
2857

29-
NOTE: This file has a different expect file for regression tests on MinGW32
58+
#line 8 "num_test.pgc"
3059

31-
*/
3260

3361

3462
int
@@ -40,38 +68,38 @@ main(void)
4068

4169
/* = {0, 0, 0, 0, 0, NULL, NULL} ; */
4270

43-
#line22 "num_test.pgc"
71+
#line17 "num_test.pgc"
4472
numeric*des ;
4573
/* exec sql end declare section */
46-
#line24 "num_test.pgc"
74+
#line19 "num_test.pgc"
4775

4876
doubled;
4977
longl1,l2;
5078
inti;
5179

5280
ECPGdebug(1,stderr);
5381
/* exec sql whenever sqlerror do sqlprint ( ) ; */
54-
#line30 "num_test.pgc"
82+
#line25 "num_test.pgc"
5583

5684

5785
{ECPGconnect(__LINE__,0,"ecpg1_regression" ,NULL,NULL ,NULL,0);
58-
#line32 "num_test.pgc"
86+
#line27 "num_test.pgc"
5987

6088
if (sqlca.sqlcode<0)sqlprint ( );}
61-
#line32 "num_test.pgc"
89+
#line27 "num_test.pgc"
6290

6391

6492
{ECPGsetcommit(__LINE__,"off",NULL);
65-
#line34 "num_test.pgc"
93+
#line29 "num_test.pgc"
6694

6795
if (sqlca.sqlcode<0)sqlprint ( );}
68-
#line34 "num_test.pgc"
96+
#line29 "num_test.pgc"
6997

7098
{ECPGdo(__LINE__,0,1,NULL,0,ECPGst_normal,"create table test ( text char ( 5 ) , num numeric ( 14 , 7 ) )",ECPGt_EOIT,ECPGt_EORT);
71-
#line35 "num_test.pgc"
99+
#line30 "num_test.pgc"
72100

73101
if (sqlca.sqlcode<0)sqlprint ( );}
74-
#line35 "num_test.pgc"
102+
#line30 "num_test.pgc"
75103

76104

77105
value1=PGTYPESnumeric_new();
@@ -100,10 +128,10 @@ if (sqlca.sqlcode < 0) sqlprint ( );}
100128
{ECPGdo(__LINE__,0,1,NULL,0,ECPGst_normal,"insert into test ( text , num ) values ( 'test' , $1 )",
101129
ECPGt_numeric,&(des),(long)1,(long)0,sizeof(numeric),
102130
ECPGt_NO_INDICATOR,NULL ,0L,0L,0L,ECPGt_EOIT,ECPGt_EORT);
103-
#line60 "num_test.pgc"
131+
#line55 "num_test.pgc"
104132

105133
if (sqlca.sqlcode<0)sqlprint ( );}
106-
#line60 "num_test.pgc"
134+
#line55 "num_test.pgc"
107135

108136

109137
value2=PGTYPESnumeric_from_asc("2369.7",NULL);
@@ -113,10 +141,10 @@ if (sqlca.sqlcode < 0) sqlprint ( );}
113141
{ECPGdo(__LINE__,0,1,NULL,0,ECPGst_normal,"select num from test where text = 'test'",ECPGt_EOIT,
114142
ECPGt_numeric,&(des),(long)1,(long)0,sizeof(numeric),
115143
ECPGt_NO_INDICATOR,NULL ,0L,0L,0L,ECPGt_EORT);
116-
#line66 "num_test.pgc"
144+
#line61 "num_test.pgc"
117145

118146
if (sqlca.sqlcode<0)sqlprint ( );}
119-
#line66 "num_test.pgc"
147+
#line61 "num_test.pgc"
120148

121149

122150
PGTYPESnumeric_mul(res,des,res);
@@ -129,7 +157,9 @@ if (sqlca.sqlcode < 0) sqlprint ( );}
129157
PGTYPESnumeric_div(res,value2,res);
130158
text=PGTYPESnumeric_to_asc(res,-1);
131159
PGTYPESnumeric_to_double(res,&d);
132-
printf("div = %s %e\n",text,d);
160+
printf("div = %s ",text);
161+
print_double(d);
162+
printf("\n");
133163

134164
PGTYPESnumeric_free(value1);
135165
PGTYPESnumeric_free(value2);
@@ -145,16 +175,16 @@ if (sqlca.sqlcode < 0) sqlprint ( );}
145175
PGTYPESnumeric_free(res);
146176

147177
{ECPGtrans(__LINE__,NULL,"rollback");
148-
#line93 "num_test.pgc"
178+
#line90 "num_test.pgc"
149179

150180
if (sqlca.sqlcode<0)sqlprint ( );}
151-
#line93 "num_test.pgc"
181+
#line90 "num_test.pgc"
152182

153183
{ECPGdisconnect(__LINE__,"CURRENT");
154-
#line94 "num_test.pgc"
184+
#line91 "num_test.pgc"
155185

156186
if (sqlca.sqlcode<0)sqlprint ( );}
157-
#line94 "num_test.pgc"
187+
#line91 "num_test.pgc"
158188

159189

160190
return0;

‎src/interfaces/ecpg/test/expected/pgtypeslib-num_test.stderr

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,31 @@
22
[NO_PID]: sqlca: code: 0, state: 00000
33
[NO_PID]: ECPGconnect: opening database ecpg1_regression on <DEFAULT> port <DEFAULT>
44
[NO_PID]: sqlca: code: 0, state: 00000
5-
[NO_PID]: ECPGsetcommit on line34: action "off"; connection "ecpg1_regression"
5+
[NO_PID]: ECPGsetcommit on line29: action "off"; connection "ecpg1_regression"
66
[NO_PID]: sqlca: code: 0, state: 00000
7-
[NO_PID]: ecpg_execute on line35: query: create table test ( text char ( 5 ) , num numeric ( 14 , 7 ) ); with 0 parameter(s) on connection ecpg1_regression
7+
[NO_PID]: ecpg_execute on line30: query: create table test ( text char ( 5 ) , num numeric ( 14 , 7 ) ); with 0 parameter(s) on connection ecpg1_regression
88
[NO_PID]: sqlca: code: 0, state: 00000
9-
[NO_PID]: ecpg_execute on line35: using PQexec
9+
[NO_PID]: ecpg_execute on line30: using PQexec
1010
[NO_PID]: sqlca: code: 0, state: 00000
11-
[NO_PID]: ecpg_process_output on line35: OK: CREATE TABLE
11+
[NO_PID]: ecpg_process_output on line30: OK: CREATE TABLE
1212
[NO_PID]: sqlca: code: 0, state: 00000
13-
[NO_PID]: ecpg_execute on line60: query: insert into test ( text , num ) values ( 'test' , $1 ); with 1 parameter(s) on connection ecpg1_regression
13+
[NO_PID]: ecpg_execute on line55: query: insert into test ( text , num ) values ( 'test' , $1 ); with 1 parameter(s) on connection ecpg1_regression
1414
[NO_PID]: sqlca: code: 0, state: 00000
15-
[NO_PID]: ecpg_execute on line60: using PQexecParams
15+
[NO_PID]: ecpg_execute on line55: using PQexecParams
1616
[NO_PID]: sqlca: code: 0, state: 00000
17-
[NO_PID]: ecpg_free_params on line60: parameter 1 = 2369.7
17+
[NO_PID]: ecpg_free_params on line55: parameter 1 = 2369.7
1818
[NO_PID]: sqlca: code: 0, state: 00000
19-
[NO_PID]: ecpg_process_output on line60: OK: INSERT 0 1
19+
[NO_PID]: ecpg_process_output on line55: OK: INSERT 0 1
2020
[NO_PID]: sqlca: code: 0, state: 00000
21-
[NO_PID]: ecpg_execute on line66: query: select num from test where text = 'test'; with 0 parameter(s) on connection ecpg1_regression
21+
[NO_PID]: ecpg_execute on line61: query: select num from test where text = 'test'; with 0 parameter(s) on connection ecpg1_regression
2222
[NO_PID]: sqlca: code: 0, state: 00000
23-
[NO_PID]: ecpg_execute on line66: using PQexec
23+
[NO_PID]: ecpg_execute on line61: using PQexec
2424
[NO_PID]: sqlca: code: 0, state: 00000
25-
[NO_PID]: ecpg_process_output on line66: correctly got 1 tuples with 1 fields
25+
[NO_PID]: ecpg_process_output on line61: correctly got 1 tuples with 1 fields
2626
[NO_PID]: sqlca: code: 0, state: 00000
27-
[NO_PID]: ecpg_get_data on line66: RESULT: 2369.7000000 offset: -1; array: no
27+
[NO_PID]: ecpg_get_data on line61: RESULT: 2369.7000000 offset: -1; array: no
2828
[NO_PID]: sqlca: code: 0, state: 00000
29-
[NO_PID]: ECPGtrans on line93: action "rollback"; connection "ecpg1_regression"
29+
[NO_PID]: ECPGtrans on line90: action "rollback"; connection "ecpg1_regression"
3030
[NO_PID]: sqlca: code: 0, state: 00000
3131
[NO_PID]: ecpg_finish: connection ecpg1_regression closed
3232
[NO_PID]: sqlca: code: 0, state: 00000

‎src/interfaces/ecpg/test/expected/pgtypeslib-num_test.stdout

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ from int = 1407.0
22
add = 2379.7
33
sub = 2369.7
44
mul = 13306998429.873000000
5-
div = 1330699.84298730000 1.330700e+06
5+
div = 1330699.84298730000 1.3307e+06
66
to long(0) = 20000000 14

‎src/interfaces/ecpg/test/expected/pgtypeslib-num_test2.c

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,39 @@
2525

2626

2727

28+
#line 1 "printf_hack.h"
2829
/*
30+
* print_double(x) has the same effect as printf("%g", x), but is intended
31+
* to produce the same formatting across all platforms.
32+
*/
33+
staticvoid
34+
print_double(doublex)
35+
{
36+
#ifdefWIN32
37+
/* Change Windows' 3-digit exponents to look like everyone else's */
38+
charconvert[128];
39+
intvallen;
40+
41+
sprintf(convert,"%g",x);
42+
vallen=strlen(convert);
43+
44+
if (vallen >=6&&
45+
convert[vallen-5]=='e'&&
46+
convert[vallen-3]=='0')
47+
{
48+
convert[vallen-3]=convert[vallen-2];
49+
convert[vallen-2]=convert[vallen-1];
50+
convert[vallen-1]='\0';
51+
}
52+
53+
printf("%s",convert);
54+
#else
55+
printf("%g",x);
56+
#endif
57+
}
2958

30-
NOTE: This file has a different expect file for regression tests on MinGW32
59+
#line 9 "num_test2.pgc"
3160

32-
*/
3361

3462

3563
char*nums[]= {"2E394","-2",".794","3.44","592.49E21","-32.84e4",
@@ -126,7 +154,9 @@ main(void)
126154

127155
r=PGTYPESnumeric_to_double(num,&d);
128156
if (r)check_errno();
129-
printf("num[%d,10]: %g (r: %d)\n",i,r?0.0:d,r);
157+
printf("num[%d,10]: ",i);
158+
print_double(r ?0.0 :d);
159+
printf(" (r: %d)\n",r);
130160
}
131161

132162
/* do not test double to numeric because

‎src/interfaces/ecpg/test/pgtypeslib/num_test.pgc

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,7 @@
55

66
exec sql include ../regression;
77

8-
9-
/*
10-
11-
NOTE: This file has a different expect file for regression tests on MinGW32
12-
13-
*/
8+
exec sql include ../printf_hack;
149

1510

1611
int
@@ -75,7 +70,9 @@ main(void)
7570
PGTYPESnumeric_div(res, value2, res);
7671
text = PGTYPESnumeric_to_asc(res, -1);
7772
PGTYPESnumeric_to_double(res, &d);
78-
printf("div = %s %e\n", text, d);
73+
printf("div = %s ", text);
74+
print_double(d);
75+
printf("\n");
7976

8077
PGTYPESnumeric_free(value1);
8178
PGTYPESnumeric_free(value2);

‎src/interfaces/ecpg/test/pgtypeslib/num_test2.pgc

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,7 @@
66

77
exec sql include ../regression;
88

9-
10-
/*
11-
12-
NOTE: This file has a different expect file for regression tests on MinGW32
13-
14-
*/
9+
exec sql include ../printf_hack;
1510

1611

1712
char* nums[] = { "2E394", "-2", ".794", "3.44", "592.49E21", "-32.84e4",
@@ -108,7 +103,9 @@ main(void)
108103

109104
r = PGTYPESnumeric_to_double(num, &d);
110105
if (r) check_errno();
111-
printf("num[%d,10]: %g (r: %d)\n", i, r?0.0:d, r);
106+
printf("num[%d,10]: ", i);
107+
print_double(r ? 0.0 : d);
108+
printf(" (r: %d)\n", r);
112109
}
113110

114111
/* do not test double to numeric because

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp