Skip to content

Commit

Permalink
Use correct lizard command when custom executable is provided
Browse files Browse the repository at this point in the history
  • Loading branch information
mgrebenets authored and Maksym Grebenets committed Apr 7, 2018
1 parent d108a9d commit 93463ba
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 9 deletions.
15 changes: 8 additions & 7 deletions lib/fastlane/plugin/lizard/actions/lizard_action.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,18 @@ def self.run(params)
UI.user_error!("The custom executable at '#{params[:executable]}' does not exist.")
end

lizard_cli_version = Gem::Version.new(`lizard --version`.scan(/(?:\d+\.?){3}/).first)
lizard_command = params[:executable].nil? ? "lizard" : "python #{params[:executable]}"

lizard_cli_version = Gem::Version.new(`#{lizard_command} --version 2>&1`.strip.scan(/(?:\d+\.?){3}/).first)
required_version = Gem::Version.new(Fastlane::Lizard::CLI_VERSION)
if lizard_cli_version < required_version
UI.user_error!("Your lizard version is outdated, please upgrade to at least version #{Fastlane::Lizard::CLI_VERSION} and start your lane again!")
UI.user_error!("Your lizard version #{lizard_cli_version} is outdated, please upgrade to at least version #{required_version} and start your lane again!")
end

command = forming_command(params)
command = forming_command(lizard_command, params)

if params[:show_warnings]
Fastlane::Actions.sh_control_output("lizard #{params[:source_folder]} | sed -n -e '/^$/,$p'", print_command: true, print_command_output: true)
Fastlane::Actions.sh_control_output("#{lizard_command} #{params[:source_folder]} | sed -n -e '/^$/,$p'", print_command: true, print_command_output: true)
end

begin
Expand All @@ -30,10 +32,9 @@ def self.run(params)
end
end

def self.forming_command(params)
def self.forming_command(lizard_command, params)
command = []
command << 'lizard' unless params[:executable]
command << "python #{params[:executable]}" if params[:executable]
command << lizard_command
command << params[:language].split(",").map { |l| "-l #{l.strip}" }.join(" ") if params[:language]
command << "--#{params[:export_type]}" if params[:export_type]
command << "-C #{params[:ccn]}" if params[:ccn] # stands for cyclomatic complexity number
Expand Down
2 changes: 2 additions & 0 deletions spec/fixtures/lizard.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Imitate "lizard.py --version" command by default.
print("1.14.10") # Matches contents of version.rb.
2 changes: 2 additions & 0 deletions spec/fixtures/newer_lizard.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Imitate "lizard.py --version" command by default.
print("2.0.0")
2 changes: 2 additions & 0 deletions spec/fixtures/outdated_lizard.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Imitate "lizard.py --version" command by default.
print("1.0.0")
38 changes: 36 additions & 2 deletions spec/lizard_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
let(:ccn) { 10 }
let(:length) { 800 }
let(:working_threads) { 3 }
let(:custom_executable) { "../spec/fixtures/lizard.py" }
let(:outdated_executable) { "../spec/fixtures/outdated_lizard.py" }
let(:newer_executable) { "../spec/fixtures/newer_lizard.py" }

context "executable" do
it "fails with invalid sourcemap path" do
Expand All @@ -22,6 +25,37 @@
end
end

context "required version" do
it "should not raise if executable version is same as required" do
expect(FastlaneCore::UI).to_not(receive(:user_error!))
Fastlane::FastFile.new.parse("lane :test do
lizard(
executable: '#{custom_executable}'
)
end").runner.execute(:test)
end

it "should not raise if executable version is newer than required" do
expect(FastlaneCore::UI).to_not(receive(:user_error!))
Fastlane::FastFile.new.parse("lane :test do
lizard(
executable: '#{newer_executable}'
)
end").runner.execute(:test)
end

it "should raise if executable version is less than required" do
expect(FastlaneCore::UI).to receive(:user_error!).with(/Your lizard version .* is outdated, please upgrade to at least version .* and start your lane again\!/).and_call_original
expect do
Fastlane::FastFile.new.parse("lane :test do
lizard(
executable: '#{outdated_executable}'
)
end").runner.execute(:test)
end.to raise_error(/Your lizard version .* is outdated, please upgrade to at least version .* and start your lane again\!/)
end
end

context "default use case" do
it "default language as swift" do
result = Fastlane::FastFile.new.parse("lane :test do
Expand All @@ -36,11 +70,11 @@
it "uses custom executable" do
result = Fastlane::FastFile.new.parse("lane :test do
lizard(
executable: '../spec/fixtures/lizard.py'
executable: '#{custom_executable}'
)
end").runner.execute(:test)

expect(result).to eq("python ../spec/fixtures/lizard.py -l swift")
expect(result).to eq("python #{custom_executable} -l swift")
end

it "should raise if custom executable does not exist" do
Expand Down

0 comments on commit 93463ba

Please sign in to comment.