Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@

# Scala Steward: Reformat with scalafmt 3.9.10
1d6b2d8f534c6fa2ede2e46c872e09f7704bdbed

# Scala Steward: Reformat with scalafmt 3.10.3
a0fad8dd5688098638685391cff1ca662b46cd44
2 changes: 1 addition & 1 deletion .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version = "3.10.1"
version = "3.10.3"

runner.dialect=scala213source3

Expand Down
6 changes: 4 additions & 2 deletions scalafix/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,13 @@ lazy val v0_9_0_tests = makeTests("v0_9_0", v0_9_0_input, v0_9_0_output)
lazy val v0_11_0_input =
makeInput("v0_11_0", "org.typelevel" %% "weaver-cats" % "0.10.1")
lazy val v0_11_0_output =
makeOutput("v0_11_0", "org.typelevel" %% "weaver-cats" % "0.11-799b8e6-SNAPSHOT")
makeOutput("v0_11_0",
"org.typelevel" %% "weaver-cats" % "0.11-799b8e6-SNAPSHOT")
lazy val v0_11_0_tests = makeTests("v0_11_0", v0_11_0_input, v0_11_0_output)

lazy val testsAggregate = Project("tests", file("target/testsAggregate"))
.aggregate(v0_8_3_tests.projectRefs ++ v0_9_0_tests.projectRefs ++ v0_11_0_tests.projectRefs: _*)
.aggregate(
v0_8_3_tests.projectRefs ++ v0_9_0_tests.projectRefs ++ v0_11_0_tests.projectRefs: _*)
.settings(
publish / skip := true
)
Expand Down
6 changes: 3 additions & 3 deletions scalafix/rules/src/main/scala/fix/AddClueToExpect.scala
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ class AddClueToExpect extends SemanticRule("AddClueToExpect") {

private def makeClue(expr: Term)(implicit doc: SemanticDocument): Term = {
expr match {
case _: Term.Name => q"clue($expr)"
case _: Term.Apply => q"clue($expr)"
case _: Term.Name => q"clue($expr)"
case _: Term.Apply => q"clue($expr)"
case _: Term.Select => q"clue($expr)"
case _ => expr
case _ => expr
}
}

Expand Down
15 changes: 11 additions & 4 deletions scalafix/rules/src/main/scala/fix/RemoveTagged.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,20 @@ class RemoveTagged extends SemanticRule("RemoveTagged") {

override def fix(implicit doc: SemanticDocument): Patch = {
val taggedMethod =
SymbolMatcher.normalized("weaver/Expectations.Helpers#StringOps#tagged().")
SymbolMatcher.normalized(
"weaver/Expectations.Helpers#StringOps#tagged().")
doc.tree.collect {
case tree @ Term.Apply.After_4_6_0(Term.Select(testName, taggedMethod(_)), Term.ArgClause(List(Lit.String("ignore")), None)) =>
case tree @ Term.Apply.After_4_6_0(
Term.Select(testName, taggedMethod(_)),
Term.ArgClause(List(Lit.String("ignore")), None)) =>
Patch.replaceTree(tree, q"$testName.ignore".toString)
case tree @ Term.Apply.After_4_6_0(Term.Select(testName, taggedMethod(_)), Term.ArgClause(List(Lit.String("only")), None)) =>
case tree @ Term.Apply.After_4_6_0(
Term.Select(testName, taggedMethod(_)),
Term.ArgClause(List(Lit.String("only")), None)) =>
Patch.replaceTree(tree, q"$testName.only".toString)
case tree @ Term.Apply.After_4_6_0(Term.Select(testName, taggedMethod(_)), Term.ArgClause(List(Lit.String(other)), None)) =>
case tree @ Term.Apply.After_4_6_0(
Term.Select(testName, taggedMethod(_)),
Term.ArgClause(List(Lit.String(other)), None)) =>
Patch.replaceTree(tree, s"$testName")
}.asPatch
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,20 @@ package fix

import scalafix.v1._
import scala.meta._
class RenameAssertionExceptionToExpectationFailed extends SemanticRule("RenameAssertionExceptionToExpectationFailed") {
class RenameAssertionExceptionToExpectationFailed
extends SemanticRule("RenameAssertionExceptionToExpectationFailed") {

override def fix(implicit doc: SemanticDocument): Patch = {
val symbol = SymbolMatcher.normalized("weaver/AssertionException")
doc.tree.collect {
case symbol(tree) =>
tree match {
case q"AssertionException" => Patch.replaceTree(tree, s"new ExpectationFailed")
case t"AssertionException" => Patch.replaceTree(tree, s"ExpectationFailed")
case importee"AssertionException" => Patch.replaceTree(tree, s"ExpectationFailed")
case q"AssertionException" =>
Patch.replaceTree(tree, s"new ExpectationFailed")
case t"AssertionException" =>
Patch.replaceTree(tree, s"ExpectationFailed")
case importee"AssertionException" =>
Patch.replaceTree(tree, s"ExpectationFailed")
case _ => Patch.empty
}
}.asPatch
Expand Down
29 changes: 21 additions & 8 deletions scalafix/rules/src/main/scala/fix/v0_11_0.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ import scala.meta._
class v0_11_0 extends SemanticRule("v0_11_0") {

override def fix(implicit doc: SemanticDocument): Patch =
List(renameCancelToIgnore, renameAssertionException, removeTagged, renameVerify).asPatch
List(renameCancelToIgnore,
renameAssertionException,
removeTagged,
renameVerify).asPatch

def renameCancelToIgnore(implicit doc: SemanticDocument): Patch = {
val cancelMethod =
Expand All @@ -26,23 +29,33 @@ class v0_11_0 extends SemanticRule("v0_11_0") {
doc.tree.collect {
case symbol(tree) =>
tree match {
case q"AssertionException" => Patch.replaceTree(tree, s"new ExpectationFailed")
case t"AssertionException" => Patch.replaceTree(tree, s"ExpectationFailed")
case importee"AssertionException" => Patch.replaceTree(tree, s"ExpectationFailed")
case q"AssertionException" =>
Patch.replaceTree(tree, s"new ExpectationFailed")
case t"AssertionException" =>
Patch.replaceTree(tree, s"ExpectationFailed")
case importee"AssertionException" =>
Patch.replaceTree(tree, s"ExpectationFailed")
case _ => Patch.empty
}
}.asPatch
}

def removeTagged(implicit doc: SemanticDocument): Patch = {
val taggedMethod =
SymbolMatcher.normalized("weaver/Expectations.Helpers#StringOps#tagged().")
SymbolMatcher.normalized(
"weaver/Expectations.Helpers#StringOps#tagged().")
doc.tree.collect {
case tree @ Term.Apply.After_4_6_0(Term.Select(testName, taggedMethod(_)), Term.ArgClause(List(Lit.String("ignore")), None)) =>
case tree @ Term.Apply.After_4_6_0(
Term.Select(testName, taggedMethod(_)),
Term.ArgClause(List(Lit.String("ignore")), None)) =>
Patch.replaceTree(tree, q"$testName.ignore".toString)
case tree @ Term.Apply.After_4_6_0(Term.Select(testName, taggedMethod(_)), Term.ArgClause(List(Lit.String("only")), None)) =>
case tree @ Term.Apply.After_4_6_0(
Term.Select(testName, taggedMethod(_)),
Term.ArgClause(List(Lit.String("only")), None)) =>
Patch.replaceTree(tree, q"$testName.only".toString)
case tree @ Term.Apply.After_4_6_0(Term.Select(testName, taggedMethod(_)), Term.ArgClause(List(Lit.String(other)), None)) =>
case tree @ Term.Apply.After_4_6_0(
Term.Select(testName, taggedMethod(_)),
Term.ArgClause(List(Lit.String(other)), None)) =>
Patch.replaceTree(tree, s"$testName")
}.asPatch
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,23 @@ import cats.effect.IO
object RenameAssertionExceptionToExpectationFailed extends SimpleIOSuite {

test("raise") {
IO.raiseError(AssertionException("some reason", NonEmptyList.of(implicitly[SourceLocation]))).as(success)
IO.raiseError(AssertionException(
"some reason",
NonEmptyList.of(implicitly[SourceLocation]))).as(success)
}

test("match") {
val program: IO[Unit] = IO.unit
program.attemptTap {
case Left(ex: AssertionException) => IO.println(ex)
case _ => IO.unit
case _ => IO.unit
}.as(success)
}

test("import") {
import weaver.AssertionException
IO.raiseError(AssertionException("some reason", NonEmptyList.of(implicitly[SourceLocation]))).as(success)
IO.raiseError(AssertionException(
"some reason",
NonEmptyList.of(implicitly[SourceLocation]))).as(success)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,23 @@ import cats.effect.IO
object RenameAssertionExceptionToExpectationFailed extends SimpleIOSuite {

test("raise") {
IO.raiseError(new ExpectationFailed("some reason", NonEmptyList.of(implicitly[SourceLocation]))).as(success)
IO.raiseError(new ExpectationFailed(
"some reason",
NonEmptyList.of(implicitly[SourceLocation]))).as(success)
}

test("match") {
val program: IO[Unit] = IO.unit
program.attemptTap {
case Left(ex: ExpectationFailed) => IO.println(ex)
case _ => IO.unit
case _ => IO.unit
}.as(success)
}

test("import") {
import weaver.ExpectationFailed
IO.raiseError(new ExpectationFailed("some reason", NonEmptyList.of(implicitly[SourceLocation]))).as(success)
IO.raiseError(new ExpectationFailed(
"some reason",
NonEmptyList.of(implicitly[SourceLocation]))).as(success)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ object AddClueToExpectTest extends SimpleIOSuite {
expect(!a.isInstanceOf[Int])
}

pureTest("select"){
pureTest("select") {
val either = Left[Int, Int](1)
expect(either.toOption.isEmpty)
}
Expand Down Expand Up @@ -79,7 +79,7 @@ object AddClueToExpectTest extends SimpleIOSuite {
}

pureTest("ignore blocks") {
expect(Some(1).fold(true)({_ => b == c }))
expect(Some(1).fold(true)({ _ => b == c }))
}

}
10 changes: 5 additions & 5 deletions scalafix/v0_9_0/input/src/main/scala/fix/RewriteExpectTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ object RewriteExpectTest extends SimpleIOSuite {
pureTest("infer order with sealed traits") {
sealed trait Pet
object Pet {
case object Cat extends Pet
case object Cat extends Pet
case class Dog(friend: Pet) extends Pet
}
val petCat = Pet.Cat
Expand All @@ -107,10 +107,10 @@ object RewriteExpectTest extends SimpleIOSuite {

pureTest("infer order with common names") {
val expectedId = 1
val actualId = 2
val actualId = 2
val obtainedId = 3
val result = 4
expect(result == expectedId && actualId == expectedId && obtainedId == expectedId)
val result = 4
expect(
result == expectedId && actualId == expectedId && obtainedId == expectedId)
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ object AddClueToExpectTest extends SimpleIOSuite {
val c: Int = 3

pureTest("multiple") {
expect(clue(a) == clue(b)) and expect(clue(b) == clue(c)) && not(expect(clue(c) == clue(a)))
expect(clue(a) == clue(b)) and expect(clue(b) == clue(c)) && not(
expect(clue(c) == clue(a)))
}

pureTest("infix") {
Expand Down Expand Up @@ -41,7 +42,7 @@ object AddClueToExpectTest extends SimpleIOSuite {
expect(!clue(a).isInstanceOf[Int])
}

pureTest("select"){
pureTest("select") {
val either = Left[Int, Int](1)
expect(clue(either.toOption).isEmpty)
}
Expand All @@ -64,7 +65,9 @@ object AddClueToExpectTest extends SimpleIOSuite {

pureTest("all") {
def isGreater(a: Int, b: Int, c: Int): Boolean = a > b && b > c
expect.all(clue(a) == clue(b), clue(Some(2)).nonEmpty, isGreater(clue(a), clue(b), clue(c)))
expect.all(clue(a) == clue(b),
clue(Some(2)).nonEmpty,
isGreater(clue(a), clue(b), clue(c)))
}

pureTest("ignore clue in expect.all") {
Expand All @@ -77,8 +80,8 @@ object AddClueToExpectTest extends SimpleIOSuite {

pureTest("ignore blocks") {
expect(clue(Some(1)).fold(true) {
_ => b == c
})
_ => b == c
})
}

}
38 changes: 21 additions & 17 deletions scalafix/v0_9_0/output/src/main/scala/fix/RewriteExpectTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ object RewriteExpectTest extends SimpleIOSuite {
}

pureTest("nested ==") {
expect.same(1, 1).and(expect.same(2, 2)) and expect.same(1, 1).and(expect(2 >= 2))
expect.same(1, 1).and(expect.same(2, 2)) and expect.same(1, 1).and(expect(
2 >= 2))
}

pureTest("===") {
Expand All @@ -37,27 +38,28 @@ object RewriteExpectTest extends SimpleIOSuite {
}

pureTest("if then else if") {
if (1 == 2) expect(3 > 4) else if (2 == 3) expect.same(5, 5) else expect(4 > 3)
if (1 == 2) expect(3 > 4)
else if (2 == 3) expect.same(5, 5) else expect(4 > 3)
}

pureTest("match") {
val n: Int = 1
n match {
case 2 =>
expect(1 > 2)
case 3 =>
success
case 4 =>
failure("Assertion failed")
}
case 2 =>
expect(1 > 2)
case 3 =>
success
case 4 =>
failure("Assertion failed")
}
}

pureTest("match with wildcard false") {
val n: Int = 1
matches(n) {
case 2 =>
expect(1 > 2)
}
case 2 =>
expect(1 > 2)
}
}

pureTest("expect.all ==") {
Expand All @@ -77,7 +79,8 @@ object RewriteExpectTest extends SimpleIOSuite {
}

pureTest("expect.all with || and &&") {
expect(1 > 0).and(expect.same(2, 2)).and(expect(2 > 0).or(expect(3 > 4))).and(expect.same(2, 2))
expect(1 > 0).and(expect.same(2, 2)).and(expect(
2 > 0).or(expect(3 > 4))).and(expect.same(2, 2))
}

pureTest("expect.all ignore clue") {
Expand All @@ -97,7 +100,7 @@ object RewriteExpectTest extends SimpleIOSuite {
pureTest("infer order with sealed traits") {
sealed trait Pet
object Pet {
case object Cat extends Pet
case object Cat extends Pet
case class Dog(friend: Pet) extends Pet
}
val petCat = Pet.Cat
Expand All @@ -107,9 +110,10 @@ object RewriteExpectTest extends SimpleIOSuite {

pureTest("infer order with common names") {
val expectedId = 1
val actualId = 2
val actualId = 2
val obtainedId = 3
val result = 4
expect.same(expectedId, result).and(expect.same(expectedId, actualId)).and(expect.same(expectedId, obtainedId))
val result = 4
expect.same(expectedId, result).and(expect.same(expectedId, actualId)).and(
expect.same(expectedId, obtainedId))
}
}