diff --git a/jvm/src/test/scala/com.paulbutcher.test/proxy/ProxyMockTest.scala b/jvm/src/test/scala/com.paulbutcher.test/proxy/ProxyMockTest.scala index ed0e24fd..076c775e 100644 --- a/jvm/src/test/scala/com.paulbutcher.test/proxy/ProxyMockTest.scala +++ b/jvm/src/test/scala/com.paulbutcher.test/proxy/ProxyMockTest.scala @@ -133,6 +133,10 @@ class ProxyMockTest extends AnyFreeSpec with MockFactory { } /* + + //! TODO - in scala 3 we can't distinguish abstract var setters with non abstract vars setters + // TODO and override modifier is not allowed when overriding abstract vars + "cope with a var" in { withExpectations { val m = mock[TestTrait] diff --git a/shared/src/main/scala-3/org/scalamock/clazz/MockMaker.scala b/shared/src/main/scala-3/org/scalamock/clazz/MockMaker.scala index 05bf4239..516258a1 100644 --- a/shared/src/main/scala-3/org/scalamock/clazz/MockMaker.scala +++ b/shared/src/main/scala-3/org/scalamock/clazz/MockMaker.scala @@ -21,7 +21,6 @@ package org.scalamock.clazz import org.scalamock.context.MockContext -import org.scalamock.util.Defaultable import scala.quoted.* import scala.reflect.Selectable diff --git a/shared/src/main/scala-3/org/scalamock/clazz/Utils.scala b/shared/src/main/scala-3/org/scalamock/clazz/Utils.scala index 28d54679..345a47bf 100644 --- a/shared/src/main/scala-3/org/scalamock/clazz/Utils.scala +++ b/shared/src/main/scala-3/org/scalamock/clazz/Utils.scala @@ -126,7 +126,7 @@ private[clazz] class Utils(using val quotes: Quotes): def apply(tpe: TypeRepr): List[MockableDefinition] = val methods = (tpe.typeSymbol.methodMembers.toSet -- TypeRepr.of[Object].typeSymbol.methodMembers).toList - .filter(sym => !sym.flags.is(Flags.Private) && !sym.flags.is(Flags.Final)) + .filter(sym => !sym.flags.is(Flags.Private) && !sym.flags.is(Flags.Final) && !sym.flags.is(Flags.Mutable)) .filterNot(sym => tpe.memberType(sym) match case defaultParam @ ByNameType(AnnotatedType(_, Apply(Select(New(Inferred()), ""), Nil))) => true case _ => false diff --git a/shared/src/test/scala-2/VarSpec.scala b/shared/src/test/scala-2/VarSpec.scala new file mode 100644 index 00000000..ad61b0ca --- /dev/null +++ b/shared/src/test/scala-2/VarSpec.scala @@ -0,0 +1,26 @@ +package com.paulbutcher.test + +import org.scalamock.scalatest.MockFactory +import org.scalatest.funspec.AnyFunSpec + +class VarSpec extends AnyFunSpec with MockFactory { + + autoVerify = false + + trait Vars { + var aVar: String + var concreteVar = "foo" + } + + it("mock traits with vars") { + withExpectations { + val m = mock[Vars] + (m.aVar_= _).expects("foo") + (() => m.aVar).expects().returning("bar") + m.aVar = "foo" + assertResult("bar") { + m.aVar + } + } + } +} \ No newline at end of file diff --git a/shared/src/test/scala-3/com/paulbutcher/test/VarSpec.scala b/shared/src/test/scala-3/com/paulbutcher/test/VarSpec.scala new file mode 100644 index 00000000..40294f95 --- /dev/null +++ b/shared/src/test/scala-3/com/paulbutcher/test/VarSpec.scala @@ -0,0 +1,19 @@ +package com.paulbutcher.test + +import org.scalamock.scalatest.MockFactory +import org.scalatest.funspec.AnyFunSpec + +class VarSpec extends AnyFunSpec with MockFactory { + + trait Vars { + var aVar: Int = scala.compiletime.uninitialized + var concreteVar = "foo" + } + + it("mock traits with vars") { + val m = mock[Vars] + m.aVar = 6 + m.concreteVar = "bar" + } + +} diff --git a/shared/src/test/scala/com/paulbutcher/test/TestTrait.scala b/shared/src/test/scala/com/paulbutcher/test/TestTrait.scala index 7c2dedde..31d1620a 100644 --- a/shared/src/test/scala/com/paulbutcher/test/TestTrait.scala +++ b/shared/src/test/scala/com/paulbutcher/test/TestTrait.scala @@ -55,9 +55,6 @@ trait TestTrait { def otherPackageUpperBound[T <: SomeClass](x: T): T def explicitPackageReference(x: yet.another.pkg.YetAnotherClass): yet.another.pkg.YetAnotherClass def explicitPackageUpperBound[T <: yet.another.pkg.YetAnotherClass](x: T): T - - //var aVar: String - //var concreteVar = "foo" val aVal: String val concreteVal = "foo" diff --git a/shared/src/test/scala/com/paulbutcher/test/mock/MockTest.scala b/shared/src/test/scala/com/paulbutcher/test/mock/MockTest.scala index 5f6dd8cd..cdd5f31a 100644 --- a/shared/src/test/scala/com/paulbutcher/test/mock/MockTest.scala +++ b/shared/src/test/scala/com/paulbutcher/test/mock/MockTest.scala @@ -35,17 +35,20 @@ class MockTest extends AnyFreeSpec with MockFactory with Matchers { autoVerify = false - "Mocks should" - {/* - "cope with a var" in { + "Mocks should" - { + //! TODO - in scala 3 we can't distinguish abstract var setters with non abstract vars setters + // TODO and override modifier is not allowed when overriding abstract vars + /* + "cope with a var" in { withExpectations { val m = mock[TestTrait] (m.aVar_= _).expects("foo") (() => m.aVar).expects().returning("bar") m.aVar = "foo" - assertResult("bar") { m.aVar } + assertResult(null) { m.aVar } } - } - */ + }*/ + "fail if an unexpected method call is made" in { withExpectations { val m = mock[TestTrait]