Skip to content

Commit

Permalink
Add basic tests
Browse files Browse the repository at this point in the history
  • Loading branch information
0xced committed Apr 10, 2016
1 parent 297d066 commit 199a9f6
Show file tree
Hide file tree
Showing 4 changed files with 281 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Info.plist
Expand Up @@ -7,7 +7,7 @@
<key>CFBundleExecutable</key>
<string>xcproj</string>
<key>CFBundleIdentifier</key>
<string>ch.pitaya.xcproj</string>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
Expand Down
24 changes: 24 additions & 0 deletions Tests/Info.plist
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
<string>BNDL</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>1</string>
</dict>
</plist>
60 changes: 60 additions & 0 deletions Tests/Tests.m
@@ -0,0 +1,60 @@
//
// Created by Cédric Luthi on 06/04/16.
// Copyright © 2016 Cédric Luthi. All rights reserved.
//

#import <XCTest/XCTest.h>

@interface Tests : XCTestCase

@property NSArray *xcodeURLs;

@end

@implementation Tests

- (void) run:(NSArray *)arguments expectedResult:(NSString *)expectedResult
{
NSString *builtProductsDir = NSProcessInfo.processInfo.environment[@"BUILT_PRODUCTS_DIR"];
NSString *projectDir = NSProcessInfo.processInfo.environment[@"PROJECT_DIR"];
for (NSURL *xcodeURL in self.xcodeURLs)
{
NSTask *xcproj = [NSTask new];
xcproj.launchPath = [builtProductsDir stringByAppendingPathComponent:@"xcproj"];
xcproj.arguments = arguments;
xcproj.environment = @{ @"XCPROJ_XCODE_APP_PATH": xcodeURL.path };
xcproj.currentDirectoryPath = [projectDir stringByAppendingPathComponent:@"Sandbox"];;
xcproj.standardOutput = [NSPipe new];
printf("%s\n", [NSString stringWithFormat:@"env XCPROJ_XCODE_APP_PATH=%@ %@ %@", xcproj.environment[@"XCPROJ_XCODE_APP_PATH"], xcproj.launchPath, [xcproj.arguments componentsJoinedByString:@" "]].UTF8String);
[xcproj launch];
[xcproj waitUntilExit];

NSData *outputData = [[xcproj.standardOutput fileHandleForReading] readDataToEndOfFile];
NSString *result = [[[NSString alloc] initWithData:outputData encoding:NSUTF8StringEncoding] stringByTrimmingCharactersInSet:[NSCharacterSet newlineCharacterSet]];
printf("%s\n", result.UTF8String);

XCTAssertEqual(xcproj.terminationStatus, 0);
XCTAssertEqualObjects(result, expectedResult);
}
}

- (void) setUp
{
self.xcodeURLs = CFBridgingRelease(LSCopyApplicationURLsForBundleIdentifier(CFSTR("com.apple.dt.Xcode"), NULL));
XCTAssertTrue(self.xcodeURLs.count > 0);
}

- (void) testReadBuildSetting
{
[self run:@[ @"--target", @"Sandbox", @"read-build-setting", @"COPY_PHASE_STRIP"] expectedResult:@"YES"];
[self run:@[ @"--target", @"Sandbox", @"--configuration", @"Debug", @"read-build-setting", @"COPY_PHASE_STRIP"] expectedResult:@"NO"];
[self run:@[ @"--target", @"Sandbox", @"--configuration", @"Release", @"read-build-setting", @"COPY_PHASE_STRIP"] expectedResult:@"YES"];
[self run:@[ @"read-build-setting", @"COPY_PHASE_STRIP"] expectedResult:@"YES"];
[self run:@[ @"--configuration", @"Debug", @"read-build-setting", @"COPY_PHASE_STRIP"] expectedResult:@"YES"];
[self run:@[ @"--configuration", @"Release", @"read-build-setting", @"COPY_PHASE_STRIP"] expectedResult:@"YES"];

[self run:@[ @"--target", @"Sandbox", @"read-build-setting", @"CURRENT_PROJECT_VERSION"] expectedResult:@"1.2.3"];
[self run:@[ @"read-build-setting", @"CURRENT_PROJECT_VERSION"] expectedResult:@"1.2.3"];
}

@end

0 comments on commit 199a9f6

Please sign in to comment.