Created
February 27, 2018 11:44
-
-
Save jianghaoyuan2007/8b7ffb5a281fca0a57ca184ede551967 to your computer and use it in GitHub Desktop.
The script of unit tests.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'xcodeproj' | |
require 'colored' | |
def insert_unit_testing_flag() | |
target_name = 'Your-Project-Name' | |
project_path = '../Your-Project-Name.xcodeproj' | |
unit_testing_identifier = "UNIT_TESTING" | |
symbol_identifier = "-D" | |
project = Xcodeproj::Project.open(project_path) | |
target = project.targets.find { |target| target.to_s == target_name } | |
puts target.name | |
definitions = target.build_settings('Debug')['OTHER_SWIFT_FLAGS'] | |
if definitions.include? unit_testing_identifier | |
puts "No operation.".yellow | |
else | |
definitions << " #{symbol_identifier}" | |
definitions << " #{unit_testing_identifier}" | |
puts definitions.green | |
project.save() | |
end | |
end | |
def delete_unit_testing_flag() | |
target_name = 'Your-Project-Name' | |
project_path = '../Your-Project-Name.xcodeproj' | |
unit_testing_identifier = "UNIT_TESTING" | |
symbol_identifier = "-D" | |
project = Xcodeproj::Project.open(project_path) | |
target = project.targets.find { |target| target.to_s == target_name } | |
puts target.name | |
definitions = target.build_settings('Debug')['OTHER_SWIFT_FLAGS'] | |
if definitions.include? unit_testing_identifier | |
elements = definitions.split(" ") | |
unit_testing_identifier_index = elements.index(unit_testing_identifier) | |
symbol_identifier_index = unit_testing_identifier_index - 1 | |
symbol_identifier_element = elements.at(symbol_identifier_index) | |
if symbol_identifier_element == symbol_identifier | |
elements.delete(symbol_identifier) | |
end | |
elements.delete(unit_testing_identifier) | |
definitions = elements.join(" ") | |
puts definitions.green | |
target.build_settings('Debug')['OTHER_SWIFT_FLAGS'] = definitions | |
project.save() | |
else | |
puts "No operation.".yellow | |
end | |
end | |
argument = ARGV[0] | |
puts "#{argument}" | |
if argument == 'enable' | |
insert_unit_testing_flag | |
elsif argument == 'disable' | |
delete_unit_testing_flag | |
else | |
puts 'The parameter is error.'.red | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment