11/*
2- * Copyright (C) 2024 DiffPlug
2+ * Copyright (C) 2024-2026 DiffPlug
33 *
44 * Licensed under the Apache License, Version 2.0 (the "License");
55 * you may not use this file except in compliance with the License.
@@ -18,18 +18,19 @@ package com.diffplug.selfie.kotest
1818import com.diffplug.selfie.guts.FS
1919import com.diffplug.selfie.guts.TypedPath
2020import io.kotest.assertions.Actual
21- import io.kotest.assertions.Exceptions
21+ import io.kotest.assertions.AssertionErrorBuilder
2222import io.kotest.assertions.Expected
2323import io.kotest.assertions.print.Printed
2424import okio.FileSystem
2525import okio.Path.Companion.toPath
2626
27- expect internal val FS_SYSTEM : FileSystem
27+ internal expect val FS_SYSTEM : FileSystem
2828internal fun TypedPath.toPath (): okio.Path = absolutePath.toPath()
2929
3030internal object FSOkio : FS {
3131 override fun fileExists (typedPath : TypedPath ): Boolean =
3232 FS_SYSTEM .metadataOrNull(typedPath.toPath())?.isRegularFile ? : false
33+
3334 /* * Walks the files (not directories) which are children and grandchildren of the given path. */
3435 override fun <T > fileWalk (typedPath : TypedPath , walk : (Sequence <TypedPath >) -> T ): T =
3536 walk(
@@ -40,9 +41,11 @@ internal object FSOkio : FS {
4041 FS_SYSTEM .read(typedPath.toPath()) { readByteArray() }
4142 override fun fileWriteBinary (typedPath : TypedPath , content : ByteArray ): Unit =
4243 FS_SYSTEM .write(typedPath.toPath()) { write(content) }
44+
4345 /* * Creates an assertion failed exception to throw. */
4446 override fun assertFailed (message : String , expected : Any? , actual : Any? ): Throwable =
45- if (expected == null && actual == null ) Exceptions .createAssertionError(message, null )
47+ if (expected == null && actual == null )
48+ AssertionErrorBuilder .create().withMessage(message).build()
4649 else {
4750 val expectedStr = nullableToString(expected, " " )
4851 val actualStr = nullableToString(actual, " " )
@@ -55,10 +58,11 @@ internal object FSOkio : FS {
5558 comparisonAssertion(message, expectedStr, actualStr)
5659 }
5760 }
58- private fun nullableToString (any : Any? , onNull : String ): String =
59- any?.let { it.toString() } ? : onNull
61+ private fun nullableToString (any : Any? , onNull : String ): String = any?.toString() ? : onNull
6062 private fun comparisonAssertion (message : String , expected : String , actual : String ): Throwable {
61- return Exceptions .createAssertionError(
62- message, null , Expected (Printed ((expected))), Actual (Printed ((actual))))
63+ return AssertionErrorBuilder .create()
64+ .withMessage(message)
65+ .withValues(Expected (Printed ((expected))), Actual (Printed ((actual))))
66+ .build()
6367 }
6468}
0 commit comments