diff --git a/CHANGELOG.md b/CHANGELOG.md index d513993..d7e8639 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -101,6 +101,7 @@ ### Chore - CI: compile-test the Windows lock package to catch platform regressions. (#188 — thanks @dinakars777) +- CLI: route `version` output through Cobra's configured output stream for easier command tests. (#78 — thanks @nikolasdehor) - Dependencies: update Go modules including `whatsmeow`, `go-sqlite3`, `x/*`, and related runtime libs. - Refactor: split WhatsApp message parsing into focused text, media, business, and context helpers. - Refactor: inject clocks in app/store paths for deterministic tests. diff --git a/cmd/wacli/version.go b/cmd/wacli/version.go index b8b048a..c752849 100644 --- a/cmd/wacli/version.go +++ b/cmd/wacli/version.go @@ -11,7 +11,7 @@ func newVersionCmd() *cobra.Command { Use: "version", Short: "Print version", Run: func(cmd *cobra.Command, args []string) { - fmt.Println(version) + fmt.Fprintln(cmd.OutOrStdout(), version) }, } } diff --git a/cmd/wacli/version_test.go b/cmd/wacli/version_test.go new file mode 100644 index 0000000..83fce5b --- /dev/null +++ b/cmd/wacli/version_test.go @@ -0,0 +1,20 @@ +package main + +import ( + "bytes" + "testing" +) + +func TestVersionCommandUsesConfiguredOutput(t *testing.T) { + var out bytes.Buffer + cmd := newVersionCmd() + cmd.SetOut(&out) + cmd.SetArgs(nil) + + if err := cmd.Execute(); err != nil { + t.Fatalf("version command: %v", err) + } + if got, want := out.String(), version+"\n"; got != want { + t.Fatalf("version output = %q, want %q", got, want) + } +}