Skip to content

Commit

Permalink
Fix unity build (#1986)
Browse files Browse the repository at this point in the history
* Add test case for unity build

* Fix unity file generation
  • Loading branch information
peckto authored Jan 25, 2025
1 parent d0d7243 commit c4037bb
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ private constructor(
.trimIndent()
)
}
?: {
?: run {
writer.write(
"""
#include "${file.absolutePath}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,4 +260,47 @@ internal class CXXIncludeTest : BaseTest() {
assertEquals(2, tu.methods.size)
assertEquals(1, tu.methods.filterIsInstance<ConstructorDeclaration>().size)
}

@Test
@Throws(Exception::class)
fun testUnityBuild() {
val file = File("src/test/resources/include.cpp")
val tus =
analyzeWithBuilder(
TranslationConfiguration.builder()
.sourceLocations(listOf(file))
.loadIncludes(true)
.useUnityBuild(true)
.debugParser(true)
.registerLanguage<CPPLanguage>()
.failOnError(true)
)
assertNotNull(tus)

val tu = tus.firstOrNull()
assertNotNull(tu)
assertFalse(tu.records.isEmpty())
}

@Test
@Throws(Exception::class)
fun testUnityBuildWithComponent() {
val file = File("src/test/resources/include.cpp")
val tus =
analyzeWithBuilder(
TranslationConfiguration.builder()
.sourceLocations(listOf(file))
.topLevel(file.parentFile)
.loadIncludes(true)
.useUnityBuild(true)
.debugParser(true)
.registerLanguage<CPPLanguage>()
.failOnError(true)
)
assertNotNull(tus)

val tu = tus.firstOrNull()
assertNotNull(tu)
assertFalse(tu.records.isEmpty())
}
}

0 comments on commit c4037bb

Please sign in to comment.