test/test_command.rb in cri-2.13.0 vs test/test_command.rb in cri-2.14.0
- old
+ new
@@ -754,7 +754,81 @@
end
assert_equal [], lines(out)
assert_equal ['moo: incorrect number of arguments given: expected 0, but got 1'], lines(err)
end
+
+ def test_load_file
+ Dir.mktmpdir('foo') do |dir|
+ filename = "#{dir}/moo.rb"
+ File.write(filename, <<~CMD)
+ name 'moo'
+ usage 'dunno whatever'
+ summary 'does stuff'
+ description 'This command does a lot of stuff.'
+ no_params
+
+ run do |_opts, args|
+ end
+ CMD
+
+ cmd = Cri::Command.load_file(filename)
+ assert_equal('moo', cmd.name)
+ end
+ end
+
+ def test_load_file_infer_name_false
+ Dir.mktmpdir('foo') do |dir|
+ filename = "#{dir}/moo.rb"
+ File.write(filename, <<~CMD)
+ usage 'dunno whatever'
+ summary 'does stuff'
+ description 'This command does a lot of stuff.'
+ no_params
+
+ run do |_opts, args|
+ end
+ CMD
+
+ cmd = Cri::Command.load_file(filename)
+ assert_equal(nil, cmd.name)
+ end
+ end
+
+ def test_load_file_infer_name
+ Dir.mktmpdir('foo') do |dir|
+ filename = "#{dir}/moo.rb"
+ File.write(filename, <<~CMD)
+ usage 'dunno whatever'
+ summary 'does stuff'
+ description 'This command does a lot of stuff.'
+ no_params
+
+ run do |_opts, args|
+ end
+ CMD
+
+ cmd = Cri::Command.load_file(filename, infer_name: true)
+ assert_equal('moo', cmd.name)
+ end
+ end
+
+ def test_load_file_infer_name_double
+ Dir.mktmpdir('foo') do |dir|
+ filename = "#{dir}/moo.rb"
+ File.write(filename, <<~CMD)
+ name 'oink'
+ usage 'dunno whatever'
+ summary 'does stuff'
+ description 'This command does a lot of stuff.'
+ no_params
+
+ run do |_opts, args|
+ end
+ CMD
+
+ cmd = Cri::Command.load_file(filename, infer_name: true)
+ assert_equal('moo', cmd.name)
+ end
+ end
end
end