md_docs_test.go
This file
Path
md_docs_test.go
67 lines · 1.9 KiB · Go
Last changed by
Deprecated subcommandsEric Parisbefore adoptionc3e48f9
History of this fileTake it
Merge pull request #87 from eparis/gen-md-docEric Parisbefore adoptionc0da825
lines 1–16why, one step back1package cobra23import (4 "bytes"5 "fmt"6 "os"7 "strings"8 "testing"9)1011var _ = fmt.Println12var _ = os.Stderr1314func TestGenMdDoc(t *testing.T) {15 c := initializeWithRootCmd()16 // Need two commands to run the command alphabetical sortDeprecated subcommandsEric Parisbefore adoptionc3e48f9
line 17why, one step back17 cmdEcho.AddCommand(cmdTimes, cmdEchoSub, cmdDeprecated)Merge pull request #87 from eparis/gen-md-docEric Parisbefore adoptionc0da825
lines 18–60why, one step back18 c.AddCommand(cmdPrint, cmdEcho)19 cmdRootWithRun.PersistentFlags().StringVarP(&flags2a, "rootflag", "r", "two", strtwoParentHelp)2021 out := new(bytes.Buffer)2223 // We generate on s subcommand so we have both subcommands and parents24 GenMarkdown(cmdEcho, out)25 found := out.String()2627 // Our description28 expected := cmdEcho.Long29 if !strings.Contains(found, expected) {30 t.Errorf("Unexpected response.\nExpecting to contain: \n %q\nGot:\n %q\n", expected, found)31 }3233 // Better have our example34 expected = cmdEcho.Example35 if !strings.Contains(found, expected) {36 t.Errorf("Unexpected response.\nExpecting to contain: \n %q\nGot:\n %q\n", expected, found)37 }3839 // A local flag40 expected = "boolone"41 if !strings.Contains(found, expected) {42 t.Errorf("Unexpected response.\nExpecting to contain: \n %q\nGot:\n %q\n", expected, found)43 }4445 // persistent flag on parent46 expected = "rootflag"47 if !strings.Contains(found, expected) {48 t.Errorf("Unexpected response.\nExpecting to contain: \n %q\nGot:\n %q\n", expected, found)49 }5051 // We better output info about our parent52 expected = cmdRootWithRun.Short53 if !strings.Contains(found, expected) {54 t.Errorf("Unexpected response.\nExpecting to contain: \n %q\nGot:\n %q\n", expected, found)55 }5657 // And about subcommands58 expected = cmdEchoSub.Short59 if !strings.Contains(found, expected) {60 t.Errorf("Unexpected response.\nExpecting to contain: \n %q\nGot:\n %q\n", expected, found)Deprecated subcommandsEric Parisbefore adoptionc3e48f9
lines 61–65why, one step back61 }6263 unexpected := cmdDeprecated.Short64 if strings.Contains(found, unexpected) {65 t.Errorf("Unexpected response.\nFound: %v\nBut should not have!!\n", unexpected)Merge pull request #87 from eparis/gen-md-docEric Parisbefore adoptionc0da825
lines 66–67why, one step back66 }67}