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",
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."
switch "--do-not-replace",
description: "Flags out discrepancy between local and upstream versions, but does not replace"
max_named 0
end
end
@ -39,16 +44,16 @@ module Homebrew
updated_spdx_hash = JSON.parse(updated_spdx_string)
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"\
"Updating existing licences data file..."
File.open(SPDX_FOLDER_PATH/FILE_NAME, "wb") do |file|
file.write(updated_spdx_string)
end
if args.fail_if_outdated
Homebrew.failed = true
end
puts "Current version is #{curr_spdx_hash["licenseListVersion"]} but newest version is #{updated_spdx_hash["licenseListVersion"]}"
unless args.do_not_replace?
puts "Updating existing licences data file..."
File.open(SPDX_FOLDER_PATH/FILE_NAME, "wb") do |file|
file.write(updated_spdx_string)
end
end
Homebrew.failed = !!args.fail_if_outdated
else
puts "Current version of license data is updated. No change required"
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