Skip to content

Commit

Permalink
Merge pull request #65 from johnno1962/feature/tdd
Browse files Browse the repository at this point in the history
Implement TDD feature
  • Loading branch information
zenangst committed Oct 25, 2018
2 parents 7b911e7 + c41a236 commit 08bf12b
Show file tree
Hide file tree
Showing 7 changed files with 99 additions and 9 deletions.
2 changes: 2 additions & 0 deletions InjectionIII.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@
BBE490DA1FB2C643003D41BB /* InjectionError.tif */ = {isa = PBXFileReference; lastKnownFileType = image.tiff; path = InjectionError.tif; sourceTree = "<group>"; };
BBEB704A1FD28C6F00127711 /* XcodeHash.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = XcodeHash.h; sourceTree = "<group>"; };
BBEB704B1FD28C6F00127711 /* XcodeHash.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = XcodeHash.m; sourceTree = "<group>"; };
BDB6A7CE21824C800001CF95 /* UserDefaults.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = UserDefaults.h; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -350,6 +351,7 @@
BBCA02581FB112F500E45F0F /* App.icns */,
BBCA02091FB0F10400E45F0F /* main.m */,
BBCA020B1FB0F10400E45F0F /* InjectionIII.entitlements */,
BDB6A7CE21824C800001CF95 /* UserDefaults.h */,
);
path = InjectionIII;
sourceTree = "<group>";
Expand Down
16 changes: 15 additions & 1 deletion InjectionIII/AppDelegate.mm
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
//#import "DDHotKeyCenter.h"

#import "InjectionIII-Swift.h"
#import "UserDefaults.h"

#ifdef XPROBE_PORT
#import "../XprobePlugin/Classes/XprobePluginMenuController.h"
Expand All @@ -32,7 +33,7 @@ @interface AppDelegate ()

@implementation AppDelegate {
IBOutlet NSMenu *statusMenu;
IBOutlet NSMenuItem *startItem, *xprobeItem, *windowItem;
IBOutlet NSMenuItem *startItem, *xprobeItem, *enabledTDDItem, *windowItem;
IBOutlet NSStatusItem *statusItem;
}

