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

Add command_line_arguments to TestAction #492

Merged
merged 3 commits into from
Jun 2, 2017
Merged
Show file tree
Hide file tree
Changes from all 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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@
[Renzo Crisóstomo](https://github.com/ruenzuo)
[#180](https://github.com/CocoaPods/Xcodeproj/pull/180)

* Add command_line_arguments to TestAction.
[Brently Jones](https://github.com/brentleyjones)
[Danielle Tomlinson](https://github.com/dantoml)
[#492](https://github.com/CocoaPods/Xcodeproj/pull/492)

##### Bug Fixes

* Do not crash when there are no `BuildActionEntries` in a scheme.
Expand Down
18 changes: 18 additions & 0 deletions lib/xcodeproj/scheme/test_action.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,24 @@ def environment_variables=(env_vars)
env_vars
end

# @todo handle 'AdditionalOptions' tag

# @return [CommandLineArguments]
# Returns the CommandLineArguments that will be passed at app launch
#
def command_line_arguments
CommandLineArguments.new(@xml_element.elements[XCScheme::COMMAND_LINE_ARGS_NODE])
end

# @return [CommandLineArguments] arguments
# Sets the CommandLineArguments that will be passed at app launch
#
def command_line_arguments=(arguments)
@xml_element.delete_element(XCScheme::COMMAND_LINE_ARGS_NODE)
@xml_element.add_element(arguments.xml_element) if arguments
arguments
end

#-------------------------------------------------------------------------#

class TestableReference < XMLElementWrapper
Expand Down
57 changes: 57 additions & 0 deletions spec/scheme/test_action_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,63 @@ module Xcodeproj
@sut.xml_element.elements['MacroExpansion[2]'].should == macro2.xml_element
end

describe '#command_line_arguments' do
vars_node_name = XCScheme::COMMAND_LINE_ARGS_NODE
var_node_name = XCScheme::COMMAND_LINE_ARG_NODE

it 'starts as nil if no xml exists' do
@sut.xml_element.elements[vars_node_name].should.equal nil
@sut.command_line_arguments.to_a.should.equal []
end

it 'picks up an existing node if exists in the XML' do
env_vars_xml = @sut.xml_element.add_element(vars_node_name)
env_vars_xml.add_element(var_node_name, 'isEnabled' => 'NO', 'argument' => '-com.foo.bar 1')
env_vars_xml.add_element(var_node_name, 'isEnabled' => 'YES', 'argument' => '-org.foo.bar 1')

# Reload content from XML
@sut = XCScheme::TestAction.new(@sut.xml_element)

@sut.command_line_arguments.to_a.should == [{ :argument => '-com.foo.bar 1', :enabled => false },
{ :argument => '-org.foo.bar 1', :enabled => true }]
end

it 'reflects direct changes to xml' do
@sut.command_line_arguments = XCScheme::CommandLineArguments.new([{ :argument => '-com.foo.bar 1', :enabled => false },
{ :argument => '-org.foo.bar 1', :enabled => true }])
node_to_delete = @sut.command_line_arguments.xml_element.elements["#{var_node_name}[@argument='-com.foo.bar 1']"]
@sut.command_line_arguments.xml_element.delete(node_to_delete)
@sut.command_line_arguments.to_a.should == [{ :argument => '-org.foo.bar 1', :enabled => true }]
end

it 'can be assigned nil' do
@sut.xml_element.get_elements(vars_node_name).count.should == 0

@sut.command_line_arguments = XCScheme::CommandLineArguments.new
@sut.command_line_arguments.should.not.equal nil
@sut.xml_element.get_elements(vars_node_name).count.should == 1

@sut.command_line_arguments = nil
@sut.command_line_arguments.to_a.should.equal []
@sut.xml_element.elements[vars_node_name].should.be.nil
end

it 'assigning an CommandLineArguments object updates the xml' do
cl_arg = XCScheme::CommandLineArguments.new([{ :argument => '-com.foo.bar 1', :enabled => false }])
cl_arg.xml_element.elements.count.should == 1

@sut.command_line_arguments = cl_arg
@sut.command_line_arguments.to_a.should == [{ :argument => '-com.foo.bar 1', :enabled => false }]
@sut.command_line_arguments.xml_element.should == cl_arg.xml_element

xml_out = ''
xml_formatter = REXML::Formatters::Pretty.new(0)
xml_formatter.compact = true
xml_formatter.write(@sut.command_line_arguments.xml_element, xml_out)
xml_out.should == "<CommandLineArguments>\n<CommandLineArgument argument='-com.foo.bar 1' isEnabled='NO'/>\n</CommandLineArguments>"
end
end

describe '#environment_variables' do
vars_node_name = XCScheme::VARIABLES_NODE
var_node_name = XCScheme::VARIABLE_NODE
Expand Down