> For the complete documentation index, see [llms.txt](https://docs.postgresql.tw/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.postgresql.tw/19/server-administration/regress/regress-variant.md). Agents can also search and read this documentation through its [MCP server](https://docs.postgresql.tw/~gitbook/mcp).

# 31.3. 變體比對檔案 \#

### 31.3. 變體比對檔案 [#](#regress-variant) <a href="#regress-variant" id="regress-variant"></a>

由於部分測試本質上會產生依環境而異的結果， 我們提供了指定替代「預期」結果檔案的方式。 每個迴歸測試都可以有多個比對檔案， 分別顯示在不同平台上可能出現的結果。 判斷每項測試要使用哪個比對檔案，有兩種獨立的機制。

第一種機制，可讓你針對特定平台選擇比對檔案。 有一個對應檔 `src/test/regress/resultmap`， 用來定義每個平台要使用哪個比對檔案。 若要消除特定平台上虛假的測試「失敗」， 你要先選擇或製作一個變體結果檔案， 再於 `resultmap` 檔案中新增一行。

對應檔中每一行的格式如下：

```

testname:output:platformpattern=comparisonfilename
```

測試名稱就是該特定迴歸測試模組的名稱。輸出值 指出要檢查哪個輸出檔案。對標準迴歸測試而言， 此值一律為 `out`， 對應於輸出檔案的副檔名。 平台樣式是採用 Unix 工具 `expr` 風格的樣式 （也就是說，在開頭隱含加上 `^` 錨點的 正規表示式），會與 `config.guess` 所印出的平台名稱進行比對。 比對檔案名稱，則是取代用結果比對檔案的基本檔名。

舉例來說：有些系統缺少可正常運作的 `strtof` 函式，我們針對此問題所做的因應措施， 會使 `float4` 迴歸測試中出現四捨五入誤差。 因此，我們提供了一份變體比對檔案 `float4-misrounded-input.out`， 其中包含在這類系統上預期會出現的結果。 為了消除 Cygwin 平台上虛假的「失敗」訊息， `resultmap` 中包含以下內容：

```

float4:out:.*-.*-cygwin.*=float4-misrounded-input.out
```

只要 `config.guess` 的輸出符合 `.*-.*-cygwin.*`， 這條規則就會在任何這樣的機器上觸發。 `resultmap` 中的其他行， 則會針對其他適用的平台選擇對應的變體比對檔案。

變體比對檔案的第二種選擇機制，則自動化得多： 它只是在多個所提供的比對檔案中， 挑選「最佳吻合」的那一個。迴歸測試驅動指令碼 會同時考慮某測試的標準比對檔案 `testname.out`，以及名為 `testname_digit.out` （其中\*`digit`*可以是 `0`-`9` 中的任一個單一數字）的變體檔案。 若其中任何一個檔案完全吻合， 就會判定該測試通過；否則， 系統就會使用能產生最短差異（diff）的那個檔案， 來建立失敗報告。（若 `resultmap` 中對該特定測試含有一筆項目， 則基本*`testname`\*就是 `resultmap` 中所指定的替代名稱。）

舉例來說，對於 `char` 測試而言， 比對檔案 `char.out` 中含有在 `C` 與 `POSIX` 地區設定下 所預期的結果，而檔案 `char_1.out` 中則含有按照許多其他地區設定所排序的結果。

最佳吻合機制，是為了因應依地區設定而異的結果而設計， 但它也能用於任何測試結果無法單純從平台名稱 輕易預測的情況。此機制的一項限制， 是測試驅動程式無法得知， 對目前環境而言，哪個變體才是真正「正確」的； 它只會挑選看起來吻合最佳的那個變體。 因此，最安全的做法， 是只在你認為所有情境中皆同樣有效的變體結果上， 使用此機制。

***

原文：[PostgreSQL 18.6 Documentation](https://www.postgresql.org/docs/18/regress-variant.html)（原文版本：18.6；核對日期：2026-09-24）


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.postgresql.tw/19/server-administration/regress/regress-variant.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
