From 503e50b5bb3a588724839b497193afbae2b0aa0b Mon Sep 17 00:00:00 2001 From: Felix Schulze Date: Thu, 17 Sep 2015 19:59:52 +0200 Subject: [PATCH] Add option for not reseting the simulator on failure --- xctool/xctool-tests/OCUnitTestRunnerTests.m | 1 + xctool/xctool-tests/OTestShimTests.m | 1 + xctool/xctool/OCUnitIOSAppTestRunner.m | 2 +- xctool/xctool/OCUnitTestRunner.h | 2 ++ xctool/xctool/OCUnitTestRunner.m | 3 +++ xctool/xctool/RunTestsAction.h | 1 + xctool/xctool/RunTestsAction.m | 6 ++++++ xctool/xctool/TestAction.m | 10 ++++++++++ 8 files changed, 25 insertions(+), 1 deletion(-) diff --git a/xctool/xctool-tests/OCUnitTestRunnerTests.m b/xctool/xctool-tests/OCUnitTestRunnerTests.m index 319f350d7..5b94fe724 100644 --- a/xctool/xctool-tests/OCUnitTestRunnerTests.m +++ b/xctool/xctool-tests/OCUnitTestRunnerTests.m @@ -55,6 +55,7 @@ static id TestRunnerWithTestLists(Class cls, NSDictionary *settings, NSArray *fo environment:environment freshSimulator:NO resetSimulator:NO + noResetSimulatorOnFailure:NO freshInstall:NO testTimeout:30 reporters:@[eventBuffer]]; diff --git a/xctool/xctool-tests/OTestShimTests.m b/xctool/xctool-tests/OTestShimTests.m index 5a2b4977f..199669397 100644 --- a/xctool/xctool-tests/OTestShimTests.m +++ b/xctool/xctool-tests/OTestShimTests.m @@ -117,6 +117,7 @@ @interface OTestShimTests : XCTestCase environment:@{} freshSimulator:NO resetSimulator:NO + noResetSimulatorOnFailure:NO freshInstall:NO testTimeout:1 reporters:@[]]; diff --git a/xctool/xctool/OCUnitIOSAppTestRunner.m b/xctool/xctool/OCUnitIOSAppTestRunner.m index fc21bbf01..3122d2b4c 100644 --- a/xctool/xctool/OCUnitIOSAppTestRunner.m +++ b/xctool/xctool/OCUnitIOSAppTestRunner.m @@ -183,7 +183,7 @@ - (void)runTestsAndFeedOutputTo:(void (^)(NSString *))outputLineBlock // we will reset iOS simulator contents and settings now if it is not done in `prepTestEnv` if (!_resetSimulator) { - prepareSimulator(YES, YES); + prepareSimulator(YES, !_noResetSimulatorOnFailure); } // Sometimes, the test host app installation retries are starting and diff --git a/xctool/xctool/OCUnitTestRunner.h b/xctool/xctool/OCUnitTestRunner.h index 05045ace6..dce23f736 100644 --- a/xctool/xctool/OCUnitTestRunner.h +++ b/xctool/xctool/OCUnitTestRunner.h @@ -31,6 +31,7 @@ BOOL _garbageCollection; BOOL _freshSimulator; BOOL _resetSimulator; + BOOL _noResetSimulatorOnFailure; BOOL _freshInstall; NSInteger _testTimeout; NSArray *_reporters; @@ -60,6 +61,7 @@ environment:(NSDictionary *)environment freshSimulator:(BOOL)freshSimulator resetSimulator:(BOOL)resetSimulator + noResetSimulatorOnFailure:(BOOL)noResetSimulatorOnFailure freshInstall:(BOOL)freshInstall testTimeout:(NSInteger)testTimeout reporters:(NSArray *)reporters; diff --git a/xctool/xctool/OCUnitTestRunner.m b/xctool/xctool/OCUnitTestRunner.m index f4c32f488..2afc05b30 100644 --- a/xctool/xctool/OCUnitTestRunner.m +++ b/xctool/xctool/OCUnitTestRunner.m @@ -34,6 +34,7 @@ @interface OCUnitTestRunner () @property (nonatomic, assign) BOOL garbageCollection; @property (nonatomic, assign) BOOL freshSimulator; @property (nonatomic, assign) BOOL resetSimulator; +@property (nonatomic, assign) BOOL noResetSimulatorOnFailure; @property (nonatomic, assign) BOOL freshInstall; @property (nonatomic, copy, readwrite) NSArray *reporters; @property (nonatomic, copy) NSDictionary *framework; @@ -135,6 +136,7 @@ - (instancetype)initWithBuildSettings:(NSDictionary *)buildSettings environment:(NSDictionary *)environment freshSimulator:(BOOL)freshSimulator resetSimulator:(BOOL)resetSimulator + noResetSimulatorOnFailure:(BOOL)noResetSimulatorOnFailure freshInstall:(BOOL)freshInstall testTimeout:(NSInteger)testTimeout reporters:(NSArray *)reporters @@ -149,6 +151,7 @@ - (instancetype)initWithBuildSettings:(NSDictionary *)buildSettings _environment = [environment copy]; _freshSimulator = freshSimulator; _resetSimulator = resetSimulator; + _noResetSimulatorOnFailure = noResetSimulatorOnFailure; _freshInstall = freshInstall; _testTimeout = testTimeout; _reporters = [reporters copy]; diff --git a/xctool/xctool/RunTestsAction.h b/xctool/xctool/RunTestsAction.h index e9664ed5a..5114a3380 100644 --- a/xctool/xctool/RunTestsAction.h +++ b/xctool/xctool/RunTestsAction.h @@ -54,6 +54,7 @@ typedef NS_ENUM(NSInteger, BucketBy) { @property (nonatomic, assign) BOOL freshSimulator; @property (nonatomic, assign) BOOL resetSimulator; +@property (nonatomic, assign) BOOL noResetSimulatorOnFailure; @property (nonatomic, assign) BOOL freshInstall; @property (nonatomic, assign) BOOL parallelize; @property (nonatomic, assign) BOOL failOnEmptyTestBundles; diff --git a/xctool/xctool/RunTestsAction.m b/xctool/xctool/RunTestsAction.m index cc4bdccec..a0e58f8ef 100644 --- a/xctool/xctool/RunTestsAction.m +++ b/xctool/xctool/RunTestsAction.m @@ -141,6 +141,11 @@ + (NSArray *)options description: @"Reset simulator content and settings and restart it before running every app test run." setFlag:@selector(setResetSimulator:)], + [Action actionOptionWithName:@"noResetSimulatorOnFailure" + aliases:nil + description: + @"Do not reset simulator content and settings if running failed." + setFlag:@selector(setNoResetSimulatorOnFailure:)], [Action actionOptionWithName:@"freshInstall" aliases:nil description: @@ -668,6 +673,7 @@ - (TestableBlock)blockForTestable:(Testable *)testable environment:environment freshSimulator:_freshSimulator resetSimulator:_resetSimulator + noResetSimulatorOnFailure:_noResetSimulatorOnFailure freshInstall:_freshInstall testTimeout:_testTimeout reporters:reporters]; diff --git a/xctool/xctool/TestAction.m b/xctool/xctool/TestAction.m index ea81a3e92..927d18506 100644 --- a/xctool/xctool/TestAction.m +++ b/xctool/xctool/TestAction.m @@ -69,6 +69,11 @@ + (NSArray *)options description: @"Reset simulator content and settings and restart it before running every app test run." setFlag:@selector(setResetSimulator:)], + [Action actionOptionWithName:@"noResetSimulatorOnFailure" + aliases:nil + description: + @"Do not reset simulator content and settings if running failed." + setFlag:@selector(setNoResetSimulatorOnFailure:)], [Action actionOptionWithName:@"freshInstall" aliases:nil description: @@ -134,6 +139,11 @@ - (void)setResetSimulator:(BOOL)resetSimulator [_runTestsAction setResetSimulator:resetSimulator]; } +- (void)setNoResetSimulatorOnFailure:(BOOL)noResetSimulatorOnFailure +{ + [_runTestsAction setNoResetSimulatorOnFailure:noResetSimulatorOnFailure]; +} + - (void)setFreshInstall:(BOOL)freshInstall { [_runTestsAction setFreshInstall:freshInstall];