@@ -44,6 +44,24 @@ func runKcal(t *testing.T, binPath, dbPath string, args ...string) (string, stri
4444 return stdout .String (), stderr .String (), exitErr .ExitCode ()
4545}
4646
47+ func runKcalRaw (t * testing.T , binPath string , args ... string ) (string , string , int ) {
48+ t .Helper ()
49+ cmd := exec .Command (binPath , args ... )
50+ var stdout bytes.Buffer
51+ var stderr bytes.Buffer
52+ cmd .Stdout = & stdout
53+ cmd .Stderr = & stderr
54+ err := cmd .Run ()
55+ if err == nil {
56+ return stdout .String (), stderr .String (), 0
57+ }
58+ exitErr , ok := err .(* exec.ExitError )
59+ if ! ok {
60+ t .Fatalf ("run kcal command: %v" , err )
61+ }
62+ return stdout .String (), stderr .String (), exitErr .ExitCode ()
63+ }
64+
4765func initDB (t * testing.T , binPath , dbPath string ) {
4866 t .Helper ()
4967 _ , stderr , exit := runKcal (t , binPath , dbPath , "init" )
@@ -254,6 +272,29 @@ func TestCLIExerciseAddAllowsNoDistance(t *testing.T) {
254272 }
255273}
256274
275+ func TestCLIVersionCommandAndFlags (t * testing.T ) {
276+ binPath := buildKcalBinary (t )
277+
278+ for _ , args := range [][]string {{"--version" }, {"-v" }, {"version" }} {
279+ stdout , stderr , exit := runKcalRaw (t , binPath , args ... )
280+ if exit != 0 {
281+ t .Fatalf ("expected version call %v to succeed: exit=%d stderr=%s" , args , exit , stderr )
282+ }
283+ if stderr != "" {
284+ t .Fatalf ("expected empty stderr for %v, got: %s" , args , stderr )
285+ }
286+ if ! strings .Contains (stdout , "kcal v1.1.0" ) {
287+ t .Fatalf ("expected version output for %v, got: %s" , args , stdout )
288+ }
289+ if ! strings .Contains (stdout , "commit:" ) {
290+ t .Fatalf ("expected commit field for %v, got: %s" , args , stdout )
291+ }
292+ if ! strings .Contains (stdout , "date:" ) {
293+ t .Fatalf ("expected date field for %v, got: %s" , args , stdout )
294+ }
295+ }
296+ }
297+
257298func TestMain (m * testing.M ) {
258299 os .Exit (m .Run ())
259300}
0 commit comments