Skip to content

Commit

Permalink
bugfix: Fix test for new project provider
Browse files Browse the repository at this point in the history
  • Loading branch information
tgodzik committed Nov 14, 2024
1 parent caf518e commit f7da3ce
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 16 deletions.
7 changes: 2 additions & 5 deletions tests/mtest/src/main/scala/tests/Assertions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,8 @@ trait Assertions extends munit.Assertions {
def assertDiffEqual[T](obtained: T, expected: T, hint: String = "")(implicit
loc: Location
): Unit = {
if (obtained != expected) {
val hintMsg = if (hint.isEmpty) "" else s" (hint: $hint)"
assertNoDiff(obtained.toString, expected.toString, hint)
fail(s"obtained=<$obtained> != expected=<$expected>$hintMsg")
}
val hintMsg = if (hint.isEmpty) "" else s" (hint: $hint)"
assertNoDiff(obtained.toString, expected.toString, hintMsg)
}

def assertLines(obtained: String, expected: String)(implicit
Expand Down
35 changes: 24 additions & 11 deletions tests/unit/src/test/scala/tests/NewProjectLspSuite.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package tests

import java.io.BufferedReader
import java.io.InputStreamReader
import java.net.URL
import java.nio.file.Files
import java.nio.file.Paths

Expand Down Expand Up @@ -29,6 +32,24 @@ class NewProjectLspSuite extends BaseLspSuite("new-project") {
.copy(inputBoxProvider = Some(true), openNewWindowProvider = Some(true))
)

def scrape(urlString: String): String = {
val url = new URL(urlString)
val connection = url.openConnection()
val reader = new BufferedReader(
new InputStreamReader(connection.getInputStream())
)

LazyList.continually(reader.readLine()).takeWhile(_ != null).mkString("\n")
}

val CubeCalculator =
"https://raw.githubusercontent.com/scala/scalatest-example.g8/refs/heads/main/src/main/g8/src/main/scala/%24package%24/CubeCalculator.scala"
val CubeCalculatorTest =
"https://raw.githubusercontent.com/scala/scalatest-example.g8/refs/heads/main/src/main/g8/src/test/scala/%24package%24/CubeCalculatorTest.scala"

lazy val CubeCalculatorInput: String = scrape(CubeCalculator)
lazy val CubeCalculatorTestInput: String = scrape(CubeCalculatorTest)

def scalatestTemplate(name: String = "scalatest-example"): String =
s"""|/$name/build.sbt
|lazy val root = (project in file(".")).
Expand All @@ -48,19 +69,11 @@ class NewProjectLspSuite extends BaseLspSuite("new-project") {
|
|
|/$name/src/main/scala/com/example/CubeCalculator.scala
|object CubeCalculator extends App {
| def cube(x: Int) = {
| x * x * x
| }
|}
|$CubeCalculatorInput
|
|/$name/src/test/scala/com/example/CubeCalculatorTest.scala
|class CubeCalculatorTest extends org.scalatest.funsuite.AnyFunSuite {
| test("CubeCalculator.cube") {
| assert(CubeCalculator.cube(3) === 27)
| }
|}
|
|/$name/src/test/scala/com/example/CubeCalculatorTest.scala
|$CubeCalculatorTestInput
|""".stripMargin

check("basic-template")(
Expand Down

0 comments on commit f7da3ce

Please sign in to comment.