Skip to content

Commit

Permalink
leverage testkit for -Xsource:3 test
Browse files Browse the repository at this point in the history
  • Loading branch information
bjaglin committed Sep 10, 2022
1 parent bfe0624 commit 7cd2869
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 66 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
rules = RemoveUnused
*/
package test.removeUnused

import java.io.*
import java.util.concurrent._

import scala.collection.mutable
import scala.util._
import scala.io.*

object RemoveUnusedImportsWildcards {
new File("")
new ConcurrentHashMap[String, String]()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package test.removeUnused

import java.io.*
import java.util.concurrent._


object RemoveUnusedImportsWildcards {
new File("")
new ConcurrentHashMap[String, String]()
}
Original file line number Diff line number Diff line change
Expand Up @@ -434,72 +434,6 @@ class ScalafixArgumentsSuite extends AnyFunSuite with DiffAssertions {
assert(obtainedError == ScalafixFileEvaluationError.ParseError)
}

test("Scala 3 style wildcard import", SkipWindows) {
// https://github.com/scalacenter/scalafix/issues/1663

if (scala.util.Properties.versionNumberString.startsWith("2.11")) {
cancel()
}

val cwd = StringFS
.string2dir(
"""|/src/Main.scala
|import scala.collection.mutable
|import scala.util._
|import scala.io.*
|
|object Main
""".stripMargin,
charset
)
.toNIO
val d = cwd.resolve("out")
val target = cwd.resolve("target")
val src = cwd.resolve("src")
Files.createDirectories(d)
val main = src.resolve("Main.scala")

val scalacOptions = Array[String](
"-Xsource:3",
"-Yrangepos",
removeUnused,
s"-Xplugin:${SemanticdbPlugin.semanticdbPluginPath()}",
"-Xplugin-require:semanticdb",
"-classpath",
s"${scalaLibrary.mkString(":")}",
s"-P:semanticdb:sourceroot:$src",
s"-P:semanticdb:targetroot:$target",
"-d",
d.toString,
main.toString
)

val _ = scala.tools.nsc.Main.process(scalacOptions)
val result = api
.withRules(
Collections.singletonList(removeUnsuedRule().name.toString())
)
.withClasspath((scalaLibrary.map(_.toNIO) :+ target).asJava)
.withScalacOptions(Collections.singletonList(removeUnused))
.withScalaVersion("2.13.8")
.withPaths(Seq(main).asJava)
.withSourceroot(src)
.evaluate()

val error = result.getError
assert(!error.isPresent)
assert(result.isSuccessful)
assert(result.getFileEvaluations.length == 1)
val fileEvaluation = result.getFileEvaluations.head
assert(fileEvaluation.isSuccessful)
val expected =
"""|
|object Main
|""".stripMargin
val obtained = fileEvaluation.previewPatches.get()
assertNoDiff(obtained, expected)
}

test("withScalaVersion: non-parsable scala version") {
val run = Try(api.withScalaVersion("213"))
assert(run.isFailure)
Expand Down

0 comments on commit 7cd2869

Please sign in to comment.