@@ -22,8 +22,8 @@ func expectFileContent(t *testing.T, file, got string) {
2222 r := require .New (t )
2323 r .NoError (err )
2424 r .Equal (
25- string (normalizeNewlines ([]byte (got ))),
2625 string (normalizeNewlines (data )),
26+ string (normalizeNewlines ([]byte (got ))),
2727 )
2828}
2929
@@ -37,7 +37,7 @@ func normalizeNewlines(d []byte) []byte {
3737 )
3838}
3939
40- func buildExtendedTestCommand () * cli.Command {
40+ func buildExtendedTestCommand (t * testing. T ) * cli.Command {
4141 return & cli.Command {
4242 Writer : io .Discard ,
4343 Name : "greet" ,
@@ -60,6 +60,11 @@ func buildExtendedTestCommand() *cli.Command {
6060 Name : "hidden-flag" ,
6161 Hidden : true ,
6262 },
63+ & cli.StringFlag {
64+ Name : "temp-dir" ,
65+ Value : t .TempDir (),
66+ DefaultText : "test temp dir" ,
67+ },
6368 },
6469 Commands : []* cli.Command {{
6570 Aliases : []string {"c" },
@@ -152,14 +157,14 @@ Should be a part of the same code block
152157}
153158
154159func TestToMarkdownFull (t * testing.T ) {
155- cmd := buildExtendedTestCommand ()
160+ cmd := buildExtendedTestCommand (t )
156161 res , err := ToMarkdown (cmd )
157162 require .NoError (t , err )
158163 expectFileContent (t , "testdata/expected-doc-full.md" , res )
159164}
160165
161166func TestToTabularMarkdown (t * testing.T ) {
162- app := buildExtendedTestCommand ()
167+ app := buildExtendedTestCommand (t )
163168
164169 t .Run ("full" , func (t * testing.T ) {
165170 res , err := ToTabularMarkdown (app , "app" )
@@ -186,7 +191,7 @@ func TestToTabularMarkdownFailed(t *testing.T) {
186191
187192 MarkdownTabularDocTemplate = "{{ .Foo }}"
188193
189- app := buildExtendedTestCommand ()
194+ app := buildExtendedTestCommand (t )
190195
191196 res , err := ToTabularMarkdown (app , "" )
192197
@@ -221,7 +226,7 @@ Some other text`)
221226 r .NoError (err )
222227 _ = tmpFile .Close ()
223228
224- r .NoError (ToTabularToFileBetweenTags (buildExtendedTestCommand (), "app" , tmpFile .Name ()))
229+ r .NoError (ToTabularToFileBetweenTags (buildExtendedTestCommand (t ), "app" , tmpFile .Name ()))
225230
226231 content , err := os .ReadFile (tmpFile .Name ())
227232 r .NoError (err )
@@ -261,7 +266,7 @@ Some other text`)
261266 r .NoError (err )
262267 _ = tmpFile .Close ()
263268
264- r .NoError (ToTabularToFileBetweenTags (buildExtendedTestCommand (), "app" , tmpFile .Name (), "foo_BAR|baz" , "lorem+ipsum" ))
269+ r .NoError (ToTabularToFileBetweenTags (buildExtendedTestCommand (t ), "app" , tmpFile .Name (), "foo_BAR|baz" , "lorem+ipsum" ))
265270
266271 content , err := os .ReadFile (tmpFile .Name ())
267272 r .NoError (err )
@@ -291,15 +296,15 @@ Some other text`))
291296
292297 r .NoError (os .Remove (tmpFile .Name ()))
293298
294- err = ToTabularToFileBetweenTags (buildExtendedTestCommand (), "app" , tmpFile .Name ())
299+ err = ToTabularToFileBetweenTags (buildExtendedTestCommand (t ), "app" , tmpFile .Name ())
295300
296301 r .ErrorIs (err , fs .ErrNotExist )
297302 })
298303}
299304
300305func TestToMarkdown (t * testing.T ) {
301306 t .Run ("no flags" , func (t * testing.T ) {
302- app := buildExtendedTestCommand ()
307+ app := buildExtendedTestCommand (t )
303308 app .Flags = nil
304309
305310 res , err := ToMarkdown (app )
@@ -309,7 +314,7 @@ func TestToMarkdown(t *testing.T) {
309314 })
310315
311316 t .Run ("no commands" , func (t * testing.T ) {
312- app := buildExtendedTestCommand ()
317+ app := buildExtendedTestCommand (t )
313318 app .Commands = nil
314319
315320 res , err := ToMarkdown (app )
@@ -319,7 +324,7 @@ func TestToMarkdown(t *testing.T) {
319324 })
320325
321326 t .Run ("no authors" , func (t * testing.T ) {
322- app := buildExtendedTestCommand ()
327+ app := buildExtendedTestCommand (t )
323328 app .Authors = []any {}
324329
325330 res , err := ToMarkdown (app )
@@ -329,7 +334,7 @@ func TestToMarkdown(t *testing.T) {
329334 })
330335
331336 t .Run ("no usage text" , func (t * testing.T ) {
332- app := buildExtendedTestCommand ()
337+ app := buildExtendedTestCommand (t )
333338 app .UsageText = ""
334339
335340 res , err := ToMarkdown (app )
@@ -340,7 +345,7 @@ func TestToMarkdown(t *testing.T) {
340345}
341346
342347func TestToMan (t * testing.T ) {
343- app := buildExtendedTestCommand ()
348+ app := buildExtendedTestCommand (t )
344349
345350 res , err := ToMan (app )
346351
@@ -349,7 +354,7 @@ func TestToMan(t *testing.T) {
349354}
350355
351356func TestToManParseError (t * testing.T ) {
352- app := buildExtendedTestCommand ()
357+ app := buildExtendedTestCommand (t )
353358
354359 tmp := MarkdownDocTemplate
355360 t .Cleanup (func () { MarkdownDocTemplate = tmp })
@@ -361,7 +366,7 @@ func TestToManParseError(t *testing.T) {
361366}
362367
363368func TestToManWithSection (t * testing.T ) {
364- cmd := buildExtendedTestCommand ()
369+ cmd := buildExtendedTestCommand (t )
365370
366371 res , err := ToManWithSection (cmd , 8 )
367372
0 commit comments