A virtual jailed shell environment for Go apps backed by an io/fs#FS.
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

test(falsecmd): cover GNU-compatible exit-1 behavior

Adds the previously missing test file for the false coreutil.
Asserts exit status 1 with empty stdout/stderr regardless of
arguments, matching GNU coreutils.

Refs: docs/posix2018/CONFORMANCE.md
Assisted-by: Claude Opus 4.7 via Claude Code
Signed-off-by: Xe Iaso <me@xeiaso.net>

+55
+55
command/internal/falsecmd/falsecmd_test.go
··· 1 + package falsecmd 2 + 3 + import ( 4 + "bytes" 5 + "context" 6 + "errors" 7 + "testing" 8 + 9 + "mvdan.cc/sh/v3/interp" 10 + "tangled.org/xeiaso.net/kefka/command" 11 + ) 12 + 13 + func run(t *testing.T, args []string) (string, string, error) { 14 + t.Helper() 15 + var stdout, stderr bytes.Buffer 16 + ec := &command.ExecContext{ 17 + Stdout: &stdout, 18 + Stderr: &stderr, 19 + } 20 + err := Impl{}.Exec(context.Background(), ec, args) 21 + return stdout.String(), stderr.String(), err 22 + } 23 + 24 + func TestFalse(t *testing.T) { 25 + tests := []struct { 26 + name string 27 + args []string 28 + }{ 29 + {name: "no args", args: nil}, 30 + {name: "ignored args", args: []string{"foo", "bar", "baz"}}, 31 + {name: "looks-like-flag args", args: []string{"--help", "-x"}}, 32 + } 33 + 34 + for _, tt := range tests { 35 + t.Run(tt.name, func(t *testing.T) { 36 + stdout, stderr, err := run(t, tt.args) 37 + if err == nil { 38 + t.Fatalf("expected non-nil error (exit 1), got nil") 39 + } 40 + var status interp.ExitStatus 41 + if !errors.As(err, &status) { 42 + t.Fatalf("expected interp.ExitStatus, got %T: %v", err, err) 43 + } 44 + if status != 1 { 45 + t.Errorf("exit status = %d, want 1", status) 46 + } 47 + if stdout != "" { 48 + t.Errorf("stdout = %q, want empty", stdout) 49 + } 50 + if stderr != "" { 51 + t.Errorf("stderr = %q, want empty", stderr) 52 + } 53 + }) 54 + } 55 + }