Skip to content

Commit

Permalink
failed
Browse files Browse the repository at this point in the history
  • Loading branch information
at-grandpa committed Dec 21, 2018
1 parent 56e01cd commit 38ef000
Show file tree
Hide file tree
Showing 3 changed files with 548 additions and 3 deletions.
12 changes: 10 additions & 2 deletions spec/clim/dsl_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ require "./../spec_helper"
macro assert_opts_and_args(spec_case)
opts.help_str.should eq {{spec_case["expect_help"]}}
{% if spec_case.keys.includes?("expect_opts".id) %}
typeof(opts.{{spec_case["expect_opts"]["method"].id}}).should eq {{spec_case["expect_opts"]["type"]}}
opts.{{spec_case["expect_opts"]["method"].id}}.should eq {{spec_case["expect_opts"]["expect_value"]}}
if opts.responds_to?(:{{spec_case["expect_opts"]["method"].id}})
typeof(opts.{{spec_case["expect_opts"]["method"].id}}).should eq {{spec_case["expect_opts"]["type"]}}
opts.{{spec_case["expect_opts"]["method"].id}}.should eq {{spec_case["expect_opts"]["expect_value"]}}
end
{% end %}
args.should eq {{spec_case["expect_args"]}}
end
Expand Down Expand Up @@ -32,6 +34,12 @@ macro it_blocks(class_name, spec_case)
{{class_name}}.start_parse({{spec_case["argv"]}}, io)
io.to_s.should eq {{spec_case["expect_help"]}}
end
{% elsif spec_case.keys.includes?("expect_version".id) %}
it "display version." do
io = IO::Memory.new
{{class_name}}.start_parse({{spec_case["argv"]}}, io)
io.to_s.should eq {{spec_case["expect_version"]}}
end
{% else %}
it "output." do
io = IO::Memory.new
Expand Down
14 changes: 13 additions & 1 deletion spec/clim/dsl_spec/sub_command_1_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,23 @@ require "../dsl_spec"
Options:
-a ARG, --array=ARG Option test. [type:Array(String)] [default:["default string"]]
--help Show this help.
-v, --version Show version.
HELP_MESSAGE
%}

spec(
spec_class_name: SubCommandWithDescAndUsage,
spec_class_name: SubCommandWithDescUsageVersionOption,
spec_sub_command_lines: [
<<-SUB_COMMAND,
sub_command "sub_command" do
desc "Sub command with desc."
usage "sub_command with usage [options] [arguments]"
version "version 1.0.0", short: "-v"
option "-a ARG", "--array=ARG", desc: "Option test.", type: Array(String), default: ["default string"]
run do |options, arguments|
end
end
Expand Down Expand Up @@ -115,6 +119,14 @@ spec(
expect_help: {{sub_help_message}},
expect_args: ["arg1", "arg2", "arg3"],
},
{
argv: ["sub_command", "--version"],
expect_version: "version 1.0.0\n",
},
{
argv: ["sub_command", "-v"],
expect_version: "version 1.0.0\n",
},
{
argv: ["sub_command", "--help", "-ignore-option"],
exception_message: "Undefined option. \"-ignore-option\"",
Expand Down
Loading

0 comments on commit 38ef000

Please sign in to comment.