github.com/alecthomas/kong@v0.9.1-0.20240410131203-2ab5733f1179/helpwrap1.18_test.go (about) 1 //go:build !go1.19 2 // +build !go1.19 3 4 package kong_test 5 6 import ( 7 "bytes" 8 "testing" 9 10 "github.com/alecthomas/assert/v2" 11 "github.com/alecthomas/kong" 12 ) 13 14 func TestCustomWrap(t *testing.T) { 15 var cli struct { 16 Flag string `help:"A string flag with very long help that wraps a lot and is verbose and is really verbose."` 17 } 18 19 w := bytes.NewBuffer(nil) 20 app := mustNew(t, &cli, 21 kong.Name("test-app"), 22 kong.Description("A test app."), 23 kong.HelpOptions{ 24 WrapUpperBound: 50, 25 }, 26 kong.Writers(w, w), 27 kong.Exit(func(int) {}), 28 ) 29 30 _, err := app.Parse([]string{"--help"}) 31 assert.NoError(t, err) 32 expected := `Usage: test-app 33 34 A test app. 35 36 Flags: 37 -h, --help Show context-sensitive 38 help. 39 --flag=STRING A string flag with very 40 long help that wraps a lot 41 and is verbose and is 42 really verbose. 43 ` 44 t.Log(w.String()) 45 t.Log(expected) 46 assert.Equal(t, expected, w.String()) 47 }