test/test_command.rb in cri-2.10.1 vs test/test_command.rb in cri-2.11.0
- old
+ new
@@ -1,5 +1,7 @@
+# frozen_string_literal: true
+
require 'helper'
module Cri
class CommandTestCase < Cri::TestCase
def simple_cmd
@@ -14,10 +16,11 @@
end
required :b, :bbb, 'opt b'
optional :c, :ccc, 'opt c'
flag :d, :ddd, 'opt d'
forbidden :e, :eee, 'opt e'
+ required :t, :transform, 'opt t', transform: method(:Integer)
run do |opts, args, c|
$stdout.puts "Awesome #{c.name}!"
$stdout.puts args.join(',')
@@ -173,22 +176,43 @@
end
assert_equal 1, err.status
end
assert_equal [], lines(out)
- assert_equal ['moo: illegal option -- z'], lines(err)
+ assert_equal ['moo: unrecognised option -- z'], lines(err)
end
def test_invoke_simple_with_illegal_opt_no_exit
out, err = capture_io_while do
simple_cmd.run(%w[-z], {}, hard_exit: false)
end
assert_equal [], lines(out)
- assert_equal ['moo: illegal option -- z'], lines(err)
+ assert_equal ['moo: unrecognised option -- z'], lines(err)
end
+ def test_invoke_simple_with_invalid_value_for_opt
+ out, err = capture_io_while do
+ err = assert_raises SystemExit do
+ simple_cmd.run(%w[-t nope])
+ end
+ assert_equal 1, err.status
+ end
+
+ assert_equal [], lines(out)
+ assert_equal ['moo: invalid value "nope" for --transform option'], lines(err)
+ end
+
+ def test_invoke_simple_with_invalid_value_for_opt_no_exit
+ out, err = capture_io_while do
+ simple_cmd.run(%w[-t nope], {}, hard_exit: false)
+ end
+
+ assert_equal [], lines(out)
+ assert_equal ['moo: invalid value "nope" for --transform option'], lines(err)
+ end
+
def test_invoke_simple_with_opt_with_block
out, err = capture_io_while do
simple_cmd.run(%w[-a 123])
end
@@ -566,18 +590,18 @@
def test_run_with_raw_args
cmd = Cri::Command.define do
name 'moo'
run do |_opts, args|
- puts "args=#{args.join(',')} args.raw=#{args.raw.join(',')}"
+ puts "args=#{args.join(',')}"
end
end
out, _err = capture_io_while do
cmd.run(%w[foo -- bar])
end
- assert_equal "args=foo,bar args.raw=foo,--,bar\n", out
+ assert_equal "args=foo,bar\n", out
end
def test_run_without_block
cmd = Cri::Command.define do
name 'moo'
@@ -591,18 +615,18 @@
def test_runner_with_raw_args
cmd = Cri::Command.define do
name 'moo'
runner(Class.new(Cri::CommandRunner) do
def run
- puts "args=#{arguments.join(',')} args.raw=#{arguments.raw.join(',')}"
+ puts "args=#{arguments.join(',')}"
end
end)
end
out, _err = capture_io_while do
cmd.run(%w[foo -- bar])
end
- assert_equal "args=foo,bar args.raw=foo,--,bar\n", out
+ assert_equal "args=foo,bar\n", out
end
def test_compare
foo = Cri::Command.define { name 'foo' }
bar = Cri::Command.define { name 'bar' }