diff --git a/xctool/xctool/OTestQuery.m b/xctool/xctool/OTestQuery.m index c52654cea..b6d06ccda 100644 --- a/xctool/xctool/OTestQuery.m +++ b/xctool/xctool/OTestQuery.m @@ -46,10 +46,27 @@ } } +static BOOL SetErrorIfBundleDoesNotExist(NSString *bundlePath, NSString **error) +{ + BOOL isDir = NO; + BOOL exists = [[NSFileManager defaultManager] fileExistsAtPath:bundlePath isDirectory:&isDir]; + + if (!IsRunningUnderTest() && !(exists && isDir)) { + *error = [NSString stringWithFormat:@"Test bundle not found at: %@", bundlePath]; + return YES; + } else { + return NO; + } +} + NSArray *OTestQueryTestCasesInIOSBundle(NSString *bundlePath, NSString *sdk, NSString **error) { NSCAssert([sdk hasPrefix:@"iphonesimulator"], @"Only iphonesimulator SDKs are supported."); + if (SetErrorIfBundleDoesNotExist(bundlePath, error)) { + return nil; + } + NSString *version = [sdk stringByReplacingOccurrencesOfString:@"iphonesimulator" withString:@""]; DTiPhoneSimulatorSystemRoot *systemRoot = [DTiPhoneSimulatorSystemRoot rootWithSDKVersion:version]; NSCAssert(systemRoot != nil, @"Cannot get systemRoot"); @@ -75,6 +92,10 @@ { NSCAssert([sdk hasPrefix:@"iphonesimulator"], @"Only iphonesimulator SDKs are supported."); + if (SetErrorIfBundleDoesNotExist(bundlePath, error)) { + return nil; + } + if (![[NSFileManager defaultManager] isExecutableFileAtPath:testHostExecutablePath]) { *error = [NSString stringWithFormat:@"The test host executable is missing: '%@'", testHostExecutablePath]; return nil; @@ -109,6 +130,10 @@ NSArray *OTestQueryTestCasesInOSXBundle(NSString *bundlePath, NSString *builtProductsDir, BOOL disableGC, NSString **error) { + if (SetErrorIfBundleDoesNotExist(bundlePath, error)) { + return nil; + } + NSTask *task = [[NSTask alloc] init]; [task setLaunchPath:[XCToolLibExecPath() stringByAppendingPathComponent:@"otest-query-osx"]]; [task setArguments:@[bundlePath]];