-
Notifications
You must be signed in to change notification settings - Fork 98
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
only cast null constructor args for primitives (#520)
* only cast null for primitives before, we tried to cast applied types to the type arguments, to capture context bounds. That fails for simple generic types that then get cast to the wrong type. However, that's all unnessecary: the only nulls we need to cast are primitives, which can't be passed as null. Anyting else doesn't need a cast at all * add failing tests * ignore failing tests * fix class type parameters * add tests from passer-by * move test that don't (yet) pass on scala 2 to scala 3 specific testsuite * simply getting target
- Loading branch information
1 parent
8de4b7b
commit 2f7b22c
Showing
3 changed files
with
91 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
shared/src/test/scala-3/com/paulbutcher/test/MockTestScala3.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package com.paulbutcher.test | ||
|
||
// Copyright (c) 2011-2015 ScalaMock Contributors (https://github.com/paulbutcher/ScalaMock/graphs/contributors) | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// of this software and associated documentation files (the "Software"), to deal | ||
// in the Software without restriction, including without limitation the rights | ||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
// copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in | ||
// all copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
// THE SOFTWARE. | ||
|
||
package com.paulbutcher.test.mock | ||
|
||
import org.scalamock.scalatest.MockFactory | ||
|
||
import com.paulbutcher.test._ | ||
import org.scalatest.freespec.AnyFreeSpec | ||
import org.scalatest.matchers.should.Matchers | ||
|
||
class MockTestScala3 extends AnyFreeSpec with MockFactory with Matchers { | ||
|
||
autoVerify = false | ||
|
||
"In Scala 3, Mocks should" - { | ||
|
||
"mock type constructor arguments" in { | ||
class WithTC[TC[_]](tc: TC[Int]) | ||
type ID[A] = A | ||
"mock[WithTC[List]]" should compile | ||
pendingUntilFixed { | ||
"mock[WithTC[ID]]" should compile | ||
} | ||
} | ||
|
||
"mock generic arguments" in { | ||
class WithGeneric[T](t: T) | ||
"mock[WithGeneric[String]]" should compile | ||
"mock[WithGeneric[Int]]" should compile | ||
} | ||
|
||
"mock type constructor context bounds" in { | ||
trait Async[F[_]] | ||
class A[F[_]: Async](val b: B[F]) | ||
class B[F[_]: Async](val c: C[F]) | ||
trait C[F[_]] | ||
"mock[A[List]]" should compile | ||
"mock[B[List]]" should compile | ||
"mock[C[List]]" should compile | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters