Skip to content

Commit

Permalink
Merge pull request #174 from ashfurrow/fix/specs
Browse files Browse the repository at this point in the history
Don't rely on the swiftlint executable for tests.
  • Loading branch information
ashfurrow authored Sep 15, 2021
2 parents 22883f6 + cd67dee commit 734cc76
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
2 changes: 1 addition & 1 deletion ext/swiftlint/Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace :swiftlint do
SWIFTLINT_MD5_HASH = DangerSwiftlint::SWIFTLINT_HASH

puts "Downloading swiftlint@#{VERSION}"
sh "sh #{SCRIPT_PATH}/downloadSwiftlint.sh -u #{URL} -d #{DESTINATION} -a #{ASSET} -dh #{SWIFTLINT_MD5_HASH}"
sh "#{SCRIPT_PATH}/downloadSwiftlint.sh -u #{URL} -d #{DESTINATION} -a #{ASSET} -dh #{SWIFTLINT_MD5_HASH}"
end
end

Expand Down
11 changes: 10 additions & 1 deletion ext/swiftlint/downloadSwiftlint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,16 @@ done
### Download
mkdir -p "${destination}"
curl -s -L "${url}" -o "${asset}"
if [[ ! -z "${SWIFTLINT_VERSION}" || $(md5 -q "${asset}") == "${default_hash}" ]]; then

# If macOS
if [[ "$OSTYPE" == "darwin"* ]]; then
resulting_hash=`md5 -q ${asset}`
# Default to linux
else
resulting_hash=`md5sum ${asset} | awk '{ print $1 }'`
fi

if [[ ! -z "${SWIFTLINT_VERSION}" || "$resulting_hash" == "${default_hash}" ]]; then
# if another version is set || our hardcoded hash is correct
unzip -o -q "${asset}" -d "${destination}"
else
Expand Down
2 changes: 2 additions & 0 deletions spec/danger_plugin_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -220,13 +220,15 @@ module Danger
end

it 'crashes if renamed_files is not configured properly' do
allow_any_instance_of(Swiftlint).to receive(:lint).and_return('')
allow(@swiftlint.git).to receive(:modified_files).and_return([
'spec/fixtures/SwiftFileThatWasRenamedToSomethingElse.swift'
])
expect { @swiftlint.lint_files }.to raise_error(NoMethodError)
end

it 'does not crash if a modified file was renamed' do
allow_any_instance_of(Swiftlint).to receive(:lint).and_return('')
allow(@swiftlint.git).to receive(:modified_files).and_return([
'spec/fixtures/SwiftFileThatWasRenamedToSomethingElse.swift'
])
Expand Down

0 comments on commit 734cc76

Please sign in to comment.