Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate arrow test modules #2753

Merged
merged 7 commits into from Jul 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions arrow-libs/core/arrow-core-test/api/arrow-core-test.api
Expand Up @@ -55,6 +55,10 @@ public final class arrow/core/test/concurrency/SideEffect {
public fun toString ()Ljava/lang/String;
}

public final class arrow/core/test/concurrency/SideEffectKt {
public static final field deprecateArrowTestModules Ljava/lang/String;
}

public final class arrow/core/test/generators/GeneratorsJvmKt {
public static final fun fatalThrowable (Lio/kotest/property/Arb$Companion;)Lio/kotest/property/Arb;
public static final fun suspendFunThatThrowsFatalThrowable (Lio/kotest/property/Arb$Companion;)Lio/kotest/property/Arb;
Expand Down
@@ -1,8 +1,14 @@
package arrow.core.test

import arrow.core.test.concurrency.deprecateArrowTestModules

@Deprecated(deprecateArrowTestModules)
public expect fun isJvm(): Boolean
@Deprecated(deprecateArrowTestModules)
public expect fun isJs(): Boolean
@Deprecated(deprecateArrowTestModules)
public expect fun isNative(): Boolean

@Deprecated(deprecateArrowTestModules)
public fun stackSafeIteration(): Int =
if (isJvm()) 500_000 else 1000
@@ -1,6 +1,7 @@
package arrow.core.test

import arrow.core.*
import arrow.core.test.concurrency.deprecateArrowTestModules
import arrow.core.test.generators.unit
import arrow.core.test.laws.Law
import io.kotest.core.names.TestName
Expand All @@ -22,31 +23,38 @@ import kotlin.math.max
/**
* Base class for unit tests
*/
@Deprecated(deprecateArrowTestModules)
public abstract class UnitSpec(
public val iterations: Int = 250,
public val maxDepth: Int = 15,
spec: UnitSpec.() -> Unit = {}
) : StringSpec() {

@Deprecated(deprecateArrowTestModules)
public constructor(spec: UnitSpec.() -> Unit) : this(250, 15, spec)

@Deprecated(deprecateArrowTestModules)
public fun <A> Arb.Companion.list(gen: Gen<A>, range: IntRange = 0..maxDepth): Arb<List<A>> =
Arb.KList(gen, range)

@Deprecated(deprecateArrowTestModules)
public fun <A> Arb.Companion.nonEmptyList(arb: Arb<A>, depth: Int = maxDepth): Arb<NonEmptyList<A>> {
return Arb.list(arb, 1..max(1, depth))
.map { Option.fromNullable(it.toNonEmptyListOrNull()) }
.filterIsInstance<Option<NonEmptyList<A>>, Some<NonEmptyList<A>>>()
.map { it.value }
}

@Deprecated(deprecateArrowTestModules)
public fun <A> Arb.Companion.sequence(arbA: Arb<A>, range: IntRange = 0..maxDepth): Arb<Sequence<A>> =
Arb.list(arbA, range).map { it.asSequence() }

@JvmOverloads
@Deprecated(deprecateArrowTestModules)
public inline fun <reified A> Arb.Companion.array(gen: Arb<A>, range: IntRange = 0..maxDepth): Arb<Array<A>> =
Arb.list(gen, range).map { it.toTypedArray() }

@Deprecated(deprecateArrowTestModules)
public fun <K, V> Arb.Companion.map(
keyArb: Arb<K>,
valueArb: Arb<V>,
Expand All @@ -59,6 +67,7 @@ public abstract class UnitSpec(
spec()
}

@Deprecated(deprecateArrowTestModules)
public fun testLaws(vararg laws: List<Law>): Unit = laws
.flatMap { list: List<Law> -> list.asIterable() }
.distinctBy { law: Law -> law.name }
Expand All @@ -68,6 +77,7 @@ public abstract class UnitSpec(
}
}

@Deprecated(deprecateArrowTestModules)
public fun testLaws(prefix: String, vararg laws: List<Law>): Unit = laws
.flatMap { list: List<Law> -> list.asIterable() }
.distinctBy { law: Law -> law.name }
Expand All @@ -77,9 +87,11 @@ public abstract class UnitSpec(
}
}

@Deprecated(deprecateArrowTestModules)
public suspend fun checkAll(property: suspend PropertyContext.() -> Unit): PropertyContext =
checkAll(iterations, Arb.unit()) { property() }

@Deprecated(deprecateArrowTestModules)
public suspend fun <A> checkAll(
genA: Arb<A>,
property: suspend PropertyContext.(A) -> Unit
Expand All @@ -90,6 +102,7 @@ public abstract class UnitSpec(
property
)

@Deprecated(deprecateArrowTestModules)
public suspend fun <A, B> checkAll(
genA: Arb<A>,
genB: Arb<B>,
Expand All @@ -102,6 +115,7 @@ public abstract class UnitSpec(
property
)

@Deprecated(deprecateArrowTestModules)
public suspend fun <A, B, C> checkAll(
genA: Arb<A>,
genB: Arb<B>,
Expand All @@ -116,6 +130,7 @@ public abstract class UnitSpec(
property
)

@Deprecated(deprecateArrowTestModules)
public suspend fun <A, B, C, D> checkAll(
genA: Arb<A>,
genB: Arb<B>,
Expand All @@ -132,6 +147,7 @@ public abstract class UnitSpec(
property
)

@Deprecated(deprecateArrowTestModules)
public suspend fun <A, B, C, D, E> checkAll(
genA: Arb<A>,
genB: Arb<B>,
Expand All @@ -150,6 +166,7 @@ public abstract class UnitSpec(
property
)

@Deprecated(deprecateArrowTestModules)
public suspend fun <A, B, C, D, E, F> checkAll(
genA: Arb<A>,
genB: Arb<B>,
Expand All @@ -170,6 +187,7 @@ public abstract class UnitSpec(
property
)

@Deprecated(deprecateArrowTestModules)
public suspend fun <A, B, C, D, E, F, G> checkAll(
gena: Arb<A>,
genb: Arb<B>,
Expand All @@ -185,6 +203,7 @@ public abstract class UnitSpec(
}
}

@Deprecated(deprecateArrowTestModules)
public suspend fun <A, B, C, D, E, F, G, H> checkAll(
gena: Arb<A>,
genb: Arb<B>,
Expand All @@ -201,6 +220,7 @@ public abstract class UnitSpec(
}
}

@Deprecated(deprecateArrowTestModules)
public suspend fun <A, B, C, D, E, F, G, H, I> checkAll(
gena: Arb<A>,
genb: Arb<B>,
Expand All @@ -218,6 +238,7 @@ public abstract class UnitSpec(
}
}

@Deprecated(deprecateArrowTestModules)
public suspend fun <A, B, C, D, E, F, G, H, I, J> checkAll(
gena: Arb<A>,
genb: Arb<B>,
Expand All @@ -243,6 +264,7 @@ public abstract class UnitSpec(
}
}

@Deprecated(deprecateArrowTestModules)
public suspend fun forFew(
iterations: Int,
property: suspend PropertyContext.(Unit) -> Unit
Expand Down
@@ -1,7 +1,12 @@
package arrow.core.test.concurrency

@Deprecated(deprecateArrowTestModules)
public data class SideEffect(var counter: Int = 0) {
@Deprecated(deprecateArrowTestModules)
public fun increment() {
counter++
}
}

public const val deprecateArrowTestModules: String =
"arrow test modules are being deprecated in favour of kotest-arrow-extension libraries"
Expand Up @@ -16,6 +16,7 @@ import arrow.core.Tuple9
import arrow.core.Validated
import arrow.core.left
import arrow.core.right
import arrow.core.test.concurrency.deprecateArrowTestModules
import arrow.core.toOption
import io.kotest.property.Arb
import io.kotest.property.arbitrary.bind
Expand All @@ -37,51 +38,65 @@ import io.kotest.property.arbitrary.string
import kotlin.Result.Companion.failure
import kotlin.Result.Companion.success
import kotlin.math.abs

@Deprecated(deprecateArrowTestModules)
public fun <A, B> Arb.Companion.functionAToB(arb: Arb<B>): Arb<(A) -> B> =
arb.map { b: B -> { _: A -> b } }

@Deprecated(deprecateArrowTestModules)
public fun <A> Arb.Companion.functionAAToA(arb: Arb<A>): Arb<(A, A) -> A> =
arb.map { a: A -> { _: A, _: A -> a } }

@Deprecated(deprecateArrowTestModules)
public fun <A, B> Arb.Companion.functionBAToB(arb: Arb<B>): Arb<(B, A) -> B> =
arb.map { b: B -> { _: B, _: A -> b } }

@Deprecated(deprecateArrowTestModules)
public fun <A, B> Arb.Companion.functionABToB(arb: Arb<B>): Arb<(A, B) -> B> =
arb.map { b: B -> { _: A, _: B -> b } }

@Deprecated(deprecateArrowTestModules)
public fun <A> Arb.Companion.functionToA(arb: Arb<A>): Arb<() -> A> =
arb.map { a: A -> { a } }

@Deprecated(deprecateArrowTestModules)
public fun Arb.Companion.throwable(): Arb<Throwable> =
Arb.of(listOf(RuntimeException(), NoSuchElementException(), IllegalArgumentException()))

@Deprecated(deprecateArrowTestModules)
public fun <A> Arb.Companion.result(arbA: Arb<A>): Arb<Result<A>> =
Arb.choice(arbA.map(::success), throwable().map(::failure))

@Deprecated(deprecateArrowTestModules)
public fun Arb.Companion.doubleSmall(): Arb<Double> =
Arb.numericDoubles(from = 0.0, to = 100.0)

@Deprecated(deprecateArrowTestModules)
public fun Arb.Companion.floatSmall(): Arb<Float> =
Arb.numericFloats(from = 0F, to = 100F)

@Deprecated(deprecateArrowTestModules)
public fun Arb.Companion.intSmall(factor: Int = 10000): Arb<Int> =
Arb.int((Int.MIN_VALUE / factor)..(Int.MAX_VALUE / factor))

@Deprecated(deprecateArrowTestModules)
public fun Arb.Companion.byteSmall(): Arb<Byte> =
Arb.byte(min = (Byte.MIN_VALUE / 10).toByte(), max = (Byte.MAX_VALUE / 10).toByte())

@Deprecated(deprecateArrowTestModules)
public fun Arb.Companion.shortSmall(): Arb<Short> {
val range = (Short.MIN_VALUE / 1000)..(Short.MAX_VALUE / 1000)
return Arb.short().filter { it in range }
}

@Deprecated(deprecateArrowTestModules)
public fun Arb.Companion.longSmall(): Arb<Long> =
Arb.long((Long.MIN_VALUE / 100000L)..(Long.MAX_VALUE / 100000L))

@Deprecated(deprecateArrowTestModules)
public fun <A, B, C, D> Arb.Companion.tuple4(arbA: Arb<A>, arbB: Arb<B>, arbC: Arb<C>, arbD: Arb<D>): Arb<Tuple4<A, B, C, D>> =
Arb.bind(arbA, arbB, arbC, arbD, ::Tuple4)

@Deprecated(deprecateArrowTestModules)
public fun <A, B, C, D, E> Arb.Companion.tuple5(
arbA: Arb<A>,
arbB: Arb<B>,
Expand All @@ -91,6 +106,7 @@ public fun <A, B, C, D, E> Arb.Companion.tuple5(
): Arb<Tuple5<A, B, C, D, E>> =
Arb.bind(arbA, arbB, arbC, arbD, arbE, ::Tuple5)

@Deprecated(deprecateArrowTestModules)
public fun <A, B, C, D, E, F> Arb.Companion.tuple6(
arbA: Arb<A>,
arbB: Arb<B>,
Expand All @@ -101,6 +117,7 @@ public fun <A, B, C, D, E, F> Arb.Companion.tuple6(
): Arb<Tuple6<A, B, C, D, E, F>> =
Arb.bind(arbA, arbB, arbC, arbD, arbE, arbF, ::Tuple6)

@Deprecated(deprecateArrowTestModules)
public fun <A, B, C, D, E, F, G> Arb.Companion.tuple7(
arbA: Arb<A>,
arbB: Arb<B>,
Expand All @@ -112,6 +129,7 @@ public fun <A, B, C, D, E, F, G> Arb.Companion.tuple7(
): Arb<Tuple7<A, B, C, D, E, F, G>> =
Arb.bind(arbA, arbB, arbC, arbD, arbE, arbF, arbG, ::Tuple7)

@Deprecated(deprecateArrowTestModules)
public fun <A, B, C, D, E, F, G, H> Arb.Companion.tuple8(
arbA: Arb<A>,
arbB: Arb<B>,
Expand All @@ -129,6 +147,7 @@ public fun <A, B, C, D, E, F, G, H> Arb.Companion.tuple8(
Tuple8(a, b, c, d, e, f, g, h)
}

@Deprecated(deprecateArrowTestModules)
public fun <A, B, C, D, E, F, G, H, I> Arb.Companion.tuple9(
arbA: Arb<A>,
arbB: Arb<B>,
Expand All @@ -147,6 +166,7 @@ public fun <A, B, C, D, E, F, G, H, I> Arb.Companion.tuple9(
Tuple9(a, b, c, d, e, f, g, h, i)
}

@Deprecated(deprecateArrowTestModules)
public fun <A, B, C, D, E, F, G, H, I, J> Arb.Companion.tuple10(
arbA: Arb<A>,
arbB: Arb<B>,
Expand All @@ -166,8 +186,10 @@ public fun <A, B, C, D, E, F, G, H, I, J> Arb.Companion.tuple10(
Tuple10(a, b, c, d, e, f, g, h, i, j)
}

@Deprecated(deprecateArrowTestModules)
public fun Arb.Companion.nonZeroInt(): Arb<Int> = Arb.int().filter { it != 0 }

@Deprecated(deprecateArrowTestModules)
public fun Arb.Companion.intPredicate(): Arb<(Int) -> Boolean> =
Arb.nonZeroInt().flatMap { num ->
val absNum = abs(num)
Expand All @@ -181,53 +203,68 @@ public fun Arb.Companion.intPredicate(): Arb<(Int) -> Boolean> =
)
}

@Deprecated(deprecateArrowTestModules)
public fun <A> Arb.Companion.endo(arb: Arb<A>): Arb<Endo<A>> = arb.map { a: A -> Endo<A> { a } }

@Deprecated(deprecateArrowTestModules)
public fun <B> Arb.Companion.option(arb: Arb<B>): Arb<Option<B>> =
arb.orNull().map { it.toOption() }

@Deprecated(deprecateArrowTestModules)
public fun <E, A> Arb.Companion.either(arbE: Arb<E>, arbA: Arb<A>): Arb<Either<E, A>> {
val arbLeft = arbE.map { Either.Left(it) }
val arbRight = arbA.map { Either.Right(it) }
return Arb.choice(arbLeft, arbRight)
}

@Deprecated(deprecateArrowTestModules)
public fun <E, A> Arb<E>.or(arbA: Arb<A>): Arb<Either<E, A>> = Arb.either(this, arbA)

@Deprecated(deprecateArrowTestModules)
public fun <E, A> Arb.Companion.validated(arbE: Arb<E>, arbA: Arb<A>): Arb<Validated<E, A>> =
Arb.either(arbE, arbA).map { Validated.fromEither(it) }

@Deprecated(deprecateArrowTestModules)
public fun Arb.Companion.unit(): Arb<Unit> =
Arb.constant(Unit)

@Deprecated(deprecateArrowTestModules)
public fun <A, B> Arb.Companion.ior(arbA: Arb<A>, arbB: Arb<B>): Arb<Ior<A, B>> =
arbA.alignWith(arbB) { it }

@Deprecated(deprecateArrowTestModules)
public fun <A, B> Arb.Companion.arbConst(arb: Arb<A>): Arb<Const<A, B>> =
arb.map { Const<A, B>(it) }

@Deprecated(deprecateArrowTestModules)
public fun <A> Arb<A>.eval(): Arb<Eval<A>> =
map { Eval.now(it) }

@Deprecated(deprecateArrowTestModules)
private fun <A, B, R> Arb<A>.alignWith(arbB: Arb<B>, transform: (Ior<A, B>) -> R): Arb<R> =
Arb.bind(this, arbB) { a, b -> transform(Ior.Both(a, b)) }

@Deprecated(deprecateArrowTestModules)
public fun Arb.Companion.suspendFunThatReturnsEitherAnyOrAnyOrThrows(): Arb<suspend () -> Either<Any, Any>> =
choice(
suspendFunThatReturnsAnyRight(),
suspendFunThatReturnsAnyLeft(),
suspendFunThatThrows()
)

@Deprecated(deprecateArrowTestModules)
public fun Arb.Companion.suspendFunThatReturnsAnyRight(): Arb<suspend () -> Either<Any, Any>> =
any().map { suspend { it.right() } }

@Deprecated(deprecateArrowTestModules)
public fun Arb.Companion.suspendFunThatReturnsAnyLeft(): Arb<suspend () -> Either<Any, Any>> =
any().map { suspend { it.left() } }

@Deprecated(deprecateArrowTestModules)
public fun Arb.Companion.suspendFunThatThrows(): Arb<suspend () -> Either<Any, Any>> =
throwable().map { suspend { throw it } } as Arb<suspend () -> Either<Any, Any>>

@Deprecated(deprecateArrowTestModules)
public fun Arb.Companion.any(): Arb<Any> =
choice(
Arb.string() as Arb<Any>,
Expand Down