Skip to content

Commit

Permalink
Replace reference of Cachable::Command to Svnx::CommandLine
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeff Pace committed Feb 15, 2019
1 parent fa918b1 commit 20bcf36
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 39 deletions.
21 changes: 8 additions & 13 deletions lib/svnx/base/command.rb
Expand Up @@ -28,40 +28,35 @@ def noncaching
attr_reader :output
attr_reader :error
attr_reader :status

attr_reader :options

def initialize options, cls: nil, optcls: nil, exec: nil, xml: false, caching: caching?
def initialize options, cmdlinecls: nil, optcls: nil, xml: false, caching: caching?
factory = CommandFactory.new
params = factory.create self.class, cmdlinecls: cls, optcls: optcls

params = factory.create self.class, cmdlinecls: cmdlinecls, optcls: optcls

optcls ||= params[:options_class]

@options = optcls.new options
cmdargs = @options.to_args

subcommand = params[:subcommand]

cls ||= params[:command_line_class]
cmdlinecls ||= params[:command_line_class]

@cmdline = exec || cls.new(subcommand: subcommand, xml: xml, caching: caching, args: cmdargs)
debug "@cmdline: #{@cmdline}"
@cmdline = cmdlinecls.new(subcommand: subcommand, xml: xml, caching: caching, args: cmdargs)

@output = @cmdline.execute
debug "@output: #{@output && @output[0 .. 100]}"

@error = @cmdline.error
debug "@error: #{@error}"

@status = @cmdline.status
debug "@status: #{@status}"
end
end

class EntriesCommand < Command
attr_reader :entries

def initialize options, cls: ::Command::Cacheable::Command, exec: nil, caching: caching?, xml: true, entries_class: nil
super options, cls: cls, exec: exec, xml: xml, caching: caching
def initialize options, cmdlinecls: CommandLine, caching: caching?, xml: true, entries_class: nil
super options, cmdlinecls: cmdlinecls, xml: xml, caching: caching

if not @output.empty?
entries_class ||= begin
Expand Down
4 changes: 2 additions & 2 deletions lib/svnx/diff/command.rb
Expand Up @@ -9,8 +9,8 @@ module Svnx::Diff
class Command < Svnx::Base::Command
attr_reader :entries

def initialize cmdopts, cls: Svnx::Base::CommandLine
super cmdopts, cls: cls, xml: false, caching: true
def initialize cmdopts, cmdlinecls: Svnx::Base::CommandLine
super cmdopts, cmdlinecls: cmdlinecls, xml: false, caching: true
if @output
@entries = Svnx::Diff::Parser.new.parse_all_output @output.dup
end
Expand Down
8 changes: 4 additions & 4 deletions lib/svnx/project.rb
Expand Up @@ -10,10 +10,10 @@ module Svnx
class Svnx::Project
attr_reader :dir

def initialize dir: nil, url: nil, cls: nil
def initialize dir: nil, url: nil, cmdlinecls: nil
@dir = dir
@url = url
@cls = cls
@cmdlinecls = cmdlinecls
end

def where
Expand Down Expand Up @@ -43,8 +43,8 @@ def self.add_delegator cmd
cmdargs = fields.collect { |key| key.to_s + ": " + key.to_s }.join ", "

src = Array.new.tap do |a|
a << "def #{cmd} #{params}, cls: @cls"
a << " cmd = Svnx::#{cmd.to_s.capitalize}::Command.new({ #{cmdargs} }, cls: cls)"
a << "def #{cmd} #{params}, cmdlinecls: @cmdlinecls"
a << " cmd = Svnx::#{cmd.to_s.capitalize}::Command.new({ #{cmdargs} }, cmdlinecls: cmdlinecls)"
a << " cmd.respond_to?(:entries) ? cmd.entries : cmd.output"
a << "end"
end.join "\n"
Expand Down
21 changes: 19 additions & 2 deletions test/svnx/base/command_test.rb
Expand Up @@ -48,14 +48,26 @@ def options_to_args
end
end

module Xyz
class Options < Svnx::Base::Options
def fields
Hash.new
end
end

class Command < Svnx::Base::EntriesCommand
caching
end
end

module Svnx::Base
class CommandTest < Svnx::TestCase
include Paramesan

