Skip to content

Commit f9d80dd

Browse files
Merge pull request #1464 from sorinc03/fix/watch-file-annotations-reset
Fix file annotation content reuse in watch mode
2 parents bf3a6ed + 55f283a commit f9d80dd

2 files changed

Lines changed: 22 additions & 0 deletions

File tree

Sourcery/Sourcery.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -526,6 +526,7 @@ extension Sourcery {
526526

527527
Log.info("Generating code...")
528528
status = ""
529+
fileAnnotatedContent.removeAll()
529530

530531
if output.isDirectory {
531532
try allTemplates.forEach { template in

SourceryTests/SourcerySpec.swift

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1183,6 +1183,27 @@ class SourcerySpecTests: QuickSpec {
11831183
expect(result).to(equal(expectedResult))
11841184
}
11851185

1186+
it("does not reuse annotated content between generations") {
1187+
let expectedResult = """
1188+
// Generated using Sourcery Major.Minor.Patch — https://github.com/krzysztofzablocki/Sourcery
1189+
// DO NOT EDIT
1190+
extension Foo {
1191+
var property = 2
1192+
// Line Three
1193+
}
1194+
1195+
"""
1196+
1197+
let sourcery = Sourcery(watcherEnabled: false, cacheDisabled: true)
1198+
expect { try sourcery.processFiles(.sources(Paths(include: [sourcePath])), usingTemplates: Paths(include: [templatePath]), output: output, baseIndentation: 0) }.toNot(throwError())
1199+
expect { try sourcery.processFiles(.sources(Paths(include: [sourcePath])), usingTemplates: Paths(include: [templatePath]), output: output, baseIndentation: 0) }.toNot(throwError())
1200+
1201+
let generatedPath = outputDir + Path("Generated/Foo.generated.swift")
1202+
1203+
let result = try? generatedPath.read(.utf8)
1204+
expect(result).to(equal(expectedResult))
1205+
}
1206+
11861207
}
11871208

11881209
context("given a restricted file") {

0 commit comments

Comments
 (0)