xcoder 0.1.11 → 0.1.12

Sign up to get free protection for your applications and to get access to all the features.
Files changed (35) hide show
  1. data/Rakefile +2 -0
  2. data/lib/xcode/builder.rb +32 -19
  3. data/lib/xcode/shell.rb +3 -1
  4. data/lib/xcode/test/parsers/ocunit_parser.rb +94 -0
  5. data/lib/xcode/test/report.rb +121 -0
  6. data/lib/xcode/test/report/suite_result.rb +67 -0
  7. data/lib/xcode/test/report/test_result.rb +49 -0
  8. data/lib/xcode/version.rb +1 -1
  9. data/lib/xcode/workspace.rb +6 -3
  10. data/spec/TestProject/{TestProjectTests/TestProjectTests-Info.plist → ApplicationTests/ApplicationTests-Info.plist} +0 -0
  11. data/spec/TestProject/ApplicationTests/ApplicationTests-Prefix.pch +8 -0
  12. data/spec/TestProject/ApplicationTests/ApplicationTests.h +13 -0
  13. data/spec/TestProject/ApplicationTests/ApplicationTests.m +32 -0
  14. data/spec/TestProject/{TestProjectTests → ApplicationTests}/en.lproj/InfoPlist.strings +0 -0
  15. data/spec/TestProject/{TestProjectTests → LogicTests}/AnotherTest.h +0 -0
  16. data/spec/TestProject/{TestProjectTests → LogicTests}/AnotherTest.m +0 -0
  17. data/spec/TestProject/LogicTests/TestProjectTests-Info.plist +22 -0
  18. data/spec/TestProject/{TestProjectTests → LogicTests}/TestProjectTests.h +0 -0
  19. data/spec/TestProject/{TestProjectTests → LogicTests}/TestProjectTests.m +0 -0
  20. data/spec/TestProject/LogicTests/en.lproj/InfoPlist.strings +2 -0
  21. data/spec/TestProject/TestProject.xcodeproj/project.pbxproj +1329 -556
  22. data/spec/TestProject/TestProject.xcodeproj/xcshareddata/xcschemes/TestProject.xcscheme +13 -2
  23. data/spec/TestWorkspace2.xcworkspace/contents.xcworkspacedata +7 -0
  24. data/spec/TestWorkspace2.xcworkspace/xcuserdata/ray.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
  25. data/spec/build_phase_spec.rb +2 -2
  26. data/spec/builder_spec.rb +51 -10
  27. data/spec/integration/builder_spec.rb +60 -4
  28. data/spec/ocunit_parser_spec.rb +164 -0
  29. data/spec/project_spec.rb +1 -1
  30. data/spec/workspace_spec.rb +8 -3
  31. metadata +44 -29
  32. data/lib/xcode/test/ocunit_report_parser.rb +0 -174
  33. data/lib/xcode/test/suite_result.rb +0 -39
  34. data/lib/xcode/test/test_result.rb +0 -43
  35. data/spec/test_report_spec.rb +0 -147
@@ -32,8 +32,18 @@
32
32
  <BuildableReference
33
33
  BuildableIdentifier = "primary"
34
34
  BlueprintIdentifier = "7165D46A146B4EA100DE2F0E"
35
- BuildableName = "TestProjectTests.octest"
36
- BlueprintName = "TestProjectTests"
35
+ BuildableName = "LogicTests.octest"
36
+ BlueprintName = "LogicTests"
37
+ ReferencedContainer = "container:TestProject.xcodeproj">
38
+ </BuildableReference>
39
+ </TestableReference>
40
+ <TestableReference
41
+ skipped = "NO">
42
+ <BuildableReference
43
+ BuildableIdentifier = "primary"
44
+ BlueprintIdentifier = "7147F906153E347700763224"
45
+ BuildableName = "ApplicationTests.octest"
46
+ BlueprintName = "ApplicationTests"
37
47
  ReferencedContainer = "container:TestProject.xcodeproj">
