xctest-runner 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9b0410f00c01ffedd26225465d0a883394e4c82f
4
- data.tar.gz: b53f6d8a4de812580cd3dd13e2aa7cd543015dcc
3
+ metadata.gz: b72725d5ad725e2222ce04ffb1d0127bd3e6c897
4
+ data.tar.gz: f87afd50444feabed1d8ef8383a11b88e1c90955
5
5
  SHA512:
6
- metadata.gz: 66b9f65e3d63becb6c61fe7c69819643962fb9e56ef351aec1768764db1daef15764060a8bf223ba294f37e95913789635b84a70ef26dc2a992a47e626642eb3
7
- data.tar.gz: 5324de9fad5f7954f8c70782158aed8324bab9eebef526fdb220b36c93ebeecb10bd038638272ea00712d06721e9b538a4f08e8829be6e77a82a30f52e23fa14
6
+ metadata.gz: 6ba9545e2a9e1d0975c34fb286dc9424a08fff53fe1e2a7b1f39ab6261ab2a174bfa085cc279dd3055ce865ff40f8d56ed51c4e3655da0834bd3e46cac27130e
7
+ data.tar.gz: c6fa012ccf099620052b42eea4df0e494a560ab0d021f4be5d86c754e167c51e79dc54d3995be00d84f877899b49a2737cc4f8178e978c84b78c80c10f243c9c
data/README.md CHANGED
@@ -18,7 +18,7 @@ $ gem install xctest-runner
18
18
  $ xctest-runner
19
19
  ```
20
20
 
21
- xctest-runner may be able to find the appropriate Target automatically.
21
+ xctest-runner may be able to find the appropriate Scheme automatically.
22
22
 
23
23
  ### If you would like to run a specific test case
24
24
 
@@ -26,12 +26,6 @@ xctest-runner may be able to find the appropriate Target automatically.
26
26
  $ xctest-runner -test SampleTests/testSample
27
27
  ```
28
28
 
29
- ### If you specify a target
30
-
31
- ```shell
32
- $ xctest-runner -target YourTestsTarget
33
- ```
34
-
35
29
  ### If you specify a scheme
36
30
 
37
31
  ```shell
@@ -44,12 +38,6 @@ $ xctest-runner -scheme YourScheme
44
38
  $ xctest-runner -workspace Sample.xcworkspace
45
39
  ```
46
40
 
47
- ### If you specify a project
48
-
49
- ```shell
50
- $ xctest-runner -project Sample.xcodeproj
51
- ```
52
-
53
41
  ## Advanced Usage
54
42
 
55
43
  ### If you would like to use [CocoaPods](http://cocoapods.org/)
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.0
1
+ 1.0.1
data/bin/xctest-runner CHANGED
@@ -12,8 +12,6 @@ opts = {}
12
12
  opt = OptionParser.new
13
13
  opt.on('--scheme NAME', 'build the scheme NAME') {|v| opts[:scheme] = v }
14
14
  opt.on('--workspace NAME', 'build the workspace NAME') {|v| opts[:workspace] = v }
15
- opt.on('--project NAME', 'build the project NAME') {|v| opts[:project] = v }
16
- opt.on('--target NAME', 'build the target NAME') {|v| opts[:target] = v }
17
15
  opt.on('--sdk SDK', 'use SDK as the name or path of the base SDK when building the project') {|v| opts[:sdk] = v }
18
16
  opt.on('--arch ARCH', 'build each target for the architecture ARCH') {|v| opts[:arch] = v }
19
17
  opt.on('--configuration NAME', 'use the build configuration NAME for building each target') {|v| opts[:configuration] = v }
@@ -24,23 +24,23 @@ class XCTestRunner
24
24
  execute_command("xcodebuild -list")
25
25
  end
26
26
 
27
- def default_target
28
- unless @default_target
29
- target = nil
30
- is_target = false
27
+ def default_scheme
28
+ unless @default_scheme
29
+ scheme = nil
30
+ is_scheme = false
31
31
 
