Skip to content

Commit

Permalink
Add tests for autocompletions
Browse files Browse the repository at this point in the history
Add basic autocompletion tests for project autocompletion. The current
tests are basic and will be expanded in the future (contributions are
welcome).

Fixes #426
  • Loading branch information
jvican committed Dec 29, 2018
1 parent 3e57aa4 commit c5a1887
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 2 deletions.
1 change: 1 addition & 0 deletions backend/src/test/scala/bloop/logging/RecordingLogger.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ final class RecordingLogger(

def clear(): Unit = messages.clear()

def infos: List[String] = getMessagesAt(Some("info"))
def getMessagesAt(level: Option[String]): List[String] = getMessages(level).map(_._2)
def getMessages(): List[(String, String)] = getMessages(None)
private def getMessages(level: Option[String]): List[(String, String)] = {
Expand Down
2 changes: 0 additions & 2 deletions frontend/src/main/scala/bloop/cli/Commands.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@ package bloop.cli
import java.net.InetAddress
import java.nio.file.Path

import bloop.cli.CliParsers.CommandsMessages
import bloop.io.AbsolutePath
import caseapp.{CommandName, ExtraName, HelpMessage, Recurse}
import caseapp.core.CommandMessages

object Commands {

Expand Down
78 changes: 78 additions & 0 deletions frontend/src/test/scala/bloop/AutoCompleteSpec.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package bloop

import bloop.cli.{CliOptions, Commands, completion}
import bloop.engine.Run
import bloop.logging.RecordingLogger
import bloop.util.TestUtil
import org.junit.Test

class AutoCompleteSpec {
@Test
def testAutoCompletionForProjects: Unit = {
val structure = Map("A" -> Map[String, String](), "B" -> Map[String, String]())
val deps = Map("B" -> Set("A"))
val logger = new RecordingLogger(ansiCodesSupported = false)

TestUtil.testState(structure, deps, userLogger = Some(logger)) { state0 =>
val cliOptions = CliOptions.default.copy(common = state0.commonOptions)
val test1 = Commands.Autocomplete(
cliOptions,
completion.Mode.Commands,
completion.ZshFormat,
None,
None
)

val test2 = Commands.Autocomplete(
cliOptions,
completion.Mode.ProjectBoundCommands,
completion.ZshFormat,
None,
None
)

// Simulate basic 'bloop compile <autocomplete>'
val test3 = Commands.Autocomplete(
cliOptions,
completion.Mode.Projects,
completion.ZshFormat,
Some("compile"),
None
)

// Simulate 'bloop compile A <autocomplete>', happens when we want to add multiple projects
val test4 = Commands.Autocomplete(
cliOptions,
completion.Mode.Projects,
completion.ZshFormat,
Some("compile"),
Some("A")
)

val action = Run(test1, Run(test2, Run(test3, Run(test4))))
val state1 = TestUtil.blockingExecute(action, state0)
TestUtil.assertNoDiff(
"""
|about
|autocomplete
|bsp
|clean
|compile
|configure
|console
|help
|link
|projects
|run
|test
|clean compile console link run test
|A
|B
|A
|B
""".stripMargin,
logger.infos.mkString(System.lineSeparator)
)
}
}
}

0 comments on commit c5a1887

Please sign in to comment.