diff options
| author | Jesse Wolfe <jes5199@gmail.com> | 2010-04-13 14:53:44 -0700 |
|---|---|---|
| committer | test branch <puppet-dev@googlegroups.com> | 2010-02-17 06:50:53 -0800 |
| commit | 748aed9a4fe70cc2ecc0c782b694114356d9eb25 (patch) | |
| tree | 749b66092e2d5dfea3a6bcf442c7a9e3cbd91d69 /spec/unit | |
| parent | eafde5cacaac79da79d9d1415618801fcc37edcc (diff) | |
| download | puppet-748aed9a4fe70cc2ecc0c782b694114356d9eb25.tar.gz puppet-748aed9a4fe70cc2ecc0c782b694114356d9eb25.tar.xz puppet-748aed9a4fe70cc2ecc0c782b694114356d9eb25.zip | |
Fix #3552 single executable should display usage
Added some tests to make the single executable command behavior
explicit.
Added logic to display the usage message if we're on a tty and no
arguments are passed.
Signed-off-by: Jesse Wolfe <jes5199@gmail.com>
Diffstat (limited to 'spec/unit')
| -rw-r--r-- | spec/unit/util/command_line.rb | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/spec/unit/util/command_line.rb b/spec/unit/util/command_line.rb new file mode 100644 index 000000000..d6bbcd1be --- /dev/null +++ b/spec/unit/util/command_line.rb @@ -0,0 +1,70 @@ +#!/usr/bin/env ruby + +Dir.chdir(File.dirname(__FILE__)) { (s = lambda { |f| File.exist?(f) ? require(f) : Dir.chdir("..") { s.call(f) } }).call("spec/spec_helper.rb") } + + +require 'puppet/util/command_line' + +describe Puppet::Util::CommandLine do + before do + @tty = stub("tty", :tty? => true ) + @pipe = stub("pipe", :tty? => false) + end + + it "should pull off the first argument if it looks like a subcommand" do + args = %w( client --help whatever.pp ) + command = Puppet::Util::CommandLine.shift_subcommand_from_argv( args, @tty ) + + command.should == "client" + args.should == %w( --help whatever.pp ) + end + + it "should use main if the first argument looks like a .pp file" do + args = %w( whatever.pp ) + command = Puppet::Util::CommandLine.shift_subcommand_from_argv( args, @tty ) + + command.should == "main" + args.should == %w( whatever.pp ) + end + + it "should use main if the first argument looks like a .rb file" do + args = %w( whatever.rb ) + command = Puppet::Util::CommandLine.shift_subcommand_from_argv( args, @tty ) + + command.should == "main" + args.should == %w( whatever.rb ) + end + + it "should use main if the first argument looks like a flag" do + args = %w( --debug ) + command = Puppet::Util::CommandLine.shift_subcommand_from_argv( args, @tty ) + + command.should == "main" + args.should == %w( --debug ) + end + + it "should use main if the first argument is -" do + args = %w( - ) + command = Puppet::Util::CommandLine.shift_subcommand_from_argv( args, @tty ) + + command.should == "main" + args.should == %w( - ) + end + + it "should return nil if there are no arguments on a tty" do + args = [] + command = Puppet::Util::CommandLine.shift_subcommand_from_argv( args, @tty ) + + command.should == nil + args.should == [] + end + + it "should use main if there are no arguments on a pipe" do + args = [] + command = Puppet::Util::CommandLine.shift_subcommand_from_argv( args, @pipe ) + + command.should == "main" + args.should == [] + end + +end |
