Skip to content

Commit 3343cec

Browse files
authored
Merge pull request #5 from WeTransfer/feature/better-reporting
Reporting no longer breaks tests
2 parents 46ba6a6 + 1bac9b7 commit 3343cec

File tree

7 files changed

+74
-27
lines changed

7 files changed

+74
-27
lines changed

.travis.yml

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
language: objective-c
2-
osx_image: xcode8.3
2+
osx_image: xcode9.2
33
script:
4-
- xcodebuild clean -project Mocker.xcodeproj -scheme Mocker | xcpretty
5-
- xcodebuild test -project Mocker.xcodeproj -scheme Mocker -destination 'platform=iOS Simulator,name=iPhone 7,OS=10.3.1' -enableCodeCoverage YES | xcpretty -f `xcpretty-json-formatter`
6-
- bundle exec danger
4+
- bundle exec fastlane test
75
before_install:
86
- brew outdated swiftlint || brew upgrade swiftlint
97
- bundle install

Gemfile

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
# frozen_string_literal: true
22
source "https://rubygems.org"
33

4+
gem 'fastlane'
45
gem 'danger'
5-
gem 'danger-swiftlint', '0.9.0'
6+
gem 'danger-swiftlint', '0.12.1'
67
gem 'danger-xcov'
78
gem 'danger-xcodebuild'
89
gem 'danger-xcode_summary'
10+
gem 'xcpretty'
911
gem 'xcpretty-json-formatter'

Mocker.xcodeproj/project.pbxproj

+4-5
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@
141141
501E26901F3DAE370048F39E /* Frameworks */,
142142
501E26911F3DAE370048F39E /* Headers */,
143143
501E26921F3DAE370048F39E /* Resources */,
144-
503446441F3DE70C0039D5E4 /* ShellScript */,
144+
503446441F3DE70C0039D5E4 /* SwiftLint */,
145145
);
146146
buildRules = (
147147
);
@@ -231,18 +231,19 @@
231231
/* End PBXResourcesBuildPhase section */
232232

233233
/* Begin PBXShellScriptBuildPhase section */
234-
503446441F3DE70C0039D5E4 /* ShellScript */ = {
234+
503446441F3DE70C0039D5E4 /* SwiftLint */ = {
235235
isa = PBXShellScriptBuildPhase;
236236
buildActionMask = 2147483647;
237237
files = (
238238
);
239239
inputPaths = (
240240
);
241+
name = SwiftLint;
241242
outputPaths = (
242243
);
243244
runOnlyForDeploymentPostprocessing = 0;
244245
shellPath = /bin/sh;
245-
shellScript = "if which swiftlint >/dev/null; then\nswiftlint lint --config \".swiftlint.yml\"\nelse\necho \"warning: SwiftLint not installed, download from https://github.com/realm/SwiftLint\"\nfi\n";
246+
shellScript = "if which swiftlint >/dev/null; then\n swiftlint lint --config \".swiftlint.yml\"\nelse\n echo \"warning: SwiftLint not installed, download from https://github.com/realm/SwiftLint\"\nfi\n\n";
246247
};
247248
/* End PBXShellScriptBuildPhase section */
248249

@@ -439,7 +440,6 @@
439440
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
440441
PRODUCT_BUNDLE_IDENTIFIER = com.wetransfer.MockerTests;
441442
PRODUCT_NAME = "$(TARGET_NAME)";
442-
SWIFT_SWIFT3_OBJC_INFERENCE = On;
443443
};
444444
name = Debug;
445445
};
@@ -452,7 +452,6 @@
452452
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
453453
PRODUCT_BUNDLE_IDENTIFIER = com.wetransfer.MockerTests;
454454
PRODUCT_NAME = "$(TARGET_NAME)";
455-
SWIFT_SWIFT3_OBJC_INFERENCE = On;
456455
};
457456
name = Release;
458457
};

Sources/MockingURLProtocol.swift

+8-2
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,21 @@ import Foundation
1010