Expand All @@ -49,6 +50,10 @@ - (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
statusItem.enabled = TRUE;
statusItem.title = @"";

enabledTDDItem.state = ([[NSUserDefaults standardUserDefaults] boolForKey:UserDefaultsTDDEnabled])
? NSControlStateValueOn
: NSControlStateValueOff;

[self setMenuIcon:@"InjectionIdle"];
#if 0
[[DDHotKeyCenter sharedHotKeyCenter] registerHotKeyWithKeyCode:kVK_ANSI_Equal
Expand All @@ -61,6 +66,15 @@ - (IBAction)openProject:sender {
[self application:NSApp openFile:nil];
}

- (IBAction)toggleTDD:(NSMenuItem *)sender {
[self toggleState:sender];

BOOL newSetting = sender.state == NSControlStateValueOn;

[[NSUserDefaults standardUserDefaults] setBool:newSetting forKey:UserDefaultsTDDEnabled];
NSLog(@"sender: %ld", (long)[sender state]);
}

- (BOOL)application:(NSApplication *)theApplication openFile:(NSString *)filename {
NSOpenPanel *open = [NSOpenPanel new];
open.prompt = NSLocalizedString(@"Select Project Directory", @"Project Directory");
Expand Down
15 changes: 11 additions & 4 deletions InjectionIII/Base.lproj/MainMenu.xib
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
<customObject id="Voe-Tx-rLC" customClass="AppDelegate">
<connections>
<outlet property="enableWatcher" destination="0iA-WA-gxc" id="vVT-sI-q78"/>
<outlet property="enabledTDDItem" destination="cCv-GY-3Rv" id="gWc-O6-aDP"/>
<outlet property="startItem" destination="vsd-ll-3nr" id="ODN-wa-BTp"/>
<outlet property="statusMenu" destination="V8Q-mq-A2f" id="Epo-HD-J21"/>
<outlet property="window" destination="QvC-M9-y7g" id="gIp-Ho-8D9"/>
Expand Down Expand Up @@ -619,13 +620,13 @@
</menuItem>
<menuItem isSeparatorItem="YES" id="hB3-LF-h0Y"/>
<menuItem title="Show Sidebar" keyEquivalent="s" id="kIP-vf-haE">
<modifierMask key="keyEquivalentModifierMask" control="YES" command="YES"/>
<modifierMask key="keyEquivalentModifierMask" control="YES" option="YES" command="YES"/>
<connections>
<action selector="toggleSourceList:" target="-1" id="iwa-gc-5KM"/>
</connections>
</menuItem>
<menuItem title="Enter Full Screen" keyEquivalent="f" id="4J7-dP-txa">
<modifierMask key="keyEquivalentModifierMask" control="YES" command="YES"/>
<menuItem title="Enter Full Screen" keyEquivalent="" id="4J7-dP-txa">
<modifierMask key="keyEquivalentModifierMask" control="YES" option="YES" command="YES"/>
<connections>
<action selector="toggleFullScreen:" target="-1" id="dU3-MA-1Rq"/>
</connections>
Expand All @@ -651,7 +652,7 @@
<windowStyleMask key="styleMask" titled="YES" closable="YES" miniaturizable="YES" resizable="YES"/>
<windowPositionMask key="initialPositionMask" leftStrut="YES" rightStrut="YES" topStrut="YES" bottomStrut="YES"/>
<rect key="contentRect" x="335" y="390" width="480" height="360"/>
<rect key="screenRect" x="0.0" y="0.0" width="1920" height="1177"/>
<rect key="screenRect" x="0.0" y="0.0" width="1680" height="1050"/>
<view key="contentView" wantsLayer="YES" id="EiT-Mj-1SZ">
<rect key="frame" x="0.0" y="0.0" width="480" height="360"/>
<autoresizingMask key="autoresizingMask"/>
Expand Down Expand Up @@ -690,6 +691,12 @@
<action selector="toggleState:" target="Voe-Tx-rLC" id="old-T7-DMa"/>
</connections>
</menuItem>
<menuItem title="Enable TDD" id="cCv-GY-3Rv">
<modifierMask key="keyEquivalentModifierMask"/>
<connections>
<action selector="toggleTDD:" target="Voe-Tx-rLC" id="tqU-Qb-3kf"/>
</connections>
</menuItem>
<menuItem title="Run Xprobe" id="R6p-Yl-7qz">
<modifierMask key="keyEquivalentModifierMask"/>
<connections>
Expand Down
7 changes: 5 additions & 2 deletions InjectionIII/FileWatcher.m
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,16 @@ - (void)filesChanged:(NSArray *)changes;
NSFileManager *fileManager = [NSFileManager defaultManager];
NSMutableSet *changed = [NSMutableSet new];

for (NSString *path in changes)
for (NSString *path in changes) {
if ([path rangeOfString:INJECTABLE_PATTERN
options:NSRegularExpressionSearch].location != NSNotFound &&
[path rangeOfString:@"DerivedData/|InjectionProject/|main.mm?$"
options:NSRegularExpressionSearch].location == NSNotFound &&
[fileManager fileExistsAtPath:path])
[fileManager fileExistsAtPath:path]) {

[changed addObject:path];
}
}

//NSLog( @"filesChanged: %@", changed );
if (changed.count)
Expand Down
2 changes: 1 addition & 1 deletion InjectionIII/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<key>CFBundleShortVersionString</key>
<string>1.2</string>
<key>CFBundleVersion</key>
<string>1199</string>
<string>1287</string>
<key>LSApplicationCategoryType</key>
<string>public.app-category.developer-tools</string>
<key>LSMinimumSystemVersion</key>
Expand Down
55 changes: 54 additions & 1 deletion InjectionIII/InjectionServer.mm
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

#import "Xcode.h"
#import "XcodeHash.h"
#import "UserDefaults.h"

#import "InjectionIII-Swift.h"

Expand Down Expand Up @@ -155,7 +156,16 @@ - (void)runInBackground {

injector = ^(NSArray *changed) {
NSTimeInterval now = [NSDate timeIntervalSinceReferenceDate];
for (NSString *swiftSource in changed)
NSMutableArray *changedFiles = [NSMutableArray arrayWithArray:changed];

if ([[NSUserDefaults standardUserDefaults] boolForKey:UserDefaultsTDDEnabled]) {
NSArray *matchedTests = [InjectionServer searchForTestWithFiles:changed
projectRoot:projectFile.stringByDeletingLastPathComponent
fileManager:[NSFileManager defaultManager]];
[changedFiles addObjectsFromArray:matchedTests];
}

for (NSString *swiftSource in changedFiles)
if (now > lastInjected[swiftSource].doubleValue + MIN_INJECTION_INTERVAL && now > pause) {
lastInjected[swiftSource] = [NSNumber numberWithDouble:now];
inject(swiftSource);
Expand Down Expand Up @@ -197,6 +207,49 @@ - (void)setProject:(NSString *)project {
plugin:injector];
}

+ (NSArray *)searchForTestWithFiles:(NSArray *)injectedFiles projectRoot:(NSString *)projectRoot fileManager:(NSFileManager *)fileManager;
{
NSMutableArray *matchedTests = [NSMutableArray array];
for (NSString *injectedFile in injectedFiles) {
NSString *injectedFileName = [[injectedFile lastPathComponent] stringByDeletingPathExtension];
NSURL *projectUrl = [NSURL URLWithString:projectRoot];
NSDirectoryEnumerator *enumerator = [fileManager enumeratorAtURL:projectUrl
includingPropertiesForKeys:@[NSURLNameKey, NSURLIsDirectoryKey]
options:NSDirectoryEnumerationSkipsHiddenFiles
errorHandler:^BOOL(NSURL *url, NSError *error)
{
if (error) {
NSLog(@"[Error] %@ (%@)", error, url);
return NO;
}

return YES;
}];


for (NSURL *fileURL in enumerator) {
NSString *filename;
NSNumber *isDirectory;

[fileURL getResourceValue:&filename forKey:NSURLNameKey error:nil];
[fileURL getResourceValue:&isDirectory forKey:NSURLIsDirectoryKey error:nil];

if ([filename hasPrefix:@"_"] && [isDirectory boolValue]) {
[enumerator skipDescendants];
continue;
}

if (![isDirectory boolValue] &&
![[filename lastPathComponent] isEqualToString:[injectedFile lastPathComponent]] &&
[[filename lowercaseString] containsString:[injectedFileName lowercaseString]]) {
[matchedTests addObject:fileURL.path];
}
}
}

return matchedTests;
}

- (void)dealloc {
NSLog(@"- [%@ dealloc]", self);
}
Expand Down
11 changes: 11 additions & 0 deletions InjectionIII/UserDefaults.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
//
// UserDefaults.h
// InjectionIII
//
// Created by Christoffer Winterkvist on 10/25/18.
// Copyright © 2018 John Holdsworth. All rights reserved.
//

#import "AppDelegate.h"

NSString *const UserDefaultsTDDEnabled = @"Enabled TDD";

0 comments on commit 08bf12b

Please sign in to comment.