38
48
  </BuildableReference>
39
49
  </TestableReference>
@@ -54,6 +64,7 @@
54
64
  launchStyle = "0"
55
65
  useCustomWorkingDirectory = "NO"
56
66
  buildConfiguration = "Debug"
67
+ ignoresPersistentStateOnLaunch = "NO"
57
68
  debugDocumentVersioning = "YES"
58
69
  allowLocationSimulation = "YES">
59
70
  <BuildableProductRunnable>
@@ -0,0 +1,7 @@
1
+ <?xml version='1.0' encoding='UTF-8'?>
2
+ <Workspace
3
+ version = '1.0'>
4
+ <FileRef
5
+ location = 'group:TestProject/TestProject.xcodeproj'>
6
+ </FileRef>
7
+ </Workspace>
@@ -71,7 +71,7 @@ describe Xcode::BuildPhase do
71
71
  source_file = project.groups.create_file 'publicheader.h'
72
72
  subject.add_build_file_with_public_privacy source_file
73
73
  subject.build_file('publicheader.h').should_not be_nil
74
- subject.file('publicheader.h').settings.should == { 'ATTRIBUTES' => "Public" }
74
+ subject.file('publicheader.h').settings.should == { 'ATTRIBUTES' => ["Public"] }
75
75
  end
76
76
  end
77
77
 
@@ -80,7 +80,7 @@ describe Xcode::BuildPhase do
80
80
  source_file = project.groups.create_file 'privateheader.h'
81
81
  subject.add_build_file_with_private_privacy source_file
82
82
  subject.build_file('privateheader.h').should_not be_nil
83
- subject.file('privateheader.h').settings.should == { 'ATTRIBUTES' => "Private" }
83
+ subject.file('privateheader.h').settings.should == { 'ATTRIBUTES' => ["Private"] }
84
84
  end
85
85
  end
86
86
 
@@ -24,7 +24,14 @@ describe Xcode::Builder do
24
24
  Xcode::Shell.should_receive(:execute).with(default_build_parameters)
25
25
  subject.build
26
26
  end
27
-
27
+
28
+ it "should allow the override of the sdk" do
29
+ expected = default_build_parameters
30
+ expected[1] = '-sdk macosx10.7'
31
+ Xcode::Shell.should_receive(:execute).with(expected)
32
+ subject.build :sdk => 'macosx10.7'
33
+ end
34
+
28
35
  end
29
36
 
30
37
  describe "#testflight" do
@@ -59,10 +66,10 @@ describe Xcode::Builder do
59
66
  describe "#test" do
60
67
 
61
68
  let(:configuration) do
62
- Xcode.project('TestProject').target('TestProjectTests').config('Debug')
69
+ Xcode.project('TestProject').target('LogicTests').config('Debug')
63
70
  end
64
71
 
65
- let(:default_test_parameters) do
72
+ let(:iphonesimulator_test_parameters) do
66
73
  [ "xcodebuild",
67
74
  "-sdk iphonesimulator",
68
75
  "-project \"#{configuration.target.project.path}\"",
@@ -70,12 +77,46 @@ describe Xcode::Builder do
70
77
  "-configuration \"#{configuration.name}\"",
71
78
  "OBJROOT=\"#{File.dirname(configuration.target.project.path)}/build/\"",
72
79
  "SYMROOT=\"#{File.dirname(configuration.target.project.path)}/build/\"",
80
+ "TEST_AFTER_BUILD=YES"
81
+ ]
82
+ end
83
+
84
+ let(:macosx_test_parameters) do
85
+ [ "xcodebuild",
86
+ "-sdk macosx10.7",
87
+ "-project \"#{configuration.target.project.path}\"",
88
+ "-target \"#{configuration.target.name}\"",
89
+ "-configuration \"#{configuration.name}\"",
90
+ "OBJROOT=\"#{File.dirname(configuration.target.project.path)}/build/\"",
91
+ "SYMROOT=\"#{File.dirname(configuration.target.project.path)}/build/\"",
73
92
  "TEST_AFTER_BUILD=YES",
74
- "TEST_HOST=''",]
93
+ ]
94
+ end
95
+
96
+
97
+ it "should be able to run the test target on iphonesimulator" do
98
+ Xcode::Shell.should_receive(:execute).with(iphonesimulator_test_parameters, false)
99
+ subject.test :sdk => 'iphonesimulator'
100
+ end
101
+
102
+ it "should be able to run the test target on macosx10.7" do
103
+ Xcode::Shell.should_receive(:execute).with(macosx_test_parameters, false)
104
+ subject.test :sdk => 'macosx10.7'
105
+ end
106
+
107
+ it "should allow the override of the sdk" do
108
+ expected = macosx_test_parameters
109
+ expected[1] = '-sdk macosx10.7'
110
+ Xcode::Shell.should_receive(:execute).with(expected, false)
111
+ subject.test :sdk => 'macosx10.7'
75
112
  end
76
113
 
77
- it "should be able to run the test target" do
78
- Xcode::Shell.should_receive(:execute).with(default_test_parameters, false)
114
+ it "should not exit when test failed" do
115
+ Xcode::Shell.stub(:execute)
116
+ fake_parser = stub(:parser)
117
+ fake_parser.stub(:failed? => true)
118
+ fake_parser.stub(:flush)
119
+ Xcode::Test::Parsers::OCUnitParser.stub(:new => fake_parser)
79
120
  subject.test
80
121
  end
81
122
 
@@ -95,7 +136,7 @@ describe Xcode::Builder do
95
136
  end
96
137
 
97
138
 
98
- it "should clean the project with the default parametesr" do
139
+ it "should clean the project with the default parameter" do
99
140
  Xcode::Shell.should_receive(:execute).with(default_clean_parameters)
100
141
  subject.clean
101
142
  end
@@ -116,7 +157,7 @@ describe Xcode::Builder do
116
157
  [ "xcodebuild",
117
158
  "-sdk iphoneos",
118
159
  "-project \"#{scheme.project.path}\"",
119
- "-scheme #{scheme.name}",
160
+ "-scheme \"#{scheme.name}\"",
120
161
  "OBJROOT=\"#{File.dirname(scheme.project.path)}/build/\"",
121
162
  "SYMROOT=\"#{File.dirname(scheme.project.path)}/build/\"" ]
122
163
  end
@@ -134,14 +175,14 @@ describe Xcode::Builder do
134
175
  [ "xcodebuild",
135
176
  "-project \"#{scheme.project.path}\"",
136
177
  "-sdk iphoneos",
137
- "-scheme #{scheme.name}",
178
+ "-scheme \"#{scheme.name}\"",
138
179
  "OBJROOT=\"#{File.dirname(scheme.project.path)}/build/\"",
139
180
  "SYMROOT=\"#{File.dirname(scheme.project.path)}/build/\"",
140
181
  "clean" ]
141
182
  end
142
183
 
143
184
 
144
- it "should clean the project with the default parametesr" do
185
+ it "should clean the project with the default parameter" do
145
186
  Xcode::Shell.should_receive(:execute).with(default_clean_parameters)
146
187
  subject.clean
147
188
  end
@@ -3,13 +3,11 @@ require_relative '../spec_helper'
3
3
  describe Xcode::Builder, :integration => true do
4
4
 
5
5
  context "when using a builder built from a configuration" do
6
-
7
- let(:configuration) { Xcode.project('TestProject').target('TestProject').config('Debug') }
8
-
9
- let(:subject) { configuration.builder }
10
6
 
11
7
  describe "#build" do
12
8
 
9
+ let(:configuration) { Xcode.project('TestProject').target('TestProject').config('Debug') }
10
+ let(:subject) { configuration.builder }
13
11
 
14
12
  it "should be able to build" do
15
13
  subject.clean
