Skip to content

Solve update kotlintest problems #1255

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

Merged
merged 27 commits into from
Jan 24, 2019
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
8abd029
fix bad merge
AdrianRaFo Jan 17, 2019
2e24093
fix laws not running
AdrianRaFo Jan 17, 2019
e33e6cf
fix deprecations
AdrianRaFo Jan 17, 2019
1956c6a
fix some laws
AdrianRaFo Jan 17, 2019
77e0d12
Merge branch 'master' into arf-solve-update-kotlintest-problems
raulraja Jan 17, 2019
82bd9ea
revert Coroutines dispatcher
AdrianRaFo Jan 17, 2019
3f7d8e5
add also regular test
AdrianRaFo Jan 17, 2019
c3b56cf
Merge remote-tracking branch 'origin/arf-solve-update-kotlintest-prob…
AdrianRaFo Jan 17, 2019
658114c
minor fix
AdrianRaFo Jan 17, 2019
97ad2b0
Merge branch 'master' into arf-solve-update-kotlintest-problems
nomisRev Jan 20, 2019
0165140
fix local IO test problems
AdrianRaFo Jan 20, 2019
5e18367
Fix ReactiveX integration Bracket implementations.
nomisRev Jan 21, 2019
52e34b1
Fix Reactor integration Bracket implementations.
nomisRev Jan 22, 2019
641817e
Merge branch 'master' into arf-solve-update-kotlintest-problems
nomisRev Jan 22, 2019
4ccd3fc
Merge branch 'master' into arf-solve-update-kotlintest-problems
nomisRev Jan 22, 2019
4fc771b
Merge branch 'master' into arf-solve-update-kotlintest-problems
raulraja Jan 23, 2019
7ab9e5d
Add comment about influence parallelism on tests
nomisRev Jan 23, 2019
f8a4778
Remove DeferredK integration
nomisRev Jan 23, 2019
3c3ff6b
set as expression body
AdrianRaFo Jan 23, 2019
27dcec9
Merge remote-tracking branch 'origin/arf-solve-update-kotlintest-prob…
AdrianRaFo Jan 23, 2019
f7e7c67
Merge branch 'master' into arf-solve-update-kotlintest-problems
raulraja Jan 23, 2019
f77b683
delete bad dependencies and fix some samples
AdrianRaFo Jan 24, 2019
fb29687
Rewrote Fiber docs, added coroutines-core to docs module
nomisRev Jan 24, 2019
b68492b
delete Deferred from docs
AdrianRaFo Jan 24, 2019
0ac2ee2
Merge remote-tracking branch 'origin/arf-solve-update-kotlintest-prob…
AdrianRaFo Jan 24, 2019
6fd968f
delete unused deps
AdrianRaFo Jan 24, 2019
1db676c
delete more unused deps
AdrianRaFo Jan 24, 2019
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
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ import arrow.typeclasses.Conested
import arrow.typeclasses.Eq
import arrow.typeclasses.conest
import arrow.typeclasses.counnest
import io.kotlintest.matchers.shouldBe
import io.kotlintest.properties.Gen
import io.kotlintest.properties.forAll
import io.kotlintest.runner.junit4.KotlinTestRunner
import io.kotlintest.shouldBe
import org.junit.runner.RunWith

@RunWith(KotlinTestRunner::class)
Expand Down
24 changes: 7 additions & 17 deletions modules/core/arrow-test/src/main/kotlin/arrow/test/UnitSpec.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package arrow.test

import arrow.test.laws.Law
import arrow.typeclasses.Eq
import io.kotlintest.TestCase
import io.kotlintest.TestType
import io.kotlintest.specs.AbstractStringSpec
Expand All @@ -11,28 +10,19 @@ import io.kotlintest.specs.AbstractStringSpec
*/
abstract class UnitSpec : AbstractStringSpec() {

private val lawTestCases = mutableListOf<TestCase>()

fun testLaws(vararg laws: List<Law>): List<TestCase> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this be an expression body like

fun testLaws(vararg laws: List<Law>): List<TestCase> = laws.flatMap { ...

laws
return laws
.flatMap { list: List<Law> -> list.asIterable() }
.distinctBy { law: Law -> law.name }
.map { law: Law ->
createTestCase(law.name, law.test, defaultTestCaseConfig, TestType.Test)
val lawTestCase = createTestCase(law.name, law.test, defaultTestCaseConfig, TestType.Test)
lawTestCases.add(lawTestCase)
lawTestCase
}
return testCases()
}

override fun testCases(): List<TestCase> = super.testCases() + lawTestCases

fun <F> Eq<F>.logged(): Eq<F> = Eq { a, b ->
try {
val result = a.eqv(b)
if (!result) {
println("$a <---> $b")
}
result
} catch (t: Throwable) {
println("EXCEPTION: ${t.message}")
println("$a <---> $b")
false
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -303,18 +303,18 @@ class IOTest : UnitSpec() {
parMapN(newSingleThreadContext("here"),
IO { Thread.currentThread().name },
IO.defer { IO.just(Thread.currentThread().name) },
IO.async<String> { TODO, cb -> cb(Thread.currentThread().name.right()) },
IO.async<String> { _, cb -> cb(Thread.currentThread().name.right()) },
::Tuple3)
.unsafeRunSync()

result shouldBe Tuple3("here", "here", "here")
}

"unsafeRunAsyncCancellable should cancel correctly" {
IO.async { TODO, cb: (Either<Throwable, Int>) -> Unit ->
IO.async { _, cb: (Either<Throwable, Int>) -> Unit ->
val cancel =
IO(newSingleThreadContext("RunThread")) { }
.flatMap { IO.async<Int> { TODO, cb -> Thread.sleep(500); cb(1.right()) } }
.flatMap { IO.async<Int> { _, cb -> Thread.sleep(500); cb(1.right()) } }
.unsafeRunAsyncCancellable(OnCancel.Silent) {
cb(it)
}
Expand All @@ -324,12 +324,12 @@ class IOTest : UnitSpec() {
}

"unsafeRunAsyncCancellable should throw the appropriate exception" {
IO.async<Throwable> { TODO, cb ->
IO.async<Throwable> { _, cb ->
val cancel =
IO(newSingleThreadContext("RunThread")) { }
.flatMap { IO.async<Int> { TODO, cb -> Thread.sleep(500); cb(1.right()) } }
.flatMap { IO.async<Int> { _, cb -> Thread.sleep(500); cb(1.right()) } }
.unsafeRunAsyncCancellable(OnCancel.ThrowCancellationException) {
it.fold({ t -> cb(t.right()) }, { _ -> })
it.fold({ t -> cb(t.right()) }, { })
}
IO(newSingleThreadContext("CancelThread")) { }
.unsafeRunAsync { cancel() }
Expand All @@ -351,10 +351,10 @@ class IOTest : UnitSpec() {
}

"unsafeRunAsyncCancellable can cancel even for infinite asyncs" {
IO.async { TODO, cb: (Either<Throwable, Int>) -> Unit ->
IO.async { _, cb: (Either<Throwable, Int>) -> Unit ->
val cancel =
IO(newSingleThreadContext("RunThread")) { }
.flatMap { IO.async<Int> { TODO, _ -> Thread.sleep(5000); } }
.flatMap { IO.async<Int> { _, _ -> Thread.sleep(5000); } }
.unsafeRunAsyncCancellable(OnCancel.ThrowCancellationException) {
cb(it)
}
Expand Down Expand Up @@ -388,7 +388,7 @@ class IOTest : UnitSpec() {

"Cancelable should run CancelToken" {
Promise.uncancelable<ForIO, Unit>(IO.async()).flatMap { p ->
IO.async().cancelable<Unit> { _ ->
IO.async().cancelable<Unit> {
p.complete(Unit)
}.fix()
.unsafeRunAsyncCancellable { }
Expand All @@ -400,7 +400,7 @@ class IOTest : UnitSpec() {

"CancelableF should run CancelToken" {
Promise.uncancelable<ForIO, Unit>(IO.async()).flatMap { p ->
IO.async().cancelableF<Unit> { _ ->
IO.async().cancelableF<Unit> {
IO { p.complete(Unit) }
}.fix()
.unsafeRunAsyncCancellable { }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ import arrow.effects.extensions.io.monad.flatMap
import arrow.effects.extensions.io.monadDefer.monadDefer
import arrow.test.UnitSpec
import arrow.test.generators.genThrowable
import io.kotlintest.matchers.shouldBe
import io.kotlintest.runner.junit4.KotlinTestRunner
import io.kotlintest.properties.Gen
import io.kotlintest.properties.forAll
import io.kotlintest.shouldBe
import kotlinx.coroutines.Dispatchers
import org.junit.runner.RunWith
import java.lang.RuntimeException
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ import arrow.effects.extensions.io.monadDefer.monadDefer
import arrow.test.UnitSpec
import arrow.test.generators.genFunctionAToB
import arrow.test.laws.equalUnderTheLaw
import io.kotlintest.matchers.shouldBe
import io.kotlintest.properties.Gen
import io.kotlintest.properties.forAll
import io.kotlintest.runner.junit4.KotlinTestRunner
import io.kotlintest.shouldBe
import kotlinx.coroutines.Dispatchers
import org.junit.runner.RunWith

Expand Down
17 changes: 0 additions & 17 deletions modules/effects/arrow-effects-kotlinx-coroutines/build.gradle

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ import arrow.data.*
import arrow.data.extensions.list.foldable.nonEmpty
import arrow.data.extensions.listk.eq.eq
import arrow.test.UnitSpec
import arrow.test.generators.genFunctionAToB
import arrow.test.generators.genTry
import arrow.test.generators.genTuple
import arrow.test.generators.*
import arrow.test.laws.OptionalLaws
import arrow.test.laws.SetterLaws
import arrow.test.laws.TraversalLaws
Expand All @@ -27,7 +25,7 @@ class OptionalTest : UnitSpec() {

testLaws(OptionalLaws.laws(
optional = optionalHead,
aGen = Gen.list(Gen.int()),
aGen = genNonEmptyList(Gen.int()).map { it.all },
bGen = Gen.int(),
funcGen = genFunctionAToB(Gen.int()),
EQA = Eq.any(),
Expand All @@ -45,7 +43,7 @@ class OptionalTest : UnitSpec() {

testLaws(OptionalLaws.laws(
optional = optionalHead.first(),
aGen = genTuple(Gen.list(Gen.int()), Gen.bool()),
aGen = genTuple(genNonEmptyList(Gen.int()).map { it.all }, Gen.bool()),
bGen = genTuple(Gen.int(), Gen.bool()),
funcGen = genFunctionAToB(genTuple(Gen.int(), Gen.bool())),
EQA = Eq.any(),
Expand All @@ -54,7 +52,7 @@ class OptionalTest : UnitSpec() {

testLaws(OptionalLaws.laws(
optional = optionalHead.first(),
aGen = genTuple(Gen.list(Gen.int()), Gen.bool()),
aGen = genTuple(genNonEmptyList(Gen.int()).map { it.all }, Gen.bool()),
bGen = genTuple(Gen.int(), Gen.bool()),
funcGen = genFunctionAToB(genTuple(Gen.int(), Gen.bool())),
EQA = Eq.any(),
Expand All @@ -63,7 +61,7 @@ class OptionalTest : UnitSpec() {

testLaws(OptionalLaws.laws(
optional = optionalHead.second(),
aGen = genTuple(Gen.bool(), Gen.list(Gen.int())),
aGen = genTuple(Gen.bool(), genNonEmptyList(Gen.int()).map { it.all }),
bGen = genTuple(Gen.bool(), Gen.int()),
funcGen = genFunctionAToB(genTuple(Gen.bool(), Gen.int())),
EQA = Eq.any(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class ListTest : UnitSpec() {

testLaws(OptionalLaws.laws(
optional = ListK.head(),
aGen = Gen.list(Gen.int()),
aGen = genNonEmptyList(Gen.int()).map { it.all },
bGen = Gen.int(),
funcGen = genFunctionAToB(Gen.int()),
EQA = Eq.any(),
Expand All @@ -35,9 +35,9 @@ class ListTest : UnitSpec() {

testLaws(OptionalLaws.laws(
optional = ListK.tail(),
aGen = Gen.list(Gen.int()),
bGen = Gen.list(Gen.int()),
funcGen = genFunctionAToB(Gen.list(Gen.int())),
aGen = genNonEmptyList(Gen.int()).map { it.all },
bGen = genNonEmptyList(Gen.int()).map { it.all },
funcGen = genFunctionAToB(genNonEmptyList(Gen.int()).map { it.all }),
EQA = Eq.any(),
EQOptionB = Eq.any()
))
Expand Down