@@ -5,6 +5,11 @@ import (
55 "testing"
66)
77
8+ // NOTE: captureStdout replaces os.Stdout with an os.Pipe, which is always
9+ // non-TTY. This means we can test the "piped stdout → auto-JSON" path but
10+ // cannot test the "real TTY → no auto-JSON" path in unit tests. The TTY
11+ // guard (term.IsTerminal) is effectively always false here.
12+
813func TestAutoJSON_Version_DefaultsToJSONWhenEnabled (t * testing.T ) {
914 t .Setenv ("GOG_AUTO_JSON" , "1" )
1015
@@ -59,6 +64,36 @@ func TestAutoJSON_Version_DefaultsToJSONWhenForceOutputEnabled(t *testing.T) {
5964 }
6065}
6166
67+ func TestAutoJSON_Version_PlainOverridesForceOutput (t * testing.T ) {
68+ t .Setenv ("GOG_FORCE_OUTPUT" , "1" )
69+
70+ out := captureStdout (t , func () {
71+ _ = captureStderr (t , func () {
72+ if err := Execute ([]string {"--plain" , "version" }); err != nil {
73+ t .Fatalf ("Execute: %v" , err )
74+ }
75+ })
76+ })
77+
78+ if strings .HasPrefix (strings .TrimSpace (out ), "{" ) || strings .Contains (out , "\" version\" " ) {
79+ t .Fatalf ("expected text output (not json), got: %q" , out )
80+ }
81+ }
82+
83+ func TestAutoJSON_Version_PlainOverridesNonInteractive (t * testing.T ) {
84+ out := captureStdout (t , func () {
85+ _ = captureStderr (t , func () {
86+ if err := Execute ([]string {"--non-interactive" , "--plain" , "version" }); err != nil {
87+ t .Fatalf ("Execute: %v" , err )
88+ }
89+ })
90+ })
91+
92+ if strings .HasPrefix (strings .TrimSpace (out ), "{" ) || strings .Contains (out , "\" version\" " ) {
93+ t .Fatalf ("expected text output (not json), got: %q" , out )
94+ }
95+ }
96+
6297func TestAutoJSON_Version_DefaultsToJSONWhenNoInputAndPiped (t * testing.T ) {
6398 out := captureStdout (t , func () {
6499 _ = captureStderr (t , func () {
0 commit comments