32
32
  output = xcodebuild_list
33
33
  output.each_line do |line|
34
34
  line = line.strip
35
35
  if line =~ /\w+:/
36
- is_target = ('Targets:' == line)
37
- elsif is_target
38
- target = line if target.nil? || line.end_with?('Tests')
36
+ is_scheme = ('Schemes:' == line)
37
+ elsif is_scheme
38
+ scheme = line if scheme.nil? || line.end_with?('Tests')
39
39
  end
40
40
  end
41
- @default_target = target
41
+ @default_scheme = scheme
42
42
  end
43
- @default_target
43
+ @default_scheme
44
44
  end
45
45
 
46
46
  end
@@ -9,6 +9,10 @@ class XCTestRunner
9
9
  TEMP_SCHEME = 'XCTestRunnerTemp'
10
10
  TEMP_SCHEME_NAME = "#{TEMP_SCHEME}.xcscheme"
11
11
 
12
+ BUILD_ACTION_TAG = 'Scheme/BuildAction'
13
+ BUILD_ACTION_ENTRY_TAG = 'Scheme/BuildAction/BuildActionEntries/BuildActionEntry'
14
+ TEST_REFERENCE_TAG = 'Scheme/TestAction/Testables/TestableReference/BuildableReference'
15
+
12
16
  def temp_scheme
13
17
  TEMP_SCHEME
14
18
  end
@@ -38,15 +42,37 @@ class XCTestRunner
38
42
  def find_xml_need_to_be_updated(scheme_path, &block)
39
43
  need_to_be_updated = false
40
44
  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
+ if doc.get_elements(BUILD_ACTION_ENTRY_TAG).empty?
46
+ need_to_be_updated = add_build_action_entry_to(doc)
47
+ else
48
+ doc.elements.each(BUILD_ACTION_ENTRY_TAG) do |element|
49
+ if element.attributes['buildForTesting'] != element.attributes['buildForRunning']
50
+ element.attributes['buildForRunning'] = element.attributes['buildForTesting']
51
+ need_to_be_updated = true
52
+ end
45
53
  end
46
54
  end
47
55
  block.call(doc) if need_to_be_updated
48
56
  end
49
57
 
58
+ def add_build_action_entry_to(doc)
59
+ buildable_reference = doc.get_elements(TEST_REFERENCE_TAG).first
60
+ return false unless buildable_reference
61
+ build_action = doc.get_elements(BUILD_ACTION_TAG).first
62
+ return false unless build_action
63
+ entries = build_action.add_element('BuildActionEntries')
64
+ attributes = {
65
+ 'buildForTesting' => 'YES',
66
+ 'buildForRunning' => 'YES',
67
+ 'buildForProfiling' => 'NO',
68
+ 'buildForArchiving' => 'NO',
69
+ 'buildForAnalyzing' => 'NO',
70
+ }
71
+ entry = entries.add_element('BuildActionEntry', attributes)
72
+ entry.add_element(buildable_reference.name, buildable_reference.attributes)
73
+ true
74
+ end
75
+
50
76
  def write_xml(doc, path)
51
77
  File.open(path, 'w') do |f|
52
78
  f.sync = true
data/lib/xctest-runner.rb CHANGED
@@ -14,8 +14,6 @@ class XCTestRunner
14
14
  @clean = opts[:clean] || false
15
15
  @scheme = opts[:scheme] || nil
16
16
  @workspace = opts[:workspace] || nil
17
- @project = opts[:project] || nil
18
- @target = opts[:target] || nil
19
17
  @sdk = opts[:sdk] || 'iphonesimulator'
20
18
  @configuration = opts[:configuration] || 'Debug'
21
19
  @arch = opts[:arch] || nil
@@ -24,6 +22,7 @@ class XCTestRunner
24
22
 
25
23
  @env = current_environment(build_command)
26
24
  @arch = default_build_arch if @arch.nil?