@@ -28,6 +26,44 @@ describe Xcode::Builder, :integration => true do
28
26
 
29
27
  end
30
28
 
29
+
30
+ describe "logic tests" do
31
+
32
+ let(:configuration) { Xcode.project('TestProject').target('LogicTests').config('Debug') }
33
+ let(:subject) { configuration.builder }
34
+
35
+ it "should be able to run unit tests" do
36
+ subject.clean
37
+ report = subject.test
38
+ report.suites.count.should == 2
39
+
40
+ tests = report.suites[1].tests
41
+ tests.count.should==2
42
+ tests[0].should be_passed
43
+ tests[1].should be_failed
44
+
45
+ tests = report.suites[0].tests
46
+ tests.count.should==1
47
+ tests[0].should be_passed
48
+ end
49
+
50
+ end
51
+
52
+
53
+ describe "application tests" do
54
+
55
+ # FIXME: known issue with xcodebuild and iphonesimulator application tests (when TEST_HOST is set)
56
+ let(:configuration) { Xcode.project('TestProject').target('ApplicationTests').config('Debug') }
57
+ let(:subject) { configuration.builder }
58
+
59
+ it "should be able to run unit tests" do
60
+ subject.clean
61
+ report = subject.test
62
+ report.should be_succeed
63
+ end
64
+
65
+ end
66
+
31
67
  end
32
68
 
33
69
  context "when using a builder built from a scheme" do
@@ -54,6 +90,26 @@ describe Xcode::Builder, :integration => true do
54
90
  end
55
91
 
56
92
  end
93
+
94
+ describe "#test" do
95
+
96
+ # FIXME: cant seem to run tests when part of a scheme
97
+ it "should be able to run unit tests" do
98
+ subject.clean
99
+ report = subject.test
100
+ report.suites.count.should == 2
101
+
102
+ tests = report.suites[1].tests
103
+ tests.count.should==2
104
+ tests[0].should be_passed
105
+ tests[1].should be_failed
106
+
107
+ tests = report.suites[0].tests
108
+ tests.count.should==1
109
+ tests[0].should be_passed
110
+ end
111
+
112
+ end
57
113
 
58
114
  end
59
115
 
