update-license-data: wrote rspec test and added one more parseable arg

This commit is contained in:
lionellloh 2020-06-23 02:25:46 +08:00
parent 8d7a9d51d3
commit e4e55c5cb3
2 changed files with 22 additions and 8 deletions

View File

@ -22,6 +22,11 @@ module Homebrew
switch "--fail-if-outdated", switch "--fail-if-outdated",
description: "Return a failing status code if current license data's version is different from the upstream. This "\ description: "Return a failing status code if current license data's version is different from the upstream. This "\
"can be used to notify CI when the SPDX license data is out of date." "can be used to notify CI when the SPDX license data is out of date."
switch "--do-not-replace",
description: "Flags out discrepancy between local and upstream versions, but does not replace"
max_named 0
end end
end end
@ -39,16 +44,16 @@ module Homebrew
updated_spdx_hash = JSON.parse(updated_spdx_string) updated_spdx_hash = JSON.parse(updated_spdx_string)
if curr_spdx_hash["licenseListVersion"] != updated_spdx_hash["licenseListVersion"] if curr_spdx_hash["licenseListVersion"] != updated_spdx_hash["licenseListVersion"]
puts "Current version is #{curr_spdx_hash["licenseListVersion"]} but newest version is #{updated_spdx_hash["licenseListVersion"]}\n"\ puts "Current version is #{curr_spdx_hash["licenseListVersion"]} but newest version is #{updated_spdx_hash["licenseListVersion"]}"
"Updating existing licences data file..." unless args.do_not_replace?
File.open(SPDX_FOLDER_PATH/FILE_NAME, "wb") do |file| puts "Updating existing licences data file..."
file.write(updated_spdx_string) File.open(SPDX_FOLDER_PATH/FILE_NAME, "wb") do |file|
end file.write(updated_spdx_string)
if args.fail_if_outdated end
Homebrew.failed = true
end
end end
Homebrew.failed = !!args.fail_if_outdated
else else
puts "Current version of license data is updated. No change required" puts "Current version of license data is updated. No change required"
end end
end end
end

View File

@ -0,0 +1,9 @@
require 'rspec'
describe 'My behaviour' do
it 'should do something' do
true.should == false
end
end