25
+ @scheme = default_scheme unless @scheme
27
26
  @build_option = nil
28
27
  end
29
28
 
@@ -39,16 +38,20 @@ class XCTestRunner
39
38
  @executable_path ||= "#{@env['BUILT_PRODUCTS_DIR']}/#{@env['EXECUTABLE_PATH']}"
40
39
  end
41
40
 
41
+ def is_valid_arch?(arch)
42
+ ['i386', 'x86_64'].include?(arch)
43
+ end
44
+
42
45
  def native_arch
43
46
  unless @native_arch
44
47
  arch = `file #{executable_path}`.split(' ').last
45
- if 'i386' == arch || 'x86_64' == arch
48
+ if is_valid_arch?(arch)
46
49
  @native_arch = arch
47
50
  else
48
51
  @native_arch = @env['CURRENT_ARCH']
49
52
  end
50
53
  end
51
- @native_arch || 'i386'
54
+ is_valid_arch?(@native_arch) ? @native_arch : 'i386'
52
55
  end
53
56
 
54
57
  def arch_command
@@ -79,12 +82,9 @@ class XCTestRunner
79
82
  options = []
80
83
  options << "-scheme #{@scheme}" if @scheme
81
84
  options << "-workspace #{@workspace}" if @workspace
82
- options << "-project #{@project}" if @project
83
- options << "-target #{@target}" if @target
84
85
  options << "-sdk #{@sdk}" if @sdk
85
86
  options << "-configuration #{@configuration}" if @configuration
86
87
  options << "-arch #{@arch} #{valid_archs}" if @arch
87
- options << "-target #{default_target}" if @scheme.nil? && @target.nil? && default_target
88
88
  @build_option = options.join(' ')
89
89
  end
90
90
  @build_option
@@ -47,6 +47,7 @@ describe XCTestRunner do
47
47
 
48
48
  Schemes:
49
49
  PodSample
50
+ Tests
50
51
  EOS
51
52
  }
52
53
  end
@@ -56,7 +57,7 @@ describe XCTestRunner do
56
57
  expect(opts.count).to eq 3
57
58
  expect(opts['-sdk']).to eq 'iphonesimulator'
58
59
  expect(opts['-configuration']).to eq 'Debug'
59
- expect(opts['-target']).to eq 'PodSampleTests'
60
+ expect(opts['-scheme']).to eq 'Tests'
60
61
  end
61
62
 
62
63
  it 'doese not run clean command' do
@@ -89,28 +90,6 @@ describe XCTestRunner do
89
90
  end
90
91
  end
91
92
 
92
- context '-project option' do
93
- let(:arguments) {
94
- {:project => 'Sample'}
95
- }
96
-
97
- it 'has some build arguments' do
98
- expect(opts.count).to eq 4
99
- expect(opts['-project']).to eq 'Sample'
100
- end
101
- end
102
-
103
- context '-target option' do
104
- let(:arguments) {
105
- {:target => 'Tests'}
106
- }
107
-
108
- it 'has some build arguments' do
109
- expect(opts.count).to eq 3
110
- expect(opts['-target']).to eq 'Tests'
111
- end
112
- end
113
-
114
93
  context '-sdk option' do
115
94
  let(:arguments) {
116
95
  {:sdk => 'iphoneos'}
@@ -405,7 +384,10 @@ EOS
405
384
  expect(File).to receive(:unlink)
406
385
  expect(temp_xml).to receive(:sync=).with(true)
407
386
  temp_xml.stub(:write) do |xml|
408
- expect(xml.to_s).to_not match /buildForRunning\s*=\s*['"NO]+\s+buildForTesting\s*=\s*['"YES]+/
387
+ entry = xml.get_elements('Scheme/BuildAction/BuildActionEntries/BuildActionEntry').first
388
+ expect(entry).to_not be_nil
389
+ expect(entry.attributes['buildForTesting']).to eq('YES')
390
+ expect(entry.attributes['buildForRunning']).to eq('YES')
409
391
  end
410
392
  runner.run
411
393
  end
@@ -536,6 +518,87 @@ EOS
536
518
  end
537
519
  end
538
520
 
521
+ context 'build action entries is not exist' do
522
+ let(:xcscheme_xml) {
523
+ StringIO.new <<EOS
524
+ <?xml version="1.0" encoding="UTF-8"?>
525
+ <Scheme
526
+ LastUpgradeVersion = "0500"
527
+ version = "1.3">
528
+ <BuildAction
529
+ parallelizeBuildables = "YES"
530
+ buildImplicitDependencies = "YES">
531
+ </BuildAction>
532
+ <TestAction
533
+ selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
534
+ selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
535
+ shouldUseLaunchSchemeArgsEnv = "YES"
536
+ buildConfiguration = "Debug">
537
+ <Testables>
538
+ <TestableReference
539
+ skipped = "NO">
540
+ <BuildableReference
541
+ BuildableIdentifier = "primary"
542
+ BlueprintIdentifier = "xxxxxxx"
543
+ BuildableName = "Tests.xctest"
544
+ BlueprintName = "Tests"
545
+ ReferencedContainer = "container:XXX.xcodeproj">
546
+ </BuildableReference>
547
+ </TestableReference>
548
+ </Testables>
549
+ </TestAction>
550
+ <LaunchAction
551
+ selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
552
+ selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
553
+ launchStyle = "0"
554
+ useCustomWorkingDirectory = "NO"
555
+ buildConfiguration = "Debug"
556
+ ignoresPersistentStateOnLaunch = "NO"
557
+ debugDocumentVersioning = "YES"
558
+ allowLocationSimulation = "YES">
559
+ <AdditionalOptions>
560
+ </AdditionalOptions>
561
+ </LaunchAction>
562
+ <ProfileAction
563
+ shouldUseLaunchSchemeArgsEnv = "YES"
564
+ savedToolIdentifier = ""
565
+ useCustomWorkingDirectory = "NO"
566
+ buildConfiguration = "Debug"
567
+ debugDocumentVersioning = "YES">
568
+ </ProfileAction>
569
+ <AnalyzeAction
570
+ buildConfiguration = "Debug">
571
+ </AnalyzeAction>
572
+ <ArchiveAction
573
+ buildConfiguration = "Debug"
574
+ revealArchiveInOrganizer = "YES">
575
+ </ArchiveAction>
576
+ </Scheme>
577
+ EOS
578
+ }
579
+
580
+ describe 'write and unlink' do
581
+ it 'is called' do
582
+ expect(File).to receive(:open).with(anything(), 'w')
583
+ expect(File).to receive(:unlink)
584
+ runner.run
585
+ end
586
+ end
587
+
588
+ it 'write temp scheme' do
589
+ expect(File).to receive(:open).with('./XCTestRunnerTemp.xcscheme', 'w').and_yield(temp_xml)
590
+ expect(File).to receive(:unlink)
591
+ expect(temp_xml).to receive(:sync=).with(true)
592
+ temp_xml.stub(:write) do |xml|
593
+ entry = xml.get_elements('Scheme/BuildAction/BuildActionEntries/BuildActionEntry').first
594
+ expect(entry).to_not be_nil
595
+ expect(entry.attributes['buildForTesting']).to eq('YES')
596
+ expect(entry.attributes['buildForRunning']).to eq('YES')
597
+ end
598
+ runner.run
599
+ end
600
+ end
601
+
539
602
  end
540
603
  end
541
604
  end
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "xctest-runner"
8
- s.version = "1.0.0"
8
+ s.version = "1.0.1"
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-19"
12
+ s.date = "2014-01-21"
13
13
  s.description = "The unit tests runner for xctest"
14
14
  s.email = "tokorom@gmail.com"
15
15
  s.executables = ["xctest-runner"]
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: 1.0.0
4
+ version: 1.0.1
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-19 00:00:00.000000000 Z
11
+ date: 2014-01-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec