diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2018-10-12 18:08:47 -0400 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2018-10-12 18:08:47 -0400 |
commit | 240cd6bc8366c9848bc2511c623743326e5a187b (patch) | |
tree | 2ce415d843bfaa3899614f316cd9a6ccf9fd4d22 /src/interfaces/ecpg/test/printf_hack.h | |
parent | 13cd7209f794d9dff8084c9748a78a0a5bf0464a (diff) | |
download | postgresql-240cd6bc8366c9848bc2511c623743326e5a187b.tar.gz postgresql-240cd6bc8366c9848bc2511c623743326e5a187b.zip |
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
Diffstat (limited to 'src/interfaces/ecpg/test/printf_hack.h')
-rw-r--r-- | src/interfaces/ecpg/test/printf_hack.h | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/src/interfaces/ecpg/test/printf_hack.h b/src/interfaces/ecpg/test/printf_hack.h new file mode 100644 index 00000000000..ef584c0d548 --- /dev/null +++ b/src/interfaces/ecpg/test/printf_hack.h @@ -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 +} |