Files
teai/internal/cli/version_test.go
T

33 lines
1.0 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// version_test.go 驗證版本字串解析:go test 環境 Main.Version 為 "(devel)"
// 時應退回開發版本號;-ldflags 覆寫測試 tag 行為則由建置驗證涵蓋。
package cli
import (
"strings"
"testing"
)
// TestBuildVersionFallsBackToDev 確認本地測試環境(Main.Version == "(devel)")
// 退回 Version;同時確保輸出是可讀版本字串(非空、無括號)。
func TestBuildVersionFallsBackToDev(t *testing.T) {
v := buildVersion()
if v == "" {
t.Fatalf("buildVersion 不應為空")
}
if strings.ContainsAny(v, "()") {
t.Errorf("buildVersion 不應含內部佔位(括號),得到:%q", v)
}
}
// TestRunVersionUsesBuildVersion 確認 version 命令輸出 buildVersion 的結果。
func TestRunVersionUsesBuildVersion(t *testing.T) {
stdout, _, code := run("version")
if code != 0 {
t.Fatalf("version 應回 0,得到 %d", code)
}
want := "teai version " + buildVersion()
if !strings.Contains(stdout, want) {
t.Errorf("version 輸出應含 %q,得到:%q", want, stdout)
}
}