Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updated semanticdb version / added tests to cli.Setup
- Loading branch information
Showing
4 changed files
with
239 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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
119
blinky-cli/src/test/scala/blinky/run/TestInstruction.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
) | ||
??? | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters