測試改斷言具體結束碼數值,對照 README 規格(#10) #19

Merged
queena merged 1 commits from fix/issue10-exitcode-tests into main 2026-09-10 10:20:23 +08:00
Member

修正 #10 的剩餘部分:測試不再以常數互比,直接對照 README「輸出與結束碼」數值。

背景與查證

  • #10 回報的常數 iota 問題,核心修正已隨 #5(commit 6951817)進 main:ExitOK=0、ExitUsage=2、ExitAPI=3 明確數值,ExitInternal=1 保留內部錯誤。實測 main(c5d5c37):./teai no-such-command 回 2、--output yaml 回 2,符合 README。
  • 尚未完成的是 issue 第二點建議:測試改斷言具體數值。

變更內容

  • cli_test.go(1 處)、dailyops_commands_test.go(3 處)、login_test.go(4 處)的 int(ExitUsage)/int(ExitAPI)/int(ExitInternal) 常數互比,改為直接斷言 2/3/1。
  • exitcode_test.go 的 TestExitCodeMapping 表格 want ExitCode 欄位改為 want int,期望值直接寫 0/2/3/1——常數若再與規格脫鉤,測試會紅。

驗證

  • go vet ./... 通過。
  • go test ./...:本 PR 修改範圍全綠;main 上既有 3 個 TestLoginAdd* 失敗(#16 的 extractGlobals 搶走 login add --token/--url,已另建 #18 追蹤、分派 max),非本 PR 引入。
修正 #10 的剩餘部分:測試不再以常數互比,直接對照 README「輸出與結束碼」數值。 ## 背景與查證 - #10 回報的常數 iota 問題,核心修正已隨 #5(commit 6951817)進 main:ExitOK=0、ExitUsage=2、ExitAPI=3 明確數值,ExitInternal=1 保留內部錯誤。實測 main(c5d5c37):`./teai no-such-command` 回 2、`--output yaml` 回 2,符合 README。 - 尚未完成的是 issue 第二點建議:測試改斷言具體數值。 ## 變更內容 - `cli_test.go`(1 處)、`dailyops_commands_test.go`(3 處)、`login_test.go`(4 處)的 `int(ExitUsage)`/`int(ExitAPI)`/`int(ExitInternal)` 常數互比,改為直接斷言 2/3/1。 - `exitcode_test.go` 的 TestExitCodeMapping 表格 `want ExitCode` 欄位改為 `want int`,期望值直接寫 0/2/3/1——常數若再與規格脫鉤,測試會紅。 ## 驗證 - `go vet ./...` 通過。 - `go test ./...`:本 PR 修改範圍全綠;main 上既有 3 個 TestLoginAdd* 失敗(#16 的 extractGlobals 搶走 `login add --token/--url`,已另建 #18 追蹤、分派 max),非本 PR 引入。
alex added 1 commit 2026-09-10 10:12:47 +08:00
cli_test、dailyops_commands_test、login_test、exitcode_test 原以
int(ExitUsage)/int(ExitAPI)/int(ExitInternal) 常數互比,常數若再
與 README 脫鉤測試仍會綠。改為直接斷言 0/2/3(內部錯誤 1)。

常數本體已隨 #5(6951817)改為明確數值,未知命令實測回 2。
alex requested review from queena 2026-09-10 10:12:58 +08:00
queena approved these changes 2026-09-10 10:20:15 +08:00
queena left a comment
Member

驗證通過。逐項核對如下:

  • diff 僅改 4 個測試檔(cli_test.go 1 處、dailyops_commands_test.go 3 處、login_test.go 4 處、exitcode_test.go 表格重構),將常數互比改為直接斷言 README「輸出與結束碼」數值(0/2/3;內部錯誤 1),完全對應 #10 第二點建議,無夾帶其他變更。
  • go vet ./... 通過。
  • 本 PR 修改範圍的測試全綠(TestRunUnknownCommand、TestIssuesListRequiresRepo、TestWriteCommandsRequireYes、TestAPIDirectPassthrough、TestExitCodeMapping、TestLoginUnknownSubcommandUsage、TestLoginNoSubcommandUsage、TestLoginRemoveNotFound)。
  • 實測二進位:no-such-command→2、錯誤 --output→2、version→0、API 連線錯誤→3,符合 README 規格。
  • 3 個 TestLoginAdd* 失敗在 main 上同樣重現(#16 extractGlobals 已知問題,#18 追蹤中),非本 PR 引入。

核准合併。

驗證通過。逐項核對如下: - diff 僅改 4 個測試檔(cli_test.go 1 處、dailyops_commands_test.go 3 處、login_test.go 4 處、exitcode_test.go 表格重構),將常數互比改為直接斷言 README「輸出與結束碼」數值(0/2/3;內部錯誤 1),完全對應 #10 第二點建議,無夾帶其他變更。 - go vet ./... 通過。 - 本 PR 修改範圍的測試全綠(TestRunUnknownCommand、TestIssuesListRequiresRepo、TestWriteCommandsRequireYes、TestAPIDirectPassthrough、TestExitCodeMapping、TestLoginUnknownSubcommandUsage、TestLoginNoSubcommandUsage、TestLoginRemoveNotFound)。 - 實測二進位:no-such-command→2、錯誤 --output→2、version→0、API 連線錯誤→3,符合 README 規格。 - 3 個 TestLoginAdd* 失敗在 main 上同樣重現(#16 extractGlobals 已知問題,#18 追蹤中),非本 PR 引入。 核准合併。
queena merged commit f7d63d6e8f into main 2026-09-10 10:20:23 +08:00
Sign in to join this conversation.
No Reviewers
2 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: alterminal/teai#19