Postgresql 中文操作指南
33.3. Variant Comparison Files #
由于某些测试本质上会产生环境相关的结果,因此我们提供了指定备用“预期”结果文件的方法。每个回归测试可以有几个比较文件,显示不同平台上的可能结果。有两种独立的机制用于确定每个测试使用的比较文件。
Since some of the tests inherently produce environment-dependent results, we have provided ways to specify alternate “expected” result files. Each regression test can have several comparison files showing possible results on different platforms. There are two independent mechanisms for determining which comparison file is used for each test.
第一个机制允许为特定平台选择比较文件。有一个映射文件 src/test/regress/resultmap,它定义了在每个平台中使用的比较文件。为了消除特定平台上的虚假测试“失败”,您首先选择或制作一个变体结果文件,然后向 resultmap 文件中添加一行。
The first mechanism allows comparison files to be selected for specific platforms. There is a mapping file, src/test/regress/resultmap, that defines which comparison file to use for each platform. To eliminate bogus test “failures” for a particular platform, you first choose or make a variant result file, and then add a line to the resultmap file.
映射文件中的每一行都采用以下形式:
Each line in the mapping file is of the form
testname:output:platformpattern=comparisonfilename
测试名称只是特定回归测试模块的名称。输出值表示要检查的输出文件。对于标准回归测试,这始终是 out。该值对应于输出文件的扩展名。平台模式采用 Unix 工具 expr 样式的模式(即,在开头带有隐式 ^ 锚点的正则表达式)。它与 config.guess 打印的平台名称相匹配。比较文件名是替代结果比较文件的基名称。
The test name is just the name of the particular regression test module. The output value indicates which output file to check. For the standard regression tests, this is always out. The value corresponds to the file extension of the output file. The platform pattern is a pattern in the style of the Unix tool expr (that is, a regular expression with an implicit ^ anchor at the start). It is matched against the platform name as printed by config.guess. The comparison file name is the base name of the substitute result comparison file.
例如:一些系统缺少工作 strtof 功能,对此我们的解决方法会导致 float4 回归测试中出现舍入误差。因此,我们提供了一个变体比较文件 float4-misrounded-input.out,其中包含预期的这些系统的结果。为了消除 Cygwin 平台上的虚假“失败”消息,resultmap 包含:
For example: some systems lack a working strtof function, for which our workaround causes rounding errors in the float4 regression test. Therefore, we provide a variant comparison file, float4-misrounded-input.out, which includes the results to be expected on these systems. To silence the bogus “failure” message on Cygwin platforms, resultmap includes:
float4:out:.*-.*-cygwin.*=float4-misrounded-input.out
它会在任何输出 config.guess 匹配 .-.-cygwin.* 的机器上触发。resultmap 中的其他行会为适当的其他平台选择变量比较文件。
which will trigger on any machine where the output of config.guess matches .-.-cygwin.*. Other lines in resultmap select the variant comparison file for other platforms where it’s appropriate.
用于变体比较文件的第二个选择机制更加自动化:它只是简单地使用提供的多个比较文件中的“最佳匹配”。回归测试驱动脚本既考虑测试的标准比较文件, testname.out_, and variant files named _ testname___digit_.out_(其中 digit 是任何一个数字 0 到 9 )。如果有任何一个这样的文件完全匹配,则认为测试通过;否则,将使用生成最短的 diff 的那个文件创建失败报告。(如果 resultmap 为特定测试包含一个条目,则基本名称 testname 是在 resultmap 中给出的替换名称。)
The second selection mechanism for variant comparison files is much more automatic: it simply uses the “best match” among several supplied comparison files. The regression test driver script considers both the standard comparison file for a test, testname_.out_, and variant files named testname___digit_.out_ (where the digit is any single digit 0-9). If any such file is an exact match, the test is considered to pass; otherwise, the one that generates the shortest diff is used to create the failure report. (If resultmap includes an entry for the particular test, then the base testname is the substitute name given in resultmap.)
例如,对于 char 测试,比较文件 char.out 包含 C 和 POSIX 本地预期结果,而文件 char_1.out 包含按许多其他本地显示排序的结果。
For example, for the char test, the comparison file char.out contains results that are expected in the C and POSIX locales, while the file char_1.out contains results sorted as they appear in many other locales.
最佳匹配机制旨在应对与区域相关的结果,但它可以在无法仅从平台名称轻松预测测试结果的任何情况下使用。此机制的一个限制是:测试驱动程序无法判断哪个变量实际上是当前环境的“正确”答案;它只挑选看起来效果最好的那个变体。因此,最安全的做法是仅将此机制用于您愿意在所有上下文中都同样考虑有效的结果变体。
The best-match mechanism was devised to cope with locale-dependent results, but it can be used in any situation where the test results cannot be predicted easily from the platform name alone. A limitation of this mechanism is that the test driver cannot tell which variant is actually “correct” for the current environment; it will just pick the variant that seems to work best. Therefore it is safest to use this mechanism only for variant results that you are willing to consider equally valid in all contexts.