scripts/add-ui-test-target.rb
42 lines · 1749 bytes
1# Adds the DayByDayUITests UI test target to the project and the shared DayByDay scheme.
2require 'xcodeproj'
3
4project_path = File.expand_path('../DayByDay.xcodeproj', __dir__)
5project = Xcodeproj::Project.open(project_path)
6app = project.targets.find { |t| t.name == 'DayByDay' }
7abort 'DayByDayUITests already exists' if project.targets.any? { |t| t.name == 'DayByDayUITests' }
8
9tests = project.new_target(:ui_test_bundle, 'DayByDayUITests', :ios, '17.5')
10tests.add_dependency(app)
11
12group = project.new(Xcodeproj::Project::Object::PBXFileSystemSynchronizedRootGroup)
13group.path = 'DayByDayUITests'
14group.source_tree = '<group>'
15project.main_group.children << group
16tests.file_system_synchronized_groups ||= []
17tests.file_system_synchronized_groups << group
18
19tests.build_configurations.each do |config|
20 s = config.build_settings
21 s['TEST_TARGET_NAME'] = 'DayByDay'
22 s['PRODUCT_BUNDLE_IDENTIFIER'] = "#{app.build_configurations.first.build_settings['PRODUCT_BUNDLE_IDENTIFIER']}.uitests"
23 s['PRODUCT_NAME'] = '$(TARGET_NAME)'
24 s['GENERATE_INFOPLIST_FILE'] = 'YES'
25 s['SWIFT_VERSION'] = '5.0'
26 s['TARGETED_DEVICE_FAMILY'] = '1,2'
27 s['DEVELOPMENT_TEAM'] = app.build_configurations.first.build_settings['DEVELOPMENT_TEAM']
28 s['CODE_SIGN_STYLE'] = 'Automatic'
29end
30
31project.save
32
33scheme_path = File.join(project_path, 'xcshareddata', 'xcschemes', 'DayByDay.xcscheme')
34scheme = Xcodeproj::XCScheme.new(scheme_path)
35scheme.build_action.add_entry(Xcodeproj::XCScheme::BuildAction::Entry.new(tests).tap do |e|
36 e.build_for_running = false
37 e.build_for_profiling = false
38 e.build_for_archiving = false
39 e.build_for_analyzing = false
40end)
41scheme.test_action.add_testable(Xcodeproj::XCScheme::TestAction::TestableReference.new(tests))
42scheme.save!