Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
70931dc
move readme to package directory
TSampley Nov 18, 2024
efe5b71
move class files to package directory
TSampley Nov 18, 2024
ed996fc
Move collection condition to dedicated file
TSampley Nov 18, 2024
d17e706
Move map conditions to dedicated file
TSampley Nov 18, 2024
d27d465
move scenario test to package directory
TSampley Nov 18, 2024
46d64af
Add collections and map condition empty unit tests
TSampley Nov 18, 2024
7a7ddf0
replace assert/assume functions with synthetic vals
TSampley Nov 18, 2024
ad34847
Add assert/assume documentation
TSampley Nov 18, 2024
4249689
inherit FailedAssumption from Exception not Throwable
TSampley Nov 18, 2024
fa661a3
replace assume function with val
TSampley Nov 18, 2024
1e63743
Fix package and imports
TSampley Nov 18, 2024
9de3e75
remove implied throwable
TSampley Nov 18, 2024
173c230
Add statement evaluation function in statement scope
TSampley Nov 18, 2024
dc6416a
create assert/assumeThat convenience functions
TSampley Nov 18, 2024
4147aa3
rename statement definition file
TSampley Nov 18, 2024
9b6ef28
Add assertThat and assumeThat docs
TSampley Nov 18, 2024
cc72c20
replace result condition with ResultStatements
TSampley Nov 18, 2024
85cf650
replace stringCondition with StringStatements
TSampley Nov 18, 2024
085836a
replace collectionCondition with CollectionStatements
TSampley Nov 18, 2024
a1156b5
replace NumberCondition with NumberStatements
TSampley Nov 18, 2024
1ff393c
Move isIn and notIn condition functions to CollectionStatements
TSampley Nov 18, 2024
89c8c66
update scenario test
TSampley Nov 18, 2024
a8b7ca9
remove assume/assert properties
TSampley Nov 18, 2024
8ad69bf
remove unused statement scope
TSampley Nov 18, 2024
1d1479c
Move object conditions to ObjectStatements
TSampley Nov 18, 2024
f933e0e
optimize imports
TSampley Nov 18, 2024
153f2ac
replace map conditions with map statements
TSampley Nov 18, 2024
9a0cc0a
Replace Condition.and with statement combiner and function
TSampley Nov 18, 2024
c37aac5
remove condition tests
TSampley Nov 18, 2024
533144f
Add failureMessage separate from evaluation function in Statement sub…
TSampley Nov 18, 2024
720bd59
Fix and with wrong failure message
TSampley Nov 18, 2024
5b519d6
abstract shared behavior between assertThat and assumeThat
TSampley Nov 18, 2024
c6f1d7a
Add statement unit test
TSampley Nov 18, 2024
b4299b3
Copy multiplatform workflow
TSampley Nov 18, 2024
352b7f7
publish only select packages to github packages
TSampley Nov 18, 2024
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
6 changes: 4 additions & 2 deletions .github/workflows/distribute.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ jobs:
git push origin $versionString
- name: Publish
run: |
./gradlew publishAllPublicationsToGitHubPackagesRepository \
./gradlew publishKotlinMultiplatformPublicationToGitHubPackagesRepository \
publishJvmPublicationToGitHubPackagesRepository \
publishAndroidDebugPublicationToGitHubPackagesRepository \
publishAndroidReleasePublicationToGitHubPackagesRepository \
-Pgithub.user=${{ secrets.BUILD_USER }} \
-Pgithub.token=${{ secrets.BUILD_TOKEN }}

59 changes: 59 additions & 0 deletions .github/workflows/main-pr-checks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: Main PR Checks
run-name: Verify `${{ github.head_ref }}` before merge to `main` by @${{ github.actor }}

on:
pull_request:
types:
- opened # initially opened
- reopened # closed then opened again
- synchronize # any changes pushed
branches:
- main
paths-ignore: # Only run checks on changes to code
- "**/docs/*"
- "**/README.md"

jobs:
build-app-android:
if: github.event.pull_request.draft == false
runs-on: ubuntu-22.04
steps:
- name: Setup
uses: Pointyware/.github/.github/actions/checkout-java-gradle@b70bbae19637171d6cf9311f06a59f1c15e2598b
- name: Build Android
run: ./gradlew :assertions:assembleDebug :assertions:assembleRelease -Pgithub.user=${{ secrets.BUILD_USER }} -Pgithub.token=${{ secrets.BUILD_TOKEN }}
- name: Android Debug Unit Tests
run: ./gradlew :assertions:testDebugUnitTest -Pgithub.user=${{ secrets.BUILD_USER }} -Pgithub.token=${{ secrets.BUILD_TOKEN }}

build-app-ios:
if: github.event.pull_request.draft == false && false
runs-on: macos-14
steps:
- name: Setup
uses: Pointyware/.github/.github/actions/checkout-java-gradle@b70bbae19637171d6cf9311f06a59f1c15e2598b
- name: Build iOS
run: ./gradlew :assertions:iosX64Binaries -Pgithub.user=${{ secrets.BUILD_USER }} -Pgithub.token=${{ secrets.BUILD_TOKEN }}
- name: Test iOS
run: ./gradlew :assertions:iosX64Test -Pgithub.user=${{ secrets.BUILD_USER }} -Pgithub.token=${{ secrets.BUILD_TOKEN }}

