diff --git a/backend/src/test/scala/bloop/logging/RecordingLogger.scala b/backend/src/test/scala/bloop/logging/RecordingLogger.scala index b9d6225368..6eead1f080 100644 --- a/backend/src/test/scala/bloop/logging/RecordingLogger.scala +++ b/backend/src/test/scala/bloop/logging/RecordingLogger.scala @@ -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)] = { diff --git a/frontend/src/main/scala/bloop/cli/Commands.scala b/frontend/src/main/scala/bloop/cli/Commands.scala index a399021245..013592c006 100644 --- a/frontend/src/main/scala/bloop/cli/Commands.scala +++ b/frontend/src/main/scala/bloop/cli/Commands.scala @@ -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 { diff --git a/frontend/src/test/scala/bloop/AutoCompleteSpec.scala b/frontend/src/test/scala/bloop/AutoCompleteSpec.scala new file mode 100644 index 0000000000..a33e0bedc7 --- /dev/null +++ b/frontend/src/test/scala/bloop/AutoCompleteSpec.scala @@ -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 ' + val test3 = Commands.Autocomplete( + cliOptions, + completion.Mode.Projects, + completion.ZshFormat, + Some("compile"), + None + ) + + // Simulate 'bloop compile A ', 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) + ) + } + } +}