2025-12-30 16:52:10 +01:00
package tools_test
import (
"bytes"
"code.squareroundforest.org/arpio/wand/tools"
"testing"
)
func TestDocreflect ( t * testing . T ) {
var b bytes . Buffer
2026-01-13 23:54:51 +01:00
if err := tools . Docreflect (
tools . DocreflectOptions { } ,
& b ,
"testlib" ,
"code.squareroundforest.org/arpio/wand/internal/tests/testlib" ,
) ; err != nil {
2025-12-30 16:52:10 +01:00
t . Fatal ( err )
}
const expect = ` / *
Generated with https : //code.squareroundforest.org/arpio/docreflect
* /
package testlib
import "code.squareroundforest.org/arpio/docreflect"
func init ( ) {
docreflect . Register ( "code.squareroundforest.org/arpio/wand/internal/tests/testlib" , "" )
docreflect . Register ( "code.squareroundforest.org/arpio/wand/internal/tests/testlib.Bar" , "\nfunc(out, a, b, c)" )
docreflect . Register ( "code.squareroundforest.org/arpio/wand/internal/tests/testlib.Baz" , "\nfunc(o)" )
docreflect . Register ( "code.squareroundforest.org/arpio/wand/internal/tests/testlib.CustomHelp" , "\nfunc(o)" )
docreflect . Register ( "code.squareroundforest.org/arpio/wand/internal/tests/testlib.Foo" , "Foo sums three numbers.\nIt prints the sum to stdout.\n\nThe input numbers can be any integer.\n\nfunc(a, b, c)" )
docreflect . Register ( "code.squareroundforest.org/arpio/wand/internal/tests/testlib.OptionWithHelp" , "" )
docreflect . Register ( "code.squareroundforest.org/arpio/wand/internal/tests/testlib.OptionWithHelp.Help" , "Custom help.\n" )
docreflect . Register ( "code.squareroundforest.org/arpio/wand/internal/tests/testlib.Options" , "" )
docreflect . Register ( "code.squareroundforest.org/arpio/wand/internal/tests/testlib.Options.Bar" , "Bars, any number.\n" )
docreflect . Register ( "code.squareroundforest.org/arpio/wand/internal/tests/testlib.Options.Duration" , "Duration is another option.\n" )
docreflect . Register ( "code.squareroundforest.org/arpio/wand/internal/tests/testlib.Options.Foo" , "Foo is an option.\n" )
docreflect . Register ( "code.squareroundforest.org/arpio/wand/internal/tests/testlib.Options.Some" , "Some is an option of any type.\n" )
docreflect . Register ( "code.squareroundforest.org/arpio/wand/internal/tests/testlib.Options.Time" , "Time is the third option here.\n" )
} `
if b . String ( ) != expect {
t . Fatal ( b . String ( ) )
}
}
func TestMan ( t * testing . T ) {
var b bytes . Buffer
if err := tools . Man (
& b ,
tools . ManOptions { DateString : "2025-12-09" , Version : "v0.9" } ,
"../internal/tests/testlib/cmd" ,
) ; err != nil {
t . Fatal ( err )
}
const expect = ` . TH "test" 1 "December 2025" "v0.9" "User Commands"
. br
. sp 1 v
. in 0
. ti 0
\ fBName : \ fR
. br
. sp 1 v
. in 4
. ti 4
test
. br
. sp 1 v
. in 0
. ti 0
\ fBSynopsis : \ fR
. br
. sp 1 v
. nf
test [ options ] ... [ -- ] < arg1 int > < arg2 int > < arg3 int >
test < subcommand >
. fi
. br
. sp 1 v
. in 0
. ti 0
\ fBOptions : \ fR
. br
. sp 1 v
. in 12
. ti 4
-- help : \ ~ Show help .
. br
. sp 1 v
. in 0
. ti 0
\ fBSubcommands : \ fR
. br
. sp 1 v
. in 0
. ti 0
Show help for each subcommand by calling < command > help or < command > -- help .
. br
. sp 1 v
. in 2
. ti 2
\ fBtest foo ( default ) \ fR
. br
. sp 1 v
. in 4
. ti 4
\ fBSynopsis : \ fR
. br
. sp 1 v
. nf
test foo [ options ] ... [ -- ] < arg1 int > < arg2 int > < arg3 int >
test foo < subcommand >
. fi
. br
. sp 1 v
. in 4
. ti 4
\ fBOptions : \ fR
. br
. sp 1 v
. in 12
. ti 4
-- help : \ ~ Show help .
. br
. sp 1 v
. in 2
. ti 2
\ fBtest bar \ fR
. br
. sp 1 v
. in 4
. ti 4
\ fBSynopsis : \ fR
. br
. sp 1 v
. nf
test bar [ options ] ... [ -- ] < arg1 int > < arg2 int > < arg3 int >
test bar < subcommand >
. fi
. br
. sp 1 v
. in 4
. ti 4
\ fBOptions : \ fR
. br
. sp 1 v
. in 12
. ti 4
-- help : \ ~ Show help .
. br
. sp 1 v
. in 2
. ti 2
\ fBtest baz \ fR
. br
. sp 1 v
. in 4
. ti 4
\ fBSynopsis : \ fR
. br
. sp 1 v
. nf
test baz [ options ] ...
test baz < subcommand >
. fi
. br
. sp 1 v
. in 4
. ti 4
\ fBOptions : \ fR
. br
. sp 1 v
. in 25
. ti 4
-- bar string [ * ] : \ ~ \ ~ \ ~ \ ~
. br
. in 25
. ti 4
-- duration duration : \ ~
. br
. in 25
. ti 4
-- foo int : \ ~ \ ~ \ ~ \ ~ \ ~ \ ~ \ ~ \ ~ \ ~ \ ~ \ ~
. br
. in 25
. ti 4
-- some any : \ ~ \ ~ \ ~ \ ~ \ ~ \ ~ \ ~ \ ~ \ ~ \ ~
. br
. in 25
. ti 4
-- time time : \ ~ \ ~ \ ~ \ ~ \ ~ \ ~ \ ~ \ ~ \ ~
. br
. in 25
. ti 4
-- help : \ ~ \ ~ \ ~ \ ~ \ ~ \ ~ \ ~ \ ~ \ ~ \ ~ \ ~ \ ~ \ ~ \ ~ Show help .
. br
. sp 1 v
. in 0
. ti 0
\ fBEnvironment variables : \ fR
. br
. sp 1 v
. in 4
. ti 4
Every command line option ' s value can also be provided as an environment variable . Environment variable names need to use snake casing like myapp_foo_bar_baz or MYAPP_FOO_BAR_BAZ , or other casing that doesn ' t include the '-' dash character , and they need to be prefixed with the name of the application , as in the base name of the command .
. br
. sp 1 v
. in 4
. ti 4
When both the environment variable and the command line option is defined , the command line option overrides the environment variable . Multiple values for the same environment variable can be defined by concatenating the values with the ':' separator character . When overriding multiple values with command line options , all the environment values of the same field are dropped .
. br
. sp 1 v
. in 4
. ti 4
\ fBExample environment variable : \ fR
. br
. sp 1 v
. nf
TEST_FOO = 42
. fi
`
if b . String ( ) != expect {
t . Fatal ( b . String ( ) )
}
}
func TestMarkdown ( t * testing . T ) {
var b bytes . Buffer
if err := tools . Markdown ( & b , tools . MarkdownOptions { } , "../internal/tests/testlib/cmd" ) ; err != nil {
t . Fatal ( err )
}
const expect = ` # test
# # Synopsis :
` + " ` ` ` " + `
test [ options ] ... [ -- ] < arg1 int > < arg2 int > < arg3 int >
test < subcommand >
` + " ` ` ` " + `
# # Options :
- -- help : Show help .
# # Subcommands :
Show help for each subcommand by calling \ < command \ > help or \ < command \ > -- help .
# # # test foo ( default )
# # # # Synopsis :
` + " ` ` ` " + `
test foo [ options ] ... [ -- ] < arg1 int > < arg2 int > < arg3 int >
test foo < subcommand >
` + " ` ` ` " + `
# # # # Options :
- -- help : Show help .
# # # test bar
# # # # Synopsis :
` + " ` ` ` " + `
test bar [ options ] ... [ -- ] < arg1 int > < arg2 int > < arg3 int >
test bar < subcommand >
` + " ` ` ` " + `
# # # # Options :
- -- help : Show help .
# # # test baz
# # # # Synopsis :
` + " ` ` ` " + `
test baz [ options ] ...
test baz < subcommand >
` + " ` ` ` " + `
# # # # Options :
- -- bar string \ [ \ * \ ] :
- -- duration duration :
- -- foo int :
- -- some any :
- -- time time :
- -- help : Show help .
# # Environment variables :
Every command line option ' s value can also be provided as an environment variable . Environment variable names
need to use snake casing like myapp \ _foo \ _bar \ _baz or MYAPP \ _FOO \ _BAR \ _BAZ , or other casing that doesn ' t include the
'-' dash character , and they need to be prefixed with the name of the application , as in the base name of the
command .
When both the environment variable and the command line option is defined , the command line option overrides the
environment variable . Multiple values for the same environment variable can be defined by concatenating the
values with the ':' separator character . When overriding multiple values with command line options , all the
environment values of the same field are dropped .
# # # Example environment variable :
` + " ` ` ` " + `
TEST_FOO = 42
` + " ` ` ` " + `
`
if b . String ( ) != expect {
t . Fatal ( b . String ( ) )
}
}