Skip to content

Commit

Permalink
Update Kotest dependency to latest (#44)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattmook authored May 18, 2020
1 parent 5f2f768 commit 126c4d8
Show file tree
Hide file tree
Showing 21 changed files with 665 additions and 923 deletions.
29 changes: 15 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ Include the following dependencies in your `build.gradle.kts` file:
```kotlin
testImplementation("com.appmattus.fixture:fixture:<latest-version>")

// Add for KotlinTest integration
testImplementation("com.appmattus.fixture:fixture-kotlintest:<latest-version>")
// Add for Kotest integration
testImplementation("com.appmattus.fixture:fixture-kotest:<latest-version>")
```

Simply create a fixture and invoke it with the type to be generated:
Expand Down Expand Up @@ -392,24 +392,25 @@ ktype kotlin.String →
Success(5878ec34-c30f-40c7-ad52-c15a39b44ac1)
```

## KotlinTest support
## Kotest support

[KotlinTest](https://github.com/kotlintest/kotlintest/) supports
[property testing](https://github.com/kotlintest/kotlintest/blob/master/doc/reference.md#property-based),
but to use it with more than just the few basic types that are built into the
library requires you to create your own custom generators that you then have to
provide.
[Kotest](https://github.com/kotest/kotest/) supports
[property testing](https://github.com/kotest/kotest/blob/master/doc/reference.md#property-based-testing-),
but to use it with more than just the few basic types that are built
into the library requires you to create your own custom generators that
you then have to provide.

Including the `fixture-kotlintest` dependency in your project adds extension
functions `assertAll`, `assertNone`, `forAll` and `forNone` to the fixture.
These functions wrap the equivalent functions from KotlinTest while providing
generation of all the classes [KotlinFixture](https://github.com/appmattus/kotlinfixture)
supports. For example:
Including the `fixture-kotest` dependency in your project adds extension
functions `checkAll` and `forAll` to the fixture. These
functions wrap the equivalent functions from Kotest while providing
generation of all the classes
[KotlinFixture](https://github.com/appmattus/kotlinfixture) supports.
For example:

```kotlin
data class Person(name: String, age: Int)

fixture.assertAll { person1: Person, person2: Person ->
fixture.checkAll { person1: Person, person2: Person ->
person1 shouldNotBeSameInstanceAs person2
}
```
Expand Down
2 changes: 1 addition & 1 deletion bintray.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ buildscript {
jcenter()
}
dependencies {
classpath("com.novoda:bintray-release:0.9.1")
classpath("com.novoda:bintray-release:0.9.2")
}
}

Expand Down
4 changes: 2 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import com.github.benmanes.gradle.versions.updates.DependencyUpdatesTask

plugins {
id("com.github.ben-manes.versions") version "0.28.0"
id("io.gitlab.arturbosch.detekt") version "1.8.0"
id("io.gitlab.arturbosch.detekt") version "1.9.0"
id("com.appmattus.markdown") version "0.6.0"
}

Expand Down Expand Up @@ -67,7 +67,7 @@ tasks.withType(DependencyUpdatesTask::class.java).all {
}

dependencies {
detektPlugins("io.gitlab.arturbosch.detekt:detekt-formatting:1.8.0")
detektPlugins("io.gitlab.arturbosch.detekt:detekt-formatting:1.9.0")
}

detekt {
Expand Down
5 changes: 5 additions & 0 deletions fixture-kotest/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# fixture-kotest module

This module provides integration with
[Kotest](https://github.com/kotest/kotest/), see the main
[readme](../README.md#kotest-support) for further details.
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,15 @@ apply(from = "$rootDir/gradle/scripts/jacoco.gradle.kts")
dependencies {
api(kotlin("stdlib-jdk8"))
api(project(":fixture"))
api("io.kotlintest:kotlintest-runner-junit5:3.4.2")
api("io.kotest:kotest-property-jvm:4.0.5")

testImplementation("junit:junit:4.13")
testImplementation(kotlin("test"))
testImplementation(kotlin("test-junit"))
testImplementation("com.nhaarman.mockitokotlin2:mockito-kotlin:2.2.0")

testImplementation(kotlin("reflect"))
testImplementation("org.jetbrains.kotlinx:kotlinx-coroutines-test:1.3.6")
}

lintOptions {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
/*
* Copyright 2020 Appmattus Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

@file:Suppress("TooManyFunctions")

package com.appmattus.kotlinfixture.kotest

import com.appmattus.kotlinfixture.Fixture
import io.kotest.property.PropTestConfig
import io.kotest.property.PropertyContext
import io.kotest.property.checkAll

// 1 parameter

suspend inline fun <reified A> Fixture.checkAll(
noinline fn: suspend PropertyContext.(a: A) -> Unit
) = checkAll(kotestGen(), fn)

suspend inline fun <reified A> Fixture.checkAll(
iterations: Int,
noinline fn: suspend PropertyContext.(a: A) -> Unit
) = checkAll(iterations, kotestGen(), fn)

suspend inline fun <reified A> Fixture.checkAll(
config: PropTestConfig,
noinline fn: suspend PropertyContext.(a: A) -> Unit
) = checkAll(config, kotestGen(), fn)

suspend inline fun <reified A> Fixture.checkAll(
iterations: Int,
config: PropTestConfig,
noinline fn: suspend PropertyContext.(a: A) -> Unit
) = checkAll(iterations, config, kotestGen(), fn)

// 2 parameters

suspend inline fun <reified A, reified B> Fixture.checkAll(
noinline fn: suspend PropertyContext.(a: A, b: B) -> Unit
) = checkAll(kotestGen(), kotestGen(), fn)

suspend inline fun <reified A, reified B> Fixture.checkAll(
iterations: Int,
noinline fn: suspend PropertyContext.(a: A, b: B) -> Unit
) = checkAll(iterations, kotestGen(), kotestGen(), fn)

suspend inline fun <reified A, reified B> Fixture.checkAll(
config: PropTestConfig,
noinline fn: suspend PropertyContext.(a: A, b: B) -> Unit
) = checkAll(config, kotestGen(), kotestGen(), fn)

suspend inline fun <reified A, reified B> Fixture.checkAll(
iterations: Int,
config: PropTestConfig,
noinline fn: suspend PropertyContext.(a: A, b: B) -> Unit
) = checkAll(iterations, config, kotestGen(), kotestGen(), fn)

// 3 parameters

suspend inline fun <reified A, reified B, reified C> Fixture.checkAll(
noinline fn: suspend PropertyContext.(a: A, b: B, c: C) -> Unit
) = checkAll(kotestGen(), kotestGen(), kotestGen(), fn)

suspend inline fun <reified A, reified B, reified C> Fixture.checkAll(
iterations: Int,
noinline fn: suspend PropertyContext.(a: A, b: B, c: C) -> Unit
) = checkAll(iterations, kotestGen(), kotestGen(), kotestGen(), fn)

suspend inline fun <reified A, reified B, reified C> Fixture.checkAll(
config: PropTestConfig,
noinline fn: suspend PropertyContext.(a: A, b: B, c: C) -> Unit
) = checkAll(config, kotestGen(), kotestGen(), kotestGen(), fn)

suspend inline fun <reified A, reified B, reified C> Fixture.checkAll(
iterations: Int,
config: PropTestConfig,
noinline fn: suspend PropertyContext.(a: A, b: B, c: C) -> Unit
) = checkAll(iterations, config, kotestGen(), kotestGen(), kotestGen(), fn)

// 4 parameters

suspend inline fun <reified A, reified B, reified C, reified D> Fixture.checkAll(
noinline fn: suspend PropertyContext.(a: A, b: B, c: C, d: D) -> Unit
) = checkAll(kotestGen(), kotestGen(), kotestGen(), kotestGen(), fn)

suspend inline fun <reified A, reified B, reified C, reified D> Fixture.checkAll(
iterations: Int,
noinline fn: suspend PropertyContext.(a: A, b: B, c: C, d: D) -> Unit
) = checkAll(iterations, kotestGen(), kotestGen(), kotestGen(), kotestGen(), fn)

suspend inline fun <reified A, reified B, reified C, reified D> Fixture.checkAll(
config: PropTestConfig,
noinline fn: suspend PropertyContext.(a: A, b: B, c: C, d: D) -> Unit
) = checkAll(config, kotestGen(), kotestGen(), kotestGen(), kotestGen(), fn)

suspend inline fun <reified A, reified B, reified C, reified D> Fixture.checkAll(
iterations: Int,
config: PropTestConfig,
noinline fn: suspend PropertyContext.(a: A, b: B, c: C, d: D) -> Unit
) = checkAll(iterations, config, kotestGen(), kotestGen(), kotestGen(), kotestGen(), fn)

// 5 parameters

suspend inline fun <reified A, reified B, reified C, reified D, reified E> Fixture.checkAll(
noinline fn: suspend PropertyContext.(a: A, b: B, c: C, d: D, e: E) -> Unit
) = checkAll(kotestGen(), kotestGen(), kotestGen(), kotestGen(), kotestGen(), fn)

suspend inline fun <reified A, reified B, reified C, reified D, reified E> Fixture.checkAll(
iterations: Int,
noinline fn: suspend PropertyContext.(a: A, b: B, c: C, d: D, e: E) -> Unit
) = checkAll(iterations, kotestGen(), kotestGen(), kotestGen(), kotestGen(), kotestGen(), fn)

suspend inline fun <reified A, reified B, reified C, reified D, reified E> Fixture.checkAll(
config: PropTestConfig,
noinline fn: suspend PropertyContext.(a: A, b: B, c: C, d: D, e: E) -> Unit
) = checkAll(config, kotestGen(), kotestGen(), kotestGen(), kotestGen(), kotestGen(), fn)

suspend inline fun <reified A, reified B, reified C, reified D, reified E> Fixture.checkAll(
iterations: Int,
config: PropTestConfig,
noinline fn: suspend PropertyContext.(a: A, b: B, c: C, d: D, e: E) -> Unit
) = checkAll(iterations, config, kotestGen(), kotestGen(), kotestGen(), kotestGen(), kotestGen(), fn)

// 6 parameters

suspend inline fun <reified A, reified B, reified C, reified D, reified E, reified F> Fixture.checkAll(
noinline fn: suspend PropertyContext.(a: A, b: B, c: C, d: D, e: E, f: F) -> Unit
) = checkAll(kotestGen(), kotestGen(), kotestGen(), kotestGen(), kotestGen(), kotestGen(), fn)

suspend inline fun <reified A, reified B, reified C, reified D, reified E, reified F> Fixture.checkAll(
iterations: Int,
noinline fn: suspend PropertyContext.(a: A, b: B, c: C, d: D, e: E, f: F) -> Unit
) = checkAll(iterations, kotestGen(), kotestGen(), kotestGen(), kotestGen(), kotestGen(), kotestGen(), fn)

suspend inline fun <reified A, reified B, reified C, reified D, reified E, reified F> Fixture.checkAll(
config: PropTestConfig,
noinline fn: suspend PropertyContext.(a: A, b: B, c: C, d: D, e: E, f: F) -> Unit
) = checkAll(config, kotestGen(), kotestGen(), kotestGen(), kotestGen(), kotestGen(), kotestGen(), fn)

suspend inline fun <reified A, reified B, reified C, reified D, reified E, reified F> Fixture.checkAll(
iterations: Int,
config: PropTestConfig,
noinline fn: suspend PropertyContext.(a: A, b: B, c: C, d: D, e: E, f: F) -> Unit
) = checkAll(iterations, config, kotestGen(), kotestGen(), kotestGen(), kotestGen(), kotestGen(), kotestGen(), fn)
Loading

0 comments on commit 126c4d8

Please sign in to comment.