From 0fcaca8e26223e47cc101c76bb7a7b02e0fc7101 Mon Sep 17 00:00:00 2001 From: zhongwuzw Date: Tue, 23 Jul 2019 11:03:55 -0700 Subject: [PATCH] Fixes template build failed in release mode (#25751) Summary: Fixes https://github.com/facebook/react-native/issues/25745, Xcode stripped dead code in Release mode, and in template test code, it should only run in Debug mode, so we can use a macro to fix this issue. ## Changelog [iOS] [Fixed] - Fixes template build failed in release mode Pull Request resolved: https://github.com/facebook/react-native/pull/25751 Test Plan: 1. Create a new project using `react-native init AwesomProject`. 2. Change project target scheme to `Release`. 3. Build and it should success. Differential Revision: D16442643 Pulled By: TheSavior fbshipit-source-id: f08ed70523aa1aa418064465f8df367a06e8974f --- template/ios/HelloWorldTests/HelloWorldTests.m | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/template/ios/HelloWorldTests/HelloWorldTests.m b/template/ios/HelloWorldTests/HelloWorldTests.m index 3b45a1a9197..1b3a4fd2701 100644 --- a/template/ios/HelloWorldTests/HelloWorldTests.m +++ b/template/ios/HelloWorldTests/HelloWorldTests.m @@ -40,11 +40,13 @@ BOOL foundElement = NO; __block NSString *redboxError = nil; +#ifdef DEBUG RCTSetLogFunction(^(RCTLogLevel level, RCTLogSource source, NSString *fileName, NSNumber *lineNumber, NSString *message) { if (level >= RCTLogLevelError) { redboxError = message; } }); +#endif while ([date timeIntervalSinceNow] > 0 && !foundElement && !redboxError) { [[NSRunLoop mainRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.1]]; @@ -57,8 +59,10 @@ return NO; }]; } - + +#ifdef DEBUG RCTSetLogFunction(RCTDefaultLogFunction); +#endif XCTAssertNil(redboxError, @"RedBox error: %@", redboxError); XCTAssertTrue(foundElement, @"Couldn't find element with text '%@' in %d seconds", TEXT_TO_LOOK_FOR, TIMEOUT_SECONDS);