Skip to content

Commit

Permalink
Merge pull request #100 from squareup/skorulis/parent-fix
Browse files Browse the repository at this point in the history
Fix assemblyValidation not taking into account having a parent assembler
  • Loading branch information
bradfol authored Dec 12, 2023
2 parents d2e818d + 96c6efc commit ace7453
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Knit.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'Knit'
s.version = '0.2.3'
s.version = '0.2.4'
s.summary = 'A tool for adding safety features to Swinject'
s.description = 'Knit parses Swinject code and generates Swift files for type safety and unit testing.'
s.homepage = 'https://github.com/squareup/knit'
Expand Down
2 changes: 1 addition & 1 deletion Sources/KnitLib/Module/DependencyBuilder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ final class DependencyBuilder {
// Assembly validation should be performed "up front"
// For example if we are validating the assemblies' `TargetResolver`, we should not walk the tree
// if the root assembly is targeting an incorrect resolver.
if let assemblyValidation {
if let assemblyValidation, !isRegisteredInParent(resolved) {
do {
try assemblyValidation(resolved)
} catch {
Expand Down
15 changes: 15 additions & 0 deletions Tests/KnitLibTests/ScopedModuleAssemblerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,15 @@ final class ScopedModuleAssemblerTests: XCTestCase {
XCTAssertEqual(assembler.internalAssembler.registeredModules.count, 1)
}

func testParentExcluded() throws {
let parent = try ScopedModuleAssembler<TestResolver>(_modules: [Assembly1()])
let assembler = try ScopedModuleAssembler<OutsideResolver>(
parent: parent.internalAssembler,
_modules: [Assembly3()]
)
XCTAssertEqual(assembler.internalAssembler.registeredModules.count, 1)
}

func testPostAssemble() throws {
let assembler = try ScopedModuleAssembler<TestResolver>(_modules: [Assembly1()]) { container in
container.register(String.self) { _ in "string" }
Expand Down Expand Up @@ -54,3 +63,9 @@ private struct Assembly2: AutoInitModuleAssembly {
static var dependencies: [any ModuleAssembly.Type] { [] }
func assemble(container: Container) { }
}

private struct Assembly3: AutoInitModuleAssembly {
typealias TargetResolver = OutsideResolver
static var dependencies: [any ModuleAssembly.Type] { [Assembly1.self] }
func assemble(container: Container) { }
}

0 comments on commit ace7453

Please sign in to comment.