xctest-runner 0.2.0 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a00f0e993f2d26eb625fce6c23898256d53168b4
4
- data.tar.gz: d6bfe7c84e27ca2522b7ecadaa50fc94206861f0
3
+ metadata.gz: 9b0410f00c01ffedd26225465d0a883394e4c82f
4
+ data.tar.gz: b53f6d8a4de812580cd3dd13e2aa7cd543015dcc
5
5
  SHA512:
6
- metadata.gz: a7d2b6ac60cb0801181f4356f79e2920b020d9c8ad6c17d12d37cc26247b309111fecfc837a663c69e849e89e207dc99021767f9b78e493e0b5de6caa4922eb2
7
- data.tar.gz: 29ecedeb967476d3504a414f97af5976433125ca48cae622a21b1ac2cb4ec313666480b6e380abb014ead8c52b6f291537d74b171ba96b08a2a2c7be6b4a8021
6
+ metadata.gz: 66b9f65e3d63becb6c61fe7c69819643962fb9e56ef351aec1768764db1daef15764060a8bf223ba294f37e95913789635b84a70ef26dc2a992a47e626642eb3
7
+ data.tar.gz: 5324de9fad5f7954f8c70782158aed8324bab9eebef526fdb220b36c93ebeecb10bd038638272ea00712d06721e9b538a4f08e8829be6e77a82a30f52e23fa14
data/.travis.yml ADDED
@@ -0,0 +1,2 @@
1
+ rvm: 2.1.0
2
+ script: rake ci
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- xctest-runner
1
+ xctest-runner [![Gem Version](https://badge.fury.io/rb/xctest-runner.png)](http://badge.fury.io/rb/xctest-runner) [![build](https://travis-ci.org/tokorom/xctest-runner.png?branch=master)](https://travis-ci.org/tokorom/xctest-runner)
2
2
  ===================
3
3
 
4
4
  The unit tests runner for xctest.
@@ -52,6 +52,12 @@ $ xctest-runner -project Sample.xcodeproj
52
52
 
53
53
  ## Advanced Usage
54
54
 
55
+ ### If you would like to use [CocoaPods](http://cocoapods.org/)
56
+
57
+ ```shell
58
+ $ xctest-runner -workspace YourCocoaPods.xcworkspace -scheme YourProjectScheme
59
+ ```
60
+
55
61
  ### If you would like to use [xcpretty](https://github.com/mneorr/XCPretty)
56
62
 
57
63
  ```shell
data/Rakefile CHANGED
@@ -48,3 +48,7 @@ Rake::RDocTask.new do |rdoc|
48
48
  rdoc.rdoc_files.include('lib/**/*.rb')
49
49
  rdoc.options = ['--charset', 'utf-8', '--line-numbers']
50
50
  end
51
+
52
+ task :ci do
53
+ Rake::Task[:spec].invoke
54
+ end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.0
1
+ 1.0.0
@@ -2,49 +2,46 @@
2
2
 
3
3
  require 'xctest-runner/shell'
4
4
 
5
- module BuildEnvironment
6
- include Shell
7
-
8
- def current_environment(build_command)
9
- env = {}
10
- settings = execute_command("#{build_command} -showBuildSettings test")
11
- settings.each_line do |line|
12
- if line =~ /^\s(.*)=(.*)/
13
- variable, value = line.split('=')
14
- variable = variable.strip
15
- value = value.strip
16
- env[variable] = value if (env[variable].nil? || env[variable].empty?)
5
+ class XCTestRunner
6
+ module BuildEnvironment
7
+ include Shell
8
+
9
+ def current_environment(build_command)
10
+ env = {}
11
+ settings = execute_command("#{build_command} -showBuildSettings test")
12
+ settings.each_line do |line|
13
+ if line.strip.start_with?('Build settings')
14
+ break if env.include?('EXECUTABLE_FOLDER_PATH') && env['EXECUTABLE_FOLDER_PATH'].end_with?('.xctest')
15
+ elsif line =~ /^\s(.*)=(.*)/
16
+ variable, value = line.split('=')
17
+ env[variable.strip] = value.strip
18
+ end
17
19
  end
20
+ env
18
21
  end
19
- env
20
- end
21
22
 
22
- def configure_environment(build_command)
23
- env = current_environment(build_command)
24
- env.each do |key, value|
25
- ENV[key] = value
23
+ def xcodebuild_list
24
+ execute_command("xcodebuild -list")
26
25
  end
27
- ENV['DYLD_ROOT_PATH'] = ENV['SDK_DIR']
28
- end
29
-
30
- def xcodebuild_list
31
- execute_command("xcodebuild -list")
32
- end
33
-
34
- def default_target
35
- target = nil
36
- is_target = false
37
26
 
38
- output = xcodebuild_list
39
- output.each_line do |line|
40
- line = line.strip
41
- if line =~ /\w+:/
42
- is_target = ('Targets:' == line)
43
- elsif is_target
44
- target = line if target.nil? || line.end_with?('Tests')
27
+ def default_target
28
+ unless @default_target
29
+ target = nil
30
+ is_target = false
31
+
32
+ output = xcodebuild_list
33
+ output.each_line do |line|
34
+ line = line.strip
35
+ if line =~ /\w+:/
36
+ is_target = ('Targets:' == line)
37
+ elsif is_target
38
+ target = line if target.nil? || line.end_with?('Tests')
39
+ end
40
+ end
41
+ @default_target = target
45
42
  end
43
+ @default_target
46
44
  end
47
- target ? target : 'Tests'
48
- end
49
45
 
46
+ end
50
47
  end
@@ -0,0 +1,62 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ require 'find'
4
+ require 'rexml/document'
5
+
6
+ class XCTestRunner
7
+ module SchemeManager
8
+
9
+ TEMP_SCHEME = 'XCTestRunnerTemp'
10
+ TEMP_SCHEME_NAME = "#{TEMP_SCHEME}.xcscheme"
11
+
12
+ def temp_scheme
13
+ TEMP_SCHEME
14
+ end
15
+
16
+ def copy_xcscheme_if_need(scheme)
17
+ return nil unless scheme
18
+ scheme_path = scheme_path_for(scheme)
19
+ return nil unless scheme_path
20
+ find_xml_need_to_be_updated(scheme_path) do |doc|
21
+ temp_scheme_path = File.dirname(scheme_path) << "/#{TEMP_SCHEME_NAME}"
22
+ write_xml(doc, temp_scheme_path)
23
+ return temp_scheme_path
24
+ end
25
+ nil
26
+ end
27
+
28
+ def scheme_path_for(scheme)
29
+ expect = "/#{scheme}.xcscheme"
30
+ Find.find('.') do |path|
31
+ if path.end_with? expect
32
+ return path
33
+ end
34
+ end
35
+ nil
36
+ end
37
+
38
+ def find_xml_need_to_be_updated(scheme_path, &block)
39
+ need_to_be_updated = false
40
+ doc = REXML::Document.new(File.open(scheme_path))
41
+ doc.elements.each('Scheme/BuildAction/BuildActionEntries/BuildActionEntry') do |element|
42
+ if 'YES' == element.attributes['buildForTesting'] && 'NO' == element.attributes['buildForRunning']
43
+ element.attributes['buildForRunning'] = 'YES'
44
+ need_to_be_updated = true
45
+ end
46
+ end
47
+ block.call(doc) if need_to_be_updated
48
+ end
49
+
50
+ def write_xml(doc, path)
51
+ File.open(path, 'w') do |f|
52
+ f.sync = true
53
+ f.write(doc)
54
+ end
55
+ end
56
+
57
+ def remove_scheme(path)
58
+ File.unlink(path)
59
+ end
60
+
61
+ end
62
+ end
@@ -1,14 +1,16 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
 
3
- module Shell
3
+ class XCTestRunner
4
+ module Shell
4
5
 
5
- def execute_command(command, need_puts = false)
6
- if need_puts
7
- puts "$ #{command}\n\n" if need_puts
8
- system command
9
- else
10
- `#{command}`
6
+ def execute_command(command, need_puts = false)
7
+ if need_puts
8
+ puts "$ #{command}\n\n" if need_puts
9
+ system command
10
+ else
11
+ `#{command}`
12
+ end
11
13
  end
12
- end
13
14
 
15
+ end
14
16
  end
data/lib/xctest-runner.rb CHANGED
@@ -2,12 +2,14 @@
2
2
 
3
3
  require 'xctest-runner/version'
4
4
  require 'xctest-runner/build-environment'
5
+ require 'xctest-runner/scheme-manager'
5
6
  require 'xctest-runner/shell'
6
7
 
7
8
  class XCTestRunner
8
9
  include BuildEnvironment
10
+ include SchemeManager
9
11
  include Shell
10
-
12
+
11
13
  def initialize(opts = {})
12
14
  @clean = opts[:clean] || false
13
15
  @scheme = opts[:scheme] || nil
@@ -15,47 +17,104 @@ class XCTestRunner
15
17
  @project = opts[:project] || nil
16
18
  @target = opts[:target] || nil
17
19
  @sdk = opts[:sdk] || 'iphonesimulator'
18
- @arch = opts[:arch] || 'x86_64'
19
20
  @configuration = opts[:configuration] || 'Debug'
21
+ @arch = opts[:arch] || nil
20
22
  @test_class = opts[:test] || 'Self'
21
23
  @suffix = opts[:suffix] || ''
22
24
 
23
25
  @env = current_environment(build_command)
26
+ @arch = default_build_arch if @arch.nil?
27
+ @build_option = nil
28
+ end
29
+
30
+ def sdk_root
31
+ @sdk_root ||= @env['SDK_DIR']
32
+ end
33
+
34
+ def bundle_path
35
+ @bundle_path ||= "#{@env['BUILT_PRODUCTS_DIR']}/#{@env['EXECUTABLE_FOLDER_PATH']}"
36
+ end
37
+
38
+ def executable_path
39
+ @executable_path ||= "#{@env['BUILT_PRODUCTS_DIR']}/#{@env['EXECUTABLE_PATH']}"
40
+ end
41
+
42
+ def native_arch
43
+ unless @native_arch
44
+ arch = `file #{executable_path}`.split(' ').last
45
+ if 'i386' == arch || 'x86_64' == arch
46
+ @native_arch = arch
47
+ else
48
+ @native_arch = @env['CURRENT_ARCH']
49
+ end
50
+ end
51
+ @native_arch || 'i386'
52
+ end
53
+
54
+ def arch_command
55
+ unless @arch_command
56
+ @arch_command = native_arch ? "arch -arch #{native_arch}" : ''
57
+ end
58
+ @arch_command
24
59
  end
25
60
 
26
61
  def xcodebuild
27
- "xcodebuild"
62
+ @xcodebuild ||= 'xcodebuild'
63
+ end
64
+
65
+ def default_build_arch
66
+ if @env && @env && @env['VALID_ARCHS'] && @env['CURRENT_ARCH']
67
+ @env['VALID_ARCHS'].include?(@env['CURRENT_ARCH']) ? nil : 'i386'
68
+ end
69
+ end
70
+
71
+ def valid_archs
72
+ if @env && @env['VALID_ARCHS'] && @env['CURRENT_ARCH']
73
+ @env['VALID_ARCHS'].include?(@env['CURRENT_ARCH']) ? '' : "VALID_ARCHS=#{@arch}"
74
+ end
75
+ end
76
+
77
+ def build_option
78
+ unless @build_option
79
+ options = []
80
+ options << "-scheme #{@scheme}" if @scheme
81
+ options << "-workspace #{@workspace}" if @workspace
82
+ options << "-project #{@project}" if @project
83
+ options << "-target #{@target}" if @target
84
+ options << "-sdk #{@sdk}" if @sdk
85
+ options << "-configuration #{@configuration}" if @configuration
86
+ options << "-arch #{@arch} #{valid_archs}" if @arch
87
+ options << "-target #{default_target}" if @scheme.nil? && @target.nil? && default_target
88
+ @build_option = options.join(' ')
89
+ end
90
+ @build_option
91
+ end
92
+
93
+
94
+ def xctest_environment
95
+ @xctest_environment ||= "-e DYLD_ROOT_PATH='#{sdk_root}'"
28
96
  end
29
97
 
30
98
  def xctest
31
- if @xctest.nil?
32
- @xctest = "#{@env['SDK_DIR']}/Developer/usr/bin/xctest"
99
+ unless @xctest
100
+ xctest_command = "#{@env['SDK_DIR']}/Developer/usr/bin/xctest"
101
+ @xctest = "#{arch_command} #{xctest_environment} #{xctest_command}"
33
102
  end
34
103
  @xctest
35
104
  end
36
105
 
37
106
  def clean_command
38
- "#{xcodebuild} clean #{xcodebuild_option}"
107
+ "#{xcodebuild} clean #{build_option}"
39
108
  end
40
109
 
41
110
  def build_command
42
- "#{xcodebuild} #{xcodebuild_option}"
111
+ "#{xcodebuild} build #{build_option}"
43
112
  end
44
113
 
45
114
  def test_command(test_class)
46
- configure_environment(build_command)
115
+ xctest_command = xctest
47
116
  additional_options = "-NSTreatUnknownArgumentsAsOpen NO -ApplePersistenceIgnoreState YES"
48
- bundle_path = "#{@env['BUILT_PRODUCTS_DIR']}/#{@env['FULL_PRODUCT_NAME']}"
49
- "#{xctest} -XCTest #{test_class} #{additional_options} #{bundle_path}"
50
- end
51
-
52
- def xcodebuild_option
53
- (@scheme ? "-scheme #{@scheme} " : '') +
54
- (@workspace ? "-workspace #{@workspace} " : '') +
55
- (@project ? "-project #{@project} " : '') +
56
- (@target ? "-target #{@target} " : '') +
57
- (@scheme.nil? && @target.nil? ? "-target #{default_target} " : '') +
58
- "-sdk #{@sdk} -arch #{@arch} -configuration #{@configuration}"
117
+ "#{xctest_command} -XCTest #{test_class} #{additional_options} #{bundle_path}"
59
118
  end
60
119
 
61
120
  def clean
@@ -72,9 +131,15 @@ class XCTestRunner
72
131
  end
73
132
 
74
133
  def run
134
+ temp_scheme_path = copy_xcscheme_if_need(@scheme)
135
+ @scheme = temp_scheme if temp_scheme_path
136
+
75
137
  clean if @clean
76
- build
77
- test(@test_class)
138
+ if build
139
+ test(@test_class)
140
+ end
141
+
142
+ remove_scheme(temp_scheme_path) if temp_scheme_path
78
143
  end
79
144
 
80
145
  end
@@ -1,19 +1,29 @@
1
1
  require 'xctest-runner'
2
2
 
3
3
  describe XCTestRunner do
4
- class XCTestRunner
5
- attr_accessor :last_command
6
-
7
- def execute_command(command, need_puts = false)
8
- @last_command = command
9
- if command.include?('-showBuildSettings')
10
- build_settings
11
- elsif command.include?('-list')
12
- xcodebuild_list
13
- end
4
+
5
+ let(:arguments) {
6
+ {}
7
+ }
8
+
9
+ let(:runner) {
10
+ XCTestRunner.new(arguments)
11
+ }
12
+
13
+ let(:opts) {
14
+ option = runner.build_option
15
+ opts = {}
16
+ option.scan(/(-\w+) (\w+)/) do |opt, value|
17
+ opts[opt] = value
14
18
  end
19
+ opts
20
+ }
15
21
 
16
- def build_settings
22
+ before(:each) do
23
+ XCTestRunner.any_instance.stub(:execute_command) {
24
+ true
25
+ }
26
+ XCTestRunner.any_instance.stub(:execute_command).with(/\s-showBuildSettings/) {
17
27
  <<-EOS
18
28
  Build settings from command line:
19
29
  SDKROOT = iphonesimulator7.0
@@ -21,9 +31,8 @@ describe XCTestRunner do
21
31
  Build settings for action test and target Tests:
22
32
  HOGE = "huga"
23
33
  EOS
24
- end
25
-
26
- def xcodebuild_list
34
+ }
35
+ XCTestRunner.any_instance.stub(:execute_command).with(/\s-list/) {
27
36
  <<-EOS
28
37
  Information about project "PodSample":
29
38
  Targets:
@@ -38,208 +47,497 @@ describe XCTestRunner do
38
47
 
39
48
  Schemes:
40
49
  PodSample
41
- EOS
42
- end
50
+ EOS
51
+ }
43
52
  end
44
53
 
45
- let(:opts) {
46
- option = @runner.xcodebuild_option
47
- opts = {}
48
- option.scan(/(-\w+) (\w+)/) do |opt, value|
49
- opts[opt] = value
50
- end
51
- opts
52
- }
53
-
54
54
  context 'Defaults' do
55
- before(:each) do
56
- @runner = XCTestRunner.new
57
- end
58
-
59
55
  it 'runs xcodebuild with default options' do
60
- expect(opts.count).to eq 4
56
+ expect(opts.count).to eq 3
61
57
  expect(opts['-sdk']).to eq 'iphonesimulator'
62
- expect(opts['-arch']).to eq 'x86_64'
63
58
  expect(opts['-configuration']).to eq 'Debug'
64
59
  expect(opts['-target']).to eq 'PodSampleTests'
65
60
  end
66
61
 
67
62
  it 'doese not run clean command' do
68
- @runner.should_not_receive(:clean)
69
- @runner.should_receive(:build)
70
- @runner.should_receive(:test).with('Self')
71
- @runner.run
63
+ expect(runner).to_not receive(:clean)
64
+ expect(runner).to receive(:build).and_return(true)
65
+ expect(runner).to receive(:test).with('Self')
66
+ runner.run
72
67
  end
73
68
  end
74
69
 
75
70
  context '-scheme option' do
76
- before(:each) do
77
- @runner = XCTestRunner.new({:scheme => 'Tests'})
78
- end
71
+ let(:arguments) {
72
+ {:scheme => 'Tests'}
73
+ }
79
74
 
80
75
  it 'has some build arguments' do
81
- expect(opts.count).to eq 4
76
+ expect(opts.count).to eq 3
82
77
  expect(opts['-scheme']).to eq 'Tests'
83
78
  end
84
79
  end
85
80
 
86
81
  context '-workspace option' do
87
- before(:each) do
88
- @runner = XCTestRunner.new({:workspace => 'Sample'})
89
- end
82
+ let(:arguments) {
83
+ {:workspace => 'Sample'}
84
+ }
90
85
 
91
86
  it 'has some build arguments' do
92
- expect(opts.count).to eq 5
87
+ expect(opts.count).to eq 4
93
88
  expect(opts['-workspace']).to eq 'Sample'
94
89
  end
95
90
  end
96
91
 
97
92
  context '-project option' do
98
- before(:each) do
99
- @runner = XCTestRunner.new({:project => 'Sample'})
100
- end
93
+ let(:arguments) {
94
+ {:project => 'Sample'}
95
+ }
101
96
 
102
97
  it 'has some build arguments' do
103
- expect(opts.count).to eq 5
98
+ expect(opts.count).to eq 4
104
99
  expect(opts['-project']).to eq 'Sample'
105
100
  end
106
101
  end
107
102
 
108
103
  context '-target option' do
109
- before(:each) do
110
- @runner = XCTestRunner.new({:target => 'Tests'})
111
- end
104
+ let(:arguments) {
105
+ {:target => 'Tests'}
106
+ }
112
107
 
113
108
  it 'has some build arguments' do
114
- expect(opts.count).to eq 4
109
+ expect(opts.count).to eq 3
115
110
  expect(opts['-target']).to eq 'Tests'
116
111
  end
117
112
  end
118
113
 
119
114
  context '-sdk option' do
120
- before(:each) do
121
- @runner = XCTestRunner.new({:sdk => 'iphoneos'})
122
- end
115
+ let(:arguments) {
116
+ {:sdk => 'iphoneos'}
117
+ }
123
118
 
124
119
  it 'has some build arguments' do
125
- expect(opts.count).to eq 4
120
+ expect(opts.count).to eq 3
126
121
  expect(opts['-sdk']).to eq 'iphoneos'
127
122
  end
128
123
  end
129
124
 
130
125
  context '-arch option' do
131
- before(:each) do
132
- @runner = XCTestRunner.new({:arch => 'armv7'})
133
- end
126
+ let(:arguments) {
127
+ {:arch => 'i386'}
128
+ }
134
129
 
135
130
  it 'has some build arguments' do
136
131
  expect(opts.count).to eq 4
137
- expect(opts['-arch']).to eq 'armv7'
132
+ expect(opts['-arch']).to eq 'i386'
138
133
  end
139
134
  end
140
135
 
141
136
  context '-configuration option' do
142
- before(:each) do
143
- @runner = XCTestRunner.new({:configuration => 'Release'})
144
- end
137
+ let(:arguments) {
138
+ {:configuration => 'Release'}
139
+ }
145
140
 
146
141
  it 'has some build arguments' do
147
- expect(opts.count).to eq 4
142
+ expect(opts.count).to eq 3
148
143
  expect(opts['-configuration']).to eq 'Release'
149
144
  end
150
145
  end
151
146
 
152
147
  context '-test option' do
153
- before(:each) do
154
- @runner = XCTestRunner.new({:test => 'SampleTests/testCase'})
155
- end
148
+ let(:arguments) {
149
+ {:test => 'SampleTests/testCase'}
150
+ }
156
151
 
157
152
  it 'has some build arguments' do
158
- expect(opts.count).to eq 4
153
+ expect(opts.count).to eq 3
159
154
  end
160
155
 
161
156
  it 'run test command with the specific test case' do
162
- @runner.run
163
- expect(@runner.last_command).to include '-XCTest SampleTests/testCase'
157
+ expect(runner).to receive(:execute_command).with(/\s-XCTest SampleTests\/testCase/, true)
158
+ runner.run
164
159
  end
165
160
  end
166
161
 
167
162
  context '-clean option' do
168
- before(:each) do
169
- @runner = XCTestRunner.new({:clean => true})
170
- end
163
+ let(:arguments) {
164
+ {:clean => true}
165
+ }
171
166
 
172
167
  it 'has some build arguments' do
173
- expect(opts.count).to eq 4
168
+ expect(opts.count).to eq 3
174
169
  end
175
170
 
176
171
  it 'run clean command' do
177
- @runner.should_receive(:clean)
178
- @runner.should_receive(:build)
179
- @runner.should_receive(:test).with('Self')
180
- @runner.run
172
+ expect(runner).to receive(:clean)
173
+ expect(runner).to receive(:build).and_return(true)
174
+ expect(runner).to receive(:test).with('Self')
175
+ runner.run
176
+ end
177
+
178
+ it 'would not run test command if build returns false' do
179
+ expect(runner).to receive(:clean)
180
+ expect(runner).to receive(:build).and_return(false)
181
+ expect(runner).to_not receive(:test).with('Self')
182
+ runner.run
181
183
  end
182
184
  end
183
185
 
184
186
  context '-suffix option' do
185
- before(:each) do
186
- @runner = XCTestRunner.new({:suffix => 'OBJROOT=.'})
187
- end
187
+ let(:arguments) {
188
+ {:suffix => 'OBJROOT=.'}
189
+ }
188
190
 
189
191
  it 'has some build arguments' do
190
- expect(opts.count).to eq 4
192
+ expect(opts.count).to eq 3
191
193
  end
192
194
 
193
195
  it 'run test command with the suffix' do
194
- @runner.build
195
- expect(@runner.last_command).to include ' OBJROOT=.'
196
- @runner.test
197
- expect(@runner.last_command).to include ' OBJROOT=.'
196
+ expect(runner).to receive(:execute_command).with(/\sOBJROOT=\./, true)
197
+ runner.build
198
+ expect(runner).to receive(:execute_command).with(/\sOBJROOT=\./, true)
199
+ runner.test
198
200
  end
199
201
  end
200
202
 
201
203
  context 'Build environment' do
202
- class XCTestRunner
203
- def build_settings
204
+ before(:each) do
205
+ XCTestRunner.any_instance.stub(:execute_command).with(/\s-showBuildSettings/) {
204
206
  <<-EOS
205
207
  Build settings from command line:
206
208
  SDKROOT = iphonesimulator7.0
207
209
 
208
- Build settings for action test and target Tests:
209
- SDKROOT = /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator7.0.sdk
210
- SDK_DIR = /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator7.0.sdk
211
- BUILT_PRODUCTS_DIR = /Users/tokorom/Library/Developer/Xcode/DerivedData/XCTestRunner-xxx/Build/Products/Debug-iphonesimulator
212
- FULL_PRODUCT_NAME = Tests.xctest
213
-
214
210
  Build settings for action test and target Demo:
215
211
  SDKROOT = xxx
216
212
  SDK_DIR = xxx
217
213
  BUILT_PRODUCTS_DIR = xxx
218
214
  FULL_PRODUCT_NAME = Demo.app
219
- EOS
220
- end
221
- end
215
+ EXECUTABLE_FOLDER_PATH = Demo.app
216
+ EXECUTABLE_PATH = Demo.app/Demo
222
217
 
223
- before(:each) do
224
- @runner = XCTestRunner.new
218
+ Build settings for action test and target Tests:
219
+ SDKROOT = /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator7.0.sdk
220
+ SDK_DIR = /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator7.0.sdk
221
+ BUILT_PRODUCTS_DIR = /Users/xxx/Library/Developer/Xcode/DerivedData/XCTestRunner-xxx/Build/Products/Debug-iphonesimulator
222
+ FULL_PRODUCT_NAME = Tests.xctest
223
+ EXECUTABLE_FOLDER_PATH = Tests.xctest
224
+ EXECUTABLE_PATH = Tests.xctest/Tests
225
+
226
+ EOS
227
+ }
225
228
  end
226
229
 
227
- context 'ENV' do
228
- it 'contains DYLD_ROOT_PATH' do
229
- @runner.configure_environment('xcodebuild -showBuildSettings test')
230
- expect(ENV['SDKROOT']).to_not eq 'xxx'
231
- expect(ENV['DYLD_ROOT_PATH']).to eq ENV['SDK_DIR']
230
+ describe 'ENV' do
231
+ it 'contains environments' do
232
+ env = runner.current_environment('xcodebuild -showBuildSettings test')
233
+ expect(env['SDKROOT']).to_not eq 'xxx'
234
+ expect(env['SDK_DIR']).to eq '/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator7.0.sdk'
235
+ expect(env['EXECUTABLE_FOLDER_PATH']).to eq 'Tests.xctest'
236
+ expect(env['EXECUTABLE_PATH']).to eq 'Tests.xctest/Tests'
232
237
  end
233
238
  end
234
239
 
235
- context 'test command' do
240
+ describe 'test command' do
236
241
  it 'contains xctest command' do
237
- expect(@runner.test_command('Self')).to include '/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator7.0.sdk/Developer/usr/bin/xctest '
242
+ expect(runner.test_command('Self')).to include '/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator7.0.sdk/Developer/usr/bin/xctest '
238
243
  end
239
244
 
240
245
  it 'contains test bundle' do
241
- expect(@runner.test_command('Self')).to include ' /Users/tokorom/Library/Developer/Xcode/DerivedData/XCTestRunner-xxx/Build/Products/Debug-iphonesimulator/Tests.xctest'
246
+ expect(runner.test_command('Self')).to include ' /Users/xxx/Library/Developer/Xcode/DerivedData/XCTestRunner-xxx/Build/Products/Debug-iphonesimulator/Tests.xctest'
247
+ end
248
+
249
+ it 'contains arch DYLD_ROOT_PATH' do
250
+ expect(runner.test_command('Self')).to include "-e DYLD_ROOT_PATH='/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator7.0.sdk'"
251
+ end
252
+
253
+ it 'contains arch command' do
254
+ expect(runner.test_command('Self')).to include 'arch -arch i386 '
255
+ end
256
+ end
257
+
258
+ describe 'SchemeManager' do
259
+ context 'without scheme' do
260
+ it 'does not call write_xml' do
261
+ expect(runner).to_not receive(:write_xml)
262
+ runner.run
263
+ end
264
+ end
265
+
266
+ context 'with scheme' do
267
+ let(:arguments) {
268
+ {:scheme => 'Tests'}
269
+ }
270
+ let (:temp_xml) {
271
+ double('xml')
272
+ }
273
+
274
+ before(:each) do
275
+ Find.stub(:find).and_yield('./Tests.xcscheme')
276
+ File.stub(:open).and_return(xcscheme_xml)
277
+ end
278
+
279
+ context 'need to be updated' do
280
+ let(:xcscheme_xml) {
281
+ StringIO.new <<EOS
282
+ <?xml version="1.0" encoding="UTF-8"?>
283
+ <Scheme
284
+ LastUpgradeVersion = "0500"
285
+ version = "1.3">
286
+ <BuildAction
287
+ parallelizeBuildables = "YES"
288
+ buildImplicitDependencies = "YES">
289
+ <BuildActionEntries>
290
+ <BuildActionEntry
291
+ buildForTesting = "YES"
292
+ buildForRunning = "YES"
293
+ buildForProfiling = "YES"
294
+ buildForArchiving = "YES"
295
+ buildForAnalyzing = "YES">
296
+ <BuildableReference
297
+ BuildableIdentifier = "primary"
298
+ BlueprintIdentifier = "06D7A7C2188AC90900D09064"
299
+ BuildableName = "CocoaPodsProjectSample.app"
300
+ BlueprintName = "CocoaPodsProjectSample"
301
+ ReferencedContainer = "container:CocoaPodsProjectSample.xcodeproj">
302
+ </BuildableReference>
303
+ </BuildActionEntry>
304
+ <BuildActionEntry
305
+ buildForTesting = "YES"
306
+ buildForRunning = "NO"
307
+ buildForProfiling = "NO"
308
+ buildForArchiving = "NO"
309
+ buildForAnalyzing = "NO">
310
+ <BuildableReference
311
+ BuildableIdentifier = "primary"
312
+ BlueprintIdentifier = "06D7A7E6188AC90900D09064"
313
+ BuildableName = "CocoaPodsProjectSampleTests.xctest"
314
+ BlueprintName = "CocoaPodsProjectSampleTests"
315
+ ReferencedContainer = "container:CocoaPodsProjectSample.xcodeproj">
316
+ </BuildableReference>
317
+ </BuildActionEntry>
318
+ </BuildActionEntries>
319
+ </BuildAction>
320
+ <TestAction
321
+ selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
322
+ selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
323
+ shouldUseLaunchSchemeArgsEnv = "YES"
324
+ buildConfiguration = "Debug">
325
+ <Testables>
326
+ <TestableReference
327
+ skipped = "NO">
328
+ <BuildableReference
329
+ BuildableIdentifier = "primary"
330
+ BlueprintIdentifier = "06D7A7E6188AC90900D09064"
331
+ BuildableName = "CocoaPodsProjectSampleTests.xctest"
332
+ BlueprintName = "CocoaPodsProjectSampleTests"
333
+ ReferencedContainer = "container:CocoaPodsProjectSample.xcodeproj">
334
+ </BuildableReference>
335
+ </TestableReference>
336
+ </Testables>
337
+ <MacroExpansion>
338
+ <BuildableReference
339
+ BuildableIdentifier = "primary"
340
+ BlueprintIdentifier = "06D7A7C2188AC90900D09064"
341
+ BuildableName = "CocoaPodsProjectSample.app"
342
+ BlueprintName = "CocoaPodsProjectSample"
343
+ ReferencedContainer = "container:CocoaPodsProjectSample.xcodeproj">
344
+ </BuildableReference>
345
+ </MacroExpansion>
346
+ </TestAction>
347
+ <LaunchAction
348
+ selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
349
+ selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
350
+ launchStyle = "0"
351
+ useCustomWorkingDirectory = "NO"
352
+ buildConfiguration = "Debug"
353
+ ignoresPersistentStateOnLaunch = "NO"
354
+ debugDocumentVersioning = "YES"
355
+ allowLocationSimulation = "YES">
356
+ <BuildableProductRunnable>
357
+ <BuildableReference
358
+ BuildableIdentifier = "primary"
359
+ BlueprintIdentifier = "06D7A7C2188AC90900D09064"
360
+ BuildableName = "CocoaPodsProjectSample.app"
361
+ BlueprintName = "CocoaPodsProjectSample"
362
+ ReferencedContainer = "container:CocoaPodsProjectSample.xcodeproj">
363
+ </BuildableReference>
364
+ </BuildableProductRunnable>
365
+ <AdditionalOptions>
366
+ </AdditionalOptions>
367
+ </LaunchAction>
368
+ <ProfileAction
369
+ shouldUseLaunchSchemeArgsEnv = "YES"
370
+ savedToolIdentifier = ""
371
+ useCustomWorkingDirectory = "NO"
372
+ buildConfiguration = "Release"
373
+ debugDocumentVersioning = "YES">
374
+ <BuildableProductRunnable>
375
+ <BuildableReference
376
+ BuildableIdentifier = "primary"
377
+ BlueprintIdentifier = "06D7A7C2188AC90900D09064"
378
+ BuildableName = "CocoaPodsProjectSample.app"
379
+ BlueprintName = "CocoaPodsProjectSample"
380
+ ReferencedContainer = "container:CocoaPodsProjectSample.xcodeproj">
381
+ </BuildableReference>
382
+ </BuildableProductRunnable>
383
+ </ProfileAction>
384
+ <AnalyzeAction
385
+ buildConfiguration = "Debug">
386
+ </AnalyzeAction>
387
+ <ArchiveAction
388
+ buildConfiguration = "Release"
389
+ revealArchiveInOrganizer = "YES">
390
+ </ArchiveAction>
391
+ </Scheme>
392
+ EOS
393
+ }
394
+
395
+ describe 'write and unlink' do
396
+ it 'is called' do
397
+ expect(File).to receive(:open).with(anything(), 'w').and_return(double('file'))
398
+ expect(File).to receive(:unlink)
399
+ runner.run
400
+ end
401
+ end
402
+
403
+ it 'write temp scheme' do
404
+ expect(File).to receive(:open).with('./XCTestRunnerTemp.xcscheme', 'w').and_yield(temp_xml)
405
+ expect(File).to receive(:unlink)
406
+ expect(temp_xml).to receive(:sync=).with(true)
407
+ temp_xml.stub(:write) do |xml|
408
+ expect(xml.to_s).to_not match /buildForRunning\s*=\s*['"NO]+\s+buildForTesting\s*=\s*['"YES]+/
409
+ end
410
+ runner.run
411
+ end
412
+ end
413
+
414
+ context 'need not to be updated' do
415
+ let(:xcscheme_xml) {
416
+ StringIO.new <<EOS
417
+ <?xml version="1.0" encoding="UTF-8"?>
418
+ <Scheme
419
+ LastUpgradeVersion = "0500"
420
+ version = "1.3">
421
+ <BuildAction
422
+ parallelizeBuildables = "YES"
423
+ buildImplicitDependencies = "YES">
424
+ <BuildActionEntries>
425
+ <BuildActionEntry
426
+ buildForTesting = "YES"
427
+ buildForRunning = "YES"
428
+ buildForProfiling = "YES"
429
+ buildForArchiving = "YES"
430
+ buildForAnalyzing = "YES">
431
+ <BuildableReference
432
+ BuildableIdentifier = "primary"
433
+ BlueprintIdentifier = "06D7A7C2188AC90900D09064"
434
+ BuildableName = "CocoaPodsProjectSample.app"
435
+ BlueprintName = "CocoaPodsProjectSample"
436
+ ReferencedContainer = "container:CocoaPodsProjectSample.xcodeproj">
437
+ </BuildableReference>
438
+ </BuildActionEntry>
439
+ <BuildActionEntry
440
+ buildForTesting = "YES"
441
+ buildForRunning = "YES"
442
+ buildForProfiling = "NO"
443
+ buildForArchiving = "NO"
444
+ buildForAnalyzing = "NO">
445
+ <BuildableReference
446
+ BuildableIdentifier = "primary"
447
+ BlueprintIdentifier = "06D7A7E6188AC90900D09064"
448
+ BuildableName = "CocoaPodsProjectSampleTests.xctest"
449
+ BlueprintName = "CocoaPodsProjectSampleTests"
450
+ ReferencedContainer = "container:CocoaPodsProjectSample.xcodeproj">
451
+ </BuildableReference>
452
+ </BuildActionEntry>
453
+ </BuildActionEntries>
454
+ </BuildAction>
455
+ <TestAction
456
+ selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
457
+ selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
458
+ shouldUseLaunchSchemeArgsEnv = "YES"
459
+ buildConfiguration = "Debug">
460
+ <Testables>
461
+ <TestableReference
462
+ skipped = "NO">
463
+ <BuildableReference
464
+ BuildableIdentifier = "primary"
465
+ BlueprintIdentifier = "06D7A7E6188AC90900D09064"
466
+ BuildableName = "CocoaPodsProjectSampleTests.xctest"
467
+ BlueprintName = "CocoaPodsProjectSampleTests"
468
+ ReferencedContainer = "container:CocoaPodsProjectSample.xcodeproj">
469
+ </BuildableReference>
470
+ </TestableReference>
471
+ </Testables>
472
+ <MacroExpansion>
473
+ <BuildableReference
474
+ BuildableIdentifier = "primary"
475
+ BlueprintIdentifier = "06D7A7C2188AC90900D09064"
476
+ BuildableName = "CocoaPodsProjectSample.app"
477
+ BlueprintName = "CocoaPodsProjectSample"
478
+ ReferencedContainer = "container:CocoaPodsProjectSample.xcodeproj">
479
+ </BuildableReference>
480
+ </MacroExpansion>
481
+ </TestAction>
482
+ <LaunchAction
483
+ selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
484
+ selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
485
+ launchStyle = "0"
486
+ useCustomWorkingDirectory = "NO"
487
+ buildConfiguration = "Debug"
488
+ ignoresPersistentStateOnLaunch = "NO"
489
+ debugDocumentVersioning = "YES"
490
+ allowLocationSimulation = "YES">
491
+ <BuildableProductRunnable>
492
+ <BuildableReference
493
+ BuildableIdentifier = "primary"
494
+ BlueprintIdentifier = "06D7A7C2188AC90900D09064"
495
+ BuildableName = "CocoaPodsProjectSample.app"
496
+ BlueprintName = "CocoaPodsProjectSample"
497
+ ReferencedContainer = "container:CocoaPodsProjectSample.xcodeproj">
498
+ </BuildableReference>
499
+ </BuildableProductRunnable>
500
+ <AdditionalOptions>
501
+ </AdditionalOptions>
502
+ </LaunchAction>
503
+ <ProfileAction
504
+ shouldUseLaunchSchemeArgsEnv = "YES"
505
+ savedToolIdentifier = ""
506
+ useCustomWorkingDirectory = "NO"
507
+ buildConfiguration = "Release"
508
+ debugDocumentVersioning = "YES">
509
+ <BuildableProductRunnable>
510
+ <BuildableReference
511
+ BuildableIdentifier = "primary"
512
+ BlueprintIdentifier = "06D7A7C2188AC90900D09064"
513
+ BuildableName = "CocoaPodsProjectSample.app"
514
+ BlueprintName = "CocoaPodsProjectSample"
515
+ ReferencedContainer = "container:CocoaPodsProjectSample.xcodeproj">
516
+ </BuildableReference>
517
+ </BuildableProductRunnable>
518
+ </ProfileAction>
519
+ <AnalyzeAction
520
+ buildConfiguration = "Debug">
521
+ </AnalyzeAction>
522
+ <ArchiveAction
523
+ buildConfiguration = "Release"
524
+ revealArchiveInOrganizer = "YES">
525
+ </ArchiveAction>
526
+ </Scheme>
527
+ EOS
528
+ }
529
+
530
+ describe 'write and unlink' do
531
+ it 'is not called' do
532
+ expect(File).to_not receive(:open).with(anything(), 'w')
533
+ expect(File).to_not receive(:unlink)
534
+ runner.run
535
+ end
536
+ end
537
+ end
538
+
242
539
  end
243
540
  end
244
541
  end
542
+
245
543
  end
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "xctest-runner"
8
- s.version = "0.2.0"
8
+ s.version = "1.0.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["tokorom"]
12
- s.date = "2014-01-13"
12
+ s.date = "2014-01-19"
13
13
  s.description = "The unit tests runner for xctest"
14
14
  s.email = "tokorom@gmail.com"
15
15
  s.executables = ["xctest-runner"]
@@ -20,6 +20,7 @@ Gem::Specification.new do |s|
20
20
  s.files = [
21
21
  ".document",
22
22
  ".rspec",
23
+ ".travis.yml",
23
24
  "Gemfile",
24
25
  "Guardfile",
25
26
  "LICENSE.txt",
@@ -29,6 +30,7 @@ Gem::Specification.new do |s|
29
30
  "bin/xctest-runner",
30
31
  "lib/xctest-runner.rb",
31
32
  "lib/xctest-runner/build-environment.rb",
33
+ "lib/xctest-runner/scheme-manager.rb",
32
34
  "lib/xctest-runner/shell.rb",
33
35
  "lib/xctest-runner/version.rb",
34
36
  "spec/lib/xctest-runner_spec.rb",
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: xctest-runner
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - tokorom
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-01-13 00:00:00.000000000 Z
11
+ date: 2014-01-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -91,6 +91,7 @@ extra_rdoc_files:
91
91
  files:
92
92
  - .document
93
93
  - .rspec
94
+ - .travis.yml
94
95
  - Gemfile
95
96
  - Guardfile
96
97
  - LICENSE.txt
@@ -100,6 +101,7 @@ files:
100
101
  - bin/xctest-runner
101
102
  - lib/xctest-runner.rb
102
103
  - lib/xctest-runner/build-environment.rb
104
+ - lib/xctest-runner/scheme-manager.rb
103
105
  - lib/xctest-runner/shell.rb
104
106
  - lib/xctest-runner/version.rb
105
107
  - spec/lib/xctest-runner_spec.rb