Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Xcode 10 changes for test schemes #583

Merged
merged 6 commits into from
Jun 28, 2018
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
* Xcode 10 changes for test schemes
[Jenn Kaplan](https://github.com/jkap)
[#583](https://github.com/CocoaPods/CocoaPods/issues/583)

##### Bug Fixes

Expand Down
102 changes: 102 additions & 0 deletions lib/xcodeproj/scheme/test_action.rb
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,36 @@ def skipped=(flag)
@xml_element.attributes['skipped'] = bool_to_string(flag)
end

# @return [Bool]
# Whether or not this TestableReference (test bundle) should be run in parallel or not
#
def parallelizable?
string_to_bool(@xml_element.attributes['parallelizable'])
end

# @param [Bool]
# Set whether or not this TestableReference (test bundle) should be run in parallel or not
#
def parallelizable=(flag)
@xml_element.attributes['parallelizable'] = bool_to_string(flag)
end

# @return [Bool]
# Whether or not this TestableReference (test bundle) should be run in randomized order.
#
def randomized?
str = @xml_element.attributes['testExecutionOrdering']
raise Informative, 'Invalid tag value. Expected `random` or nil.' unless ['random', nil].include?(str)
str == 'random'
end

# @param [Bool] flag
# Set whether or not this TestableReference (test bundle) should be run in randomized order.
#
def randomized=(flag)
@xml_element.attributes['testExecutionOrdering'] = flag ? 'random' : nil
end

# @return [Array<BuildableReference>]
# The list of BuildableReferences this action will build.
# (The list usually contains only one element)
Expand Down Expand Up @@ -200,6 +230,52 @@ def add_skipped_test(skipped_test)
entries.add_element(skipped_test.xml_element)
end

# @return [Bool]
# Whether or not this TestableReference (test bundle) should use a whitelist or not
#
def whitelist?
string_to_bool(@xml_element.attributes['useTestSelectionWhitelist'])
end

# @param [Bool] flag
# Set whether or not this TestableReference (test bundle) should use a whitelist or not
#
def whitelist=(flag)
@xml_element.attributes['useTestSelectionWhitelist'] = bool_to_string(flag)
end

# @return [Array<SelectedTest>]
# The list of SelectedTest this action will run.
#
def selected_tests
return [] if @xml_element.elements['SelectedTests'].nil?
@xml_element.elements['SelectedTests'].get_elements('Test').map do |node|
TestableReference::SelectedTest.new(node)
end
end

# @param [Array<SelectedTest>] tests
# Set the list of SelectedTest this action will run.
#
def selected_tests=(tests)
@xml_element.delete_element('SelectedTests') unless @xml_element.elements['SelectedTests'].nil?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be able to delete the conditional on this line -- calling delete with a parameter that's not in the collection will just return nil

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is copied from skipped_tests= so i removed it there too

if tests.nil?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return if tests.nil?

return
end
entries = @xml_element.add_element('SelectedTests')
tests.each do |selected|
entries.add_element(selected.xml_element)
end
end

# @param [SelectedTest] selected_test
# The SelectedTest to add to the list of tests this action will run.
#
def add_selected_test(selected_test)
entries = @xml_element.elements['SelectedTests'] || @xml_element.add_element('SelectedTests')
entries.add_element(selected_test.xml_element)
end

class SkippedTest < XMLElementWrapper
# @param [REXML::Element] node
# The 'Test' XML node that this object will wrap.
Expand All @@ -226,6 +302,32 @@ def identifier=(value)
end
end

class SelectedTest < XMLElementWrapper
# @param [REXML::Element] node
# The 'Test' XML node that this object will wrap.
# If nil, will create a default XML node to use.
#
def initialize(node = nil)
create_xml_element_with_fallback(node, 'Test') do
self.identifier = node.attributes['Identifier'] unless node.nil?
end
end

# @return [String]
# Selected test class name
#
def identifier
@xml_element.attributes['Identifier']
end

# @param [String] value
# Set the name of the selected test class name
#
def identifier=(value)
@xml_element.attributes['Identifier'] = value
end
end

# @todo handle 'AdditionalOptions' tag
end
end
Expand Down
83 changes: 83 additions & 0 deletions spec/scheme/test_action_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ module Xcodeproj
test_ref.xml_element.name.should == 'TestableReference'
test_ref.xml_element.attributes.count.should == 1
test_ref.xml_element.attributes['skipped'].should == 'NO'
test_ref.randomized?.should.be.false?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

test_ref.should.not.be.randomized

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

did not know abt this syntax!

end

it 'raises if created with an invalid XML node' do
Expand All @@ -246,8 +247,38 @@ module Xcodeproj

attributes = {
:skipped => 'skipped',
:parallelizable => 'parallelizable',
:whitelist => 'useTestSelectionWhitelist',
}
specs_for_bool_attr(attributes)

# Reimplemented because `testExecutionOrdering` doesn't use standard YES/NO
describe 'randomized' do
it '#randomized? detect a true value' do
@sut.xml_element.attributes['testExecutionOrdering'] = 'random'
@sut.randomized?.should == true
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sut.should.be.randomized

end

it '#randomized? detect a false value' do
@sut.xml_element.attributes['testExecutionOrdering'] = nil
@sut.randomized?.should == false
end

it '#randomized? detect an invalid value' do
@sut.xml_element.attributes['testExecutionOrdering'] = 'BadValue'
should.raise(Xcodeproj::Informative) { @sut.randomized? }
end

it '#randomized= set true value' do
@sut.randomized = true
@sut.xml_element.attributes['testExecutionOrdering'].should == 'random'
end

it '#randomized= set false value' do
@sut.randomized = false
@sut.xml_element.attributes['testExecutionOrdering'].should.nil?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should.be.nil

end
end
end

it '#add_skipped_test' do
Expand Down Expand Up @@ -302,6 +333,58 @@ module Xcodeproj
test_ref.skipped_tests[1].xml_element.should == test2.xml_element
end

it '#add_selected_test' do
test_ref = XCScheme::TestAction::TestableReference.new
selected_test = XCScheme::TestAction::TestableReference::SelectedTest.new
selected_test.identifier = 'MyClassTests'
test_ref.add_selected_test(selected_test)
test_ref.xml_element.elements['SelectedTests'].should.not.nil?
test_ref.xml_element.elements['SelectedTests'].count.should == 1
test_ref.xml_element.elements['SelectedTests'].elements['Test'].should == selected_test.xml_element
end

it '#set_selected_tests_nil' do
test_ref = XCScheme::TestAction::TestableReference.new
test_ref.selected_tests = [XCScheme::TestAction::TestableReference::SelectedTest.new]
test_ref.selected_tests.count.should == 1
test_ref.selected_tests = nil
test_ref.xml_element.elements['SelectedTests'].should.nil?
test_ref.selected_tests.count.should == 0
end

it '#set_selected_tests' do
test_ref = XCScheme::TestAction::TestableReference.new

test1 = XCScheme::TestAction::TestableReference::SelectedTest.new
test1.identifier = 'MyClassTests1'

test2 = XCScheme::TestAction::TestableReference::SelectedTest.new
test2.identifier = 'MyClassTests2'

test_ref.selected_tests = [test1, test2]
test_ref.selected_tests.count.should == 2
test_ref.selected_tests.all? { |e| e.class.should == XCScheme::TestAction::TestableReference::SelectedTest }
test_ref.selected_tests[0].xml_element.should == test1.xml_element
test_ref.selected_tests[1].xml_element.should == test2.xml_element
end

it '#selected_tests' do
test_ref = XCScheme::TestAction::TestableReference.new

test1 = XCScheme::TestAction::TestableReference::SelectedTest.new
test1.identifier = 'MyClassTests1'
test_ref.add_selected_test(test1)

test2 = XCScheme::TestAction::TestableReference::SelectedTest.new
test2.identifier = 'MyClassTests2'
test_ref.add_selected_test(test2)

test_ref.selected_tests.count.should == 2
test_ref.selected_tests.all? { |e| e.class.should == XCScheme::TestAction::TestableReference::SelectedTest }
test_ref.selected_tests[0].xml_element.should == test1.xml_element
test_ref.selected_tests[1].xml_element.should == test2.xml_element
end

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