diff --git a/CHANGELOG.md b/CHANGELOG.md index 0a4c5970f..d56c516cb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/lib/xcodeproj/scheme/test_action.rb b/lib/xcodeproj/scheme/test_action.rb index 126bcabcd..af85e9c1c 100644 --- a/lib/xcodeproj/scheme/test_action.rb +++ b/lib/xcodeproj/scheme/test_action.rb @@ -151,6 +151,41 @@ 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] flag + # 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 [String] + # The execution order for this TestableReference (test bundle) + # + def test_execution_ordering + @xml_element.attributes['testExecutionOrdering'] + end + + # @param [String] order + # Set the execution order for this TestableReference (test bundle) + # + def test_execution_ordering=(order) + @xml_element.attributes['testExecutionOrdering'] = order + end + + # @return [Bool] + # Whether or not this TestableReference (test bundle) should be run in randomized order. + # + def randomized? + test_execution_ordering == 'random' + end + # @return [Array] # The list of BuildableReferences this action will build. # (The list usually contains only one element) @@ -168,21 +203,21 @@ def add_buildable_reference(ref) @xml_element.add_element(ref.xml_element) end - # @return [Array] + # @return [Array] # The list of SkippedTest this action will skip. # def skipped_tests return [] if @xml_element.elements['SkippedTests'].nil? @xml_element.elements['SkippedTests'].get_elements('Test').map do |node| - TestableReference::SkippedTest.new(node) + Test.new(node) end end - # @param [Array] tests + # @param [Array] tests # Set the list of SkippedTest this action will skip. # def skipped_tests=(tests) - @xml_element.delete_element('SkippedTests') unless @xml_element.elements['SkippedTests'].nil? + @xml_element.delete_element('SkippedTests') if tests.nil? return end @@ -192,7 +227,7 @@ def skipped_tests=(tests) end end - # @param [SkippedTest] skipped_test + # @param [Test] skipped_test # The SkippedTest to add to the list of tests this action will skip # def add_skipped_test(skipped_test) @@ -200,7 +235,51 @@ def add_skipped_test(skipped_test) entries.add_element(skipped_test.xml_element) end - class SkippedTest < XMLElementWrapper + # @return [Bool] + # Whether or not this TestableReference (test bundle) should use a whitelist or not + # + def use_test_selection_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 use_test_selection_whitelist=(flag) + @xml_element.attributes['useTestSelectionWhitelist'] = bool_to_string(flag) + end + + # @return [Array] + # 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| + Test.new(node) + end + end + + # @param [Array] tests + # Set the list of SelectedTest this action will run. + # + def selected_tests=(tests) + @xml_element.delete_element('SelectedTests') + return if tests.nil? + entries = @xml_element.add_element('SelectedTests') + tests.each do |selected| + entries.add_element(selected.xml_element) + end + end + + # @param [Test] 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 Test < XMLElementWrapper # @param [REXML::Element] node # The 'Test' XML node that this object will wrap. # If nil, will create a default XML node to use. @@ -226,6 +305,11 @@ def identifier=(value) end end + # Aliased to`Test` for compatibility + # @todo Remove in Xcodeproj 2 + # + SkippedTest = Test + # @todo handle 'AdditionalOptions' tag end end diff --git a/spec/scheme/test_action_spec.rb b/spec/scheme/test_action_spec.rb index 4d26f5981..70c8000d6 100644 --- a/spec/scheme/test_action_spec.rb +++ b/spec/scheme/test_action_spec.rb @@ -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.should.not.be.randomized? end it 'raises if created with an invalid XML node' do @@ -246,13 +247,40 @@ module Xcodeproj attributes = { :skipped => 'skipped', + :parallelizable => 'parallelizable', + :use_test_selection_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.should.be.randomized? + end + + it '#randomized? detect a false value' do + @sut.xml_element.attributes['testExecutionOrdering'] = nil + @sut.should.not.be.randomized? + end + end + + describe 'test_execution_ordering' do + it '#test_execution_ordering return actual value' do + @sut.xml_element.attributes['testExecutionOrdering'] = 'value' + @sut.test_execution_ordering.should == 'value' + end + + it '#test_execution_ordering= set actual value' do + @sut.test_execution_ordering = 'newValue' + @sut.xml_element.attributes['testExecutionOrdering'].should == 'newValue' + end + end end it '#add_skipped_test' do test_ref = XCScheme::TestAction::TestableReference.new - skipped_test = XCScheme::TestAction::TestableReference::SkippedTest.new + skipped_test = XCScheme::TestAction::TestableReference::Test.new skipped_test.identifier = 'MyClassTests' test_ref.add_skipped_test(skipped_test) test_ref.xml_element.elements['SkippedTests'].should.not.nil? @@ -262,7 +290,7 @@ module Xcodeproj it '#set_skipped_tests_nil' do test_ref = XCScheme::TestAction::TestableReference.new - test_ref.skipped_tests = [XCScheme::TestAction::TestableReference::SkippedTest.new] + test_ref.skipped_tests = [XCScheme::TestAction::TestableReference::Test.new] test_ref.skipped_tests.count.should == 1 test_ref.skipped_tests = nil test_ref.xml_element.elements['SkippedTests'].should.nil? @@ -272,15 +300,15 @@ module Xcodeproj it '#set_skipped_tests' do test_ref = XCScheme::TestAction::TestableReference.new - test1 = XCScheme::TestAction::TestableReference::SkippedTest.new + test1 = XCScheme::TestAction::TestableReference::Test.new test1.identifier = 'MyClassTests1' - test2 = XCScheme::TestAction::TestableReference::SkippedTest.new + test2 = XCScheme::TestAction::TestableReference::Test.new test2.identifier = 'MyClassTests2' test_ref.skipped_tests = [test1, test2] test_ref.skipped_tests.count.should == 2 - test_ref.skipped_tests.all? { |e| e.class.should == XCScheme::TestAction::TestableReference::SkippedTest } + test_ref.skipped_tests.all? { |e| e.class.should == XCScheme::TestAction::TestableReference::Test } test_ref.skipped_tests[0].xml_element.should == test1.xml_element test_ref.skipped_tests[1].xml_element.should == test2.xml_element end @@ -288,20 +316,72 @@ module Xcodeproj it '#skipped_tests' do test_ref = XCScheme::TestAction::TestableReference.new - test1 = XCScheme::TestAction::TestableReference::SkippedTest.new + test1 = XCScheme::TestAction::TestableReference::Test.new test1.identifier = 'MyClassTests1' test_ref.add_skipped_test(test1) - test2 = XCScheme::TestAction::TestableReference::SkippedTest.new + test2 = XCScheme::TestAction::TestableReference::Test.new test2.identifier = 'MyClassTests2' test_ref.add_skipped_test(test2) test_ref.skipped_tests.count.should == 2 - test_ref.skipped_tests.all? { |e| e.class.should == XCScheme::TestAction::TestableReference::SkippedTest } + test_ref.skipped_tests.all? { |e| e.class.should == XCScheme::TestAction::TestableReference::Test } test_ref.skipped_tests[0].xml_element.should == test1.xml_element 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::Test.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::Test.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::Test.new + test1.identifier = 'MyClassTests1' + + test2 = XCScheme::TestAction::TestableReference::Test.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::Test } + 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::Test.new + test1.identifier = 'MyClassTests1' + test_ref.add_selected_test(test1) + + test2 = XCScheme::TestAction::TestableReference::Test.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::Test } + 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