Skip to content

Commit

Permalink
Updated semanticdb version / added tests to cli.Setup
Browse files Browse the repository at this point in the history
  • Loading branch information
RCMartins committed Mar 1, 2021
1 parent f3f3276 commit 9dbda54
Show file tree
Hide file tree
Showing 4 changed files with 239 additions and 2 deletions.
2 changes: 1 addition & 1 deletion blinky-cli/src/main/scala/blinky/run/Setup.scala
Expand Up @@ -22,7 +22,7 @@ object Setup {
"sbt",
Seq(
"set ThisBuild / semanticdbEnabled := true",
"set ThisBuild / semanticdbVersion := \"4.3.17\"",
"set ThisBuild / semanticdbVersion := \"4.4.10\"",
"compile"
),
envArgs = Map("BLINKY" -> "true"),
Expand Down
118 changes: 118 additions & 0 deletions blinky-cli/src/test/scala/blinky/run/SetupTest.scala
@@ -0,0 +1,118 @@
package blinky.run

import ammonite.ops.pwd
import blinky.TestSpec
import blinky.run.TestInstruction._
import zio.test._
import zio.test.environment.TestEnvironment

object SetupTest extends TestSpec {

private val path = pwd

val spec: Spec[TestEnvironment, TestFailure[Nothing], TestSuccess] =
suite("Setup")(
suite("setupCoursier")(
test("return the correct instruction when 'coursier' is available") {
testInstruction(
Setup.setupCoursier(path),
TestRunAsyncSuccess(
"coursier",
Seq("--help"),
Map.empty,
path,
mockResult = true,
TestReturn("coursier")
)
)
},
test("return the correct instruction when 'cs' is available") {
testInstruction(
Setup.setupCoursier(path),
TestRunAsyncSuccess(
"coursier",
Seq("--help"),
Map.empty,
path,
mockResult = false,
TestRunAsyncSuccess(
"cs",
Seq("--help"),
Map.empty,
path,
mockResult = true,
TestReturn("cs")
)
)
)
},
test("return the correct instruction when 'coursier and 'cs' is unavailable") {
testInstruction(
Setup.setupCoursier(path),
TestRunAsyncSuccess(
"coursier",
Seq("--help"),
Map.empty,
path,
mockResult = false,
TestRunAsyncSuccess(
"cs",
Seq("--help"),
Map.empty,
path,
mockResult = false,
TestCopyResource(
"/coursier",
path / "coursier",
TestRunSync(
"chmod",
Seq("+x", "coursier"),
Map.empty,
path,
TestReturn("./coursier")
)
)
)
)
)
}
),
suite("sbtCompileWithSemanticDB")(
test("return the correct instruction") {
testInstruction(
Setup.sbtCompileWithSemanticDB(path),
TestRunSync(
"sbt",
Seq(
"set ThisBuild / semanticdbEnabled := true",
"set ThisBuild / semanticdbVersion := \"4.4.10\"",
"compile"
),
Map("BLINKY" -> "true"),
path,
TestReturn(())
)
)
}
),
suite("setupScalafix")(
test("return the correct instruction") {
testInstruction(
Setup.setupScalafix(path),
TestCopyResource(
"/scalafix",
path / "scalafix",
TestRunSync(
"chmod",
Seq("+x", "scalafix"),
Map.empty,
path,
TestReturn(())
)
)
)
}
)
)

}
119 changes: 119 additions & 0 deletions blinky-cli/src/test/scala/blinky/run/TestInstruction.scala
@@ -0,0 +1,119 @@
package blinky.run

import ammonite.ops.Path
import blinky.run.Instruction.{CopyResource, Return, RunAsyncSuccess, RunSync}
import zio.test.Assertion.equalTo
import zio.test.{TestResult, assert}

trait TestInstruction[A]

object TestInstruction {

final case class TestReturn[A](value: A) extends TestInstruction[A]

final case class TestPrintLine[A](line: String, next: TestInstruction[A])
extends TestInstruction[A]

final case class TestPrintErrorLine[A](line: String, next: TestInstruction[A])
extends TestInstruction[A]

final case class TestRunSync[A](
op: String,
args: Seq[String],
envArgs: Map[String, String],
path: Path,
next: TestInstruction[A]
) extends TestInstruction[A]

final case class TestRunAsync[A](
op: String,
args: Seq[String],
envArgs: Map[String, String],
path: Path,
mockResult: String,
next: TestInstruction[A]
) extends TestInstruction[A]

final case class TestRunAsyncSuccess[A](
op: String,
args: Seq[String],
envArgs: Map[String, String],
path: Path,
mockResult: Boolean,
next: TestInstruction[A]
) extends TestInstruction[A]

final case class TestRunAsyncEither[A](
op: String,
args: Seq[String],
envArgs: Map[String, String],
path: Path,
next: Either[String, String] => TestInstruction[A]
) extends TestInstruction[A]

final case class TestMakeTemporaryDirectory[A](next: Path => TestInstruction[A])
extends TestInstruction[A]

final case class TestMakeDirectory[A](path: Path, next: TestInstruction[A])
extends TestInstruction[A]

final case class TestCopyInto[A](from: Path, to: Path, next: TestInstruction[A])
extends TestInstruction[A]

final case class TestCopyResource[A](
resource: String,
destinationPath: Path,
next: TestInstruction[A]
) extends TestInstruction[A]

final case class TestWriteFile[A](path: Path, content: String, next: TestInstruction[A])
extends TestInstruction[A]

final case class TestReadFile[A](path: Path, next: String => TestInstruction[A])
extends TestInstruction[A]

final case class TestIsFile[A](path: Path, next: Boolean => TestInstruction[A])
extends TestInstruction[A]

def testInstruction[A](
actualInstruction: Instruction[A],
expectationInstruction: TestInstruction[A]
): TestResult =
(actualInstruction, expectationInstruction) match {
case (Return(value1), TestReturn(value2)) =>
assert(value1())(equalTo(value2))
case (
RunSync(op1, args1, envArgs1, path1, next1),
TestRunSync(op2, args2, envArgs2, path2, next2)
) =>
assert(op1)(equalTo(op2)) &&
assert(args1)(equalTo(args2)) &&
assert(envArgs1)(equalTo(envArgs2)) &&
assert(path1)(equalTo(path2)) &&
testInstruction(next1, next2)
case (
RunAsyncSuccess(op1, args1, envArgs1, path1, next1),
TestRunAsyncSuccess(op2, args2, envArgs2, path2, mockResult, next2)
) =>
assert(op1)(equalTo(op2)) &&
assert(args1)(equalTo(args2)) &&
assert(envArgs1)(equalTo(envArgs2)) &&
assert(path1)(equalTo(path2)) &&
testInstruction(next1(mockResult), next2)
case (
CopyResource(resource1, destinationPath1, next1),
TestCopyResource(resource2, destinationPath2, next2)
) =>
assert(resource1)(equalTo(resource2)) &&
assert(destinationPath1)(equalTo(destinationPath2)) &&
testInstruction(next1, next2)
case (other1, other2) =>
println(
s"""elem1: ${println(other1.getClass.getSimpleName)}
|elem2: ${println(other2.getClass.getSimpleName)}
|""".stripMargin
)
???
}

}
2 changes: 1 addition & 1 deletion ci-tests/cli.blinky.conf
@@ -1,6 +1,6 @@
projectPath = "."
filesToMutate = "blinky-cli/src/main"
filesToExclude = "**/{Cli,Setup,Run,TestMutationsBloop,AmmoniteExternalCalls,ExternalCalls,Interpreter,Instruction}.scala" # There are no unit tests for this files yet...
filesToExclude = "**/{Cli,Run,TestMutationsBloop,AmmoniteExternalCalls,ExternalCalls,Interpreter,Instruction}.scala" # There are no unit tests for this files yet...
options = {
maxRunningTime = 40 minutes
compileCommand = "cli-test"
Expand Down

0 comments on commit 9dbda54

Please sign in to comment.