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

[4/y] Show help message no mockable types are generated #252

Merged
merged 1 commit into from
Jan 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ extension Generator {
findMockedTypesResult: findMockedTypesOperation?.result,
config: GenerateFileConfig(
moduleName: moduleName,
testTargetName: config.environmentTargetName,
outputPath: outputPath,
header: config.header,
compilationCondition: config.compilationCondition,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,14 @@ class FileGenerator {
}

private func generateFileBody() -> PartialFileContent {
guard !mockableTypes.isEmpty else { return PartialFileContent(contents: "") }
let operations = mockableTypes
guard !mockableTypes.isEmpty else {
return PartialFileContent(contents: """
// No mockable types in \(singleQuoted: config.moduleName). Check that the module's
// source files have classes or protocols that are not private and not marked as final.
""")
}

let availableMockableTypes = mockableTypes
.filter({ mockableType in
switch config.pruningMethod {
case .omit:
Expand All @@ -100,6 +106,16 @@ class FileGenerator {
case .disable, .stub: return true
}
})
guard !availableMockableTypes.isEmpty else {
let testTarget = config.testTargetName?.singleQuoted ?? "your test target"
return PartialFileContent(contents: """
// No mocks used in \(testTarget). Mockingbird is configured to
// only generate mocks for types that are explicitly initialized in your tests with
// `mock(SomeType.self)`. For more information, see 'Thunk Pruning' in the README.
""")
}

let operations = availableMockableTypes
.sorted(by: <)
.flatMap({ mockableType -> [RenderTemplateOperation] in
let mockableTypeTemplate = MockableTypeTemplate(mockableType: mockableType,
Expand Down Expand Up @@ -137,7 +153,7 @@ class FileGenerator {
substructure: [generateFileHeader(),
generateFileBody(),
generateFileFooter()].filter({ !$0.isEmpty }),
delimiter: "\n",
delimiter: "\n\n",
footer: "\n")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import os.log

public struct GenerateFileConfig {
let moduleName: String
let testTargetName: String?
let outputPath: Path
let header: [String]
let compilationCondition: String?
Expand All @@ -20,13 +21,15 @@ public struct GenerateFileConfig {
let pruningMethod: PruningMethod

public init(moduleName: String,
testTargetName: String?,
outputPath: Path,
header: [String],
compilationCondition: String?,
onlyMockProtocols: Bool,
disableSwiftlint: Bool,
pruningMethod: PruningMethod) {
self.moduleName = moduleName
self.testTargetName = testTargetName
self.outputPath = outputPath
self.header = header
self.compilationCondition = compilationCondition
Expand Down