返回 DeepSeek-Reasonix
setup_flags_test.go
根目录 / internal / cli / setup_flags_test.go
1 package cli
2
3 import (
4 "os"
5 "path/filepath"
6 "strings"
7 "testing"
8 )
9
10 // resolveSetupTargets treats any unrecognized argument as the config path, so
11 // before this guard `reasonix setup --help` wrote a config file literally named
12 // "--help" into the working directory — and so did every mistyped flag.
13 func TestSetupRejectsDashedArgumentsInsteadOfWritingThem(t *testing.T) {
14 dir := t.TempDir()
15 t.Chdir(dir)
16
17 for _, arg := range []string{"--help", "-h"} {
18 if rc := setupConfig([]string{arg}); rc != 0 {
19 t.Fatalf("setup %s returned %d, want 0 (help is not an error)", arg, rc)
20 }
21 }
22 if rc := setupConfig([]string{"--not-a-flag"}); rc != 2 {
23 t.Fatalf("setup --not-a-flag returned %d, want 2", rc)
24 }
25
26 entries, err := os.ReadDir(dir)
27 if err != nil {
28 t.Fatal(err)
29 }
30 for _, e := range entries {
31 if strings.HasPrefix(e.Name(), "-") {
32 t.Fatalf("setup wrote a file from a flag argument: %s", filepath.Join(dir, e.Name()))
33 }
34 }
35 }
36
36 lines GO