github.com/maresnic/mr-kong@v1.0.0/helpwrap1.19_test.go (about)

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