From c1ae9621937977b27d887ccec77f652c81eefe07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BE=90=E6=99=93=E4=BC=9F?= Date: Wed, 4 Oct 2023 22:29:47 +0800 Subject: [PATCH] =?UTF-8?q?:white=5Fcheck=5Fmark:=20=E6=B7=BB=E5=8A=A0=20p?= =?UTF-8?q?rojects=20=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main_test.go | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/main_test.go b/main_test.go index df1fdf5..1dc483e 100644 --- a/main_test.go +++ b/main_test.go @@ -1,11 +1,41 @@ package main import ( + "bytes" "fmt" "github.com/xuxiaowei-com-cn/git-go/buildinfo" + "os" + "strings" "testing" ) func Test_CommitSha(t *testing.T) { fmt.Println(buildinfo.CommitSha()) } + +func Test_Projects(t *testing.T) { + var buf bytes.Buffer + + // 不带参数的测试输出 + os.Args = []string{"cmd"} + main() + if got := buf.String(); !strings.Contains(got, "") { + t.Errorf("异常信息:\n%s", got) + } + + buf.Reset() + + // 使用版本参数测试输出 + os.Args = []string{"cmd", "projects"} + main() + if got := buf.String(); !strings.Contains(got, "") { + t.Errorf("异常信息:\n%s", got) + } + + // 使用版本参数测试输出 + os.Args = []string{"cmd", "p"} + main() + if got := buf.String(); !strings.Contains(got, "") { + t.Errorf("异常信息:\n%s", got) + } +}