Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support .xccovreport files #13

Merged
merged 4 commits into from
Apr 2, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
80 changes: 4 additions & 76 deletions src/xcov-core.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
// Copyright © 2016 nakioStudio. All rights reserved.
//

#import "DVTSourceFileLineCoverageData.h"
#import <Foundation/Foundation.h>

@interface DVTSourceFileLineCoverageData (Report)
- (NSDictionary *)convertToDictionary;
@interface NSObject (DVTSourceFileLineCoverageData)

- (NSDictionary *)DVTSourceFileLineCoverageData_convertToDictionary;

@end
23 changes: 11 additions & 12 deletions src/xcov-core/Categories/DVTSourceFileLineCoverageData+Report.m
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@
//

#import "DVTSourceFileLineCoverageData+Report.h"
#import "DVTSourceFileCodeCoverageRange.h"

@implementation DVTSourceFileLineCoverageData (Report)
@implementation NSObject (DVTSourceFileLineCoverageData)

- (NSDictionary *)convertToDictionary {
- (NSDictionary *)DVTSourceFileLineCoverageData_convertToDictionary {
NSMutableDictionary *dictionary = [[NSMutableDictionary alloc] init];
dictionary[@"executable"] = @(self.isExecutable);
dictionary[@"executionCount"] = @(self.executionCount);
dictionary[@"executable"] = @(((BOOL) [self performSelector:@selector(isExecutable)]));
dictionary[@"executionCount"] = @(((unsigned long long) [self performSelector:@selector(executionCount)]));

if ([self shouldAddSubranges]) {
dictionary[@"ranges"] = [self convertRangesIntoDictionaries];
Expand All @@ -23,24 +22,24 @@ - (NSDictionary *)convertToDictionary {
#pragma mark - Private Methods

- (NSArray *)convertRangesIntoDictionaries {
NSUInteger capacity = [self.subRanges count];
NSUInteger capacity = (NSUInteger)[[self performSelector:@selector(subRanges)] performSelector:@selector(count)];
NSMutableArray *dictionaries = [[NSMutableArray alloc] initWithCapacity:capacity];

for (DVTSourceFileCodeCoverageRange *range in self.subRanges) {
NSDictionary *dictionary = @{@"location": @(range.column),
@"length": @(range.length),
@"executionCount": @(range.executionCount)};
for (NSObject *range in [self performSelector:@selector(subRanges)]) {
NSDictionary *dictionary = @{@"location": @(((unsigned long long) [range performSelector:@selector(columnn)])),
@"length": @(((unsigned long long) [range performSelector:@selector(length)])),
@"executionCount": @(((unsigned long long) [range performSelector:@selector(executionCount)]))};
[dictionaries addObject:dictionary];
}

return [NSArray arrayWithArray:dictionaries];
}

- (BOOL)shouldAddSubranges {
if (self.subRanges == nil) { return NO; }
if ([self performSelector:@selector(subRanges)] == nil) { return NO; }

// If there is one range, we asume the entire line was covered
if (self.subRanges.count == 1) { return NO; }
if (((NSUInteger)[[self performSelector:@selector(subRanges)] performSelector:@selector(count)]) == 1) { return NO; }

return YES;
}
Expand Down
7 changes: 4 additions & 3 deletions src/xcov-core/Categories/IDESchemeActionCodeCoverage+Report.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
// Copyright © 2016 nakioStudio. All rights reserved.
//

#import "IDESchemeActionCodeCoverage.h"
#import <Foundation/Foundation.h>

@interface IDESchemeActionCodeCoverage (Report)
- (NSDictionary *)convertToDictionaryIncludingLines:(BOOL)includeLines;
@interface NSObject (IDESchemeActionCodeCoverage)

- (NSDictionary *)IDESchemeActionCodeCoverage_convertToDictionaryIncludingLines:(BOOL)includeLines;

@end
8 changes: 4 additions & 4 deletions src/xcov-core/Categories/IDESchemeActionCodeCoverage+Report.m
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
#import "IDESchemeActionCodeCoverage+Report.h"
#import "IDESchemeActionCodeCoverageTarget+Report.h"

@implementation IDESchemeActionCodeCoverage (Report)
@implementation NSObject (IDESchemeActionCodeCoverage)

- (NSDictionary *)convertToDictionaryIncludingLines:(BOOL)includeLines {
- (NSDictionary *)IDESchemeActionCodeCoverage_convertToDictionaryIncludingLines:(BOOL)includeLines {
NSMutableArray *targets = [NSMutableArray array];

for (IDESchemeActionCodeCoverageTarget *target in self.codeCoverageTargets) {
[targets addObject:[target convertToDictionaryIncludingLines:includeLines]];
for (NSObject *target in [self performSelector:@selector(codeCoverageTargets)]) {
[targets addObject:[target IDESchemeActionCodeCoverageTarget_convertToDictionaryIncludingLines:includeLines]];
}

return @{@"targets": targets};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
// Copyright © 2016 nakioStudio. All rights reserved.
//

#import "IDESchemeActionCodeCoverageFile.h"
#import <Foundation/Foundation.h>

@interface IDESchemeActionCodeCoverageFile (Report)
- (NSArray *)convertFunctionsToDictionaries;
- (NSArray *)convertLinesToDictionaries;
@interface NSObject (IDESchemeActionCodeCoverageFile)

- (NSArray *)IDESchemeActionCodeCoverageFile_convertFunctionsToDictionaries;
- (NSArray *)IDESchemeActionCodeCoverageFile_convertLinesToDictionaries;

@end
20 changes: 9 additions & 11 deletions src/xcov-core/Categories/IDESchemeActionCodeCoverageFile+Report.m
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,28 @@
//

#import "IDESchemeActionCodeCoverageFile+Report.h"

#import "IDESchemeActionCodeCoverageFunction.h"
#import "DVTSourceFileLineCoverageData+Report.h"

@implementation IDESchemeActionCodeCoverageFile (Report)
@implementation NSObject (IDESchemeActionCodeCoverageFile)

- (NSArray *)convertFunctionsToDictionaries {
- (NSArray *)IDESchemeActionCodeCoverageFile_convertFunctionsToDictionaries {
NSMutableArray *functions = [NSMutableArray array];

for (IDESchemeActionCodeCoverageFunction *function in self.functions) {
NSDictionary *dictionary = @{@"coverage": function.lineCoverage,
@"name": function.name};
for (NSObject *function in [self performSelector:@selector(functions)]) {
NSDictionary *dictionary = @{@"coverage": [function performSelector:@selector(lineCoverage)],
@"name": [function performSelector:@selector(name)]};
[functions addObject:dictionary];
}

return [NSArray arrayWithArray:functions];
}

- (NSArray *)convertLinesToDictionaries {
NSUInteger capacity = [self.lines count];
- (NSArray *)IDESchemeActionCodeCoverageFile_convertLinesToDictionaries {
NSUInteger capacity = [[self performSelector:@selector(lines)] count];
NSMutableArray *dictionaries = [[NSMutableArray alloc] initWithCapacity:capacity];

for (DVTSourceFileLineCoverageData *line in self.lines) {
[dictionaries addObject:[line convertToDictionary]];
for (NSObject *line in [self performSelector:@selector(lines)]) {
[dictionaries addObject:[line DVTSourceFileLineCoverageData_convertToDictionary]];
}

return [NSArray arrayWithArray:dictionaries];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
// Copyright © 2016 nakioStudio. All rights reserved.
//

#import "IDESchemeActionCodeCoverageTarget.h"
#import <Foundation/Foundation.h>

@interface IDESchemeActionCodeCoverageTarget (Report)
- (NSDictionary *)convertToDictionaryIncludingLines:(BOOL)includeLines;
@interface NSObject (IDESchemeActionCodeCoverageTarget)

- (NSDictionary *)IDESchemeActionCodeCoverageTarget_convertToDictionaryIncludingLines:(BOOL)includeLines;

@end
26 changes: 13 additions & 13 deletions src/xcov-core/Categories/IDESchemeActionCodeCoverageTarget+Report.m
Original file line number Diff line number Diff line change
Expand Up @@ -6,34 +6,34 @@
#import "IDESchemeActionCodeCoverageTarget+Report.h"
#import "IDESchemeActionCodeCoverageFile+Report.h"

@implementation IDESchemeActionCodeCoverageTarget (Report)
- (NSDictionary *)convertToDictionaryIncludingLines:(BOOL)includeLines {
@implementation NSObject (IDESchemeActionCodeCoverageTarget)

- (NSDictionary *)IDESchemeActionCodeCoverageTarget_convertToDictionaryIncludingLines:(BOOL)includeLines {
NSMutableArray *files = [NSMutableArray array];

for (IDESchemeActionCodeCoverageFile *file in self.sourceFiles) {
NSDictionary *fileDictionary = [self dictionaryFromCodeCoverageFile:file
includeLines:includeLines];
for (NSObject *file in [self performSelector:@selector(sourceFiles)]) {
NSDictionary *fileDictionary = [self dictionaryFromCodeCoverageFile:file includeLines:includeLines];
[files addObject:fileDictionary];
}

return @{@"name": self.name,
@"coverage": self.lineCoverage,
return @{@"name": [self performSelector:@selector(name)],
@"coverage": [self performSelector:@selector(lineCoverage)],
@"files": files};
}

#pragma mark - Private methods

- (NSDictionary *)dictionaryFromCodeCoverageFile:(IDESchemeActionCodeCoverageFile *)file
- (NSDictionary *)dictionaryFromCodeCoverageFile:(NSObject *)file
includeLines:(BOOL)includeLines {
NSMutableDictionary *dictionary = [[NSMutableDictionary alloc] init];

dictionary[@"name"] = file.name;
dictionary[@"coverage"] = file.lineCoverage;
dictionary[@"functions"] = [file convertFunctionsToDictionaries];
dictionary[@"location"] = file.documentLocation;
dictionary[@"name"] = [file performSelector:@selector(name)];
dictionary[@"coverage"] = [file performSelector:@selector(lineCoverage)];
dictionary[@"functions"] = [file IDESchemeActionCodeCoverageFile_convertFunctionsToDictionaries];
dictionary[@"location"] = [file performSelector:@selector(documentLocation)];

if (includeLines) {
dictionary[@"lines"] = [file convertLinesToDictionaries];
dictionary[@"lines"] = [file IDESchemeActionCodeCoverageFile_convertLinesToDictionaries];
}

return dictionary;
Expand Down
9 changes: 6 additions & 3 deletions src/xcov-core/Core/Reader.m
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
// Copyright © 2016 nakioStudio. All rights reserved.
//

#include <dlfcn.h>
#import "IDESchemeActionCodeCoverage+Report.h"

#import "DDCliUtil.h"
#import "Reader.h"

Expand Down Expand Up @@ -36,16 +36,19 @@ - (NSDictionary *)read {
exit(66);
}

// TODO: Instead the path should be provided to the command line tool or extracted using xcode-select
dlopen("/Applications/Xcode-beta.app/Contents/Frameworks/IDEFoundation.framework/Versions/A/IDEFoundation", RTLD_LAZY);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👆


ddprintf(@"Opening .xccoverage file at path: %@\n", self.options.source);
IDESchemeActionCodeCoverage *coverage = [NSKeyedUnarchiver unarchiveObjectWithFile:self.options.source];
NSObject *coverage = [NSKeyedUnarchiver unarchiveObjectWithFile:self.options.source];
if (coverage == nil) {
ddprintf(@"Unable to read .xccoverage file\n");
exit(65);
}

ddprintf(@"Parsing .xccoverage file...\n");
BOOL includeLines = self.options.includeLinesInfo;
NSDictionary *report = [coverage convertToDictionaryIncludingLines:includeLines];
NSDictionary *report = [coverage IDESchemeActionCodeCoverage_convertToDictionaryIncludingLines:includeLines];
if (report == nil) {
ddprintf(@"Unable to parse .xccoverage file\n");
exit(65);
Expand Down
14 changes: 0 additions & 14 deletions src/xcov-core/IDE/DVTCoverageDataContainer.h

This file was deleted.

26 changes: 0 additions & 26 deletions src/xcov-core/IDE/DVTCoverageDataContainer.m

This file was deleted.

18 changes: 0 additions & 18 deletions src/xcov-core/IDE/DVTSourceCodeSymbolKind.h

This file was deleted.

24 changes: 0 additions & 24 deletions src/xcov-core/IDE/DVTSourceCodeSymbolKind.m

This file was deleted.

10 changes: 0 additions & 10 deletions src/xcov-core/IDE/DVTSourceFileCodeCoverageCoveredRange.h

This file was deleted.

10 changes: 0 additions & 10 deletions src/xcov-core/IDE/DVTSourceFileCodeCoverageCoveredRange.m

This file was deleted.

16 changes: 0 additions & 16 deletions src/xcov-core/IDE/DVTSourceFileCodeCoverageRange.h

This file was deleted.

27 changes: 0 additions & 27 deletions src/xcov-core/IDE/DVTSourceFileCodeCoverageRange.m

This file was deleted.