Skip to content

Commit

Permalink
We should check the expectedPath against the thrift file name, instea…
Browse files Browse the repository at this point in the history
…d of the full path, which might contain directories.
  • Loading branch information
CoolTomatos committed Jun 7, 2024
1 parent 3c6d808 commit 9c12bfe
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ internal class Linker(
val expectedPath = "$includeName.thrift"
constant = program.includes
.asSequence()
.filter { p -> p.location.path == expectedPath } // TODO: Should this be ==, or endsWith?
.filter { p -> File(p.location.path).name == expectedPath }
.mapNotNull { p -> p.constantMap[qualifiedName] }
.firstOrNull()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,47 @@ class LoaderTest {
enum.location.path shouldBe listOf("nested", "a.thrift").joinToString(File.separator)
}

@Test
fun crazyIncludeReferencedConst() {
val nestedDir = File(tempDir, "nested").apply { mkdir() }
val f1 = File(nestedDir, "a.thrift")
val f2 = File(tempDir, "another_a.thrift")
val f3 = File(tempDir, "b.thrift")

val a = """
namespace java com.microsoft.thrifty.test.crazyIncludeReferencedConst
const string HELLO = "hello"
"""

val b = """
namespace java com.microsoft.thrifty.test.crazyIncludeReferencedConst
const string HELLO = "actually goodbye"
"""

val c = """
include 'another_a.thrift'
include 'nested/a.thrift'
namespace java com.microsoft.thrifty.test.crazyIncludeReferencedConst
const string HELLO_AGAIN = a.HELLO
"""

f1.writeText(a)
f2.writeText(b)
f3.writeText(c)

val loader = Loader()
loader.addIncludePath(tempDir.toPath())

val schema = loader.load()

val helloAgain = schema.constants.single { const -> const.name == "HELLO_AGAIN" }
val referencedConstant = helloAgain.referencedConstants.single()
referencedConstant.location.path shouldBe listOf("nested", "a.thrift").joinToString(File.separator)
}

@Test
fun relativeIncludesConsiderIncludingFileLocation() {
val thriftDir = File(tempDir, "thrift").apply { mkdir() }
Expand Down Expand Up @@ -1370,4 +1411,4 @@ class LoaderTest {
name
}
}
}
}

0 comments on commit 9c12bfe

Please sign in to comment.