Skip to content

Commit

Permalink
Add new APIs to set testables or entries in schemes.
Browse files Browse the repository at this point in the history
  • Loading branch information
dnkoutso committed Feb 12, 2020
1 parent ea1e1f4 commit d371e03
Show file tree
Hide file tree
Showing 5 changed files with 104 additions and 1 deletion.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

##### Enhancements

* None.
* Add new APIs to set testables or entries in schemes.
[Dimitris Koutsogiorgas](https://github.com/dnkoutso)
[#707](https://github.com/CocoaPods/Xcodeproj/pull/707)

##### Bug Fixes

Expand Down
21 changes: 21 additions & 0 deletions lib/xcodeproj/scheme/build_action.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,20 @@ def entries
end
end

# @param [Array<BuildAction::Entry>] entries
# Sets the list of BuildActionEntry nodes associated with this Build Action.
#
def entries=(entries)
@xml_element.delete_element('BuildActionEntries')
unless entries.empty?
entries_element = @xml_element.add_element('BuildActionEntries')
entries.each do |entry_node|
entries_element.add_element(entry_node.xml_element)
end
end
entries
end

# @param [BuildAction::Entry] entry
# The BuildActionEntry to add to the list of targets to build for the various actions
#
Expand Down Expand Up @@ -185,6 +199,13 @@ def buildable_references
def add_buildable_reference(ref)
@xml_element.add_element(ref.xml_element)
end

# @param [BuildableReference] ref
# The BuildableReference to remove from the list of targets this entry will build
#
def remove_buildable_reference(ref)
@xml_element.delete_element(ref.xml_element)
end
end
end
end
Expand Down
19 changes: 19 additions & 0 deletions lib/xcodeproj/scheme/test_action.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,18 @@ def testables
end
end

# @param [Array<TestableReference>] testables
# Sets the list of TestableReference (test bundles) associated with this Test Action
#
def testables=(testables)
@xml_element.delete_element('Testables')
testables_element = @xml_element.add_element('Testables')
testables.each do |testable|
testables_element.add_element(testable.xml_element)
end
testables
end

# @param [TestableReference] testable
# Add a TestableReference (test bundle) to this Test Action
#
Expand Down Expand Up @@ -219,6 +231,13 @@ def add_buildable_reference(ref)
@xml_element.add_element(ref.xml_element)
end

# @param [BuildableReference] ref
# The BuildableReference to remove from the list of targets this entry will build
#
def remove_buildable_reference(ref)
@xml_element.delete_element(ref.xml_element)
end

# @return [Array<Test>]
# The list of SkippedTest this action will skip.
#
Expand Down
31 changes: 31 additions & 0 deletions spec/scheme/build_action_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,25 @@ module Xcodeproj
@sut.entries.should.nil?
end

it '#entries=' do
project = Xcodeproj::Project.new('/foo/bar/baz.xcodeproj')

target1 = project.new_target(:application, 'FooApp', :ios)
entry1 = XCScheme::BuildAction::Entry.new
entry1.add_buildable_reference(XCScheme::BuildableReference.new(target1))

target2 = project.new_target(:static_library, 'FooLib', :ios)
entry2 = XCScheme::BuildAction::Entry.new
entry2.add_buildable_reference(XCScheme::BuildableReference.new(target2))

@sut.entries = [entry1, entry2]

@sut.entries.count.should == 2
@sut.entries.all? { |e| e.class.should == XCScheme::BuildAction::Entry }
@sut.entries[0].xml_element.should == entry1.xml_element
@sut.entries[1].xml_element.should == entry2.xml_element
end

it 'when there are entries' do
project = Xcodeproj::Project.new('/foo/bar/baz.xcodeproj')

Expand Down Expand Up @@ -166,6 +185,18 @@ module Xcodeproj
entry.xml_element.elements['BuildableReference'].should == ref.xml_element
end

it '#remove_buildable_reference' do
project = Xcodeproj::Project.new('/foo/bar/baz.xcodeproj')
entry = XCScheme::BuildAction::Entry.new

target = project.new_target(:application, 'FooApp', :ios)
ref = XCScheme::BuildableReference.new(target)
entry.add_buildable_reference(ref)
entry.xml_element.elements['BuildableReference'].should == ref.xml_element
entry.remove_buildable_reference(ref)
entry.xml_element.elements['BuildableReference'].should.nil?
end

it '#buildable_references' do
project = Xcodeproj::Project.new('/foo/bar/baz.xcodeproj')
entry = XCScheme::BuildAction::Entry.new
Expand Down
30 changes: 30 additions & 0 deletions spec/scheme/test_action_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,23 @@ module Xcodeproj
@sut.testables[1].xml_element.should == test_ref2.xml_element
end

it '#testables=' do
project = Xcodeproj::Project.new('/foo/bar/baz.xcodeproj')

target1 = project.new_target(:application, 'FooApp', :ios)
test_ref1 = XCScheme::TestAction::TestableReference.new(target1)

target2 = project.new_target(:application, 'FooApp', :ios)
test_ref2 = XCScheme::TestAction::TestableReference.new(target2)

@sut.testables = [test_ref1, test_ref2]

@sut.testables.count.should == 2
@sut.testables.all? { |t| t.class.should == XCScheme::TestAction::TestableReference }
@sut.testables[0].xml_element.should == test_ref1.xml_element
@sut.testables[1].xml_element.should == test_ref2.xml_element
end

it '#add_testables' do
project = Xcodeproj::Project.new('/foo/bar/baz.xcodeproj')

Expand Down Expand Up @@ -395,6 +412,19 @@ module Xcodeproj
test_ref.xml_element.elements['BuildableReference'].should == ref.xml_element
end

it '#remove_buildable_reference' do
project = Xcodeproj::Project.new('/foo/bar/baz.xcodeproj')
test_ref = XCScheme::TestAction::TestableReference.new

target = project.new_target(:application, 'FooApp', :ios)
ref = XCScheme::BuildableReference.new(target)
test_ref.add_buildable_reference(ref)

test_ref.xml_element.elements['BuildableReference'].should == ref.xml_element
test_ref.remove_buildable_reference(ref)
test_ref.xml_element.elements['BuildableReference'].should.nil?
end

it '#buildable_references' do
project = Xcodeproj::Project.new('/foo/bar/baz.xcodeproj')
test_ref = XCScheme::TestAction::TestableReference.new
Expand Down

0 comments on commit d371e03

Please sign in to comment.