Skip to content

Commit 14d28c2

Browse files
committed
compensate for xcodebuild bug where 'archive' always claims to succeed
xcodebuild's archive action always claims to succeed (with exit status of 0) even when there are failing build commands. To compensate, we only claim xcodebuild succeeds when we see no failing build commands from xcodebuild.
1 parent fa81b34 commit 14d28c2

File tree

5 files changed

+439
-2
lines changed

5 files changed

+439
-2
lines changed

xctool/xctool-tests/ArchiveActionTests.m

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,75 @@ - (void)testArchiveActionTriggersBuildForProjectAndScheme
4242
}];
4343
}
4444

45+
- (void)testArchiveWithFailingCommandShouldFail
46+
{
47+
[[FakeTaskManager sharedManager] runBlockWithFakeTasks:^{
48+
[[FakeTaskManager sharedManager] addLaunchHandlerBlocks:@[
49+
// Make sure -showBuildSettings returns some data
50+
[LaunchHandlers handlerForShowBuildSettingsWithProject:TEST_DATA @"TestProject-App-OSX/TestProject-App-OSX.xcodeproj"
51+
scheme:@"TestProject-App-OSX"
52+
settingsPath:TEST_DATA @"TestProject-App-OSX-showBuildSettings.txt"],
53+
[[^(FakeTask *task){
54+
if ([[task launchPath] hasSuffix:@"xcodebuild"] &&
55+
[[task arguments] containsObject:@"archive"])
56+
{
57+
[task pretendTaskReturnsStandardOutput:
58+
[NSString stringWithContentsOfFile:TEST_DATA @"xcodebuild-archive-bad.txt"
59+
encoding:NSUTF8StringEncoding
60+
error:nil]];
61+
// Even when archive fails, 'xcodebuild' returns zero.
62+
[task pretendExitStatusOf:0];
63+
}
64+
} copy] autorelease],
65+
]];
66+
67+
XCTool *tool = [[[XCTool alloc] init] autorelease];
68+
69+
tool.arguments = @[@"-project", TEST_DATA @"TestProject-App-OSX/TestProject-App-OSX.xcodeproj",
70+
@"-scheme", @"TestProject-App-OSX",
71+
@"archive",
72+
];
73+
74+
NSDictionary *output = [TestUtil runWithFakeStreams:tool];
75+
76+
assertThatInt([tool exitStatus], equalToInt(1));
77+
assertThat(output[@"stdout"], containsString(@"** ARCHIVE FAILED **"));
78+
}];
79+
}
80+
81+
- (void)testArchiveWithAllPassingCommandsShouldSucceed
82+
{
83+
[[FakeTaskManager sharedManager] runBlockWithFakeTasks:^{
84+
[[FakeTaskManager sharedManager] addLaunchHandlerBlocks:@[
85+
// Make sure -showBuildSettings returns some data
86+
[LaunchHandlers handlerForShowBuildSettingsWithProject:TEST_DATA @"TestProject-App-OSX/TestProject-App-OSX.xcodeproj"
87+
scheme:@"TestProject-App-OSX"
88+
settingsPath:TEST_DATA @"TestProject-App-OSX-showBuildSettings.txt"],
89+
[[^(FakeTask *task){
90+
if ([[task launchPath] hasSuffix:@"xcodebuild"] &&
91+
[[task arguments] containsObject:@"archive"])
92+
{
93+
[task pretendTaskReturnsStandardOutput:
94+
[NSString stringWithContentsOfFile:TEST_DATA @"xcodebuild-archive-good.txt"
95+
encoding:NSUTF8StringEncoding
96+
error:nil]];
97+
[task pretendExitStatusOf:0];
98+
}
99+
} copy] autorelease],
100+
]];
101+
102+
XCTool *tool = [[[XCTool alloc] init] autorelease];
103+
104+
tool.arguments = @[@"-project", TEST_DATA @"TestProject-App-OSX/TestProject-App-OSX.xcodeproj",
105+
@"-scheme", @"TestProject-App-OSX",
106+
@"archive",
107+
];
108+
109+
NSDictionary *output = [TestUtil runWithFakeStreams:tool];
110+
111+
assertThatInt([tool exitStatus], equalToInt(0));
112+
assertThat(output[@"stdout"], containsString(@"** ARCHIVE SUCCEEDED **"));
113+
}];
114+
}
115+
45116
@end

0 commit comments

Comments
 (0)