Skip to content
Permalink
Browse files

Replace Kotlintest with Kotest (#991)

Closes #948
  • Loading branch information...
Kerooker committed Sep 29, 2019
1 parent 1f78735 commit 5de3419ff131e715b74f4fd1ac0a90df6c52cc0e
Showing 1,229 changed files with 46,755 additions and 46,198 deletions.
@@ -26,9 +26,9 @@ allure-results/
!gradle/wrapper/gradle-wrapper.jar

allure.log
kotlintest.log
kotlintest-tests-junit-report.log
kotlintest-tests-core.log
kotest.log
kotest-tests-junit-report.log
kotest-tests-core.log

local.properties
.kotlintest
.kotest
@@ -23,8 +23,8 @@ jobs:
name: "run MPP unit tests"
script: "./gradlew check"
# - stage: test
# name: "kotlintest gradle plugin"
# script: "./gradlew compileKotlin kotlintest"
# name: "kotest gradle plugin"
# script: "./gradlew compileKotlin kotest"
- stage: deploy
name: "deploy maven snapshot"
script: "./snapshot_deploy.sh"
@@ -23,7 +23,7 @@ buildscript {

dependencies {
classpath "org.jetbrains.dokka:dokka-gradle-plugin:$dokkaVersion"
// classpath "io.kotlintest:kotlintest-gradle-plugin:1.1.1-LOCAL"
// classpath "io.kotest:kotest-gradle-plugin:1.1.1-LOCAL"
}
}

@@ -36,7 +36,7 @@ plugins {
id 'net.researchgate.release' version '2.8.0'
}

// apply plugin: "io.kotlintest"
// apply plugin: "io.kotest"

allprojects {

@@ -48,7 +48,7 @@ allprojects {
sourceCompatibility = 1.6
targetCompatibility = 1.6

group = "io.kotlintest"
group = "io.kotest"

if (isTravis) {
version "4.0." + travisBuildNumber + "-SNAPSHOT"
@@ -0,0 +1,86 @@
plugins {
id 'java'
id 'org.jetbrains.kotlin.multiplatform'
id 'java-library'
}

// apply plugin: 'kotlin-kapt'

repositories {
mavenCentral()
}

dependencies {
// kapt "io.arrow-kt:arrow-meta:$arrow_version"
// compile group: 'org.jetbrains.kotlin', name: 'kotlin-reflect', version: '0.11.91.1'
}

kotlin {

jvm()
js()

sourceSets {

commonMain {
dependencies {
implementation kotlin("stdlib-common")
}
}

jsMain {
dependsOn commonMain
dependencies {
implementation kotlin('stdlib-js')
}
}

jvmMain {
dependsOn commonMain
dependencies {
implementation kotlin('stdlib-jdk8')
implementation kotlin("reflect")
implementation 'com.github.wumpz:diffutils:2.2'
implementation 'com.univocity:univocity-parsers:2.8.3'
api "io.arrow-kt:arrow-core:$arrow_version"

implementation 'com.github.mifmif:generex:1.0.2'
}
}

jvmTest {
dependencies {
implementation project(':kotest-runner:kotest-runner-junit5')
}
}
}
}

compileKotlinJs.configure {
kotlinOptions {
moduleKind = 'commonjs'
}
}

compileKotlinJvm {
kotlinOptions {
freeCompilerArgs += '-Xuse-experimental=kotlin.Experimental'
}
}

jvmTest {
useJUnitPlatform()

// show standard out and standard error of the test JVM(s) on the console
testLogging.showStandardStreams = true

// Always run tests, even when nothing changed.
dependsOn 'cleanTest'

testLogging {
events "FAILED", "SKIPPED", "STANDARD_OUT", "STANDARD_ERROR"
exceptionFormat = 'full'
}
}

apply from: '../publish.gradle'
@@ -0,0 +1,47 @@
plugins {
id 'java'
id 'org.jetbrains.kotlin.multiplatform'
id 'java-library'
}

repositories {
mavenCentral()
}

kotlin {

jvm()

sourceSets {

jvmMain {
dependencies {
implementation project(":kotest-assertions")
implementation "io.arrow-kt:arrow-syntax:$arrow_version"

api "io.arrow-kt:arrow-validation:$arrow_version"

implementation "io.arrow-kt:arrow-fx:$arrow_version"
}
}

jvmTest {
dependencies {
implementation project(':kotest-runner:kotest-runner-junit5')
}
}
}
}

compileKotlinJvm {
kotlinOptions {
freeCompilerArgs += '-Xuse-experimental=kotlin.Experimental'
}
}

//dependencies {
// kapt "io.arrow-kt:arrow-meta:$arrow_version"
// kaptTest "io.arrow-kt:arrow-meta:$arrow_version"
//}

apply from: '../../publish.gradle'
@@ -0,0 +1,38 @@
package io.kotest.assertions.arrow.either

import arrow.core.Either
import arrow.core.Left
import arrow.core.Right
import arrow.core.extensions.either.applicativeError.applicativeError
import arrow.core.fix
import io.kotest.assertions.arrow.choose
import io.kotest.properties.Gen

/**
* [Gen] extension instance for [Either].
*
* Generates random [Right] and [Left] values based on the constants
* provided by the [GA] and [GB] generators.
*
* ```kotlin
* import io.kotest.assertions.arrow.either.either
* import io.kotest.properties.forAll
* import io.kotest.properties.Gen
*
* forAll(Gen.either(Gen.constant(1), Gen.constant(0))) {
* it.fold({ l -> l == 1 }, { r -> r == 0 })
* }
* ```
*/
fun <A, B> Gen.Companion.either(GA: Gen<A>, GB: Gen<B>): Gen<Either<A, B>> =
object : Gen<Either<A, B>> {
override fun constants(): Iterable<Either<A, B>> =
GA.constants().map(::Left) + GB.constants().map(::Right)

override fun random(seed: Long?): Sequence<Either<A, B>> =
Either.applicativeError<A>().run {
generateSequence {
choose({ GA.random(seed).iterator().next() }, { GB.random(seed).iterator().next() }).fix()
}
}
}
@@ -0,0 +1,100 @@
package io.kotest.assertions.arrow.either

import arrow.core.Either
import io.kotest.Matcher
import io.kotest.MatcherResult
import io.kotest.matchers.beInstanceOf2
import io.kotest.should
import io.kotest.shouldNot
import kotlin.contracts.ExperimentalContracts
import kotlin.contracts.contract

@UseExperimental(ExperimentalContracts::class)
fun <T> Either<*, T>.shouldBeRight() {
contract {
returns() implies (this@shouldBeRight is Either.Right<*>)
}
this should beRight()
}

fun <T> Either<Any?, T>.shouldNotBeRight() = this shouldNot beRight()
fun <T> beRight() = beInstanceOf2<Either<Any?, T>, Either.Right<T>>()

inline infix fun <B> Either<*, B>.shouldBeRight(fn: (B) -> Unit) {
this should beRight()
fn((this as Either.Right<B>).b)
}

infix fun <B> Either<Any?, B>.shouldBeRight(b: B) = this should beRight(b)
infix fun <B> Either<Any?, B>.shouldNotBeRight(b: B) = this shouldNot beRight(b)
fun <B> beRight(b: B) = object : Matcher<Either<Any?, B>> {
override fun test(value: Either<Any?, B>): MatcherResult {
return when (value) {
is Either.Left -> {
MatcherResult(false, "Either should be Right($b) but was Left(${value.a})", "Either should not be Right($b)")
}
is Either.Right -> {
if (value.b == b)
MatcherResult(true, "Either should be Right($b)", "Either should not be Right($b)")
else
MatcherResult(false, "Either should be Right($b) but was Right(${value.b})", "Either should not be Right($b)")
}
}
}
}

@UseExperimental(ExperimentalContracts::class)
fun <T> Either<T, Any?>.shouldBeLeft() {
contract {
returns() implies (this@shouldBeLeft is Either.Left<*>)
}
this should beLeft()
}

fun <T> Either<T, Any?>.shouldNotBeLeft() = this shouldNot beLeft()
fun <T> beLeft() = beInstanceOf2<Either<T, Any?>, Either.Left<T>>()

inline infix fun <A> Either<A, *>.shouldBeLeft(fn: (A) -> Unit) {
this should beLeft()
fn((this as Either.Left<A>).a)
}


infix fun <A> Either<A, Any?>.shouldBeLeft(a: A) = this should beLeft(a)
infix fun <A> Either<A, Any?>.shouldNotBeLeft(a: A) = this shouldNot beLeft(a)
fun <A> beLeft(a: A) = object : Matcher<Either<A, Any?>> {
override fun test(value: Either<A, Any?>): MatcherResult {
return when (value) {
is Either.Right -> {
MatcherResult(false, "Either should be Left($a) but was Right(${value.b})", "Either should not be Right($a)")
}
is Either.Left -> {
if (value.a == a)
MatcherResult(true, "Either should be Left($a)", "Either should not be Left($a)")
else
MatcherResult(false, "Either should be Left($a) but was Left(${value.a})", "Either should not be Right($a)")
}
}
}
}

inline fun <reified A> Either<Any?, Any?>.shouldBeLeftOfType() = this should beLeftOfType<A>()
inline fun <reified A> Either<Any?, Any?>.shouldNotBeLeftOfType() = this shouldNot beLeftOfType<A>()
inline fun <reified A> beLeftOfType() = object : Matcher<Either<Any?, Any?>> {
override fun test(value: Either<Any?, Any?>): MatcherResult {
return when (value) {
is Either.Right -> {
MatcherResult(false, "Either should be Left<${A::class.qualifiedName}> but was Right(${value.b})", "")
}
is Either.Left -> {
val valueA = value.a
if (valueA is A)
MatcherResult(true, "Either should be Left<${A::class.qualifiedName}>", "Either should not be Left")
else
MatcherResult(false,
"Either should be Left<${A::class.qualifiedName}> but was Left<${if (valueA == null) "Null" else valueA::class.qualifiedName}>",
"Either should not be Left")
}
}
}
}
@@ -0,0 +1,40 @@
package io.kotest.assertions.arrow.eq

import arrow.typeclasses.Eq
import io.kotest.Matcher
import io.kotest.assertions.arrow.matcher
import io.kotest.should

/**
* Provides assertions for [Eq]
*
* ```kotlin
* EqAssertions(Int.eq()).run {
* 0 shouldBeEqvTo 0
* 0 shouldNotBeEqvTo -1
* }
* ```
*/
interface EqAssertions<A> {

fun EQA(): Eq<A>

infix fun A.shouldBeEqvTo(b: A): Unit =
this should eqv(b)

infix fun A.shouldNotBeEqvTo(b: A): Unit =
this should neqv(b)

private fun A.eqv(b: A): Matcher<A> =
EQA().run { matcher(eqv(b), "value ${this@eqv} != expected $b") }
private fun A.neqv(b: A): Matcher<A> =
EQA().run { matcher(neqv(b), "value ${this@neqv} == expected not equal to $b") }
companion object {
operator fun <A> invoke(EQA: Eq<A>, f: (EqAssertions<A>).() -> Unit): Unit = f(object : EqAssertions<A> {
override fun EQA(): Eq<A> = EQA
})
}
}

0 comments on commit 5de3419

Please sign in to comment.
You can’t perform that action at this time.