Skip to content

Commit 645c80a

Browse files
committed
review fix
1 parent 85383d0 commit 645c80a

2 files changed

Lines changed: 24 additions & 1 deletion

File tree

src/main/kotlin/file/Wc3ClientDetector.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ object Wc3ClientDetector {
7878

7979
private fun findExecutable(root: Path): Path? {
8080
if (Files.isRegularFile(root)) {
81-
return root
81+
return root.takeIf { classifyExecutable(it) != null }
8282
}
8383
return exeCandidates
8484
.map { root.resolve(it) }

src/test/kotlin/Wc3ClientDetectorTests.kt

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,29 @@ class Wc3ClientDetectorTests {
3737
Assert.assertEquals(info.kind, Wc3ClientDetector.ClientKind.CLASSIC)
3838
}
3939

40+
@Test
41+
fun testRejectsUnsupportedExplicitFilePath() {
42+
val root = Files.createTempDirectory("wc3-explicit-file")
43+
val textFile = root.resolve("notes.txt")
44+
Files.writeString(textFile, "not a wc3 executable")
45+
46+
val info = Wc3ClientDetector.inspectGameRoot(textFile)
47+
48+
Assert.assertNull(info)
49+
}
50+
51+
@Test
52+
fun testAcceptsSupportedExplicitFilePath() {
53+
val root = Files.createTempDirectory("wc3-explicit-exe")
54+
val exe = root.resolve("war3.exe")
55+
Files.writeString(exe, "")
56+
57+
val info = Wc3ClientDetector.inspectGameRoot(exe)!!
58+
59+
Assert.assertEquals(info.kind, Wc3ClientDetector.ClientKind.PRE_129)
60+
Assert.assertEquals(info.root, root.toAbsolutePath().normalize())
61+
}
62+
4063
@Test
4164
fun testWarnsWhenProjectPatchAndClientKindDiffer() {
4265
val root = Files.createTempDirectory("wc3-mismatch")

0 commit comments

Comments
 (0)