Skip to content

Commit

Permalink
Merge pull request #40 from cashapp/juho/bug-when-adding-new-hermit
Browse files Browse the repository at this point in the history
Correctly detect `bin` dir creation.
jvmakine authored Mar 7, 2022
2 parents d96ac69 + a074fb1 commit a201950
Showing 3 changed files with 19 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -31,16 +31,17 @@ class HermitVFSChangeListener : BulkFileListener {
private fun isHermitChange(project: Project, file: VirtualFile): Boolean {
val root = project.guessProjectDir()
// Check if we are in a bin/ directory
if (root == null || file.parent == null || file.parent.name != "bin") {
if (root == null || file.parent == null || (file.parent.name != "bin" && file.name != "bin")) {
return false
}
// Check if we are at root bin/ directory
if (file.parent.parent != null && file.parent.parent != root) {
if (file.parent.parent != null && file.parent.parent != root && file.parent != root) {
return false
}
val isPackageChange = file.name.endsWith(".pkg") && file.name.startsWith(".")
val isHermitScriptChange = file.name == "hermit" || file.name == "hermit.hcl"
val isHermitBinCreation = file.name == "bin"

return isPackageChange || isHermitScriptChange
return isPackageChange || isHermitScriptChange || isHermitBinCreation
}
}
Original file line number Diff line number Diff line change
@@ -32,4 +32,12 @@ abstract class HermitProjectTestCase : JavaProjectTestCase() {
protected fun waitAppThreads() {
waitForAppLeakingThreads(1000, TimeUnit.MILLISECONDS)
}

override fun setUpProject() {
super.setUpProject()

// Create the project root dir
Files.createDirectories(projectDirOrFile.parent)
updateVFS()
}
}
Original file line number Diff line number Diff line change
@@ -7,6 +7,7 @@ import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.application.runWriteAction
import com.intellij.openapi.application.runWriteActionAndWait
import com.intellij.openapi.externalSystem.service.execution.ExternalSystemJdkUtil
import com.intellij.openapi.project.guessProjectDir
import com.intellij.openapi.projectRoots.ProjectJdkTable
import com.intellij.openapi.roots.ProjectRootManager
import com.intellij.openapi.wm.WindowManager
@@ -16,6 +17,7 @@ import com.squareup.cash.hermit.ui.statusbar.HermitStatusBarPresentation
import com.squareup.cash.hermit.ui.statusbar.HermitStatusBarWidget
import junit.framework.TestCase
import org.junit.Test
import java.nio.file.Files

class PluginIntegrationTest : HermitProjectTestCase() {
@Test fun `test it negatively detects hermit correctly`() {
@@ -47,7 +49,12 @@ class PluginIntegrationTest : HermitProjectTestCase() {

@Test fun `test it works if hermit is initialised after opening`() {
Hermit(project).open()
TestCase.assertEquals(false, Hermit(project).hasHermit())

withHermit(FakeHermit(listOf(TestPackage("name", "version", "", "root", mapOf(Pair("FOO", "BAR"))))))
waitAppThreads()
TestCase.assertEquals(true, Hermit(project).hasHermit())

Hermit(project).enable()
waitAppThreads()

0 comments on commit a201950

Please sign in to comment.