def self.build_params
options = { file: "abc", paths: [ "def", "ghi" ] }
command = SvnxTest::MockCommand.new options, optcls: SvnxTest::MockOptions, cls: Svnx::Base::MockCommandLine
other = SvnxTest2::Nesting::MockCommand.new options, cls: Svnx::Base::MockCommandLine
command = SvnxTest::MockCommand.new options, optcls: SvnxTest::MockOptions, cmdlinecls: Svnx::Base::MockCommandLine
other = SvnxTest2::Nesting::MockCommand.new options, cmdlinecls: Svnx::Base::MockCommandLine
Array.new.tap do |a|
a << [ SvnxTest::MockOptions, command ]
a << [ SvnxTest2::Nesting::Options, other ]
Expand All @@ -65,5 +77,10 @@ def self.build_params
param_test build_params.each do |expoptcls, cmd|
assert_equal expoptcls, cmd.options.class, "cmd: #{cmd}"
end

def test_default
options = Hash.new
cmd = Xyz::Command.new options
end
end
end
6 changes: 3 additions & 3 deletions test/svnx/command/tc.rb
Expand Up @@ -5,9 +5,9 @@

module Svnx::Command
class TestCase < Svnx::TestCase
def assert_command cmdcls, subcmd, cmdopts, clcls = command_line
cmdcls.new cmdopts, cls: clcls
ex = clcls::latest_executed? subcmd
def assert_command cmdcls, subcmd, cmdopts, cmdlinecls = command_line
cmdcls.new cmdopts, cmdlinecls: cmdlinecls
ex = cmdlinecls::latest_executed? subcmd
assert_equal true, ex, "cmdopts: #{cmdopts}"
# assert_empty cmd.output, "cmdopts: #{cmdopts}"
end
Expand Down
6 changes: 3 additions & 3 deletions test/svnx/commit/command_test.rb
Expand Up @@ -8,9 +8,9 @@
module Svnx::Commit
class CommandTest < Svnx::Command::TestCase
def assert_command exp, cmdopts = Hash.new
clcls = Svnx::Base::MockCommandLine
Command.new cmdopts, cls: clcls
cl = clcls::EXECUTED[-1]
cmdlinecls = Svnx::Base::MockCommandLine
Command.new cmdopts, cmdlinecls: cmdlinecls
cl = cmdlinecls::EXECUTED[-1]
msg = "cmdopts: #{cmdopts}"
assert_equal true, cl.executed, msg
assert_equal exp[:args], cl.args, msg
Expand Down
25 changes: 13 additions & 12 deletions test/svnx/project_test.rb
Expand Up @@ -21,19 +21,19 @@ def execute
end

def self.to_args args = Hash.new
args.merge({ cls: MockCommandLine })
args.merge({ cmdlinecls: MockCommandLine })
end

def self.dir_args dirname = "/tmp/svnx-test"
Hash[dir: dirname, cls: MockCommandLine]
Hash[dir: dirname, cmdlinecls: MockCommandLine]
end

def self.url_args urlname = "p://svnx/abc"
Hash[url: urlname, cls: MockCommandLine]
Hash[url: urlname, cmdlinecls: MockCommandLine]
end

def self.dir_url_args dirname = "/tmp/svnx-test", urlname = "p://svnx/abc"
Hash[dir: dirname, url: urlname, cls: MockCommandLine]
Hash[dir: dirname, url: urlname, cmdlinecls: MockCommandLine]
end

# dir and url
Expand Down Expand Up @@ -76,7 +76,7 @@ def mock_cmdline
:update,
#$$$ merge takes more than one dir/url, so it's not on a project now
# :merge,
#$$$ not enabled because commit validates options, and cls and url are not valid for it:
#$$$ not enabled because commit validates options, and cmdlinecls and url are not valid for it:
# :commit,
:log,
:diff,
Expand All @@ -85,20 +85,21 @@ def mock_cmdline
].each do |meth|
MockCommandLine::ELEMENTS.clear
proj = Svnx::Project.new self.class.dir_args
proj.send meth, cls: MockCommandLine
assert_true MockCommandLine::ELEMENTS.last.executed
assert_equal MockCommandLine::ELEMENTS.last.subcommand, meth.to_s
proj.send meth, cmdlinecls: MockCommandLine
el = MockCommandLine::ELEMENTS.last
assert_true el.executed
assert_equal el.subcommand, meth.to_s
end

param_test [
{ revision: 123 },
{ limit: 123 },
{ verbose: true },
{ revision: 123 },
{ limit: 123 },
{ verbose: true },
{ url: "abc" },
{ path: "def" },
].each do |args|
proj = Svnx::Project.new self.class.dir_args
args = args.merge({ cls: MockCommandLine })
args = args.merge({ cmdlinecls: MockCommandLine })
proj.log args
end
end
Expand Down

0 comments on commit 20bcf36

Please sign in to comment.