@@ -0,0 +1,164 @@
1
+ require 'rspec'
2
+ require 'xcoder'
3
+
4
+ require 'xcode/test/parsers/ocunit_parser'
5
+
6
+ describe Xcode::Test::Parsers::OCUnitParser do
7
+
8
+ let :parser do
9
+ Xcode::Test::Parsers::OCUnitParser.new
10
+ end
11
+
12
+ let :example_report do
13
+ parser << "Run test suite AnExampleTestSuite"
14
+ parser << "Test Suite 'AnExampleTestSuite' started at 2012-02-10 00:37:04 +0000"
15
+
16
+ parser << "Run test case anExampleTest1"
17
+ parser << "Test Case '-[AnExampleTestSuite anExampleTest1]' started."
18
+ parser << "Test Case '-[AnExampleTestSuite anExampleTest1]' passed (0.003 seconds)."
19
+
20
+ parser << "Run test case anExampleTest2"
21
+ parser << "Test Case '-[AnExampleTestSuite anExampleTest2]' started."
22
+ parser << "Test Case '-[AnExampleTestSuite anExampleTest2]' passed (0.003 seconds)."
23
+
24
+ parser << "Test Suite 'AnExampleTestSuite' finished at 2012-02-10 00:37:04 +0000."
25
+ parser << "Executed 1 test, with 0 failures (0 unexpected) in 0.000 (0.000) seconds"
26
+
27
+ parser.report
28
+ end
29
+
30
+ let :example_failing_report do
31
+ parser << "Run test suite AnExampleTestSuite"
32
+ parser << "Test Suite 'AnExampleTestSuite' started at 2012-02-10 00:37:04 +0000"
33
+ parser << "Test Case '-[AnExampleTestSuite aFailingTest]' started."
34
+
35
+ parser << '2012-02-17 15:03:06.521 otest[24979:7803] line1'
36
+ parser << '2012-02-17 15:03:06.521 otest[24979:7803] line2'
37
+ parser << '2012-02-17 15:03:06.521 otest[24979:7803] line3'
38
+ parser << '2012-02-17 15:03:06.521 otest[24979:7803] line4'
39
+ parser << '/Some/Path/To/Test.m:1234: error: -[AnExampleTestSuite aFailingTest] : This is an error message'
40
+
41
+ parser << "Test Case '-[AnExampleTestSuite aFailingTest]' failed (2 seconds)."
42
+ parser << "Test Suite 'AnExampleTestSuite' finished at 2012-02-10 00:37:04 +0000."
43
+ parser << "Executed 1 test, with 0 failures (0 unexpected) in 0.000 (0.000) seconds"
44
+
45
+ parser.report
46
+ end
47
+
48
+ it "should start the report" do
49
+ parser.report.start_time.should be_nil
50
+ parser << "Test Suite '/Users/blake/Projects/RestKit/RestKit/Build/Products/Debug-iphonesimulator/RestKitTests.octest(Tests)' started at 2012-04-17 01:36:20 +0000\n"
51
+ parser.report.start_time.should_not be_nil
52
+ end
53
+
54
+ it "should capture output for a test case" do
55
+
56
+ failure = example_failing_report.suites.first.tests[0]
57
+ failure.passed?.should==false
58
+ failure.errors.count.should==1
59
+ failure.errors[0][:data].count.should==4
60
+ failure.errors[0][:data][0].should=~/line1/
61
+ failure.errors[0][:data][1].should=~/line2/
62
+ failure.errors[0][:data][2].should=~/line3/
63
+ failure.errors[0][:data][3].should=~/line4/
64
+ end
65
+
66
+ it "should capture errors reported during a test" do
67
+ failure = example_failing_report.suites.first.tests[0]
68
+ failure.passed?.should==false
69
+ failure.errors.count.should==1
70
+ failure.errors[0][:message].should=='This is an error message'
71
+ failure.errors[0][:location].should=='/Some/Path/To/Test.m:1234'
72
+ end
73
+
74
+ it "should create a test case" do
75
+ t = example_report.suites
76
+ t.count.should==1
77
+ t.first.name.should=="AnExampleTestSuite"
78
+ t.first.start_time.should==Time.parse("2012-02-10 00:37:04 +0000")
79
+ t.first.end_time.should==Time.parse("2012-02-10 00:37:04 +0000")
80
+ end
81
+
82
+ it "should detect a passing report" do
83
+ t = example_report
84
+ t.should be_succeed
85
+ t.should_not be_failed
86
+ end
87
+
88
+ it "should detect a failing report" do
89
+ t = example_failing_report
90
+ t.should_not be_succeed
91
+ t.should be_failed
92
+ end
93
+
94
+ it "should record a failure" do
95
+ t = example_failing_report
96
+ t.suites.first.total_failed_tests.should==1
97
+ end
98
+
99
+ it "should create a test case with some tests" do
100
+ t = example_report.suites
101
+
102
+ t.count.should==1
103
+ t.first.tests.count.should==2
104
+ t.first.tests[0].name.should=='anExampleTest1'
105
+ t.first.tests[0].time.should==0.003
106
+ t.first.tests[0].passed?.should==true
107
+
108
+ t.first.tests[1].name.should=='anExampleTest2'
109
+ t.first.tests[1].time.should==0.003
110
+ t.first.tests[1].passed?.should==true
111
+ end
112
+
113
+ it "should capture failed build" do
114
+ parser << "Run test suite AnExampleTestSuite"
115
+ parser << "Test Suite 'AnExampleTestSuite' started at 2012-02-10 00:37:04 +0000"
116
+ parser << "Run test case anExampleTest1"
117
+ parser << "Test Case '-[AnExampleTestSuite anExampleTest1]' started."
118
+ parser << "/Path/To/Project/Tests/YPKeywordSuggestHandlerTest.m:45: error: -[AnExampleTestSuite anExampleTest1] : 'An example test spec' [FAILED], mock received unexpected message -setSuspended: 1 "
119
+ parser << "/Developer/Tools/RunPlatformUnitTests.include: line 415: 32225 Bus error: 10 \"${THIN_TEST_RIG}\" \"${OTHER_TEST_FLAGS}\" \"${TEST_BUNDLE_PATH}\""
120
+ parser << "/Developer/Tools/RunPlatformUnitTests.include:451: error: Test rig '/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.0.sdk/Developer/usr/bin/otest' exited abnormally with code 138 (it may have crashed)."
121
+
122
+ parser.flush
123
+
124
+ report = parser.report
125
+
126
+ report.failed?.should==true
127
+ report.finished?.should==true
128
+ failure = report.suites.first.tests[0]
129
+ failure.passed?.should==false
130
+ failure.data.count.should==2
131
+ failure.data[0].should=~/32225 Bus error: 10/
132
+ failure.data[1].should=~/Test rig/
133
+ end
134
+
135
+ context "encoding" do
136
+ it "should not fail due to Unicode characters" do
137
+ expect do
138
+ string = "2012-04-09 16:56:32.682 otest[81203:7803] E restkit.object_mapping:RKObjectMappingOperation.m:248 Validation failed while mapping attribute at key path boolString to value FAIL. Error: The operation couldn\xE2\x80\x99t be completed. (org.restkit.RestKit.ErrorDomain error 1003.)"
139
+ string.force_encoding("US-ASCII")
140
+ parser << string
141
+ end.not_to raise_error
142
+ end
143
+ end
144
+
145
+ context "Junit output" do
146
+
147
+ it "should write out reports in junit format" do
148
+ report_dir = "#{File.dirname(__FILE__)}/test-reports"
149
+ FileUtils.rm_rf report_dir
150
+
151
+ parser.report.add_formatter :junit, report_dir
152
+
153
+ example_report
154
+
155
+ files = Dir["#{report_dir}/*.xml"]
156
+ files.count.should==1
157
+ files.first.should=~/TEST-AnExampleTestSuite.xml$/
158
+
159
+ # FIXME: parse the report
160
+ end
161
+
162
+ end
163
+
164
+ end
@@ -7,7 +7,7 @@ describe Xcode::Project do
7
7
  describe "Targets" do
