require 'pathname' require Pathname.new( File.dirname(__FILE__)).join( 'test_helper' ).cleanpath require 'build-tool/configuration' require 'build-tool/commands' require 'build-tool/commands/build' require 'build-tool/commands/help' require 'build-tool/commands/recipes' require 'build-tool/commands/recipes/list' require 'build-tool/commands/recipes/install' class TestCli < Test::Unit::TestCase def setup cfg = BuildTool::Configuration.new(nil) @cmd = BuildTool::Commands::Shell.new( cfg ) @cmd.add_command( BuildTool::Commands::Build.new( cfg ) ) @cmd.add_command( BuildTool::Commands::Help.new( cfg ) ) @cmd.add_command( BuildTool::Commands::Recipes::CLI.new( cfg ) ) @cmd.get_command( "recipes" ).add_command( BuildTool::Commands::Recipes::List.new( cfg ) ) @cmd.get_command( "recipes" ).add_command( BuildTool::Commands::Recipes::Install.new( cfg ) ) end def teardown @cmd = nil end def test_command_completion assert_equal ["build"], @cmd.complete_command("bui") assert_equal ["build", "help", "recipes"], @cmd.complete_command("") assert_equal ["build"], @cmd.complete("bui") assert_equal ["build", "help", "recipes"], @cmd.complete("") end def test_subcommand_completion if !Readline.respond_to? 'line_buffer' assert_equal ["recipes list", "recipes install"], @cmd.complete( "recipes") assert_equal ["recipes list", "recipes install"], @cmd.complete( "recipes ") else assert_equal ["list", "install"], @cmd.complete( "recipes") assert_equal ["list", "install"], @cmd.complete( "recipes ") end end def test_argument_completion require 'readline' cmd = @cmd.get_command( "build" ) if !Readline.respond_to? 'line_buffer' assert_equal ["build --clean", "build --configure"], cmd.complete( "build --c" ) assert_equal ["build --from-scratch --clean", "build --from-scratch --configure"], cmd.complete( "build --from-scratch --c") assert_equal ["build --from-scratch --install"], cmd.complete( "build --from-scratch --inst") else assert_equal ["--clean", "--configure"], cmd.complete( "build --c" ) assert_equal ["--clean", "--configure"], cmd.complete( "build --from-scratch --c" ) end end end