Got rid of :prepare()

This commit is contained in:
mpeterv
2014-03-02 02:03:44 +04:00
parent 085f152127
commit f24cfe9627
3 changed files with 79 additions and 59 deletions

View File

@@ -8,7 +8,7 @@ describe("tests related to help message generation", function()
"",
"Options: ",
" -h, --help Show this help message and exit. "
}, "\r\n"), parser:prepare():get_help())
}, "\r\n"), parser:get_help())
end)
it("does not create extra help options when :prepare is called several times", function()
@@ -18,7 +18,7 @@ describe("tests related to help message generation", function()
"",
"Options: ",
" -h, --help Show this help message and exit. "
}, "\r\n"), parser:prepare():prepare():get_help())
}, "\r\n"), parser:get_help())
end)
it("uses custom help option", function()
@@ -29,7 +29,7 @@ describe("tests related to help message generation", function()
"",
"Options: ",
" /? Show this help message and exit. "
}, "\r\n"), parser:prepare():get_help())
}, "\r\n"), parser:get_help())
end)
it("uses description and epilog", function()
@@ -46,7 +46,7 @@ describe("tests related to help message generation", function()
" -h, --help Show this help message and exit. ",
"",
"An epilog. "
}, "\r\n"), parser:prepare():get_help())
}, "\r\n"), parser:get_help())
end)
it("creates correct help message for arguments", function()
@@ -72,7 +72,7 @@ describe("tests related to help message generation", function()
"",
"Options: ",
" -h, --help Show this help message and exit. "
}, "\r\n"), parser:prepare():get_help())
}, "\r\n"), parser:get_help())
end)
it("creates correct help message for options", function()
@@ -91,7 +91,7 @@ describe("tests related to help message generation", function()
" --from <server>",
" --config <config>",
" -h, --help Show this help message and exit. "
}, "\r\n"), parser:prepare():get_help())
}, "\r\n"), parser:get_help())
end)
it("adds margin for multiline descriptions", function()
@@ -112,7 +112,7 @@ Sets verbosity level.
" -v: Report all warnings. ",
" -vv: Report all debugging information. ",
" -h, --help Show this help message and exit. "
}, "\r\n"), parser:prepare():get_help())
}, "\r\n"), parser:get_help())
end)
it("creates correct help message for commands", function()
@@ -131,7 +131,7 @@ Sets verbosity level.
"",
"Commands: ",
" run Run! "
}, "\r\n"), parser:prepare():get_help())
}, "\r\n"), parser:get_help())
end)
it("creates correct help message for subcommands", function()
@@ -140,15 +140,13 @@ Sets verbosity level.
local run = parser:command "run"
run:option "--where"
parser:prepare()
assert.equal(table.concat({
"Usage: foo run [--where <where>] [-h]",
"",
"Options: ",
" --where <where>",
" -h, --help Show this help message and exit. ",
}, "\r\n"), run:prepare():get_help())
}, "\r\n"), run:get_help())
end)
it("uses message provided by user", function()
@@ -158,7 +156,7 @@ Sets verbosity level.
assert.equal(
[=[I don't like your format of help messages]=],
parser:prepare():get_help()
parser:get_help()
)
end)
end)

View File

@@ -4,7 +4,7 @@ describe("tests related to usage message generation", function()
it("creates correct usage message for empty parser", function()
local parser = Parser "foo"
:add_help(false)
assert.equal(parser:prepare():get_usage(), "Usage: foo")
assert.equal(parser:get_usage(), "Usage: foo")
end)
it("creates correct usage message for arguments", function()
@@ -21,7 +21,7 @@ describe("tests related to usage message generation", function()
assert.equal(table.concat({
"Usage: foo <first> <second-and-third> <second-and-third>",
" [<maybe-fourth>] [<others>] ..."
}, "\r\n"), parser:prepare():get_usage()
}, "\r\n"), parser:get_usage()
)
end)
@@ -36,7 +36,7 @@ describe("tests related to usage message generation", function()
assert.equal(
[=[Usage: foo [-q] --from <server> [--config <config>]]=],
parser:prepare():get_usage()
parser:get_usage()
)
end)
@@ -55,7 +55,7 @@ describe("tests related to usage message generation", function()
assert.equal(
[=[Usage: foo [<input>] [<pair> <pair>] [<pair2>] [<pair2>]]=],
parser:prepare():get_usage()
parser:get_usage()
)
end)
@@ -70,7 +70,7 @@ describe("tests related to usage message generation", function()
assert.equal(
[=[Usage: foo [-f <from>] [-o [<output>]]]=],
parser:prepare():get_usage()
parser:get_usage()
)
end)
@@ -83,7 +83,7 @@ describe("tests related to usage message generation", function()
assert.equal(
[=[Usage: foo [-q] <command> ...]=],
parser:prepare():get_usage()
parser:get_usage()
)
end)
@@ -95,15 +95,13 @@ describe("tests related to usage message generation", function()
:add_help(false)
run:option "--where"
parser:prepare()
assert.equal(
[=[Usage: foo run [--where <where>]]=],
run:prepare():get_usage()
run:get_usage()
)
end)
it("usage messages for commands are correct after several :prepare() invocations", function()
it("usage messages for commands are correct after several invocations", function()
local parser = Parser "foo"
:add_help(false)
parser:flag "-q" "--quiet"
@@ -111,12 +109,12 @@ describe("tests related to usage message generation", function()
:add_help(false)
run:option "--where"
parser:prepare()
parser:prepare()
parser:parse{"run"}
parser:parse{"run"}
assert.equal(
[=[Usage: foo run [--where <where>]]=],
run:prepare():get_usage()
run:get_usage()
)
end)
@@ -129,7 +127,7 @@ describe("tests related to usage message generation", function()
assert.equal(
[=[Usage: obvious]=],
parser:prepare():get_usage()
parser:get_usage()
)
end)
@@ -141,7 +139,7 @@ describe("tests related to usage message generation", function()
assert.equal(
[=[Usage: foo [-q | --quiet]]=],
parser:prepare():get_usage()
parser:get_usage()
)
end)
@@ -154,7 +152,7 @@ describe("tests related to usage message generation", function()
assert.equal(
[=[Usage: foo <input> [<input>]]=],
parser:prepare():get_usage()
parser:get_usage()
)
end)
end)