8
8
 
9
9
  let(:expected_first_target) { "TestProject" }
10
- let(:expected_second_target) { "TestProjectTests" }
10
+ let(:expected_second_target) { "LogicTests" }
11
11
 
12
12
  describe "#targets" do
13
13
 
@@ -3,9 +3,9 @@ require_relative 'spec_helper'
3
3
  describe Xcode::Workspace do
4
4
  it "should enumerate all workspaces in current directory" do
5
5
  workspaces = Xcode.workspaces
6
- workspaces.size.should==1
7
- workspaces.first.name.should=="TestWorkspace"
8
- workspaces.first.projects.size.should==1
6
+ workspaces.size.should == 2
7
+ workspaces.first.name.should == "TestWorkspace"
8
+ workspaces.first.projects.size.should == 1
9
9
  end
10
10
 
11
11
  it "should fetch workspace by name" do
@@ -18,6 +18,11 @@ describe Xcode::Workspace do
18
18
  w.should_not be_nil
19
19
  end
20
20
 
21
+ it "should handle workspace that use ' in the XML" do
22
+ w = Xcode.workspace "#{File.dirname(__FILE__)}/TestWorkspace2.xcworkspace"
23
+ w.should_not be_nil
24
+ end
25
+
21
26
  it "should have many projects" do
22
27
  w = Xcode.workspace "TestWorkspace"
23
28
  w.projects.size.should==1