slather 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <Workspace
3
+ version = "1.0">
4
+ <FileRef
5
+ location = "self:fixtures.xcodeproj">
6
+ </FileRef>
7
+ </Workspace>
@@ -0,0 +1,9 @@
1
+ //
2
+ // Prefix header
3
+ //
4
+ // The contents of this file are implicitly included at the beginning of every source file.
5
+ //
6
+
7
+ #ifdef __OBJC__
8
+ #import <Cocoa/Cocoa.h>
9
+ #endif
@@ -0,0 +1,16 @@
1
+ //
2
+ // fixtures.h
3
+ // fixtures
4
+ //
5
+ // Created by Mark Larsen on 6/24/14.
6
+ // Copyright (c) 2014 marklarr. All rights reserved.
7
+ //
8
+
9
+ #import <Foundation/Foundation.h>
10
+
11
+ @interface fixtures : NSObject
12
+
13
+ - (void)testedMethod;
14
+ - (void)untestedMethod;
15
+
16
+ @end
@@ -0,0 +1,23 @@
1
+ //
2
+ // fixtures.m
3
+ // fixtures
4
+ //
5
+ // Created by Mark Larsen on 6/24/14.
6
+ // Copyright (c) 2014 marklarr. All rights reserved.
7
+ //
8
+
9
+ #import "fixtures.h"
10
+
11
+ @implementation fixtures
12
+
13
+ - (void)testedMethod
14
+ {
15
+ NSLog(@"tested");
16
+ }
17
+
18
+ - (void)untestedMethod
19
+ {
20
+ NSLog(@"untested");
21
+ }
22
+
23
+ @end
@@ -0,0 +1,13 @@
1
+ //
2
+ // peekaview.h
3
+ // fixtures
4
+ //
5
+ // Created by Mark Larsen on 6/25/14.
6
+ // Copyright (c) 2014 marklarr. All rights reserved.
7
+ //
8
+
9
+ #import <AppKit/AppKit.h>
10
+
11
+ @interface peekaview : NSView
12
+
13
+ @end
@@ -0,0 +1,31 @@
1
+ //
2
+ // peekaview.m
3
+ // fixtures
4
+ //
5
+ // Created by Mark Larsen on 6/25/14.
6
+ // Copyright (c) 2014 marklarr. All rights reserved.
7
+ //
8
+
9
+ #import "peekaview.h"
10
+
11
+ @implementation peekaview
12
+
13
+ - (id)initWithFrame:(CGRect)frame
14
+ {
15
+ self = [super initWithFrame:frame];
16
+ if (self) {
17
+ // Initialization code
18
+ }
19
+ return self;
20
+ }
21
+
22
+ /*
23
+ // Only override drawRect: if you perform custom drawing.
24
+ // An empty implementation adversely affects performance during animation.
25
+ - (void)drawRect:(CGRect)rect
26
+ {
27
+ // Drawing code
28
+ }
29
+ */
30
+
31
+ @end
@@ -0,0 +1,2 @@
1
+ /* Localized versions of Info.plist keys */
2
+
@@ -0,0 +1,22 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3
+ <plist version="1.0">
4
+ <dict>
5
+ <key>CFBundleDevelopmentRegion</key>
6
+ <string>en</string>
7
+ <key>CFBundleExecutable</key>
8
+ <string>${EXECUTABLE_NAME}</string>
9
+ <key>CFBundleIdentifier</key>
10
+ <string>marklarr.${PRODUCT_NAME:rfc1034identifier}</string>
11
+ <key>CFBundleInfoDictionaryVersion</key>
12
+ <string>6.0</string>
13
+ <key>CFBundlePackageType</key>
14
+ <string>BNDL</string>
15
+ <key>CFBundleShortVersionString</key>
16
+ <string>1.0</string>
17
+ <key>CFBundleSignature</key>
18
+ <string>????</string>
19
+ <key>CFBundleVersion</key>
20
+ <string>1</string>
21
+ </dict>
22
+ </plist>
@@ -0,0 +1,36 @@
1
+ //
2
+ // fixturesTests.m
3
+ // fixturesTests
4
+ //
5
+ // Created by Mark Larsen on 6/24/14.
6
+ // Copyright (c) 2014 marklarr. All rights reserved.
7
+ //
8
+
9
+ #import <XCTest/XCTest.h>
10
+ #import "fixtures.h"
11
+
12
+ @interface fixturesTests : XCTestCase
13
+
14
+ @end
15
+
16
+ @implementation fixturesTests
17
+
18
+ - (void)setUp
19
+ {
20
+ [super setUp];
21
+ // Put setup code here. This method is called before the invocation of each test method in the class.
22
+ }
23
+
24
+ - (void)tearDown
25
+ {
26
+ // Put teardown code here. This method is called after the invocation of each test method in the class.
27
+ [super tearDown];
28
+ }
29
+
30
+ - (void)testExample
31
+ {
32
+ fixtures *f = [[fixtures alloc] init];
33
+ [f testedMethod];
34
+ }
35
+
36
+ @end
@@ -0,0 +1,34 @@
1
+ //
2
+ // peekaviewTests.m
3
+ // fixtures
4
+ //
5
+ // Created by Mark Larsen on 6/25/14.
6
+ // Copyright (c) 2014 marklarr. All rights reserved.
7
+ //
8
+
9
+ #import <XCTest/XCTest.h>
10
+
11
+ @interface peekaviewTests : XCTestCase
12
+
13
+ @end
14
+
15
+ @implementation peekaviewTests
16
+
17
+ - (void)setUp
18
+ {
19
+ [super setUp];
20
+ // Put setup code here. This method is called before the invocation of each test method in the class.
21
+ }
22
+
23
+ - (void)tearDown
24
+ {
25
+ // Put teardown code here. This method is called after the invocation of each test method in the class.
26
+ [super tearDown];
27
+ }
28
+
29
+ - (void)testExample
30
+ {
31
+ XCTAssert(YES, @"woot");
32
+ }
33
+
34
+ @end
@@ -0,0 +1,136 @@
1
+ require File.join(File.dirname(__FILE__), '..', 'spec_helper')
2
+
3
+ describe Slather::CoverageFile do
4
+
5
+ let(:fixtures_project) do
6
+ Slather::Project.open(FIXTURES_PROJECT_PATH)
7
+ end
8
+
9
+ let(:coverage_file) do
10
+ gcno_path = Pathname(File.join(File.dirname(__FILE__), "fixtures.gcno")).to_s
11
+ Slather::CoverageFile.new(fixtures_project, gcno_path)
12
+ end
13
+
14
+ describe "#initialize" do
15
+ it "should convert the provided path string to a Pathname object, and set it as the gcno_file_pathname" do
16
+ expect(coverage_file.gcno_file_pathname).to eq(Pathname(File.join(File.dirname(__FILE__), "fixtures.gcno")))
17
+ end
18
+ end
19
+
20
+ describe "#source_file_pathname" do
21
+ it "should return the path to the coverage files's source implementation file" do
22
+ expect(coverage_file.source_file_pathname).to eq(fixtures_project["fixtures/fixtures.m"].real_path)
23
+ end
24
+
25
+ it "should return nil if it couldn't find the coverage files's source implementation file in the project" do
26
+ whoami_file = Slather::CoverageFile.new(fixtures_project, "/some/path/whoami.gcno")
27
+ expect(whoami_file.source_file_pathname).to be_nil
28
+ end
29
+ end
30
+
31
+ describe "#source_file" do
32
+ it "should return a file object for the source_file_pathname" do
33
+ file = coverage_file.source_file
34
+ expect(file.kind_of?(File)).to be_truthy
35
+ expect(Pathname(file.path)).to eq(coverage_file.source_file_pathname)
36
+ end
37
+ end
38
+
39
+ describe "#source_data" do
40
+ it "should return the contents of the source_file" do
41
+ expected = <<-OBJC
42
+ //
43
+ // fixtures.m
44
+ // fixtures
45
+ //
46
+ // Created by Mark Larsen on 6/24/14.
47
+ // Copyright (c) 2014 marklarr. All rights reserved.
48
+ //
49
+
50
+ #import "fixtures.h"
51
+
52
+ @implementation fixtures
53
+
54
+ - (void)testedMethod
55
+ {
56
+ NSLog(@"tested");
57
+ }
58
+
59
+ - (void)untestedMethod
60
+ {
61
+ NSLog(@"untested");
62
+ }
63
+
64
+ @end
65
+ OBJC
66
+ expect(coverage_file.source_data).to eq(expected)
67
+ end
68
+
69
+ describe "source_file_pathname_relative_to_repo_root" do
70
+ it "should return a pathname to the source_file, relative to the root of the repo" do
71
+ expect(coverage_file.source_file_pathname_relative_to_repo_root).to eq(Pathname("spec/fixtures/fixtures/fixtures.m"))
72
+ end
73
+ end
74
+
75
+ describe "#coverage_for_line" do
76
+ it "should return nil if the line is not relevant to coverage" do
77
+ expect(coverage_file.coverage_for_line(" -: 75: }")).to be_nil
78
+ end
79
+
80
+ it "should return the number of times the line was executed if the line is relevant to coverage" do
81
+ expect(coverage_file.coverage_for_line(" 1: 75: }")).to eq(1)
82
+ expect(coverage_file.coverage_for_line(" 15: 75: }")).to eq(15)
83
+ expect(coverage_file.coverage_for_line(" ####: 75: }")).to eq(0)
84
+ end
85
+ end
86
+
87
+ describe "#ignored" do
88
+ it "should return true if the source_file_pathname globs against anything in the project.ignore_list" do
89
+ coverage_file.project.ignore_list = ["*spec*", "*test*"]
90
+ expect(coverage_file.ignored?).to be_truthy
91
+ end
92
+
93
+ it "should return false if the source_file_pathname does not glob against anything in the project.ignore_list" do
94
+ coverage_file.project.ignore_list = ["*test*", "*XCTest*"]
95
+ expect(coverage_file.ignored?).to be_falsy
96
+ end
97
+ end
98
+
99
+ describe "gcov_data" do
100
+ it "should process the gcno file with gcov and return the contents of the file" do
101
+ expected = <<-GCOV
102
+ -: 0:Source:/Users/marklarsen/github.com/slather/spec/fixtures/fixtures/fixtures.m
103
+ -: 0:Graph:/Users/marklarsen/github.com/slather/spec/slather/fixtures.gcno
104
+ -: 0:Data:-
105
+ -: 0:Runs:0
106
+ -: 0:Programs:0
107
+ -: 1://
108
+ -: 2:// fixtures.m
109
+ -: 3:// fixtures
110
+ -: 4://
111
+ -: 5:// Created by Mark Larsen on 6/24/14.
112
+ -: 6:// Copyright (c) 2014 marklarr. All rights reserved.
113
+ -: 7://
114
+ -: 8:
115
+ -: 9:#import "fixtures.h"
116
+ -: 10:
117
+ -: 11:@implementation fixtures
118
+ -: 12:
119
+ -: 13:- (void)testedMethod
120
+ -: 14:{
121
+ #####: 15: NSLog(@"tested");
122
+ #####: 16:}
123
+ -: 17:
124
+ -: 18:- (void)untestedMethod
125
+ -: 19:{
126
+ #####: 20: NSLog(@"untested");
127
+ #####: 21:}
128
+ -: 22:
129
+ -: 23:@end
130
+ GCOV
131
+ expect(coverage_file.gcov_data).to eq(expected)
132
+ end
133
+ end
134
+
135
+ end
136
+ end
@@ -0,0 +1,66 @@
1
+ require File.join(File.dirname(__FILE__), '..', '..', 'spec_helper')
2
+
3
+ describe Slather::CoverageService::Coveralls do
4
+
5
+ let(:fixtures_project) do
6
+ proj = Slather::Project.open(FIXTURES_PROJECT_PATH)
7
+ proj.extend(Slather::CoverageService::Coveralls)
8
+ end
9
+
10
+ describe "#coverage_file_class" do
11
+ it "should return CoverallsCoverageFile" do
12
+ expect(fixtures_project.send(:coverage_file_class)).to eq(Slather::CoverallsCoverageFile)
13
+ end
14
+ end
15
+
16
+ describe "#travis_job_id" do
17
+ it "should return the TRAVIS_JOB_ID environment variable" do
18
+ ENV['TRAVIS_JOB_ID'] = "9182"
19
+ expect(fixtures_project.send(:travis_job_id)).to eq("9182")
20
+ end
21
+ end
22
+
23
+ describe '#coveralls_coverage_data' do
24
+
25
+ context "coverage_service is :travis_ci" do
26
+ before(:each) { fixtures_project.ci_service = :travis_ci }
27
+
28
+ it "should return valid json for coveralls coverage data" do
29
+ fixtures_project.stub(:travis_job_id).and_return("9182")
30
+ expect(fixtures_project.send(:coveralls_coverage_data)).to eq("{\"service_job_id\":\"9182\",\"service_name\":\"travis-ci\",\"source_files\":[{\"name\":\"spec/fixtures/fixtures/fixtures.m\",\"source\":\"//\\n// fixtures.m\\n// fixtures\\n//\\n// Created by Mark Larsen on 6/24/14.\\n// Copyright (c) 2014 marklarr. All rights reserved.\\n//\\n\\n#import \\\"fixtures.h\\\"\\n\\n@implementation fixtures\\n\\n- (void)testedMethod\\n{\\n NSLog(@\\\"tested\\\");\\n}\\n\\n- (void)untestedMethod\\n{\\n NSLog(@\\\"untested\\\");\\n}\\n\\n@end\\n\",\"coverage\":[null,null,null,null,null,null,null,null,null,null,null,null,null,null,1,1,null,null,null,0,0,null,null]},{\"name\":\"spec/fixtures/fixtures/more_files/peekaview.m\",\"source\":\"//\\n// peekaview.m\\n// fixtures\\n//\\n// Created by Mark Larsen on 6/25/14.\\n// Copyright (c) 2014 marklarr. All rights reserved.\\n//\\n\\n#import \\\"peekaview.h\\\"\\n\\n@implementation peekaview\\n\\n- (id)initWithFrame:(CGRect)frame\\n{\\n self = [super initWithFrame:frame];\\n if (self) {\\n // Initialization code\\n }\\n return self;\\n}\\n\\n/*\\n// Only override drawRect: if you perform custom drawing.\\n// An empty implementation adversely affects performance during animation.\\n- (void)drawRect:(CGRect)rect\\n{\\n // Drawing code\\n}\\n*/\\n\\n@end\\n\",\"coverage\":[null,null,null,null,null,null,null,null,null,null,null,null,0,null,0,0,null,0,0,0,null,null,null,null,null,null,null,null,null,null,null]},{\"name\":\"spec/fixtures/fixturesTests/fixturesTests.m\",\"source\":\"//\\n// fixturesTests.m\\n// fixturesTests\\n//\\n// Created by Mark Larsen on 6/24/14.\\n// Copyright (c) 2014 marklarr. All rights reserved.\\n//\\n\\n#import <XCTest/XCTest.h>\\n#import \\\"fixtures.h\\\"\\n\\n@interface fixturesTests : XCTestCase\\n\\n@end\\n\\n@implementation fixturesTests\\n\\n- (void)setUp\\n{\\n [super setUp];\\n // Put setup code here. This method is called before the invocation of each test method in the class.\\n}\\n\\n- (void)tearDown\\n{\\n // Put teardown code here. This method is called after the invocation of each test method in the class.\\n [super tearDown];\\n}\\n\\n- (void)testExample\\n{\\n fixtures *f = [[fixtures alloc] init];\\n [f testedMethod];\\n}\\n\\n@end\\n\",\"coverage\":[null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,1,null,1,null,null,null,null,1,1,null,null,null,1,1,1,null,null]},{\"name\":\"spec/fixtures/fixturesTests/peekaviewTests.m\",\"source\":\"//\\n// peekaviewTests.m\\n// fixtures\\n//\\n// Created by Mark Larsen on 6/25/14.\\n// Copyright (c) 2014 marklarr. All rights reserved.\\n//\\n\\n#import <XCTest/XCTest.h>\\n\\n@interface peekaviewTests : XCTestCase\\n\\n@end\\n\\n@implementation peekaviewTests\\n\\n- (void)setUp\\n{\\n [super setUp];\\n // Put setup code here. This method is called before the invocation of each test method in the class.\\n}\\n\\n- (void)tearDown\\n{\\n // Put teardown code here. This method is called after the invocation of each test method in the class.\\n [super tearDown];\\n}\\n\\n- (void)testExample\\n{\\n XCTAssert(YES, @\\\"woot\\\");\\n}\\n\\n@end\\n\",\"coverage\":[null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,1,null,1,null,null,null,null,1,1,null,null,null,2,1,null,null]}]}")
31
+ end
32
+
33
+ it "should raise an error if there is no TRAVIS_JOB_ID" do
34
+ fixtures_project.stub(:travis_job_id).and_return(nil)
35
+ expect { fixtures_project.send(:coveralls_coverage_data) }.to raise_error(StandardError)
36
+ end
37
+ end
38
+
39
+ it "should raise an error if it does not recognize the ci_service" do
40
+ fixtures_project.ci_service = :jenkins_ci
41
+ expect { fixtures_project.send(:coveralls_coverage_data) }.to raise_error(StandardError)
42
+ end
43
+ end
44
+
45
+ describe '#post' do
46
+ it "should save the coveralls_coverage_data to a file and post it to coveralls" do
47
+ fixtures_project.stub(:travis_job_id).and_return("9182")
48
+ expect(fixtures_project).to receive(:`) do |cmd|
49
+ expect(cmd).to eq("curl -s --form json_file=@coveralls_json_file https://coveralls.io/api/v1/jobs")
50
+ expect(File.open('coveralls_json_file', 'r').read).to eq("{\"service_job_id\":\"9182\",\"service_name\":\"travis-ci\",\"source_files\":[{\"name\":\"spec/fixtures/fixtures/fixtures.m\",\"source\":\"//\\n// fixtures.m\\n// fixtures\\n//\\n// Created by Mark Larsen on 6/24/14.\\n// Copyright (c) 2014 marklarr. All rights reserved.\\n//\\n\\n#import \\\"fixtures.h\\\"\\n\\n@implementation fixtures\\n\\n- (void)testedMethod\\n{\\n NSLog(@\\\"tested\\\");\\n}\\n\\n- (void)untestedMethod\\n{\\n NSLog(@\\\"untested\\\");\\n}\\n\\n@end\\n\",\"coverage\":[null,null,null,null,null,null,null,null,null,null,null,null,null,null,1,1,null,null,null,0,0,null,null]},{\"name\":\"spec/fixtures/fixtures/more_files/peekaview.m\",\"source\":\"//\\n// peekaview.m\\n// fixtures\\n//\\n// Created by Mark Larsen on 6/25/14.\\n// Copyright (c) 2014 marklarr. All rights reserved.\\n//\\n\\n#import \\\"peekaview.h\\\"\\n\\n@implementation peekaview\\n\\n- (id)initWithFrame:(CGRect)frame\\n{\\n self = [super initWithFrame:frame];\\n if (self) {\\n // Initialization code\\n }\\n return self;\\n}\\n\\n/*\\n// Only override drawRect: if you perform custom drawing.\\n// An empty implementation adversely affects performance during animation.\\n- (void)drawRect:(CGRect)rect\\n{\\n // Drawing code\\n}\\n*/\\n\\n@end\\n\",\"coverage\":[null,null,null,null,null,null,null,null,null,null,null,null,0,null,0,0,null,0,0,0,null,null,null,null,null,null,null,null,null,null,null]},{\"name\":\"spec/fixtures/fixturesTests/fixturesTests.m\",\"source\":\"//\\n// fixturesTests.m\\n// fixturesTests\\n//\\n// Created by Mark Larsen on 6/24/14.\\n// Copyright (c) 2014 marklarr. All rights reserved.\\n//\\n\\n#import <XCTest/XCTest.h>\\n#import \\\"fixtures.h\\\"\\n\\n@interface fixturesTests : XCTestCase\\n\\n@end\\n\\n@implementation fixturesTests\\n\\n- (void)setUp\\n{\\n [super setUp];\\n // Put setup code here. This method is called before the invocation of each test method in the class.\\n}\\n\\n- (void)tearDown\\n{\\n // Put teardown code here. This method is called after the invocation of each test method in the class.\\n [super tearDown];\\n}\\n\\n- (void)testExample\\n{\\n fixtures *f = [[fixtures alloc] init];\\n [f testedMethod];\\n}\\n\\n@end\\n\",\"coverage\":[null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,1,null,1,null,null,null,null,1,1,null,null,null,1,1,1,null,null]},{\"name\":\"spec/fixtures/fixturesTests/peekaviewTests.m\",\"source\":\"//\\n// peekaviewTests.m\\n// fixtures\\n//\\n// Created by Mark Larsen on 6/25/14.\\n// Copyright (c) 2014 marklarr. All rights reserved.\\n//\\n\\n#import <XCTest/XCTest.h>\\n\\n@interface peekaviewTests : XCTestCase\\n\\n@end\\n\\n@implementation peekaviewTests\\n\\n- (void)setUp\\n{\\n [super setUp];\\n // Put setup code here. This method is called before the invocation of each test method in the class.\\n}\\n\\n- (void)tearDown\\n{\\n // Put teardown code here. This method is called after the invocation of each test method in the class.\\n [super tearDown];\\n}\\n\\n- (void)testExample\\n{\\n XCTAssert(YES, @\\\"woot\\\");\\n}\\n\\n@end\\n\",\"coverage\":[null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,1,null,1,null,null,null,null,1,1,null,null,null,2,1,null,null]}]}")
51
+ end.once
52
+ fixtures_project.post
53
+ end
54
+
55
+ it "should always remove the coveralls_json_file after it's done" do
56
+ fixtures_project.stub(:`)
57
+
58
+ fixtures_project.stub(:travis_job_id).and_return("9182")
59
+ fixtures_project.post
60
+ expect(File.exist?("coveralls_json_file")).to be_falsy
61
+ fixtures_project.stub(:travis_job_id).and_return(nil)
62
+ expect { fixtures_project.post }.to raise_error
63
+ expect(File.exist?("coveralls_json_file")).to be_falsy
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,26 @@
1
+ require File.join(File.dirname(__FILE__), '..', '..', 'spec_helper')
2
+
3
+ describe Slather::CoverageService::SimpleOutput do
4
+
5
+ let(:fixtures_project) do
6
+ proj = Slather::Project.open(FIXTURES_PROJECT_PATH)
7
+ proj.extend(Slather::CoverageService::SimpleOutput)
8
+ end
9
+
10
+ describe '#coverage_file_class' do
11
+ it "should return CoverallsCoverageFile" do
12
+ expect(fixtures_project.send(:coverage_file_class)).to eq(Slather::CoverallsCoverageFile)
13
+ end
14
+ end
15
+
16
+ describe '#post' do
17
+ it "should print out the coverage for each file, and then total coverage" do
18
+ expect(fixtures_project).to receive(:puts).with("spec/fixtures/fixtures/fixtures.m: 2 of 4 lines (50.00%)")
19
+ expect(fixtures_project).to receive(:puts).with("spec/fixtures/fixtures/more_files/peekaview.m: 0 of 6 lines (0.00%)")
20
+ expect(fixtures_project).to receive(:puts).with("spec/fixtures/fixturesTests/fixturesTests.m: 7 of 7 lines (100.00%)")
21
+ expect(fixtures_project).to receive(:puts).with("spec/fixtures/fixturesTests/peekaviewTests.m: 6 of 6 lines (100.00%)")
22
+ expect(fixtures_project).to receive(:puts).with("Test Coverage: 65.22%")
23
+ fixtures_project.post
24
+ end
25
+ end
26
+ end
Binary file