build-app-desktop:
if: github.event.pull_request.draft == false
runs-on: ubuntu-22.04
steps:
- name: Setup
uses: Pointyware/.github/.github/actions/checkout-java-gradle@b70bbae19637171d6cf9311f06a59f1c15e2598b
- name: Build Desktop
run: ./gradlew :assertions:assembleJvm -Pgithub.user=${{ secrets.BUILD_USER }} -Pgithub.token=${{ secrets.BUILD_TOKEN }}
- name: Test Desktop
run: ./gradlew :assertions:jvmTest -Pgithub.user=${{ secrets.BUILD_USER }} -Pgithub.token=${{ secrets.BUILD_TOKEN }}

build-app-browser:
if: github.event.pull_request.draft == false && false
runs-on: ubuntu-22.04
steps:
- name: Setup
uses: Pointyware/.github/.github/actions/checkout-java-gradle@b70bbae19637171d6cf9311f06a59f1c15e2598b
- name: Build Browser
run: ./gradlew :assertions:assembleBrowser -Pgithub.user=${{ secrets.BUILD_USER }} -Pgithub.token=${{ secrets.BUILD_TOKEN }}
- name: Test Browser
run: ./gradlew :assertions:jsTest -Pgithub.user=${{ secrets.BUILD_USER }} -Pgithub.token=${{ secrets.BUILD_TOKEN }}
141 changes: 0 additions & 141 deletions assertions/src/commonMain/kotlin/Condition.kt

This file was deleted.

46 changes: 0 additions & 46 deletions assertions/src/commonMain/kotlin/Statements.kt

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package org.pointyware.kass.assertions

import kotlin.test.Asserter
import kotlin.test.asserter

/**
* Represents a statement that can be evaluated against a subject. The statement also provides a
* [failureMessage] in case the evaluation returns false.
*/
interface Statement<T> {
fun evaluate(subject: T): Boolean
val failureMessage: String
}

/**
* Combines the receiver statement with [other] to create a new statement that evaluates both.
*/
fun <T> Statement<T>.and(other: Statement<T>) = object: Statement<T> {

override fun evaluate(subject: T): Boolean {
return [email protected](subject) && other.evaluate(subject)
}

override val failureMessage: String
get() = [email protected] + " or " + other.failureMessage
}

private inline fun <T> throwOnEvaluationFail(subject: T, statement: Statement<T>, asserter: Asserter) {
if (statement.evaluate(subject).not()) {
asserter.fail(statement.failureMessage)
}
}

/**
* Evaluates the given [statement] with the given [subject] and the default asserter.
*/
fun <T:Any?> assertThat(subject: T, statement: Statement<T>) {
throwOnEvaluationFail(subject, statement, asserter)
}

/**
* Evaluates the given [statement] with the given [subject] and a presumptuous asserter. When the
* statement fails, it will throw a [FailedAssumption].
*/
fun <T:Any?> assumeThat(subject: T, statement: Statement<T>) {
throwOnEvaluationFail(subject, statement, presumptuousAsserter)
}

private val presumptuousAsserter = object: Asserter {
override fun fail(message: String?): Nothing {
throw FailedAssumption("Assumption failed - $message", null)
}

override fun fail(message: String?, cause: Throwable?): Nothing {
throw FailedAssumption("Assumption failed - $message", cause)
}
}

class FailedAssumption(msg: String?, cause: Throwable?): Exception(msg, cause)
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package org.pointyware.kass.assertions.collections

import org.pointyware.kass.assertions.Statement

/**
*
*/
object CollectionStatements {
fun <T> contains(item: T) = object: Statement<Collection<T>> {
override fun evaluate(subject: Collection<T>): Boolean {
return item in subject
}

override val failureMessage: String
get() = "The collection does not contain $item"
}

fun <T> doesNotContain(item: T) = object: Statement<Collection<T>> {
override fun evaluate(subject: Collection<T>): Boolean {
return item !in subject
}

override val failureMessage: String
get() = "The collection contains $item"
}

fun <T> isIn(items: Collection<T>) = object: Statement<T> {
override fun evaluate(subject: T): Boolean {
return subject in items
}

override val failureMessage: String
get() = "The item is not in $items"
}

fun <T> isNotIn(items: Collection<T>) = object: Statement<T> {
override fun evaluate(subject: T): Boolean {
return subject !in items
}

override val failureMessage: String
get() = "The subject is in $items"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package org.pointyware.kass.assertions.collections

import org.pointyware.kass.assertions.Statement

/**
*
*/
object MapStatements {
fun <K, V> containsKey(key: K) = object: Statement<Map<K, V>> {
override fun evaluate(subject: Map<K, V>): Boolean {
return key in subject
}

override val failureMessage: String
get() = "The subject does not contain key $key"
}

fun <K, V> doesNotContainKey(key: K) = object: Statement<Map<K, V>> {
override fun evaluate(subject: Map<K, V>): Boolean {
return key !in subject
}

override val failureMessage: String
get() = "The subject contains key $key"
}
}
Loading
Loading