

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# test
<a name="cfn-guard-test"></a>

根據 JSON 或 YAML 格式的 Guard 單位測試檔案驗證 AWS CloudFormation Guard 規則檔案，以判斷個別規則是否成功。

## 語法
<a name="cfn-guard-test-synopsis"></a>

```
cfn-guard test 
--rules-file <value>
--test-data <value>
```

## Parameters
<a name="cfn-guard-test-flags"></a>

`-a`, `--alphabetical`

在目錄中依字母順序排序。

`-h`, `--help`

列印說明資訊。

`-m`, `--last-modified`

依目錄中上次修改的時間排序

`-V`, `--version`

列印版本資訊。

`-v`, `--verbose`

增加輸出詳細程度。可以多次指定。

詳細輸出遵循 Guard 規則檔案的結構。規則檔案中的每個區塊都是詳細輸出中的區塊。最上方的區塊是每個規則。如果有針對規則`when`的條件，它們會顯示為同盟條件區塊。

## 選項
<a name="cfn-guard-test-options"></a>

`-d`, `--dir`

提供規則的根目錄。

`-o`, `--output-format`

指定輸出應顯示的格式。

*預設*：`single-line-summary`

*允許的值*：`json` \$1 `yaml` \$1 `single-line-summary` \$1 `junit`

`-r`, `--rules-file`

提供規則檔案的名稱。

`-t`, `--test-data`

提供 JSON 或 YAML 格式之資料檔案的檔案名稱或目錄。

## 範例
<a name="cfn-guard-test-examples"></a>

```
cfn-guard test --rules-file rules.guard --test-data example.json
```

## Output
<a name="cfn-guard-test-output"></a>

```
PASS|FAIL Expected Rule = rule_name, Status = SKIP|FAIL|PASS, Got Status = SKIP|FAIL|PASS
```

## 另請參閱
<a name="cfn-guard-test-see-also"></a>

[測試 Guard 規則](testing-rules.md)