Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issues with lizard executable logic #8

Merged
merged 1 commit into from
Mar 19, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions lib/fastlane/plugin/lizard/actions/lizard_action.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@ module Fastlane
module Actions
class LizardAction < Action
def self.run(params)
if `which lizard`.to_s.empty?
if params[:executable].nil? && `which lizard`.to_s.empty?
UI.user_error!("You have to install lizard using `[sudo] pip install lizard` or specify the executable path with the `:executable` option.")
end

if params[:executable] && !File.exist?(params[:executable])
UI.user_error!("The custom executable at '#{params[:executable]}' does not exist.")
end

command = forming_command(params)

if params[:show_warnings]
Expand All @@ -24,7 +28,6 @@ def self.forming_command(params)
command = []
command << 'lizard' unless params[:executable]
command << "python #{params[:executable]}" if params[:executable]
command << params[:source_folder].to_s if params[:source_folder]
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 All @@ -36,6 +39,7 @@ def self.forming_command(params)
command << "-E #{params[:extensions]}" if params[:extensions]
command << "-s #{params[:sorting]}" if params[:sorting]
command << "-W #{params[:whitelist]}" if params[:whitelist]
command << params[:source_folder].to_s if params[:source_folder]
command << "> #{params[:report_file].shellescape}" if params[:report_file]

return command
Expand Down
Empty file added spec/fixtures/lizard.py
Empty file.
20 changes: 16 additions & 4 deletions spec/lizard_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,27 @@

expect(result).to eq("lizard -l swift")
end
end

it 'custom executable default as swift' do
context "when specify custom executable" do
it "uses custom executable" do
result = Fastlane::FastFile.new.parse("lane :test do
lizard(
executable: 'lizard/lizard.py'
executable: '../spec/fixtures/lizard.py'
)
end").runner.execute(:test)

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

it "should raise if custom executable does not exist" do
expect do
Fastlane::FastFile.new.parse("lane :test do
lizard(
executable: 'no/such/file/lizard.py'
)
end").runner.execute(:test)
end.to raise_error("The custom executable at 'no/such/file/lizard.py' does not exist.")
end
end

Expand Down Expand Up @@ -61,7 +73,7 @@
)
end").runner.execute(:test)

expect(result).to eq("lizard #{folder} -l swift")
expect(result).to eq("lizard -l swift #{folder}")
end
end

Expand Down