Skip to content

Commit

Permalink
Generate a comment when no roots are found
Browse files Browse the repository at this point in the history
  • Loading branch information
dfed committed Dec 8, 2023
1 parent 49d21a2 commit e794ded
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
20 changes: 11 additions & 9 deletions Sources/SafeDICore/Generators/DependencyTreeGenerator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,7 @@ public final class DependencyTreeGenerator {
.sorted()
.compactMap { try typeDescriptionToScopeMap[$0]?.createCombinedScope() }

return """
// This file was generated by the SafeDIGenerateDependencyTree build tool plugin.
// Any modifications made to this file will be overwritten on subsequent builds.
// Please refrain from editing this file directly.
\(imports)
\(try await withThrowingTaskGroup(
let dependencyTree = try await withThrowingTaskGroup(
of: String.self,
returning: String.self
) { taskGroup in
Expand All @@ -75,7 +68,16 @@ public final class DependencyTreeGenerator {
generatedCombinedScopes.append(generatedCombinedScope)
}
return generatedCombinedScopes.sorted().joined(separator: "\n\n")
})
}

return """
// This file was generated by the SafeDIGenerateDependencyTree build tool plugin.
// Any modifications made to this file will be overwritten on subsequent builds.
// Please refrain from editing this file directly.
\(imports)
\(dependencyTree.isEmpty ? "// No root @\(InstantiableVisitor.macroName)-decorated types found." : dependencyTree)
"""
}

Expand Down
8 changes: 6 additions & 2 deletions Tests/SafeDIPluginTests/SafeDIPluginTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,16 @@ final class SafeDIPluginTests: XCTestCase {
)

XCTAssertEqual(
try XCTUnwrap(output.dependencyTree).trimmingCharacters(in: .newlines),
try XCTUnwrap(output.dependencyTree),
"""
// This file was generated by the SafeDIGenerateDependencyTree build tool plugin.
// Any modifications made to this file will be overwritten on subsequent builds.
// Please refrain from editing this file directly.
import SwiftUI
import UIKit
// No root @Instantiable-decorated types found.
"""
)
}
Expand All @@ -68,14 +70,16 @@ final class SafeDIPluginTests: XCTestCase {
)

XCTAssertEqual(
try XCTUnwrap(output.dependencyTree).trimmingCharacters(in: .newlines),
try XCTUnwrap(output.dependencyTree),
"""
// This file was generated by the SafeDIGenerateDependencyTree build tool plugin.
// Any modifications made to this file will be overwritten on subsequent builds.
// Please refrain from editing this file directly.
import SwiftUI
import UIKit
// No root @Instantiable-decorated types found.
"""
)
}
Expand Down

0 comments on commit e794ded

Please sign in to comment.