Skip to content
Myr

Add explicit doc.GenMan SEE ALSO test covering #229

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Garth Kidd · committed by Garth Kidd · parent cb8496d · Browse files · 1 file+65 added−0 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+65 added−0 removed

  • other:+65 added−0 removed

1 file+65 added−0 removed

modified:doc/man_docs_test.go+65 added
1package doc23import (4 "bufio"5 "bytes"6 "fmt"7 "os"8 "strings"9 "testing"1011 "github.com/spf13/cobra"12)1314var _ = fmt.Println15var _ = os.Stderr
81 unmodified lines
9798 unexpected := translate("#HISTORY")99 checkStringOmits(t, found, unexpected)100}101102func TestGenManSeeAlso(t *testing.T) {103 noop := func(cmd *cobra.Command, args []string) {}104105 top := &cobra.Command{Use: "top", Run: noop}106 aaa := &cobra.Command{Use: "aaa", Run: noop, Hidden: true} // #229107 bbb := &cobra.Command{Use: "bbb", Run: noop}108 ccc := &cobra.Command{Use: "ccc", Run: noop}109 top.AddCommand(aaa, bbb, ccc)110111 out := new(bytes.Buffer)112 header := &GenManHeader{}113 if err := GenMan(top, header, out); err != nil {114 t.Fatal(err)115 }116117 scanner := bufio.NewScanner(out)118119 if err := AssertLineFound(scanner, ".SH SEE ALSO"); err != nil {120 t.Fatal(fmt.Errorf("Couldn't find SEE ALSO section header: %s", err.Error()))121 }122123 if err := AssertNextLineEquals(scanner, ".PP"); err != nil {124 t.Fatal(fmt.Errorf("First line after SEE ALSO wasn't break-indent: %s", err.Error()))125 }126127 if err := AssertNextLineEquals(scanner, `\fBtop\-bbb(1)\fP, \fBtop\-ccc(1)\fP`); err != nil {128 t.Fatal(fmt.Errorf("Second line after SEE ALSO wasn't correct: %s", err.Error()))129 }130}131132func AssertLineFound(scanner *bufio.Scanner, expectedLine string) error {133 for scanner.Scan() {134 line := scanner.Text()135 if line == expectedLine {136 return nil137 }138 }139140 if err := scanner.Err(); err != nil {141 return fmt.Errorf("AssertLineFound: scan failed: %s", err.Error())142 }143144 return fmt.Errorf("AssertLineFound: hit EOF before finding %#v", expectedLine)145}146147func AssertNextLineEquals(scanner *bufio.Scanner, expectedLine string) error {148 if scanner.Scan() {149 line := scanner.Text()150 if line == expectedLine {151 return nil152 } else {153 return fmt.Errorf("AssertNextLineEquals: got %#v, not %#v", line, expectedLine)154 }155 }156157 if err := scanner.Err(); err != nil {158 return fmt.Errorf("AssertNextLineEquals: scan failed: %s", err.Error())159 }160161 return fmt.Errorf("AssertNextLineEquals: hit EOF before finding %#v", expectedLine)162}