Skip to content

Commit

Permalink
Merge c272930 into c8f712e
Browse files Browse the repository at this point in the history
  • Loading branch information
RCMartins committed Mar 15, 2021
2 parents c8f712e + c272930 commit acd22c8
Show file tree
Hide file tree
Showing 9 changed files with 207 additions and 70 deletions.
13 changes: 13 additions & 0 deletions .github/workflows/pr.yml
Expand Up @@ -47,3 +47,16 @@ jobs:
apps: bloop
- run: ./.github/scripts/setup.sh
- run: sbt runExamples
scalaTests:
name: Run Tests Matrix
runs-on: ubuntu-latest
strategy:
matrix:
scalaVersion: [2.13.3] #[2.12.10, 2.12.11, 2.12.13, 2.13.2, 2.13.3, 2.13.4, 2.13.5]
fail-fast: false
steps:
- uses: actions/checkout@v2
- uses: olafurpg/setup-scala@v10
- run: sbt "++ $VERSION_TO_TEST!" core/test tests/test
env:
VERSION_TO_TEST: ${{ matrix.scalaVersion }}
2 changes: 2 additions & 0 deletions .github/workflows/release.yml
Expand Up @@ -9,6 +9,8 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- uses: olafurpg/setup-scala@v10
- run: git fetch --unshallow
- run: |
Expand Down
14 changes: 8 additions & 6 deletions blinky-cli/src/main/scala/blinky/run/Run.scala
Expand Up @@ -18,11 +18,11 @@ object Run {
for {
pwd <- CliModule.pwd

originalProjectRoot: Path = Path(pwd.path.toAbsolutePath)
originalProjectRelPath: RelPath =
originalProjectRoot = Path(pwd.path.toAbsolutePath)
originalProjectRelPath =
Try(Path(config.projectPath.pathAsString).relativeTo(originalProjectRoot))
.getOrElse(RelPath(config.projectPath.pathAsString))
originalProjectPath: Path = originalProjectRoot / originalProjectRelPath
originalProjectPath = originalProjectRoot / originalProjectRelPath

inst = {
for {
Expand All @@ -42,10 +42,11 @@ object Run {
case Right(gitRevParse) =>
val gitFolder = Path(gitRevParse)
val cloneProjectBaseFolder: Path = cloneProjectTempFolder / gitFolder.baseName
val projectRealRelPath: RelPath = originalProjectPath.relativeTo(gitFolder)
val projectRealPath: Path = cloneProjectBaseFolder / projectRealRelPath

for {
_ <- makeDirectory(cloneProjectBaseFolder)
projectRealRelPath: RelPath = originalProjectPath.relativeTo(gitFolder)
projectRealPath: Path = cloneProjectBaseFolder / projectRealRelPath

// Setup files to mutate ('scalafix --diff' does not work like I want...)
filesToMutateEither <- {
Expand Down Expand Up @@ -214,7 +215,8 @@ object Run {
.gitIssues(commandError)
.map(_ => Left(ExitCode.failure))
case Right(gitResult) =>
val filesToCopy = gitResult.split(System.lineSeparator()).map(RelPath(_))
val filesToCopy: Seq[RelPath] =
gitResult.split(System.lineSeparator()).map(RelPath(_)).toSeq
for {
copyResult <- copyRelativeFiles(
filesToCopy,
Expand Down
4 changes: 2 additions & 2 deletions blinky-core/src/main/scala/blinky/internal/Blinky.scala
Expand Up @@ -106,8 +106,8 @@ class Blinky(config: BlinkyConfig) extends SemanticRule("Blinky") {
val gitDiff =
Try(
%%(
'git,
'diff,
"git",
"diff",
"--no-index",
originalFile.toString,
mutatedFile.toString
Expand Down
119 changes: 65 additions & 54 deletions blinky-core/src/main/scala/blinky/v0/Mutator.scala
Expand Up @@ -311,14 +311,6 @@ object Mutator {
object Collections extends MutatorGroup {
override val groupName: String = "Collections"

override val getSubMutators: List[Mutator] =
List(
ListApply,
SeqApply,
SetApply,
Reverse
)

private val MaxSize = 25

@tailrec
Expand All @@ -337,8 +329,8 @@ object Mutator {
class RemoveApplyArgMutator(
mutatorName: String,
collectionName: String,
symbolsToMatch: Seq[String],
minimum: Int = 1
val symbolsToMatch: Seq[String],
minimum: Int
) extends SimpleMutator(mutatorName) {
override def getMutator(implicit doc: SemanticDocument): MutationResult = {
case collection @ Term.Apply(
Expand All @@ -351,51 +343,70 @@ object Mutator {
}
}

object ListApply
extends RemoveApplyArgMutator(
"ListApply",
"List",
Seq(
"scala/collection/immutable/List."
)
)

object SeqApply
extends RemoveApplyArgMutator(
"SeqApply",
"Seq",
Seq(
"scala/collection/Seq.",
"scala/collection/mutable/Seq.",
"scala/collection/immutable/Seq."
)
)

object SetApply
extends RemoveApplyArgMutator(
"SetApply",
"Set",
Seq(
"scala/Predef.Set.",
"scala/collection/mutable/Set.",
"scala/collection/immutable/Set."
),
minimum = 2
)

object Reverse extends SimpleMutator("Reverse") {
override def getMutator(implicit doc: SemanticDocument): MutationResult = {
case reverse @ Term.Select(term, Term.Name("reverse"))
if SymbolMatcher
.exact(
"scala/collection/SeqLike#reverse().",
"scala/collection/immutable/List#reverse().",
"scala/collection/IndexedSeqOptimized#reverse()."
)
.matches(reverse.symbol) =>
default(term)
val ListApply: RemoveApplyArgMutator =
new RemoveApplyArgMutator(
"ListApply",
"List",
Seq(
"scala/collection/immutable/List.",
"scala/package.List."
),
minimum = 1
)

val SeqApply: RemoveApplyArgMutator =
new RemoveApplyArgMutator(
"SeqApply",
"Seq",
Seq(
"scala/collection/Seq.",
"scala/collection/mutable/Seq.",
"scala/collection/immutable/Seq.",
"scala/package.Seq."
),
minimum = 1
)

val SetApply: RemoveApplyArgMutator =
new RemoveApplyArgMutator(
"SetApply",
"Set",
Seq(
"scala/Predef.Set.",
"scala/collection/mutable/Set.",
"scala/collection/immutable/Set.",
"scala/package.Set."
),
minimum = 2
)

val ReverseSymbols: Seq[String] =
Seq(
"scala/collection/SeqLike#reverse().",
"scala/collection/immutable/List#reverse().",
"scala/collection/IndexedSeqOptimized#reverse().",
"scala/collection/SeqOps#reverse().",
"scala/collection/IndexedSeqOps#reverse().",
"scala/collection/ArrayOps#reverse().",
"scala/collection/StringOps#reverse()."
)

val Reverse: SimpleMutator =
new SimpleMutator("Reverse") {
override def getMutator(implicit doc: SemanticDocument): MutationResult = {
case reverse @ Term.Select(term, Term.Name("reverse"))
if SymbolMatcher.exact(ReverseSymbols: _*).matches(reverse.symbol) =>
default(term)
}
}
}

override val getSubMutators: List[Mutator] =
List(
ListApply,
SeqApply,
SetApply,
Reverse
)

}

Expand Down
52 changes: 52 additions & 0 deletions blinky-core/src/test/scala/blinky/v0/MutatorTest.scala
@@ -0,0 +1,52 @@
package blinky.v0

import blinky.TestSpec

class MutatorTest extends TestSpec {

"Collections" should {

"return the correct ListApply 'symbolsToMatch'" in {
Mutator.Collections.ListApply.symbolsToMatch mustEqual
Seq(
"scala/collection/immutable/List.",
"scala/package.List."
)
}

"return the correct SeqApply 'symbolsToMatch'" in {
Mutator.Collections.SeqApply.symbolsToMatch mustEqual
Seq(
"scala/collection/Seq.",
"scala/collection/mutable/Seq.",
"scala/collection/immutable/Seq.",
"scala/package.Seq."
)
}

"return the correct SetApply 'symbolsToMatch'" in {
Mutator.Collections.SetApply.symbolsToMatch mustEqual
Seq(
"scala/Predef.Set.",
"scala/collection/mutable/Set.",
"scala/collection/immutable/Set.",
"scala/package.Set."
)
}

"return the correct Reverse 'symbolsToMatch'" in {
Mutator.Collections.ReverseSymbols mustEqual
Seq(
"scala/collection/SeqLike#reverse().",
"scala/collection/immutable/List#reverse().",
"scala/collection/IndexedSeqOptimized#reverse().",
"scala/collection/SeqOps#reverse().",
"scala/collection/IndexedSeqOps#reverse().",
"scala/collection/ArrayOps#reverse().",
"scala/collection/StringOps#reverse()."
)
}

}

}
22 changes: 16 additions & 6 deletions build.sbt
@@ -1,5 +1,6 @@
import java.nio.file.Path
import SBTDefaults.scalafixTestkitV

import java.nio.file.Path
import sbt.Keys._
import sbt.nio.file.FileAttributes
import sbt.util.FileInfo
Expand All @@ -21,8 +22,16 @@ inThisBuild(
)
),
scalaVersion := V.scala212,
addCompilerPlugin(scalafixSemanticdb),
scalacOptions ++= SBTDefaults.defaultScalacFlags,
// addCompilerPlugin(scalafixSemanticdb),
addCompilerPlugin(
"org.scalameta" % "semanticdb-scalac" % "4.4.10" cross CrossVersion.full
),
scalacOptions ++= {
if (scalaVersion.value.startsWith("2.13."))
SBTDefaults.defaultScalacFlags213
else
SBTDefaults.defaultScalacFlags212
},
scalacOptions -= (if (sys.env.contains("CI") && !sys.env.contains("BLINKY")) ""
else "-Xfatal-warnings"),
coverageEnabled := false,
Expand Down Expand Up @@ -111,16 +120,17 @@ lazy val tests =
project
.enablePlugins(ScalafixTestkitPlugin)
.settings(
libraryDependencies += "ch.epfl.scala" % "scalafix-testkit" % V.scalafixVersion % Test cross CrossVersion.full,
libraryDependencies += "org.scalatest" %% "scalatest" % "3.2.6" % Test,
libraryDependencies += "ch.epfl.scala" % "scalafix-testkit" %
scalafixTestkitV(scalaVersion.value) % Test cross CrossVersion.full,
libraryDependencies += "org.scalatest" %% "scalatest" % "3.2.6" % Test,
scalafixTestkitOutputSourceDirectories :=
sourceDirectories.in(output, Compile).value,
scalafixTestkitInputSourceDirectories :=
sourceDirectories.in(input, Compile).value,
scalafixTestkitInputClasspath :=
fullClasspath.in(input, Compile).value
)
.dependsOn(core, cli, output)
.dependsOn(core, output)

lazy val docs =
project
Expand Down
2 changes: 1 addition & 1 deletion docs/installation.md
Expand Up @@ -10,7 +10,7 @@ Every pull request is tested on a Linux machine. Official support for macOS in t

* **Java 8**

* **Scala @SCALA_VERSION@ or 2.13.3**
* **Tested Scala versions: @SCALA_VERSION@, 2.13.3, 2.13.5**

* **Sbt >= 1.3.4**

Expand Down
49 changes: 48 additions & 1 deletion project/SBTDefaults.scala
@@ -1,6 +1,6 @@
object SBTDefaults {

val defaultScalacFlags: List[String] =
lazy val defaultScalacFlags212: List[String] =
List(
"-encoding",
"UTF-8",
Expand Down Expand Up @@ -41,4 +41,51 @@ object SBTDefaults {
"-Xfatal-warnings"
)

lazy val defaultScalacFlags213: List[String] =
List(
"-encoding",
"UTF-8",
"-explaintypes",
"-unchecked",
"-feature",
"-Xlint:deprecation",
"-Werror",
"-Xcheckinit",
"-Xlint:constant",
"-Xlint:delayedinit-select",
"-Xlint:doc-detached",
"-Xlint:missing-interpolator",
"-Xlint:option-implicit",
"-Xlint:package-object-classes",
"-Xlint:poly-implicit-overload",
"-Xlint:private-shadow",
"-Xlint:stars-align",
"-Xlint:type-parameter-shadow",
"-Ywarn-dead-code",
"-Xlint:inaccessible",
"-Xlint:nullary-unit",
"-Ywarn-numeric-widen",
"-Ywarn-extra-implicit",
"-Xlint:infer-any",
"-Xlint:unused",
"-Ywarn-unused:patvars",
"-Xlint:adapted-args",
"-Ywarn-unused:params",
"-Ywarn-macros:after"
)

lazy val scalafixTestkitV: Map[String, String] =
Map(
// 2.12.x:
"2.12.10" -> "0.9.11",
"2.12.11" -> "0.9.18",
"2.12.12" -> "0.9.24",
"2.12.13" -> "0.9.26",
// 2.13.x:
"2.13.2" -> "0.9.17",
"2.13.3" -> "0.9.23",
"2.13.4" -> "0.9.25",
"2.13.5" -> "0.9.26"
)

}

0 comments on commit acd22c8

Please sign in to comment.