1111
/// The protocol which can be used to send Mocked data back. Use the `Mocker` to register `Mock` data
1212
public final class MockingURLProtocol: URLProtocol {
13-
13+
14+
enum MockingURLProtocolError: Swift.Error {
15+
case missingMockedData(url: String)
16+
}
17+
1418
/// Returns Mocked data based on the mocks register in the `Mocker`. Will end up in an error when no Mock data is found for the request.
1519
public override func startLoading() {
1620
guard
1721
let mock = Mocker.mock(for: request),
1822
let response = HTTPURLResponse(url: mock.url, statusCode: mock.statusCode, httpVersion: Mocker.httpVersion.rawValue, headerFields: mock.headers),
1923
let data = mock.data(for: request)
2024
else {
21-
fatalError("No mocked data found for url \(String(describing: request.url?.absoluteString)) method \(String(describing: request.httpMethod)). Did you forget to use `register()`?")
25+
print("\n\n 🚨 No mocked data found for url \(String(describing: request.url?.absoluteString)) method \(String(describing: request.httpMethod)). Did you forget to use `register()`? 🚨 \n\n")
26+
client?.urlProtocol(self, didFailWithError: MockingURLProtocolError.missingMockedData(url: String(describing: request.url?.absoluteString)))
27+
return
2228
}
2329

2430
DispatchQueue.global(qos: DispatchQoS.QoSClass.background).asyncAfter(deadline: .now() + (mock.delay ?? DispatchTimeInterval.seconds(0))) {

danger/shared/Dangerfile

+32-15
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ end
88

99
def lineIsPropertyMethodClassOrStruct(line)
1010
if line.include?("var") or line.include?("let") or line.include?("func") or line.include?("class") or line.include?("struct")
11-
if line.include?("guard") or line.include?("==")
11+
if line.include?("guard")
1212
return false
1313
end
1414
return true
@@ -23,6 +23,15 @@ def lineIncludesDocumentComment(line)
2323
return false
2424
end
2525

26+
def lineRequiresDocumentation(line)
27+
if line.include?("override") or line.include?("==")
28+
# Overrides will use documentation of the original method. Operators don't need documentation.
29+
return false
30+
end
31+
32+
return true
33+
end
34+
2635
# Make it more obvious that a PR is a work in progress and shouldn't be merged yet.
2736
has_wip_label = github.pr_labels.any? { |label| label.include? "WIP" }
2837
has_wip_title = github.pr_title.include? "[WIP]"
@@ -35,24 +44,29 @@ end
3544
warn("Big PR") if git.lines_of_code > 500
3645

3746
# Check for warnings
38-
xcodebuild.json_file = "build/reports/errors.json"
39-
xcodebuild.post_messages = false
40-
number_of_warnings = xcodebuild.parse_warnings
47+
json_file = "build/reports/errors.json"
48+
if File.file?(json_file)
49+
xcodebuild.json_file = json_file
50+
xcodebuild.post_messages = false
51+
number_of_warnings = xcodebuild.parse_warnings
52+
53+
if number_of_warnings > 0
54+
warn("The project still contains #{number_of_warnings} warnings 😱")
55+
end
4156

42-
if number_of_warnings > 0
43-
warn("The project still contains #{number_of_warnings} warnings 😱")
57+
xcode_summary.ignored_files = 'Submodules/**'
58+
xcode_summary.inline_mode = true
59+
xcode_summary.report 'build/reports/errors.json'
4460
end
4561

46-
xcode_summary.inline_mode = true
47-
xcode_summary.report 'build/reports/errors.json'
48-
49-
5062
# Check to see if any of our project files contains a line with "SOURCE_ROOT" which indicates that the file isn't in sync with Finder.
5163
["Mocker.xcodeproj/project.pbxproj"].each do |project_file|
5264
next unless File.file?(project_file)
5365
File.readlines(project_file).each_with_index do |line, index|
5466
# The folder Resources is a folder references for sharing resources for testing. Don't warn for that folder.
55-
if line.include?("sourceTree = SOURCE_ROOT;") and line.include?("PBXFileReference") and line.include?("name = Resources") == false
67+
files_to_ignore = ["Resources", "Toucan.swift"]
68+
line_should_be_ignored = files_to_ignore.map { |name| "name = " + name }.any? { |file_to_ignore| line.include?(file_to_ignore) }
69+
if line.include?("sourceTree = SOURCE_ROOT;") and line.include?("PBXFileReference") and !line_should_be_ignored
5670
warn("Files should be in sync with project structure", file: project_file, line: index+1)
5771
end
5872
end
@@ -81,7 +95,10 @@ files_to_check = (git.modified_files + git.added_files).uniq
8195
next unless File.file?(file)
8296
# Only check for classes inside swift files
8397
next unless File.extname(file).include?(".swift")
84-
98+
99+
# Determine if we're in a test file
100+
isTestFile = File.basename(file, ".*" ).downcase.include?("test")
101+
85102
# Will be used to check if we're inside a comment block.
86103
isCommentBlock = false
87104

@@ -125,14 +142,14 @@ files_to_check = (git.modified_files + git.added_files).uniq
125142
end
126143

127144
## Check for public properties which aren't commented
128-
if disabled_rules.include?("public_docs") == false and lineContainsPublicPropertyMethodClassOrStruct(line) && lineIncludesDocumentComment(filelines[index-1]) == false
145+
if disabled_rules.include?("public_docs") == false and lineContainsPublicPropertyMethodClassOrStruct(line) && lineIncludesDocumentComment(filelines[index-1]) == false && lineRequiresDocumentation(line)
129146
warn("Public properties, methods, classes or structs should be documented. Make use of `///` or `/* */` so it will show up inside the docs. (public_docs)", file: file, line: index+1)
130147
end
131148
end
132149
end
133150

134151
## Check wether our file is larger than 200 lines and doesn't include any Marks
135-
if filelines.count > 200 and foundMark == false
136-
warn("Consider to place some `MARK:` lines for files over 200 lines big.")
152+
if filelines.count > 200 and foundMark == false and isTestFile == false
153+
warn("Consider to place some `MARK:` lines for #{file}, which is over 200 lines big.")
137154
end
138155
end

fastlane/.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
installer/
2+
test_output/
3+
README.md
4+
report.xml

fastlane/Fastfile

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Fastlane requirements
2+
fastlane_version "1.109.0"
3+
generated_fastfile_id "0121e253-f9e2-40ac-b489-f17f36e24ec6"
4+
5+
default_platform :ios
6+
7+
desc "Run tests and Danger"
8+
lane :test do
9+
clear_derived_data
10+
11+
scan(
12+
scheme: "Mocker",
13+
project: "Mocker.xcodeproj",
14+
skip_slack: true,
15+
device: "iPhone 7",
16+
clean: true,
17+
code_coverage: true,
18+
formatter: "xcpretty-json-formatter")
19+
20+
danger
21+
end

0 commit comments

Comments
 (0)