diff --git a/.editorconfig b/.editorconfig index a17e1dd73..d42d6bc77 100644 --- a/.editorconfig +++ b/.editorconfig @@ -8,4 +8,4 @@ trim_trailing_whitespace = true insert_final_newline = true [*.{kt, kts}] -kotlin_imports_layout = ascii +ij_kotlin_imports_layout = * diff --git a/.git-blame-ignore-revs b/.git-blame-ignore-revs new file mode 100644 index 000000000..179f1ab70 --- /dev/null +++ b/.git-blame-ignore-revs @@ -0,0 +1,2 @@ +# Run './gradlew spotlessApply' +782fd524b15c8de7952ed6dc944d83484d075082 diff --git a/build.gradle.kts b/build.gradle.kts index 8fc8af371..e10b4cda7 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,4 +1,5 @@ import com.android.build.gradle.BaseExtension +import com.diffplug.gradle.spotless.SpotlessExtension import com.vanniktech.maven.publish.MavenPublishBaseExtension import com.vanniktech.maven.publish.SonatypeHost import java.net.URI @@ -30,6 +31,7 @@ buildscript { plugins { id("com.github.gmazzo.buildconfig") version "3.1.0" apply false + alias(libs.plugins.spotless) } apply(plugin = "org.jetbrains.dokka") @@ -40,6 +42,20 @@ tasks.named("dokkaHtmlMultiModule", DokkaMultiModuleTask::class.java).configure apply(plugin = "com.vanniktech.maven.publish.base") +configure { + kotlin { + target("**/*.kt") + ktlint() + .editorConfigOverride( + mapOf( + "ktlint_standard_comment-spacing" to "disabled", // TODO Re-enable + "ktlint_standard_filename" to "disabled", + "ktlint_standard_indent" to "disabled", // TODO Re-enable + ) + ) + } +} + allprojects { group = "app.cash.zipline" version = project.property("VERSION_NAME") as String diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 3182ceef1..d91ed5a86 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -65,4 +65,5 @@ truth = { module = "com.google.truth:truth", version = "1.1.3" } downloadTask-gradle-plugin = { module = "de.undercouch:gradle-download-task", version = "5.4.0" } [plugins] +spotless = { id = "com.diffplug.spotless", version = "6.18.0" } zipline-kotlin = { id = "app.cash.zipline.kotlin" } diff --git a/samples/trivia/trivia-js/src/jsMain/kotlin/app/cash/zipline/samples/trivia/triviaJs.kt b/samples/trivia/trivia-js/src/jsMain/kotlin/app/cash/zipline/samples/trivia/triviaJs.kt index df48bab60..ed432f9d4 100644 --- a/samples/trivia/trivia-js/src/jsMain/kotlin/app/cash/zipline/samples/trivia/triviaJs.kt +++ b/samples/trivia/trivia-js/src/jsMain/kotlin/app/cash/zipline/samples/trivia/triviaJs.kt @@ -26,11 +26,11 @@ class RealTriviaService : TriviaService { override fun result(answer: String) = when { answer.trim().equals("Eclipse", ignoreCase = true) -> AnswerResult( correct = true, - message = "Yep! Next they'll need to block out an Oracle." + message = "Yep! Next they'll need to block out an Oracle.", ) else -> AnswerResult( correct = false, - message = "Nope! The stars aren't in alignment for you." + message = "Nope! The stars aren't in alignment for you.", ) } }, @@ -41,19 +41,18 @@ class RealTriviaService : TriviaService { override fun result(answer: String) = when { answer.matches(Regex("vim?", option = RegexOption.IGNORE_CASE)) -> AnswerResult( correct = true, - message = "You got it! :wq while you're ahead!" + message = "You got it! :wq while you're ahead!", ) else -> AnswerResult( correct = false, - message = "Not that! Are you taking your VItamins?" + message = "Not that! Are you taking your VItamins?", ) } }, ), - ) + ), ) - override fun games() = gameWithAnswersList.map { it.game } override fun answer(gameId: Int, questionId: Int, answer: String) = @@ -68,7 +67,7 @@ interface QuestionAndAnswer { class GameWithAnswers( private val id: Int, private val name: String, - val questionList: List + val questionList: List, ) { val game: TriviaGame get() = TriviaGame( diff --git a/samples/world-clock/presenters/src/androidMain/kotlin/app/cash/zipline/samples/worldclock/android.kt b/samples/world-clock/presenters/src/androidMain/kotlin/app/cash/zipline/samples/worldclock/android.kt index 1018a7652..783ee6652 100644 --- a/samples/world-clock/presenters/src/androidMain/kotlin/app/cash/zipline/samples/worldclock/android.kt +++ b/samples/world-clock/presenters/src/androidMain/kotlin/app/cash/zipline/samples/worldclock/android.kt @@ -21,7 +21,6 @@ import app.cash.zipline.loader.ZiplineLoader import java.util.concurrent.Executors import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.asCoroutineDispatcher -import kotlinx.coroutines.cancel import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.flowOf import okhttp3.OkHttpClient diff --git a/samples/world-clock/presenters/src/iosMain/kotlin/app/cash/zipline/samples/worldclock/ios.kt b/samples/world-clock/presenters/src/iosMain/kotlin/app/cash/zipline/samples/worldclock/ios.kt index 135c6c252..d64bd8824 100644 --- a/samples/world-clock/presenters/src/iosMain/kotlin/app/cash/zipline/samples/worldclock/ios.kt +++ b/samples/world-clock/presenters/src/iosMain/kotlin/app/cash/zipline/samples/worldclock/ios.kt @@ -16,7 +16,6 @@ package app.cash.zipline.samples.worldclock import app.cash.zipline.loader.ManifestVerifier.Companion.NO_SIGNATURE_CHECKS -import app.cash.zipline.loader.ZiplineHttpClient import app.cash.zipline.loader.ZiplineLoader import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers diff --git a/samples/world-clock/presenters/src/jsMain/kotlin/app/cash/zipline/samples/worldclock/js.kt b/samples/world-clock/presenters/src/jsMain/kotlin/app/cash/zipline/samples/worldclock/js.kt index 569d0dde0..1534a3414 100644 --- a/samples/world-clock/presenters/src/jsMain/kotlin/app/cash/zipline/samples/worldclock/js.kt +++ b/samples/world-clock/presenters/src/jsMain/kotlin/app/cash/zipline/samples/worldclock/js.kt @@ -30,22 +30,22 @@ fun main() { val worldClockHost = zipline.take("WorldClockHost") zipline.bind( name = "WorldClockPresenter", - instance = RealWorldClockPresenter(worldClockHost) + instance = RealWorldClockPresenter(worldClockHost), ) } class RealWorldClockPresenter( - private val host: WorldClockHost + private val host: WorldClockHost, ) : WorldClockPresenter { override fun models( - events: Flow + events: Flow, ): Flow { return flow { while (true) { emit( WorldClockModel( - label = TimeFormatter().formatLocalTime() - ) + label = TimeFormatter().formatLocalTime(), + ), ) delay(16) } diff --git a/zipline-bytecode/src/main/kotlin/app/cash/zipline/bytecode/JsObjectReader.kt b/zipline-bytecode/src/main/kotlin/app/cash/zipline/bytecode/JsObjectReader.kt index 01dac429e..b8869f7bb 100644 --- a/zipline-bytecode/src/main/kotlin/app/cash/zipline/bytecode/JsObjectReader.kt +++ b/zipline-bytecode/src/main/kotlin/app/cash/zipline/bytecode/JsObjectReader.kt @@ -123,7 +123,7 @@ class JsObjectReader( closureVars = closureVars, bytecode = bytecode, constantPool = constantPool, - debug = debug + debug = debug, ) } @@ -180,7 +180,7 @@ class JsObjectReader( return Debug( fileName = fileName.string, lineNumber = lineNumber, - pc2Line = pc2line + pc2Line = pc2line, ) } } diff --git a/zipline-bytecode/src/main/kotlin/app/cash/zipline/bytecode/JsObjectWriter.kt b/zipline-bytecode/src/main/kotlin/app/cash/zipline/bytecode/JsObjectWriter.kt index f567da248..feaa5003c 100644 --- a/zipline-bytecode/src/main/kotlin/app/cash/zipline/bytecode/JsObjectWriter.kt +++ b/zipline-bytecode/src/main/kotlin/app/cash/zipline/bytecode/JsObjectWriter.kt @@ -26,7 +26,7 @@ import okio.Closeable */ class JsObjectWriter( private val atoms: AtomSet, - private val sink: BufferedSink + private val sink: BufferedSink, ) : Closeable by sink { private var used: Boolean = false @@ -134,7 +134,7 @@ class JsObjectWriter( value.kind or value.isConst.toBit(4) or value.isLexical.toBit(5) or - value.isCaptured.toBit(6) + value.isCaptured.toBit(6), ) } @@ -146,7 +146,7 @@ class JsObjectWriter( value.isArg.toBit(1) or value.isConst.toBit(2) or value.isLexical.toBit(3) or - (value.kind shl 4) + (value.kind shl 4), ) } diff --git a/zipline-bytecode/src/main/kotlin/app/cash/zipline/bytecode/applySourceMap.kt b/zipline-bytecode/src/main/kotlin/app/cash/zipline/bytecode/applySourceMap.kt index e17736826..6f616000e 100644 --- a/zipline-bytecode/src/main/kotlin/app/cash/zipline/bytecode/applySourceMap.kt +++ b/zipline-bytecode/src/main/kotlin/app/cash/zipline/bytecode/applySourceMap.kt @@ -36,7 +36,7 @@ fun applySourceMapToBytecode( val atoms = jsReader.atoms.toMutableAtomSet() val rewriter = SourceMapBytecodeRewriter( sourceMap = sourceMap, - atoms = atoms + atoms = atoms, ) val ktObject = with(rewriter) { @@ -59,7 +59,7 @@ private class SourceMapBytecodeRewriter( is JsFunctionBytecode -> { copy( debug = debug?.jsToKt(), - constantPool = constantPool.map { it.jsToKt() } + constantPool = constantPool.map { it.jsToKt() }, ) } else -> this @@ -71,7 +71,7 @@ private class SourceMapBytecodeRewriter( val jsReader = LineNumberReader( functionLineNumber = lineNumber, - source = Buffer().write(pc2Line) + source = Buffer().write(pc2Line), ) var ktFileName: String? = null diff --git a/zipline-bytecode/src/main/kotlin/app/cash/zipline/bytecode/atoms.kt b/zipline-bytecode/src/main/kotlin/app/cash/zipline/bytecode/atoms.kt index 3c0031b05..9c4de8a35 100644 --- a/zipline-bytecode/src/main/kotlin/app/cash/zipline/bytecode/atoms.kt +++ b/zipline-bytecode/src/main/kotlin/app/cash/zipline/bytecode/atoms.kt @@ -29,7 +29,7 @@ interface AtomSet { } class MutableAtomSet( - strings: List + strings: List, ) : AtomSet { private val _strings = strings.toMutableList() private val stringToId = mutableMapOf() @@ -270,18 +270,18 @@ private val BUILT_IN_ATOMS: List = listOf( "TypeError", "URIError", "InternalError", - "", // Symbols - "Symbol.toPrimitive", // Symbols - "Symbol.iterator", // Symbols - "Symbol.match", // Symbols - "Symbol.matchAll", // Symbols - "Symbol.replace", // Symbols - "Symbol.search", // Symbols - "Symbol.split", // Symbols - "Symbol.toStringTag", // Symbols - "Symbol.isConcatSpreadable", // Symbols - "Symbol.hasInstance", // Symbols - "Symbol.species", // Symbols - "Symbol.unscopables", // Symbols - "Symbol.asyncIterator", // Symbols + "", // Symbols + "Symbol.toPrimitive", // Symbols + "Symbol.iterator", // Symbols + "Symbol.match", // Symbols + "Symbol.matchAll", // Symbols + "Symbol.replace", // Symbols + "Symbol.search", // Symbols + "Symbol.split", // Symbols + "Symbol.toStringTag", // Symbols + "Symbol.isConcatSpreadable", // Symbols + "Symbol.hasInstance", // Symbols + "Symbol.species", // Symbols + "Symbol.unscopables", // Symbols + "Symbol.asyncIterator", // Symbols ).map { it.toJsString() } diff --git a/zipline-bytecode/src/test/kotlin/app/cash/zipline/bytecode/ApplySourceMapToBytecodeTest.kt b/zipline-bytecode/src/test/kotlin/app/cash/zipline/bytecode/ApplySourceMapToBytecodeTest.kt index 3b4d99e57..a9e68657d 100644 --- a/zipline-bytecode/src/test/kotlin/app/cash/zipline/bytecode/ApplySourceMapToBytecodeTest.kt +++ b/zipline-bytecode/src/test/kotlin/app/cash/zipline/bytecode/ApplySourceMapToBytecodeTest.kt @@ -27,7 +27,8 @@ import org.junit.Test class ApplySourceMapToBytecodeTest { private val quickJs = QuickJs.create() - private val emptySourceMap = SourceMap.parse(""" + private val emptySourceMap = SourceMap.parse( + """ |{ | "version": 3, | "sources": [], @@ -35,7 +36,8 @@ class ApplySourceMapToBytecodeTest { | "names": [], | "mappings": ";;" |} - """.trimMargin()) + """.trimMargin(), + ) @Before fun setUp() { @@ -117,14 +119,17 @@ class ApplySourceMapToBytecodeTest { val exception = assertFailsWith { quickJs.evaluate("require('demo').sayHello()") } - assertThat(exception.stackTraceToString()).startsWith(""" + assertThat(exception.stackTraceToString()).startsWith( + """ |app.cash.zipline.QuickJsException: boom! | at JavaScript.goBoom1(throwException.kt) | at JavaScript.goBoom2(throwException.kt:9) | at JavaScript.goBoom3(throwException.kt:6) | at JavaScript.sayHello(throwException.kt:3) | at JavaScript.(?) - |""".trimMargin()) + | +""".trimMargin(), + ) } @Test fun removeLeadingDotDotsInSourceMap() { @@ -167,21 +172,25 @@ class ApplySourceMapToBytecodeTest { val exception = assertFailsWith { quickJs.evaluate("require('goBoom').app.cash.zipline.testing.goBoom(3)") } - assertThat(exception.stackTraceToString().replace("\t", " ")).startsWith(""" + assertThat(exception.stackTraceToString().replace("\t", " ")).startsWith( + """ |app.cash.zipline.QuickJsException: boom | at JavaScript.(go-boom/src/jsMain/kotlin/app/cash/zipline/testing/goBoom.kt:4) | at JavaScript.(go-boom/src/jsMain/kotlin/app/cash/zipline/testing/goBoom.kt:10) | at JavaScript.(go-boom/src/jsMain/kotlin/app/cash/zipline/testing/goBoom.kt:10) | at JavaScript.(go-boom/src/jsMain/kotlin/app/cash/zipline/testing/goBoom.kt:10) | at JavaScript.(?) - |""".trimMargin()) + | +""".trimMargin(), + ) } @Test fun functionWithNoInstructions() { val js = """ |function doNothing() { |} - |""".trimMargin() + | +""".trimMargin() // Just confirm the empty function can be transformed successfully. val bytecode = quickJs.compile(js, "demo.js") @@ -203,7 +212,8 @@ class ApplySourceMapToBytecodeTest { | : b + c + d + Array(e-d.length+1).join(0); | }); |} - |""".trimMargin() + | +""".trimMargin() val bytecode = quickJs.compile(js, "demo.js") val bytecodeWithSourceMap = applySourceMapToBytecode(bytecode, emptySourceMap) diff --git a/zipline-bytecode/src/test/kotlin/app/cash/zipline/bytecode/JsObjectEncodingTest.kt b/zipline-bytecode/src/test/kotlin/app/cash/zipline/bytecode/JsObjectEncodingTest.kt index cae2ab75b..8de46e9ac 100644 --- a/zipline-bytecode/src/test/kotlin/app/cash/zipline/bytecode/JsObjectEncodingTest.kt +++ b/zipline-bytecode/src/test/kotlin/app/cash/zipline/bytecode/JsObjectEncodingTest.kt @@ -35,7 +35,8 @@ class JsObjectEncodingTest { |function greet(name) { | return "hello, " + name; |} - """.trimMargin(), "hello.js" + """.trimMargin(), + "hello.js", ) assertThat(evalFunction.name).isEqualTo("") @@ -64,7 +65,7 @@ class JsObjectEncodingTest { | "hello" | ]; |} - """.trimMargin() + """.trimMargin(), ) } @@ -74,7 +75,7 @@ class JsObjectEncodingTest { |function toString() { | return "JSON" |} - """.trimMargin() + """.trimMargin(), ) assertThat(evalFunction.name).isEqualTo("") val toStringFunction = evalFunction.constantPool.single() as JsFunctionBytecode @@ -94,7 +95,7 @@ class JsObjectEncodingTest { | console.log("line 8"); | return 0; |} - """.trimMargin() + """.trimMargin(), ) assertThat(evalFunction.name).isEqualTo("") @@ -116,7 +117,7 @@ class JsObjectEncodingTest { | "Café 🍩", // NFD (7 code points) | ]; |} - """.trimMargin() + """.trimMargin(), ) } @@ -129,7 +130,7 @@ class JsObjectEncodingTest { | "\u00ff" | ]; |} - """.trimMargin() + """.trimMargin(), ) } @@ -153,7 +154,8 @@ class JsObjectEncodingTest { |} |function newThrowable(message, cause) { |} - """.trimMargin(), "hello.js" + """.trimMargin(), + "hello.js", ) assertThat(evalFunction.name).isEqualTo("") @@ -168,7 +170,7 @@ class JsObjectEncodingTest { /** Returns the model object for the bytecode of [script]. */ private fun assertRoundTrip( script: String, - fileName: String = "test.js" + fileName: String = "test.js", ): JsFunctionBytecode { // Use QuickJS to compile a script into bytecode. val bytecode: ByteArray = quickJs.compile(script, fileName) diff --git a/zipline-bytecode/src/test/kotlin/app/cash/zipline/bytecode/SourceMapParsingTest.kt b/zipline-bytecode/src/test/kotlin/app/cash/zipline/bytecode/SourceMapParsingTest.kt index 82865444b..19f65e289 100644 --- a/zipline-bytecode/src/test/kotlin/app/cash/zipline/bytecode/SourceMapParsingTest.kt +++ b/zipline-bytecode/src/test/kotlin/app/cash/zipline/bytecode/SourceMapParsingTest.kt @@ -83,7 +83,7 @@ class SourceMapParsingTest { sourceColumn = 3, name = null, ), - sourceMap.find(lineNumber = 14) + sourceMap.find(lineNumber = 14), ) // Doesn't match any lines in the source file. assertNull(sourceMap.find(lineNumber = 17)) diff --git a/zipline-cli/src/main/kotlin/app/cash/zipline/cli/Download.kt b/zipline-cli/src/main/kotlin/app/cash/zipline/cli/Download.kt index e17458d0a..125e54bee 100644 --- a/zipline-cli/src/main/kotlin/app/cash/zipline/cli/Download.kt +++ b/zipline-cli/src/main/kotlin/app/cash/zipline/cli/Download.kt @@ -30,25 +30,30 @@ import picocli.CommandLine.Command import picocli.CommandLine.Option @Command( - name = NAME, description = ["Recursively download Zipline code to a directory from a URL"], - mixinStandardHelpOptions = true, versionProvider = Main.VersionProvider::class + name = NAME, + description = ["Recursively download Zipline code to a directory from a URL"], + mixinStandardHelpOptions = true, + versionProvider = Main.VersionProvider::class, ) class Download : Runnable { @Option( names = ["-A", "--application-name"], - description = ["Application name for the Zipline Manifest."], required = true + description = ["Application name for the Zipline Manifest."], + required = true, ) lateinit var applicationName: String @Option( names = ["-M", "--manifest-url"], - description = ["URL to the Zipline Manifest for the code to download."], required = true + description = ["URL to the Zipline Manifest for the code to download."], + required = true, ) lateinit var manifestUrl: String @Option( - names = ["-D", "--download-dir"], description = ["Directory where code will be downloaded to."], - required = true + names = ["-D", "--download-dir"], + description = ["Directory where code will be downloaded to."], + required = true, ) lateinit var downloadDir: File diff --git a/zipline-cli/src/main/kotlin/app/cash/zipline/cli/GenerateKeyPair.kt b/zipline-cli/src/main/kotlin/app/cash/zipline/cli/GenerateKeyPair.kt index 567792385..3f837e866 100644 --- a/zipline-cli/src/main/kotlin/app/cash/zipline/cli/GenerateKeyPair.kt +++ b/zipline-cli/src/main/kotlin/app/cash/zipline/cli/GenerateKeyPair.kt @@ -27,7 +27,7 @@ import picocli.CommandLine.Option @Command( name = NAME, description = [ - "Generate an Ed25519 key pair for ManifestSigner and ManifestVerifier" + "Generate an Ed25519 key pair for ManifestSigner and ManifestVerifier", ], mixinStandardHelpOptions = true, versionProvider = Main.VersionProvider::class, diff --git a/zipline-cli/src/main/kotlin/app/cash/zipline/cli/Main.kt b/zipline-cli/src/main/kotlin/app/cash/zipline/cli/Main.kt index 3e7bdbf1f..4941dfd04 100644 --- a/zipline-cli/src/main/kotlin/app/cash/zipline/cli/Main.kt +++ b/zipline-cli/src/main/kotlin/app/cash/zipline/cli/Main.kt @@ -27,7 +27,9 @@ import picocli.CommandLine.Option import picocli.CommandLine.ParameterException import picocli.CommandLine.Spec -@Command(name = NAME, description = ["Use Zipline without Gradle."], +@Command( + name = NAME, + description = ["Use Zipline without Gradle."], mixinStandardHelpOptions = true, synopsisSubcommandLabel = "COMMAND", subcommands = [Download::class, GenerateKeyPair::class, HelpCommand::class], diff --git a/zipline-cli/src/test/kotlin/app/cash/zipline/cli/DownloadTest.kt b/zipline-cli/src/test/kotlin/app/cash/zipline/cli/DownloadTest.kt index 4c31b7412..0693a1b6b 100644 --- a/zipline-cli/src/test/kotlin/app/cash/zipline/cli/DownloadTest.kt +++ b/zipline-cli/src/test/kotlin/app/cash/zipline/cli/DownloadTest.kt @@ -77,9 +77,9 @@ class DownloadTest { url = webServer.url("/latest/app/alpha.zipline").toString(), sha256 = testFixtures.alphaSha256, dependsOnIds = listOf(), - ) + ), ), - mainFunction = "zipline.ziplineMain" + mainFunction = "zipline.ziplineMain", ) val manifestJsonString = manifest.encodeToString() @@ -87,14 +87,14 @@ class DownloadTest { webServer.enqueue( MockResponse() .setResponseCode(200) - .setBody(manifestJsonString) + .setBody(manifestJsonString), ) // Enqueue the zipline file webServer.enqueue( MockResponse() .setResponseCode(200) - .setBody(Buffer().write(testFixtures.alphaByteString)) + .setBody(Buffer().write(testFixtures.alphaByteString)), ) val manifestUrl = webServer.url("/latest/app/manifest.zipline.json").toString() diff --git a/zipline-gradle-plugin/src/main/kotlin/app/cash/zipline/gradle/ZiplineCompileTask.kt b/zipline-gradle-plugin/src/main/kotlin/app/cash/zipline/gradle/ZiplineCompileTask.kt index 58d0b620e..e622aa058 100644 --- a/zipline-gradle-plugin/src/main/kotlin/app/cash/zipline/gradle/ZiplineCompileTask.kt +++ b/zipline-gradle-plugin/src/main/kotlin/app/cash/zipline/gradle/ZiplineCompileTask.kt @@ -73,14 +73,15 @@ abstract class ZiplineCompileTask : DefaultTask() { outputDir.fileProvider( linkOutputFolderProvider.map { it.parentFile.resolve("${it.name}Zipline") - } + }, ) mainModuleId.set(extension.mainModuleId) mainFunction.set(extension.mainFunction) version.set(extension.version) - signingKeys.set(project.provider { + signingKeys.set( + project.provider { extension.signingKeys.asMap.values }.flatMap { it.map { dslKey -> @@ -88,7 +89,8 @@ abstract class ZiplineCompileTask : DefaultTask() { ManifestSigningKey(dslKey.name, algorithmId, privateKeyHex.decodeHex()) } }.flatten() - }) + }, + ) } @TaskAction diff --git a/zipline-gradle-plugin/src/main/kotlin/app/cash/zipline/gradle/ZiplineCompiler.kt b/zipline-gradle-plugin/src/main/kotlin/app/cash/zipline/gradle/ZiplineCompiler.kt index a2d83c7d6..129cd88b0 100644 --- a/zipline-gradle-plugin/src/main/kotlin/app/cash/zipline/gradle/ZiplineCompiler.kt +++ b/zipline-gradle-plugin/src/main/kotlin/app/cash/zipline/gradle/ZiplineCompiler.kt @@ -86,7 +86,7 @@ internal object ZiplineCompiler { } // Delete Zipline files for any removed JS files - removedFileNames.forEach { File(outputDir.path + "/" + it.removeSuffix(".js") + ZIPLINE_EXTENSION).delete()} + removedFileNames.forEach { File(outputDir.path + "/" + it.removeSuffix(".js") + ZIPLINE_EXTENSION).delete() } // Compile the newly added or modified files and add them into the module list val addedOrModifiedFiles = getJsFiles(addedFiles) + getJsFiles(modifiedFiles) @@ -150,7 +150,7 @@ internal object ZiplineCompiler { return "$MODULE_PATH_PREFIX${jsFile.name}" to ZiplineManifest.Module( url = outputZiplineFilePath, sha256 = sha256, - dependsOnIds = dependencies + dependsOnIds = dependencies, ) } } diff --git a/zipline-gradle-plugin/src/main/kotlin/app/cash/zipline/gradle/ZiplineDevelopmentServer.kt b/zipline-gradle-plugin/src/main/kotlin/app/cash/zipline/gradle/ZiplineDevelopmentServer.kt index 540843515..15a604ff8 100644 --- a/zipline-gradle-plugin/src/main/kotlin/app/cash/zipline/gradle/ZiplineDevelopmentServer.kt +++ b/zipline-gradle-plugin/src/main/kotlin/app/cash/zipline/gradle/ZiplineDevelopmentServer.kt @@ -57,14 +57,14 @@ internal open class ZiplineDevelopmentServer @Inject constructor( ws.onClose { websockets.remove(ws) } - } + }, ) val http = routes( "/" bind static( ResourceLoader.Directory(inputDirectory.asFile.absolutePath), - Pair("zipline", ContentType.TEXT_PLAIN) - ) + Pair("zipline", ContentType.TEXT_PLAIN), + ), ) // Keep the connection open by sending a message periodically. diff --git a/zipline-gradle-plugin/src/main/kotlin/app/cash/zipline/gradle/ZiplinePlugin.kt b/zipline-gradle-plugin/src/main/kotlin/app/cash/zipline/gradle/ZiplinePlugin.kt index a46b31c7c..f4e557501 100644 --- a/zipline-gradle-plugin/src/main/kotlin/app/cash/zipline/gradle/ZiplinePlugin.kt +++ b/zipline-gradle-plugin/src/main/kotlin/app/cash/zipline/gradle/ZiplinePlugin.kt @@ -107,7 +107,7 @@ class ZiplinePlugin : KotlinCompilerPluginSupportPlugin { } override fun applyToCompilation( - kotlinCompilation: KotlinCompilation<*> + kotlinCompilation: KotlinCompilation<*>, ): Provider> { return kotlinCompilation.target.project.provider { listOf() // No options. diff --git a/zipline-gradle-plugin/src/test/kotlin/app/cash/zipline/gradle/ZiplineCompilerTest.kt b/zipline-gradle-plugin/src/test/kotlin/app/cash/zipline/gradle/ZiplineCompilerTest.kt index d6cac3297..4fd284482 100644 --- a/zipline-gradle-plugin/src/test/kotlin/app/cash/zipline/gradle/ZiplineCompilerTest.kt +++ b/zipline-gradle-plugin/src/test/kotlin/app/cash/zipline/gradle/ZiplineCompilerTest.kt @@ -68,7 +68,8 @@ class ZiplineCompilerTest { | at JavaScript.goBoom3(throwException.kt:6) | at JavaScript.sayHello(throwException.kt:3) | at JavaScript.(test.js) - |""".trimMargin() + | +""".trimMargin(), ) } @@ -102,10 +103,11 @@ class ZiplineCompilerTest { // Start with base compile to generate manifest and starting files compile("$rootProject/base", false) - val moduleNameToFile = assertZiplineIncrementalCompile("$rootProject/base", + val moduleNameToFile = assertZiplineIncrementalCompile( + "$rootProject/base", addedFiles = File("$rootProject/added").listFiles()!!.asList(), modifiedFiles = File("$rootProject/modified").listFiles()!!.asList(), - removedFiles = File("$rootProject/removed").listFiles()!!.asList() + removedFiles = File("$rootProject/removed").listFiles()!!.asList(), ) for ((_, ziplineFile) in moduleNameToFile) { quickJs.execute(ziplineFile.quickjsBytecode.toByteArray()) diff --git a/zipline-gradle-plugin/src/test/kotlin/app/cash/zipline/gradle/ZiplineGradleDownloaderTest.kt b/zipline-gradle-plugin/src/test/kotlin/app/cash/zipline/gradle/ZiplineGradleDownloaderTest.kt index e279a670b..75b36393c 100644 --- a/zipline-gradle-plugin/src/test/kotlin/app/cash/zipline/gradle/ZiplineGradleDownloaderTest.kt +++ b/zipline-gradle-plugin/src/test/kotlin/app/cash/zipline/gradle/ZiplineGradleDownloaderTest.kt @@ -59,9 +59,9 @@ class ZiplineGradleDownloaderTest { url = webServer.url("/latest/app/alpha.zipline").toString(), sha256 = testFixtures.alphaSha256, dependsOnIds = listOf(), - ) + ), ), - mainFunction = "zipline.ziplineMain" + mainFunction = "zipline.ziplineMain", ) val manifestJsonString = manifest.encodeToString() @@ -69,14 +69,14 @@ class ZiplineGradleDownloaderTest { webServer.enqueue( MockResponse() .setResponseCode(200) - .setBody(manifestJsonString) + .setBody(manifestJsonString), ) // Enqueue the zipline file webServer.enqueue( MockResponse() .setResponseCode(200) - .setBody(Buffer().write(testFixtures.alphaByteString)) + .setBody(Buffer().write(testFixtures.alphaByteString)), ) val applicationName = "app1" @@ -90,7 +90,7 @@ class ZiplineGradleDownloaderTest { assertTrue(fileSystem.exists(downloadDirPath / getApplicationManifestFileName(applicationName))) val actualManifestByteString = fileSystem.read( - downloadDirPath / getApplicationManifestFileName(applicationName) + downloadDirPath / getApplicationManifestFileName(applicationName), ) { readByteString() } assertDownloadedToEmbeddedManifest( manifest.copy(baseUrl = manifestUrl), @@ -99,6 +99,7 @@ class ZiplineGradleDownloaderTest { assertTrue(fileSystem.exists(downloadDirPath / testFixtures.alphaSha256Hex)) assertEquals( testFixtures.alphaByteString, - fileSystem.read(downloadDirPath / testFixtures.alphaSha256Hex) { readByteString() }) + fileSystem.read(downloadDirPath / testFixtures.alphaSha256Hex) { readByteString() }, + ) } } diff --git a/zipline-gradle-plugin/src/test/kotlin/app/cash/zipline/gradle/ZiplinePluginTest.kt b/zipline-gradle-plugin/src/test/kotlin/app/cash/zipline/gradle/ZiplinePluginTest.kt index 94e0ec8b4..766645b12 100644 --- a/zipline-gradle-plugin/src/test/kotlin/app/cash/zipline/gradle/ZiplinePluginTest.kt +++ b/zipline-gradle-plugin/src/test/kotlin/app/cash/zipline/gradle/ZiplinePluginTest.kt @@ -34,7 +34,7 @@ class ZiplinePluginTest { .contains(result.task(taskName)!!.outcome) val ziplineOut = projectDir.resolve( - "lib/build/compileSync/js/main/productionExecutable/kotlinZipline" + "lib/build/compileSync/js/main/productionExecutable/kotlinZipline", ) assertThat(ziplineOut.resolve(MANIFEST_FILE_NAME).exists()).isTrue() assertThat(ziplineOut.resolve("basic-lib.zipline").exists()).isTrue() @@ -54,7 +54,7 @@ class ZiplinePluginTest { .contains(result.task(taskName)!!.outcome) val ziplineOut = projectDir.resolve( - "lib/build/compileSync/js/main/developmentExecutable/kotlinZipline" + "lib/build/compileSync/js/main/developmentExecutable/kotlinZipline", ) assertThat(ziplineOut.resolve(MANIFEST_FILE_NAME).exists()).isTrue() assertThat(ziplineOut.resolve("basic-lib.zipline").exists()).isTrue() @@ -74,7 +74,7 @@ class ZiplinePluginTest { .contains(result.task(taskName)!!.outcome) val ziplineOut = projectDir.resolve( - "lib/build/distributionsZipline" + "lib/build/distributionsZipline", ) assertThat(ziplineOut.listFiles()?.size).isEqualTo(2) assertThat(ziplineOut.resolve(MANIFEST_FILE_NAME).exists()).isTrue() @@ -127,7 +127,7 @@ class ZiplinePluginTest { .contains(result.task(taskName)!!.outcome) val ziplineOut = projectDir.resolve( - "lib/build/compileSync/js/main/developmentExecutable/kotlinZipline" + "lib/build/compileSync/js/main/developmentExecutable/kotlinZipline", ) val manifest = ziplineOut.resolve(MANIFEST_FILE_NAME) assertThat(manifest.exists()).isTrue() @@ -146,7 +146,7 @@ class ZiplinePluginTest { .contains(result.task(taskName)!!.outcome) val ziplineOut = projectDir.resolve( - "lib/build/compileSync/js/main/developmentExecutable/kotlinZipline" + "lib/build/compileSync/js/main/developmentExecutable/kotlinZipline", ) val manifest = ziplineOut.resolve(MANIFEST_FILE_NAME) assertThat(manifest.readText()) @@ -165,7 +165,8 @@ class ZiplinePluginTest { | ALGORITHM: Ed25519 | PUBLIC KEY: [\da-f]{64} | PRIVATE KEY: [\da-f]{64} - |""".trimMargin() + | +""".trimMargin(), ) } @@ -182,7 +183,8 @@ class ZiplinePluginTest { | ALGORITHM: EcdsaP256 | PUBLIC KEY: [\da-f]{130} | PRIVATE KEY: [\da-f]{134} - |""".trimMargin() + | +""".trimMargin(), ) } diff --git a/zipline-gradle-plugin/src/test/projects/basic/lib/src/jvmMain/kotlin/app/cash/zipline/tests/launchGreetServiceJvm.kt b/zipline-gradle-plugin/src/test/projects/basic/lib/src/jvmMain/kotlin/app/cash/zipline/tests/launchGreetServiceJvm.kt index aad0c724a..d9fd4b228 100644 --- a/zipline-gradle-plugin/src/test/projects/basic/lib/src/jvmMain/kotlin/app/cash/zipline/tests/launchGreetServiceJvm.kt +++ b/zipline-gradle-plugin/src/test/projects/basic/lib/src/jvmMain/kotlin/app/cash/zipline/tests/launchGreetServiceJvm.kt @@ -16,11 +16,10 @@ package app.cash.zipline.tests import app.cash.zipline.Zipline +import app.cash.zipline.loader.LoadResult import app.cash.zipline.loader.ManifestVerifier.Companion.NO_SIGNATURE_CHECKS import app.cash.zipline.loader.ZiplineHttpClient import app.cash.zipline.loader.ZiplineLoader -import app.cash.zipline.loader.LoadResult -import java.time.Instant import java.util.concurrent.Executors import kotlin.system.exitProcess import kotlinx.coroutines.CoroutineDispatcher diff --git a/zipline-gradle-plugin/src/test/projects/jvmOnly/lib/src/jvmMain/kotlin/app/cash/zipline/tests/bindAndTakeJvm.kt b/zipline-gradle-plugin/src/test/projects/jvmOnly/lib/src/jvmMain/kotlin/app/cash/zipline/tests/bindAndTakeJvm.kt index 4b885f4d5..6f262a2b6 100644 --- a/zipline-gradle-plugin/src/test/projects/jvmOnly/lib/src/jvmMain/kotlin/app/cash/zipline/tests/bindAndTakeJvm.kt +++ b/zipline-gradle-plugin/src/test/projects/jvmOnly/lib/src/jvmMain/kotlin/app/cash/zipline/tests/bindAndTakeJvm.kt @@ -26,10 +26,13 @@ internal interface UnusedService : ZiplineService { fun main() { val zipline = Zipline.create(Dispatchers.Default) zipline.take("takenService") - zipline.bind("boundService", object : UnusedService { + zipline.bind( + "boundService", + object : UnusedService { override fun unusedMethod() { } - }) + }, + ) // If we reach this line without crashing, bind() and take() were rewritten. (If the Zipline // plugin is not installed we'll get an error like "is the Zipline plugin configured?") diff --git a/zipline-kotlin-plugin/src/main/kotlin/app/cash/zipline/kotlin/AdapterGenerator.kt b/zipline-kotlin-plugin/src/main/kotlin/app/cash/zipline/kotlin/AdapterGenerator.kt index 4237123df..55e4fbab8 100644 --- a/zipline-kotlin-plugin/src/main/kotlin/app/cash/zipline/kotlin/AdapterGenerator.kt +++ b/zipline-kotlin-plugin/src/main/kotlin/app/cash/zipline/kotlin/AdapterGenerator.kt @@ -74,7 +74,7 @@ internal class AdapterGenerator( private val pluginContext: IrPluginContext, private val ziplineApis: ZiplineApis, private val scope: ScopeWithIr, - private val original: IrClass + private val original: IrClass, ) { private val irFactory = pluginContext.irFactory private val irTypeSystemContext = IrTypeSystemContextImpl(pluginContext.irBuiltIns) @@ -85,7 +85,7 @@ internal class AdapterGenerator( scope, original, "Zipline.take()", - original.defaultType + original.defaultType, ) /** Returns an expression that references the adapter, generating it if necessary. */ @@ -123,7 +123,7 @@ internal class AdapterGenerator( irVararg( ziplineApis.kSerializer.starProjectedType, serializersExpressions, - ) + ), ) } @@ -155,11 +155,11 @@ internal class AdapterGenerator( ).apply { putValueArgument( 0, - serializersListExpression + serializersListExpression, ) putValueArgument( 1, - irString(serialName) + irString(serialName), ) } } @@ -190,7 +190,7 @@ internal class AdapterGenerator( } private fun getOrCreateAdapterClass( - companion: IrClass + companion: IrClass, ): IrClass { // class Adapter : ZiplineServiceAdapter( // val serializers: List>, @@ -235,7 +235,7 @@ internal class AdapterGenerator( statements += irDelegatingConstructorCall( context = pluginContext, symbol = ziplineApis.ziplineServiceAdapter.constructors.single(), - typeArgumentsCount = 1 + typeArgumentsCount = 1, ) { putTypeArgument(0, original.defaultType.remapTypeParameters(original, adapterClass)) } @@ -288,8 +288,8 @@ internal class AdapterGenerator( listOf( serialNameProperty, ziplineFunctionsFunction, - outboundServiceFunction - ) + outboundServiceFunction, + ), ) companion.declarations += adapterClass @@ -382,12 +382,12 @@ internal class AdapterGenerator( ) { val serializersLocal = irTemporary( value = irCall( - callee = serializersProperty.getter!! + callee = serializersProperty.getter!!, ).apply { dispatchReceiver = irGet(ziplineFunctionsFunction.dispatchReceiverParameter!!) }, nameHint = "serializers", - isMutable = false + isMutable = false, ).apply { origin = IrDeclarationOrigin.DEFINED } @@ -413,15 +413,19 @@ internal class AdapterGenerator( typeArguments = adapterClass.typeParameters.map { it.defaultType }, ).apply { type = ziplineFunctionT - putValueArgument(0, irCall(ziplineApis.listOfFunction).apply { + putValueArgument( + 0, + irCall(ziplineApis.listOfFunction).apply { putTypeArgument(0, ziplineApis.kSerializer.starProjectedType) - putValueArgument(0, + putValueArgument( + 0, irVararg( ziplineApis.kSerializer.starProjectedType, - bridgedFunction.owner.valueParameters.map { irGet(serializers[it.type]!!) } - ) + bridgedFunction.owner.valueParameters.map { irGet(serializers[it.type]!!) }, + ), ) - }) + }, + ) val returnType = bridgedFunction.owner.returnType putValueArgument(1, irGet(serializers[returnType]!!)) if (bridgedFunction.isSuspend) { @@ -435,16 +439,18 @@ internal class AdapterGenerator( // ZiplineFunction0(...), // ZiplineFunction1(...), // ) - +irReturn(irCall(ziplineApis.listOfFunction).apply { + +irReturn( + irCall(ziplineApis.listOfFunction).apply { putTypeArgument(0, ziplineFunctionT) putValueArgument( 0, irVararg( ziplineFunctionT, expressions, - ) + ), ) - }) + }, + ) } return ziplineFunctionsFunction @@ -541,7 +547,7 @@ internal class AdapterGenerator( // We add overrides here, so we can call them below. functionClass.addFakeOverrides( irTypeSystemContext, - listOf(callFunction) + listOf(callFunction), ) callFunction.irFunctionBody( @@ -554,7 +560,7 @@ internal class AdapterGenerator( ziplineFunctionClass = functionClass, callFunction = callFunction, bridgedFunction = bridgedFunction, - ) + ), ) } @@ -625,7 +631,7 @@ internal class AdapterGenerator( }, bridgedInterface.resolveTypeParameters(bridgedFunction.owner.valueParameters[p].type) .remapTypeParameters(original, ziplineFunctionClass), - ) + ), ) } } @@ -669,7 +675,7 @@ internal class AdapterGenerator( ).apply { putValueArgument(0, irGet(outboundServiceFunction.valueParameters[0])) type = bridgedInterfaceT - } + }, ) } return outboundServiceFunction @@ -822,16 +828,16 @@ internal class AdapterGenerator( // return callHandler.call(this, scope, 0, request) as SampleResponse result.irFunctionBody( context = pluginContext, - scopeOwnerSymbol = result.symbol + scopeOwnerSymbol = result.symbol, ) { val callHandlerLocal = irTemporary( value = irCall( - callee = callHandlerProperty.getter!! + callee = callHandlerProperty.getter!!, ).apply { dispatchReceiver = irGet(result.dispatchReceiverParameter!!) }, nameHint = "callHandler", - isMutable = false + isMutable = false, ).apply { origin = IrDeclarationOrigin.DEFINED } @@ -862,15 +868,15 @@ internal class AdapterGenerator( type = it.type, variable = it.symbol, ) - } - ) + }, + ), ) } +irReturn( value = irAs( argument = call, - type = functionReturnType + type = functionReturnType, ), returnTargetSymbol = result.symbol, type = pluginContext.irBuiltIns.nothingType, diff --git a/zipline-kotlin-plugin/src/main/kotlin/app/cash/zipline/kotlin/AddAdapterArgumentRewriter.kt b/zipline-kotlin-plugin/src/main/kotlin/app/cash/zipline/kotlin/AddAdapterArgumentRewriter.kt index 81156996f..10e422d34 100644 --- a/zipline-kotlin-plugin/src/main/kotlin/app/cash/zipline/kotlin/AddAdapterArgumentRewriter.kt +++ b/zipline-kotlin-plugin/src/main/kotlin/app/cash/zipline/kotlin/AddAdapterArgumentRewriter.kt @@ -67,7 +67,7 @@ internal class AddAdapterArgumentRewriter( scope, original, "Zipline.${original.symbol.owner.name.identifier}()", - bridgedInterfaceType + bridgedInterfaceType, ) fun rewrite(): IrCall { @@ -75,7 +75,7 @@ internal class AddAdapterArgumentRewriter( pluginContext, ziplineApis, scope, - bridgedInterface.typeIrClass + bridgedInterface.typeIrClass, ).adapterExpression(bridgedInterfaceType as IrSimpleType) return irCall(original, rewrittenFunction).apply { diff --git a/zipline-kotlin-plugin/src/main/kotlin/app/cash/zipline/kotlin/BridgedInterface.kt b/zipline-kotlin-plugin/src/main/kotlin/app/cash/zipline/kotlin/BridgedInterface.kt index d07703e02..c9c078a7a 100644 --- a/zipline-kotlin-plugin/src/main/kotlin/app/cash/zipline/kotlin/BridgedInterface.kt +++ b/zipline-kotlin-plugin/src/main/kotlin/app/cash/zipline/kotlin/BridgedInterface.kt @@ -183,7 +183,7 @@ internal class BridgedInterface( irVararg( ziplineApis.kSerializer.starProjectedType, parameterExpressions.map { it.expression }, - ) + ), ) } @@ -212,7 +212,7 @@ internal class BridgedInterface( pluginContext.referenceClass(type.getClass()!!.classId!!)!!.owner, ).adapterExpression( serializersListExpression = parameterList, - serialName = type.asString() + serialName = type.asString(), ) } @@ -227,7 +227,7 @@ internal class BridgedInterface( putTypeArgument(0, type) putValueArgument( 0, - irKClass(pluginContext.referenceClass(type.getClass()!!.classId!!)!!.owner) + irKClass(pluginContext.referenceClass(type.getClass()!!.classId!!)!!.owner), ) putValueArgument(1, parameterList) } @@ -296,7 +296,7 @@ internal class BridgedInterface( ziplineApis, scope, type, - classSymbol + classSymbol, ) } } diff --git a/zipline-kotlin-plugin/src/main/kotlin/app/cash/zipline/kotlin/CallAdapterConstructorRewriter.kt b/zipline-kotlin-plugin/src/main/kotlin/app/cash/zipline/kotlin/CallAdapterConstructorRewriter.kt index bc6e2b062..fb6e2ba7f 100644 --- a/zipline-kotlin-plugin/src/main/kotlin/app/cash/zipline/kotlin/CallAdapterConstructorRewriter.kt +++ b/zipline-kotlin-plugin/src/main/kotlin/app/cash/zipline/kotlin/CallAdapterConstructorRewriter.kt @@ -71,14 +71,14 @@ internal class CallAdapterConstructorRewriter( scope, original, "ziplineServiceSerializer()", - bridgedInterfaceType + bridgedInterfaceType, ) val result = AdapterGenerator( pluginContext, ziplineApis, scope, - bridgedInterface.typeIrClass + bridgedInterface.typeIrClass, ).adapterExpression(serializersListExpression, serialName) result.patchDeclarationParents(declarationParent) return result diff --git a/zipline-kotlin-plugin/src/main/kotlin/app/cash/zipline/kotlin/ZiplineApis.kt b/zipline-kotlin-plugin/src/main/kotlin/app/cash/zipline/kotlin/ZiplineApis.kt index 6e220d53e..ffadf848d 100644 --- a/zipline-kotlin-plugin/src/main/kotlin/app/cash/zipline/kotlin/ZiplineApis.kt +++ b/zipline-kotlin-plugin/src/main/kotlin/app/cash/zipline/kotlin/ZiplineApis.kt @@ -89,7 +89,7 @@ internal class ZiplineApis( val requireContextual: IrSimpleFunctionSymbol get() = pluginContext.referenceFunctions( - bridgeFqPackage.callableId("requireContextual") + bridgeFqPackage.callableId("requireContextual"), ).single() /** This symbol for `ziplineServiceSerializer(KClass<*>, List>)`. */ @@ -103,7 +103,7 @@ internal class ZiplineApis( val listGetFunction: IrSimpleFunctionSymbol get() = pluginContext.referenceFunctions( - StandardClassIds.List.callableId("get") + StandardClassIds.List.callableId("get"), ).single() val ziplineFunction: IrClassSymbol @@ -117,12 +117,12 @@ internal class ZiplineApis( val returningZiplineFunctionCall: IrSimpleFunctionSymbol get() = pluginContext.referenceFunctions( - bridgeFqPackage.classId("ReturningZiplineFunction").callableId("call") + bridgeFqPackage.classId("ReturningZiplineFunction").callableId("call"), ).single() val suspendingZiplineFunctionCallSuspending: IrSimpleFunctionSymbol get() = pluginContext.referenceFunctions( - bridgeFqPackage.classId("SuspendingZiplineFunction").callableId("callSuspending") + bridgeFqPackage.classId("SuspendingZiplineFunction").callableId("callSuspending"), ).single() private val outboundCallHandlerClassId = bridgeFqPackage.classId("OutboundCallHandler") @@ -132,12 +132,12 @@ internal class ZiplineApis( val outboundCallHandlerCall: IrSimpleFunctionSymbol get() = pluginContext.referenceFunctions( - outboundCallHandlerClassId.callableId("call") + outboundCallHandlerClassId.callableId("call"), ).single() val outboundCallHandlerCallSuspending: IrSimpleFunctionSymbol get() = pluginContext.referenceFunctions( - outboundCallHandlerClassId.callableId("callSuspending") + outboundCallHandlerClassId.callableId("callSuspending"), ).single() val outboundService: IrClassSymbol @@ -145,7 +145,7 @@ internal class ZiplineApis( val outboundServiceCallHandler: IrPropertySymbol get() = pluginContext.referenceProperties( - outboundServiceClassId.callableId("callHandler") + outboundServiceClassId.callableId("callHandler"), ).single() val ziplineService: IrClassSymbol @@ -156,17 +156,17 @@ internal class ZiplineApis( val ziplineServiceAdapterSerialName: IrPropertySymbol get() = pluginContext.referenceProperties( - ziplineServiceAdapterClassId.callableId("serialName") + ziplineServiceAdapterClassId.callableId("serialName"), ).single() val ziplineServiceAdapterSerializers: IrPropertySymbol get() = pluginContext.referenceProperties( - ziplineServiceAdapterClassId.callableId("serializers") + ziplineServiceAdapterClassId.callableId("serializers"), ).single() val ziplineServiceAdapterSimpleName: IrPropertySymbol get() = pluginContext.referenceProperties( - ziplineServiceAdapterClassId.callableId("simpleName") + ziplineServiceAdapterClassId.callableId("simpleName"), ).single() val ziplineServiceAdapterZiplineFunctions: IrSimpleFunctionSymbol diff --git a/zipline-kotlin-plugin/src/main/kotlin/app/cash/zipline/kotlin/ZiplineCompilerPluginRegistrar.kt b/zipline-kotlin-plugin/src/main/kotlin/app/cash/zipline/kotlin/ZiplineCompilerPluginRegistrar.kt index a80db44ea..00469d435 100644 --- a/zipline-kotlin-plugin/src/main/kotlin/app/cash/zipline/kotlin/ZiplineCompilerPluginRegistrar.kt +++ b/zipline-kotlin-plugin/src/main/kotlin/app/cash/zipline/kotlin/ZiplineCompilerPluginRegistrar.kt @@ -31,10 +31,10 @@ class ZiplineCompilerPluginRegistrar : CompilerPluginRegistrar() { override fun ExtensionStorage.registerExtensions(configuration: CompilerConfiguration) { val messageCollector = configuration.get( CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY, - MessageCollector.NONE + MessageCollector.NONE, ) IrGenerationExtension.registerExtension( - extension = ZiplineIrGenerationExtension(messageCollector) + extension = ZiplineIrGenerationExtension(messageCollector), ) } } diff --git a/zipline-kotlin-plugin/src/main/kotlin/app/cash/zipline/kotlin/ZiplineIrGenerationExtension.kt b/zipline-kotlin-plugin/src/main/kotlin/app/cash/zipline/kotlin/ZiplineIrGenerationExtension.kt index 37457c4a8..54812d7c3 100644 --- a/zipline-kotlin-plugin/src/main/kotlin/app/cash/zipline/kotlin/ZiplineIrGenerationExtension.kt +++ b/zipline-kotlin-plugin/src/main/kotlin/app/cash/zipline/kotlin/ZiplineIrGenerationExtension.kt @@ -57,7 +57,7 @@ class ZiplineIrGenerationExtension( pluginContext, ziplineApis, currentScope!!, - declaration + declaration, ).generateAdapterIfAbsent() // When iterating on Kotlin compiler plugin, set breakpoint here and // run `declarataion.dump()` to get current compiler parse tree. diff --git a/zipline-kotlin-plugin/src/main/kotlin/app/cash/zipline/kotlin/ir.kt b/zipline-kotlin-plugin/src/main/kotlin/app/cash/zipline/kotlin/ir.kt index ae7b79aab..70089a89c 100644 --- a/zipline-kotlin-plugin/src/main/kotlin/app/cash/zipline/kotlin/ir.kt +++ b/zipline-kotlin-plugin/src/main/kotlin/app/cash/zipline/kotlin/ir.kt @@ -84,12 +84,12 @@ internal val IrSimpleFunction.signature: String if (valueParameters.size == 1) { // setter append( - "var ${name}: ${(valueParameters[0].type as IrSimpleType).asString()}" + "var $name: ${(valueParameters[0].type as IrSimpleType).asString()}", ) } else { // getter append( - "val ${name}: ${(returnType as IrSimpleType).asString()}" + "val $name: ${(returnType as IrSimpleType).asString()}", ) } } else { @@ -97,7 +97,7 @@ internal val IrSimpleFunction.signature: String append("suspend ") } append( - "fun ${name.identifier}(${valueParameters.joinToString { (it.type as IrSimpleType).asString() }}): ${(returnType as IrSimpleType).asString()}" + "fun ${name.identifier}(${valueParameters.joinToString { (it.type as IrSimpleType).asString() }}): ${(returnType as IrSimpleType).asString()}", ) } } @@ -113,7 +113,7 @@ class ZiplineCompilationException( fun IrFile.locationOf(irElement: IrElement?): CompilerMessageSourceLocation { val sourceRangeInfo = fileEntry.getSourceRangeInfo( beginOffset = irElement?.startOffset ?: SYNTHETIC_OFFSET, - endOffset = irElement?.endOffset ?: SYNTHETIC_OFFSET + endOffset = irElement?.endOffset ?: SYNTHETIC_OFFSET, ) return CompilerMessageLocationWithRange.create( path = sourceRangeInfo.filePath, @@ -121,7 +121,7 @@ fun IrFile.locationOf(irElement: IrElement?): CompilerMessageSourceLocation { columnStart = sourceRangeInfo.startColumnNumber + 1, lineEnd = sourceRangeInfo.endLineNumber + 1, columnEnd = sourceRangeInfo.endColumnNumber + 1, - lineContent = null + lineContent = null, )!! } @@ -178,13 +178,13 @@ private fun Int.toSyntheticIfUnknown(): Int { fun IrConstructor.irConstructorBody( context: IrGeneratorContext, - blockBody: DeclarationIrBuilder.(MutableList) -> Unit + blockBody: DeclarationIrBuilder.(MutableList) -> Unit, ) { val constructorIrBuilder = DeclarationIrBuilder( generatorContext = context, symbol = IrSimpleFunctionSymbolImpl(), startOffset = startOffset, - endOffset = endOffset + endOffset = endOffset, ) body = context.irFactory.createBlockBody( startOffset = constructorIrBuilder.startOffset, @@ -207,7 +207,7 @@ fun DeclarationIrBuilder.irDelegatingConstructorCall( type = context.irBuiltIns.unitType, symbol = symbol, typeArgumentsCount = typeArgumentsCount, - valueArgumentsCount = valueArgumentsCount + valueArgumentsCount = valueArgumentsCount, ) result.block() return result @@ -228,7 +228,7 @@ fun DeclarationIrBuilder.irInstanceInitializerCall( fun IrSimpleFunction.irFunctionBody( context: IrGeneratorContext, scopeOwnerSymbol: IrSymbol, - blockBody: IrBlockBodyBuilder.() -> Unit + blockBody: IrBlockBodyBuilder.() -> Unit, ) { val bodyBuilder = IrBlockBodyBuilder( startOffset = startOffset, @@ -282,7 +282,7 @@ fun irVal( visibility = DescriptorVisibilities.PRIVATE, isFinal = true, isExternal = false, - isStatic = false + isStatic = false, ).apply { parent = declaringClass correspondingPropertySymbol = result.symbol @@ -312,7 +312,7 @@ fun irVal( isInfix = false, isExpect = false, isFakeOverride = false, - containerSource = null + containerSource = null, ).apply { parent = declaringClass correspondingPropertySymbol = result.symbol @@ -320,13 +320,13 @@ fun irVal( createDispatchReceiverParameter() irFunctionBody( context = pluginContext, - scopeOwnerSymbol = symbol + scopeOwnerSymbol = symbol, ) { +irReturn( value = irGetField( irGet(dispatchReceiverParameter!!), - result.backingField!! - ) + result.backingField!!, + ), ) } } @@ -342,14 +342,14 @@ internal fun IrBuilderWithScope.irKClass( endOffset = endOffset, type = context.irBuiltIns.kClassClass.typeWith(containerClass.defaultType), symbol = containerClass.symbol, - classType = containerClass.defaultType + classType = containerClass.defaultType, ) } fun irBlockBodyBuilder( irPluginContext: IrGeneratorContext, scopeWithIr: ScopeWithIr, - original: IrElement + original: IrElement, ): IrBlockBodyBuilder { return IrBlockBodyBuilder( context = irPluginContext, @@ -388,7 +388,7 @@ fun getOrCreateCompanion( irConstructorBody(irPluginContext) { statements -> statements += irDelegatingConstructorCall( context = irPluginContext, - symbol = anyType.constructors.single() + symbol = anyType.constructors.single(), ) statements += irInstanceInitializerCall( context = irPluginContext, diff --git a/zipline-kotlin-plugin/src/main/kotlin/app/cash/zipline/kotlin/typeToString.kt b/zipline-kotlin-plugin/src/main/kotlin/app/cash/zipline/kotlin/typeToString.kt index 804827773..a5a911f3d 100644 --- a/zipline-kotlin-plugin/src/main/kotlin/app/cash/zipline/kotlin/typeToString.kt +++ b/zipline-kotlin-plugin/src/main/kotlin/app/cash/zipline/kotlin/typeToString.kt @@ -20,9 +20,11 @@ import org.jetbrains.kotlin.utils.addToStdlib.ifNotEmpty /** Inspired by [org.jetbrains.kotlin.ir.backend.js.utils.asString]. */ fun IrSimpleType.asString(): String = classifier.asString() + - (arguments.ifNotEmpty { + ( + arguments.ifNotEmpty { joinToString(separator = ",", prefix = "<", postfix = ">") { it.asString() } - } ?: "") + + } ?: "" + ) + (if (isMarkedNullable()) "?" else "") /** Copied from [org.jetbrains.kotlin.ir.backend.js.utils.asString]. */ diff --git a/zipline-kotlin-plugin/tests/src/test/kotlin/app/cash/zipline/kotlin/ZiplineKotlinPluginTest.kt b/zipline-kotlin-plugin/tests/src/test/kotlin/app/cash/zipline/kotlin/ZiplineKotlinPluginTest.kt index 76a3fbd7f..79b55f77b 100644 --- a/zipline-kotlin-plugin/tests/src/test/kotlin/app/cash/zipline/kotlin/ZiplineKotlinPluginTest.kt +++ b/zipline-kotlin-plugin/tests/src/test/kotlin/app/cash/zipline/kotlin/ZiplineKotlinPluginTest.kt @@ -47,13 +47,13 @@ class ZiplineKotlinPluginTest { interface SampleService : ZiplineService { fun hello(request: EchoRequest): EchoResponse } - """ - ) + """, + ), ) assertEquals(KotlinCompilation.ExitCode.OK, result.exitCode, result.messages) val adapterClass = result.classLoader.loadClass( - "app.cash.zipline.testing.SampleService\$Companion\$Adapter" + "app.cash.zipline.testing.SampleService\$Companion\$Adapter", ) assertThat(adapterClass).isNotNull() assertThat(adapterClass.interfaces).asList().containsExactly(KSerializer::class.java) @@ -80,8 +80,8 @@ class ZiplineKotlinPluginTest { fun prepareJsBridges(endpoint: Endpoint) { endpoint.bind("helloService", TestingEchoService("hello")) } - """ - ) + """, + ), ) assertEquals(KotlinCompilation.ExitCode.OK, result.exitCode, result.messages) @@ -107,8 +107,8 @@ class ZiplineKotlinPluginTest { fun takeHelloService(endpoint: Endpoint): EchoZiplineService { return endpoint.take("helloService") } - """ - ) + """, + ), ) assertEquals(KotlinCompilation.ExitCode.OK, result.exitCode, result.messages) @@ -146,8 +146,8 @@ class ZiplineKotlinPluginTest { object TestingEchoService : EchoService { override fun echo(request: EchoRequest): EchoResponse = error("") } - """ - ) + """, + ), ) assertEquals(KotlinCompilation.ExitCode.COMPILATION_ERROR, result.exitCode, result.messages) assertThat(result.messages) @@ -170,8 +170,8 @@ class ZiplineKotlinPluginTest { fun takeHelloService(endpoint: Endpoint): Concrete { return endpoint.take("helloService") } - """ - ) + """, + ), ) assertEquals(KotlinCompilation.ExitCode.COMPILATION_ERROR, result.exitCode, result.messages) assertThat(result.messages) @@ -200,8 +200,8 @@ class ZiplineKotlinPluginTest { TestingGenericEchoService() ) } - """ - ) + """, + ), ) assertEquals(KotlinCompilation.ExitCode.OK, result.exitCode, result.messages) @@ -226,8 +226,8 @@ class ZiplineKotlinPluginTest { fun takeGenericService(endpoint: Endpoint): GenericEchoService { return endpoint.take("genericService") } - """ - ) + """, + ), ) assertEquals(KotlinCompilation.ExitCode.OK, result.exitCode, result.messages) @@ -265,8 +265,8 @@ class ZiplineKotlinPluginTest { } }) } - """ - ) + """, + ), ) assertEquals(KotlinCompilation.ExitCode.OK, result.exitCode, result.messages) @@ -293,8 +293,8 @@ class ZiplineKotlinPluginTest { interface SampleService : ZiplineService { fun hello(request: Flow): Flow } - """ - ) + """, + ), ) assertEquals(KotlinCompilation.ExitCode.OK, result.exitCode, result.messages) } @@ -313,8 +313,8 @@ class ZiplineKotlinPluginTest { fun createServiceSerializer(): KSerializer { return ziplineServiceSerializer(EchoZiplineService::class, listOf()) } - """ - ) + """, + ), ) assertEquals(KotlinCompilation.ExitCode.OK, result.exitCode, result.messages) @@ -338,13 +338,13 @@ class ZiplineKotlinPluginTest { val count: Int var total: Int } - """ - ) + """, + ), ) assertEquals(KotlinCompilation.ExitCode.OK, result.exitCode, result.messages) val adapterClass = result.classLoader.loadClass( - "app.cash.zipline.testing.SampleService\$Companion\$Adapter" + "app.cash.zipline.testing.SampleService\$Companion\$Adapter", ) assertThat(adapterClass).isNotNull() assertThat(adapterClass.interfaces).asList().containsExactly(KSerializer::class.java) @@ -361,13 +361,15 @@ class ZiplineKotlinPluginTest { import app.cash.zipline.ZiplineScoped interface SomeInterface : ZiplineScoped - """ - ) + """, + ), ) assertEquals(KotlinCompilation.ExitCode.COMPILATION_ERROR, result.exitCode, result.messages) assertThat(result.messages) - .contains(":5:1 Only classes may implement ZiplineScoped, but " + - "app.cash.zipline.testing.SomeInterface is an interface") + .contains( + ":5:1 Only classes may implement ZiplineScoped, but " + + "app.cash.zipline.testing.SomeInterface is an interface", + ) } @Test @@ -387,8 +389,8 @@ class ZiplineKotlinPluginTest { interface ChildService : ParentService, ZiplineService { fun test(first: Int, second: Int) } - """ - ) + """, + ), ) assertEquals(KotlinCompilation.ExitCode.OK, result.exitCode, result.messages) } diff --git a/zipline-loader-testing/src/engineMain/kotlin/app/cash/zipline/loader/testing/LoaderTestFixtures.kt b/zipline-loader-testing/src/engineMain/kotlin/app/cash/zipline/loader/testing/LoaderTestFixtures.kt index 53a485012..516b49ebc 100644 --- a/zipline-loader-testing/src/engineMain/kotlin/app/cash/zipline/loader/testing/LoaderTestFixtures.kt +++ b/zipline-loader-testing/src/engineMain/kotlin/app/cash/zipline/loader/testing/LoaderTestFixtures.kt @@ -61,7 +61,7 @@ class LoaderTestFixtures { ), ), mainFunction = "zipline.ziplineMain", - baseUrl = manifestUrl + baseUrl = manifestUrl, ) val manifestJsonString = manifest.encodeToString() @@ -93,7 +93,7 @@ class LoaderTestFixtures { } val ziplineFile = ZiplineFile( CURRENT_ZIPLINE_VERSION, - compiledJavaScript.toByteString() + compiledJavaScript.toByteString(), ) val buffer = Buffer() ziplineFile.writeTo(buffer) @@ -117,7 +117,7 @@ class LoaderTestFixtures { seed to ZiplineManifest.Module( url = "$seed.zipline", sha256 = seedFileSha256, - ) + ), ), mainFunction = "zipline.ziplineMain", ) @@ -139,7 +139,7 @@ class LoaderTestFixtures { return LoadedManifest( manifestJson.encodeUtf8(), manifest, - 1L + 1L, ) } @@ -178,13 +178,13 @@ class LoaderTestFixtures { mainBody = """ globalThis.mainLog = globalThis.mainLog || ""; globalThis.mainLog += "$seed loaded\n"; - """.trimIndent() + """.trimIndent(), ) fun createFailureJs(seed: String) = jsBoilerplate( seed = seed, loadBody = "throw Error('$seed');", - mainBody = "throw Error('$seed');" + mainBody = "throw Error('$seed');", ) private fun jsBoilerplate(seed: String, loadBody: String, mainBody: String) = """ diff --git a/zipline-loader/src/androidInstrumentedTest/kotlin/app/cash/zipline/loader/loaderTestsAndroid.kt b/zipline-loader/src/androidInstrumentedTest/kotlin/app/cash/zipline/loader/loaderTestsAndroid.kt index d414e21ca..2ff86edf1 100644 --- a/zipline-loader/src/androidInstrumentedTest/kotlin/app/cash/zipline/loader/loaderTestsAndroid.kt +++ b/zipline-loader/src/androidInstrumentedTest/kotlin/app/cash/zipline/loader/loaderTestsAndroid.kt @@ -15,13 +15,11 @@ */ package app.cash.zipline.loader -import app.cash.zipline.EventListener -import kotlinx.coroutines.CoroutineDispatcher -import okio.FileSystem +import app.cash.zipline.loader.internal.cache.SqlDriverFactory import java.security.SecureRandom import okio.ByteString import okio.ByteString.Companion.toByteString -import app.cash.zipline.loader.internal.cache.SqlDriverFactory +import okio.FileSystem // This file is necessary to get Android tests to build. // diff --git a/zipline-loader/src/androidMain/kotlin/app/cash/zipline/loader/loaderAndroid.kt b/zipline-loader/src/androidMain/kotlin/app/cash/zipline/loader/loaderAndroid.kt index 087711d10..67446ef5c 100644 --- a/zipline-loader/src/androidMain/kotlin/app/cash/zipline/loader/loaderAndroid.kt +++ b/zipline-loader/src/androidMain/kotlin/app/cash/zipline/loader/loaderAndroid.kt @@ -16,7 +16,6 @@ package app.cash.zipline.loader import android.content.Context -import app.cash.zipline.EventListener import app.cash.zipline.loader.internal.cache.SqlDriverFactory import okio.FileSystem import okio.Path diff --git a/zipline-loader/src/commonMain/kotlin/app/cash/zipline/loader/FastCodeUpdates.kt b/zipline-loader/src/commonMain/kotlin/app/cash/zipline/loader/FastCodeUpdates.kt index a696034a2..d4d12943c 100644 --- a/zipline-loader/src/commonMain/kotlin/app/cash/zipline/loader/FastCodeUpdates.kt +++ b/zipline-loader/src/commonMain/kotlin/app/cash/zipline/loader/FastCodeUpdates.kt @@ -24,7 +24,6 @@ import kotlinx.coroutines.flow.collect import kotlinx.coroutines.flow.takeWhile import kotlinx.coroutines.flow.transformLatest - /** * Returns a flow that emits every time this flow emits, and also emits whenever the websocket * for the most recent URL signals an update. @@ -36,7 +35,7 @@ import kotlinx.coroutines.flow.transformLatest @OptIn(ExperimentalCoroutinesApi::class) fun Flow.withDevelopmentServerPush( httpClient: ZiplineHttpClient, - pollingInterval: Duration = 500.milliseconds + pollingInterval: Duration = 500.milliseconds, ): Flow { return transformLatest { manifestUrl -> // Attempt once before any websocket setup or polling. diff --git a/zipline-loader/src/commonMain/kotlin/app/cash/zipline/loader/LoadResult.kt b/zipline-loader/src/commonMain/kotlin/app/cash/zipline/loader/LoadResult.kt index fbdfce6bc..90b6db3db 100644 --- a/zipline-loader/src/commonMain/kotlin/app/cash/zipline/loader/LoadResult.kt +++ b/zipline-loader/src/commonMain/kotlin/app/cash/zipline/loader/LoadResult.kt @@ -41,12 +41,12 @@ sealed class LoadResult { * embedded manifests it is computed by whatever machine performed the embedding. */ val freshAtEpochMs: Long, - ): LoadResult() + ) : LoadResult() /** * [Exception] from the Zipline code load failure and corresponding metadata. */ data class Failure( val exception: Exception, - ): LoadResult() + ) : LoadResult() } diff --git a/zipline-loader/src/commonMain/kotlin/app/cash/zipline/loader/ManifestVerifier.kt b/zipline-loader/src/commonMain/kotlin/app/cash/zipline/loader/ManifestVerifier.kt index 17c907345..41533b048 100644 --- a/zipline-loader/src/commonMain/kotlin/app/cash/zipline/loader/ManifestVerifier.kt +++ b/zipline-loader/src/commonMain/kotlin/app/cash/zipline/loader/ManifestVerifier.kt @@ -50,11 +50,13 @@ class ManifestVerifier private constructor( for ((keyName, signature) in manifest.signatures) { val verifier = verifiers[keyName] ?: continue - check(verifier.algorithm.verify( + check( + verifier.algorithm.verify( message = signaturePayloadBytes, signature = signature.decodeHex(), publicKey = verifier.trustedKey, - )) { + ), + ) { "manifest signature for key $keyName did not verify!" } @@ -66,7 +68,7 @@ class ManifestVerifier private constructor( |no keys in the manifest were recognized for signature verification! | trusted keys: ${verifiers.keys} | manifest keys: ${manifest.signatures.keys} - """.trimMargin() + """.trimMargin(), ) } diff --git a/zipline-loader/src/commonMain/kotlin/app/cash/zipline/loader/ZiplineCache.kt b/zipline-loader/src/commonMain/kotlin/app/cash/zipline/loader/ZiplineCache.kt index 2d3c7ecd3..aaf7094c2 100644 --- a/zipline-loader/src/commonMain/kotlin/app/cash/zipline/loader/ZiplineCache.kt +++ b/zipline-loader/src/commonMain/kotlin/app/cash/zipline/loader/ZiplineCache.kt @@ -215,7 +215,7 @@ class ZiplineCache internal constructor( .executeAsOneOrNull() ?: return null val manifestBytes = read(manifestFile, nowEpochMs) ?: throw FileNotFoundException( - "No manifest file on disk with [fileName=${manifestFile.sha256_hex}]" + "No manifest file on disk with [fileName=${manifestFile.sha256_hex}]", ) return LoadedManifest(manifestBytes, manifestFile.fresh_at_epoch_ms!!) } @@ -281,11 +281,11 @@ class ZiplineCache internal constructor( // Pin the fallback manifest, which removes all pins prior to pinning. val fallbackManifestBytes = read(fallbackManifestFile, nowEpochMs) ?: throw FileNotFoundException( - "No manifest file on disk with [fileName=${fallbackManifestFile.sha256_hex}]" + "No manifest file on disk with [fileName=${fallbackManifestFile.sha256_hex}]", ) val fallbackManifest = LoadedManifest( fallbackManifestBytes, - fallbackManifestFile.fresh_at_epoch_ms!! + fallbackManifestFile.fresh_at_epoch_ms!!, ) pinManifest(applicationName, fallbackManifest, nowEpochMs) } @@ -372,11 +372,11 @@ class ZiplineCache internal constructor( } private fun getOrNull( - sha256: ByteString + sha256: ByteString, ): Files? = database.filesQueries.get(sha256.hex()).executeAsOneOrNull() private fun getOrNull( - id: Long + id: Long, ): Files? = database.filesQueries.getById(id).executeAsOneOrNull() /** @@ -452,7 +452,7 @@ class ZiplineCache internal constructor( ) ?: return // Pruned. database.filesQueries.updateFresh( id = manifestMetadata.id, - fresh_at_epoch_ms = freshAtMs + fresh_at_epoch_ms = freshAtMs, ) } } diff --git a/zipline-loader/src/commonMain/kotlin/app/cash/zipline/loader/ZiplineFile.kt b/zipline-loader/src/commonMain/kotlin/app/cash/zipline/loader/ZiplineFile.kt index 173e19b67..901a16923 100644 --- a/zipline-loader/src/commonMain/kotlin/app/cash/zipline/loader/ZiplineFile.kt +++ b/zipline-loader/src/commonMain/kotlin/app/cash/zipline/loader/ZiplineFile.kt @@ -53,7 +53,7 @@ data class ZiplineFile( val ziplineVersion = source.readInt() if (ziplineVersion != CURRENT_ZIPLINE_VERSION) { throw IOException( - "unsupported version [version=$ziplineVersion][currentVersion=$CURRENT_ZIPLINE_VERSION]" + "unsupported version [version=$ziplineVersion][currentVersion=$CURRENT_ZIPLINE_VERSION]", ) } while (!source.exhausted()) { @@ -64,12 +64,14 @@ data class ZiplineFile( return ZiplineFile( ziplineVersion = ziplineVersion, - quickjsBytecode = quickjsBytecode ?: throw IOException("QuickJS bytecode section missing") + quickjsBytecode = quickjsBytecode ?: throw IOException("QuickJS bytecode section missing"), ) } private fun BufferedSource.readSection( - quickjsBytecode: ByteString? = null, sectionHeader: Int, sectionLength: Int + quickjsBytecode: ByteString? = null, + sectionHeader: Int, + sectionLength: Int, ): ByteString? = when (sectionHeader) { SECTION_HEADER_QUICKJS_BYTECODE -> { if (quickjsBytecode != null) { diff --git a/zipline-loader/src/commonMain/kotlin/app/cash/zipline/loader/ZiplineLoader.kt b/zipline-loader/src/commonMain/kotlin/app/cash/zipline/loader/ZiplineLoader.kt index bd9995ac0..7847cc0f7 100644 --- a/zipline-loader/src/commonMain/kotlin/app/cash/zipline/loader/ZiplineLoader.kt +++ b/zipline-loader/src/commonMain/kotlin/app/cash/zipline/loader/ZiplineLoader.kt @@ -83,7 +83,7 @@ class ZiplineLoader internal constructor( fun withEmbedded( embeddedDir: Path, - embeddedFileSystem: FileSystem + embeddedFileSystem: FileSystem, ): ZiplineLoader = copy( embeddedDir = embeddedDir, embeddedFileSystem = embeddedFileSystem, @@ -92,7 +92,7 @@ class ZiplineLoader internal constructor( fun withCache( cache: ZiplineCache, ): ZiplineLoader = copy( - cache = cache + cache = cache, ) private fun copy( @@ -227,12 +227,10 @@ class ZiplineLoader internal constructor( eventListener.applicationLoadSuccess(applicationName, manifestUrl, zipline, startValue) send(LoadResult.Success(zipline, loadedManifest.manifest, loadedManifest.freshAtEpochMs)) return loadedManifest.manifest - } catch (e: CancellationException) { // If emit() threw a CancellationException, consider that emit to be successful. // That's 'cause loadOnce() accepts an element and then immediately cancels the flow. throw e - } catch (e: Exception) { eventListener.applicationLoadFailed(applicationName, manifestUrl, e, startValue) if (loadedManifest != null) { @@ -264,12 +262,10 @@ class ZiplineLoader internal constructor( eventListener.applicationLoadSuccess(applicationName, null, zipline, startValue) send(LoadResult.Success(zipline, loadedManifest.manifest, loadedManifest.freshAtEpochMs)) return loadedManifest.manifest - } catch (e: CancellationException) { // If emit() threw a CancellationException, consider that emit to be successful. // That's 'cause loadOnce() accepts an element and then immediately cancels the flow. throw e - } catch (e: Exception) { send(LoadResult.Failure(e)) eventListener.applicationLoadFailed(applicationName, null, e, startValue) @@ -286,7 +282,7 @@ class ZiplineLoader internal constructor( applicationName, flowOf(manifestUrl), serializersModule, - initializer + initializer, ).first() /** @@ -378,7 +374,7 @@ class ZiplineLoader internal constructor( baseUrl = loadedManifest.manifest.baseUrl, nowEpochMs = nowEpochMs, module = it.value, - receiver = receiver + receiver = receiver, ) } for (load in loads) { diff --git a/zipline-loader/src/commonMain/kotlin/app/cash/zipline/loader/internal/cache/FileState.kt b/zipline-loader/src/commonMain/kotlin/app/cash/zipline/loader/internal/cache/FileState.kt index e168ddea8..2ec64ba4f 100644 --- a/zipline-loader/src/commonMain/kotlin/app/cash/zipline/loader/internal/cache/FileState.kt +++ b/zipline-loader/src/commonMain/kotlin/app/cash/zipline/loader/internal/cache/FileState.kt @@ -31,5 +31,5 @@ enum class FileState { * The file is on the file system and ready to read. * It will not be modified until it is deleted. */ - READY + READY, } diff --git a/zipline-loader/src/commonMain/kotlin/app/cash/zipline/loader/internal/cache/database.kt b/zipline-loader/src/commonMain/kotlin/app/cash/zipline/loader/internal/cache/database.kt index 69b71a24f..347f77f0a 100644 --- a/zipline-loader/src/commonMain/kotlin/app/cash/zipline/loader/internal/cache/database.kt +++ b/zipline-loader/src/commonMain/kotlin/app/cash/zipline/loader/internal/cache/database.kt @@ -41,7 +41,7 @@ internal fun createDatabase(driver: SqlDriver): Database { return Database( driver, filesAdapter = Files.Adapter( - file_stateAdapter = EnumColumnAdapter() - ) + file_stateAdapter = EnumColumnAdapter(), + ), ) } diff --git a/zipline-loader/src/commonMain/kotlin/app/cash/zipline/loader/internal/fetcher/Fetcher.kt b/zipline-loader/src/commonMain/kotlin/app/cash/zipline/loader/internal/fetcher/Fetcher.kt index c7b1f52bc..7702e9b51 100644 --- a/zipline-loader/src/commonMain/kotlin/app/cash/zipline/loader/internal/fetcher/Fetcher.kt +++ b/zipline-loader/src/commonMain/kotlin/app/cash/zipline/loader/internal/fetcher/Fetcher.kt @@ -60,7 +60,7 @@ internal suspend fun List.fetch( sha256 = sha256, nowEpochMs = nowEpochMs, baseUrl = baseUrl, - url = url + url = url, ) ?: continue } catch (e: Exception) { if (firstException == null) { diff --git a/zipline-loader/src/commonMain/kotlin/app/cash/zipline/loader/internal/fetcher/FsEmbeddedFetcher.kt b/zipline-loader/src/commonMain/kotlin/app/cash/zipline/loader/internal/fetcher/FsEmbeddedFetcher.kt index 3fad318fc..228ca1ee0 100644 --- a/zipline-loader/src/commonMain/kotlin/app/cash/zipline/loader/internal/fetcher/FsEmbeddedFetcher.kt +++ b/zipline-loader/src/commonMain/kotlin/app/cash/zipline/loader/internal/fetcher/FsEmbeddedFetcher.kt @@ -38,7 +38,7 @@ internal class FsEmbeddedFetcher( fun loadEmbeddedManifest(applicationName: String): LoadedManifest? { val manifestBytes = fetchByteString( - filePath = embeddedDir / getApplicationManifestFileName(applicationName) + filePath = embeddedDir / getApplicationManifestFileName(applicationName), ) ?: return null return LoadedManifest(manifestBytes) } @@ -50,4 +50,3 @@ internal class FsEmbeddedFetcher( else -> null } } - diff --git a/zipline-loader/src/commonMain/kotlin/app/cash/zipline/loader/internal/fetcher/HttpFetcher.kt b/zipline-loader/src/commonMain/kotlin/app/cash/zipline/loader/internal/fetcher/HttpFetcher.kt index 78d6f6efb..8369d4d0e 100644 --- a/zipline-loader/src/commonMain/kotlin/app/cash/zipline/loader/internal/fetcher/HttpFetcher.kt +++ b/zipline-loader/src/commonMain/kotlin/app/cash/zipline/loader/internal/fetcher/HttpFetcher.kt @@ -69,7 +69,7 @@ internal class HttpFetcher( val manifestJsonElement = withBaseUrl(manifestJsonElementWithoutBaseUrl, url) val manifestJson = Json.encodeToString( JsonElement.serializer(), - manifestJsonElement + manifestJsonElement, ) return LoadedManifest( manifestBytes = manifestJson.encodeUtf8(), diff --git a/zipline-loader/src/commonMain/kotlin/app/cash/zipline/loader/internal/receiver/FsSaveReceiver.kt b/zipline-loader/src/commonMain/kotlin/app/cash/zipline/loader/internal/receiver/FsSaveReceiver.kt index f5cd5ccf1..6b78fc58a 100644 --- a/zipline-loader/src/commonMain/kotlin/app/cash/zipline/loader/internal/receiver/FsSaveReceiver.kt +++ b/zipline-loader/src/commonMain/kotlin/app/cash/zipline/loader/internal/receiver/FsSaveReceiver.kt @@ -26,7 +26,7 @@ import okio.Path internal class FsSaveReceiver( private val downloadFileSystem: FileSystem, private val downloadDir: Path, -): Receiver { +) : Receiver { override suspend fun receive(byteString: ByteString, id: String, sha256: ByteString) { downloadFileSystem.write(downloadDir / sha256.hex()) { write(byteString) diff --git a/zipline-loader/src/commonMain/kotlin/app/cash/zipline/loader/internal/receiver/Receiver.kt b/zipline-loader/src/commonMain/kotlin/app/cash/zipline/loader/internal/receiver/Receiver.kt index e0e78e6c7..78667c0bb 100644 --- a/zipline-loader/src/commonMain/kotlin/app/cash/zipline/loader/internal/receiver/Receiver.kt +++ b/zipline-loader/src/commonMain/kotlin/app/cash/zipline/loader/internal/receiver/Receiver.kt @@ -28,7 +28,6 @@ internal interface Receiver { suspend fun receive( byteString: ByteString, id: String, - sha256: ByteString + sha256: ByteString, ) } - diff --git a/zipline-loader/src/commonMain/kotlin/app/cash/zipline/loader/internal/tink/subtle/Ed25519.kt b/zipline-loader/src/commonMain/kotlin/app/cash/zipline/loader/internal/tink/subtle/Ed25519.kt index 72b5d8e3d..964e02ee6 100644 --- a/zipline-loader/src/commonMain/kotlin/app/cash/zipline/loader/internal/tink/subtle/Ed25519.kt +++ b/zipline-loader/src/commonMain/kotlin/app/cash/zipline/loader/internal/tink/subtle/Ed25519.kt @@ -48,7 +48,7 @@ internal object Ed25519 : SignatureAlgorithm { XYZ( longArrayOf(0, 0, 0, 0, 0, 0, 0, 0, 0, 0), longArrayOf(1, 0, 0, 0, 0, 0, 0, 0, 0, 0), - longArrayOf(1, 0, 0, 0, 0, 0, 0, 0, 0, 0) + longArrayOf(1, 0, 0, 0, 0, 0, 0, 0, 0, 0), ), longArrayOf(1, 0, 0, 0, 0, 0, 0, 0, 0, 0), ) @@ -63,7 +63,7 @@ internal object Ed25519 : SignatureAlgorithm { 0x00.toByte(), 0x00.toByte(), 0x00.toByte(), 0x00.toByte(), 0x00.toByte(), 0x00.toByte(), 0x00.toByte(), 0x00.toByte(), 0x00.toByte(), 0x00.toByte(), 0x00.toByte(), 0x00.toByte(), - 0x00.toByte(), 0x00.toByte(), 0x00.toByte(), 0x10.toByte() + 0x00.toByte(), 0x00.toByte(), 0x00.toByte(), 0x10.toByte(), ) /** diff --git a/zipline-loader/src/commonMain/kotlin/app/cash/zipline/loader/internal/tink/subtle/Ed25519Constants.kt b/zipline-loader/src/commonMain/kotlin/app/cash/zipline/loader/internal/tink/subtle/Ed25519Constants.kt index a190d10d8..c63cbee5c 100644 --- a/zipline-loader/src/commonMain/kotlin/app/cash/zipline/loader/internal/tink/subtle/Ed25519Constants.kt +++ b/zipline-loader/src/commonMain/kotlin/app/cash/zipline/loader/internal/tink/subtle/Ed25519Constants.kt @@ -1378,7 +1378,7 @@ internal object Ed25519Constants { yMinusX = longArrayOf(29701166, 19180498, 56230743, 9279287, 67091296, 13127209, 21382910, 11042292, 25838796, 4642684), t2d = longArrayOf(46678630, 14955536, 42982517, 8124618, 61739576, 27563961, 30468146, 19653792, 18423288, 4177476), ), - ) + ), ) val B2 = listOf( CachedXYT( diff --git a/zipline-loader/src/commonMain/kotlin/app/cash/zipline/loader/internal/tink/subtle/Field25519.kt b/zipline-loader/src/commonMain/kotlin/app/cash/zipline/loader/internal/tink/subtle/Field25519.kt index aa49b719c..fb7a0f0b2 100644 --- a/zipline-loader/src/commonMain/kotlin/app/cash/zipline/loader/internal/tink/subtle/Field25519.kt +++ b/zipline-loader/src/commonMain/kotlin/app/cash/zipline/loader/internal/tink/subtle/Field25519.kt @@ -110,89 +110,128 @@ internal object Field25519 { */ fun product(out: LongArray, in2: LongArray, in1: LongArray) { out[0] = (in2[0] * in1[0]) - out[1] = ((in2[0] * in1[1] - + in2[1] * in1[0])) - out[2] = (2 * in2[1] * in1[1] - + in2[0] * in1[2] - + in2[2] * in1[0]) - out[3] = (in2[1] * in1[2] - + in2[2] * in1[1] - + in2[0] * in1[3] - + in2[3] * in1[0]) - out[4] = (in2[2] * in1[2] - + 2 * (in2[1] * in1[3] + in2[3] * in1[1]) - + in2[0] * in1[4] - + in2[4] * in1[0]) - out[5] = (in2[2] * in1[3] - + in2[3] * in1[2] - + in2[1] * in1[4] - + in2[4] * in1[1] - + in2[0] * in1[5] - + in2[5] * in1[0]) - out[6] = (2 * (in2[3] * in1[3] + in2[1] * in1[5] + in2[5] * in1[1]) - + in2[2] * in1[4] - + in2[4] * in1[2] - + in2[0] * in1[6] - + in2[6] * in1[0]) - out[7] = (in2[3] * in1[4] - + in2[4] * in1[3] - + in2[2] * in1[5] - + in2[5] * in1[2] - + in2[1] * in1[6] - + in2[6] * in1[1] - + in2[0] * in1[7] - + in2[7] * in1[0]) - out[8] = (in2[4] * in1[4] - + 2 * (in2[3] * in1[5] + in2[5] * in1[3] + in2[1] * in1[7] + in2[7] * in1[1]) - + in2[2] * in1[6] - + in2[6] * in1[2] - + in2[0] * in1[8] - + in2[8] * in1[0]) - out[9] = (in2[4] * in1[5] - + in2[5] * in1[4] - + in2[3] * in1[6] - + in2[6] * in1[3] - + in2[2] * in1[7] - + in2[7] * in1[2] - + in2[1] * in1[8] - + in2[8] * in1[1] - + in2[0] * in1[9] - + in2[9] * in1[0]) + out[1] = ( + ( + in2[0] * in1[1] + + in2[1] * in1[0] + ) + ) + out[2] = ( + 2 * in2[1] * in1[1] + + in2[0] * in1[2] + + in2[2] * in1[0] + ) + out[3] = ( + in2[1] * in1[2] + + in2[2] * in1[1] + + in2[0] * in1[3] + + in2[3] * in1[0] + ) + out[4] = ( + in2[2] * in1[2] + + 2 * (in2[1] * in1[3] + in2[3] * in1[1]) + + in2[0] * in1[4] + + in2[4] * in1[0] + ) + out[5] = ( + in2[2] * in1[3] + + in2[3] * in1[2] + + in2[1] * in1[4] + + in2[4] * in1[1] + + in2[0] * in1[5] + + in2[5] * in1[0] + ) + out[6] = ( + 2 * (in2[3] * in1[3] + in2[1] * in1[5] + in2[5] * in1[1]) + + in2[2] * in1[4] + + in2[4] * in1[2] + + in2[0] * in1[6] + + in2[6] * in1[0] + ) + out[7] = ( + in2[3] * in1[4] + + in2[4] * in1[3] + + in2[2] * in1[5] + + in2[5] * in1[2] + + in2[1] * in1[6] + + in2[6] * in1[1] + + in2[0] * in1[7] + + in2[7] * in1[0] + ) + out[8] = ( + in2[4] * in1[4] + + 2 * (in2[3] * in1[5] + in2[5] * in1[3] + in2[1] * in1[7] + in2[7] * in1[1]) + + in2[2] * in1[6] + + in2[6] * in1[2] + + in2[0] * in1[8] + + in2[8] * in1[0] + ) + out[9] = ( + in2[4] * in1[5] + + in2[5] * in1[4] + + in2[3] * in1[6] + + in2[6] * in1[3] + + in2[2] * in1[7] + + in2[7] * in1[2] + + in2[1] * in1[8] + + in2[8] * in1[1] + + in2[0] * in1[9] + + in2[9] * in1[0] + ) out[10] = ( - 2 * (in2[5] * in1[5] + in2[3] * in1[7] + in2[7] * in1[3] + in2[1] * in1[9] + in2[9] * in1[1]) - + in2[4] * in1[6] - + in2[6] * in1[4] - + in2[2] * in1[8] - + in2[8] * in1[2]) - out[11] = (in2[5] * in1[6] - + in2[6] * in1[5] - + in2[4] * in1[7] - + in2[7] * in1[4] - + in2[3] * in1[8] - + in2[8] * in1[3] - + in2[2] * in1[9] - + in2[9] * in1[2]) - out[12] = (in2[6] * in1[6] - + 2 * (in2[5] * in1[7] + in2[7] * in1[5] + in2[3] * in1[9] + in2[9] * in1[3]) - + in2[4] * in1[8] - + in2[8] * in1[4]) - out[13] = (in2[6] * in1[7] - + in2[7] * in1[6] - + in2[5] * in1[8] - + in2[8] * in1[5] - + in2[4] * in1[9] - + in2[9] * in1[4]) - out[14] = (2 * (in2[7] * in1[7] + in2[5] * in1[9] + in2[9] * in1[5]) - + in2[6] * in1[8] - + in2[8] * in1[6]) - out[15] = (in2[7] * in1[8] - + in2[8] * in1[7] - + in2[6] * in1[9] - + in2[9] * in1[6]) - out[16] = ((in2[8] * in1[8] - + 2 * (in2[7] * in1[9] + in2[9] * in1[7]))) - out[17] = ((in2[8] * in1[9] - + in2[9] * in1[8])) + 2 * (in2[5] * in1[5] + in2[3] * in1[7] + in2[7] * in1[3] + in2[1] * in1[9] + in2[9] * in1[1]) + + in2[4] * in1[6] + + in2[6] * in1[4] + + in2[2] * in1[8] + + in2[8] * in1[2] + ) + out[11] = ( + in2[5] * in1[6] + + in2[6] * in1[5] + + in2[4] * in1[7] + + in2[7] * in1[4] + + in2[3] * in1[8] + + in2[8] * in1[3] + + in2[2] * in1[9] + + in2[9] * in1[2] + ) + out[12] = ( + in2[6] * in1[6] + + 2 * (in2[5] * in1[7] + in2[7] * in1[5] + in2[3] * in1[9] + in2[9] * in1[3]) + + in2[4] * in1[8] + + in2[8] * in1[4] + ) + out[13] = ( + in2[6] * in1[7] + + in2[7] * in1[6] + + in2[5] * in1[8] + + in2[8] * in1[5] + + in2[4] * in1[9] + + in2[9] * in1[4] + ) + out[14] = ( + 2 * (in2[7] * in1[7] + in2[5] * in1[9] + in2[9] * in1[5]) + + in2[6] * in1[8] + + in2[8] * in1[6] + ) + out[15] = ( + in2[7] * in1[8] + + in2[8] * in1[7] + + in2[6] * in1[9] + + in2[9] * in1[6] + ) + out[16] = ( + ( + in2[8] * in1[8] + + 2 * (in2[7] * in1[9] + in2[9] * in1[7]) + ) + ) + out[17] = ( + ( + in2[8] * in1[9] + + in2[9] * in1[8] + ) + ) out[18] = (2 * in2[9] * in1[9]) } @@ -329,22 +368,36 @@ internal object Field25519 { out[1] = (2 * in1[0] * in1[1]) out[2] = (2 * (in1[1] * in1[1] + in1[0] * in1[2])) out[3] = (2 * (in1[1] * in1[2] + in1[0] * in1[3])) - out[4] = (in1[2] * in1[2] - + 4 * in1[1] * in1[3] - + 2 * in1[0] * in1[4]) + out[4] = ( + in1[2] * in1[2] + + 4 * in1[1] * in1[3] + + 2 * in1[0] * in1[4] + ) out[5] = (2 * (in1[2] * in1[3] + in1[1] * in1[4] + in1[0] * in1[5])) out[6] = (2 * (in1[3] * in1[3] + in1[2] * in1[4] + in1[0] * in1[6] + 2 * in1[1] * in1[5])) out[7] = (2 * (in1[3] * in1[4] + in1[2] * in1[5] + in1[1] * in1[6] + in1[0] * in1[7])) - out[8] = ((in1[4] * in1[4] - + 2 * (in1[2] * in1[6] + in1[0] * in1[8] + 2 * (in1[1] * in1[7] + in1[3] * in1[5])))) + out[8] = ( + ( + in1[4] * in1[4] + + 2 * (in1[2] * in1[6] + in1[0] * in1[8] + 2 * (in1[1] * in1[7] + in1[3] * in1[5])) + ) + ) out[9] = (2 * (in1[4] * in1[5] + in1[3] * in1[6] + in1[2] * in1[7] + in1[1] * in1[8] + in1[0] * in1[9])) - out[10] = (2 * (in1[5] * in1[5] - + in1[4] * in1[6] - + in1[2] * in1[8] - + 2 * (in1[3] * in1[7] + in1[1] * in1[9]))) + out[10] = ( + 2 * ( + in1[5] * in1[5] + + in1[4] * in1[6] + + in1[2] * in1[8] + + 2 * (in1[3] * in1[7] + in1[1] * in1[9]) + ) + ) out[11] = (2 * (in1[5] * in1[6] + in1[4] * in1[7] + in1[3] * in1[8] + in1[2] * in1[9])) - out[12] = ((in1[6] * in1[6] - + 2 * (in1[4] * in1[8] + 2 * (in1[5] * in1[7] + in1[3] * in1[9])))) + out[12] = ( + ( + in1[6] * in1[6] + + 2 * (in1[4] * in1[8] + 2 * (in1[5] * in1[7] + in1[3] * in1[9])) + ) + ) out[13] = (2 * (in1[6] * in1[7] + in1[5] * in1[8] + in1[4] * in1[9])) out[14] = (2 * (in1[7] * in1[7] + in1[6] * in1[8] + 2 * in1[5] * in1[9])) out[15] = (2 * (in1[7] * in1[8] + in1[6] * in1[9])) @@ -375,10 +428,12 @@ internal object Field25519 { fun expand(input: ByteArray): LongArray { val output = LongArray(LIMB_CNT) for (i in 0 until LIMB_CNT) { - output[i] = ((input[EXPAND_START[i]].toInt() and 0xff).toLong() + output[i] = ( + (input[EXPAND_START[i]].toInt() and 0xff).toLong() or ((input[EXPAND_START[i] + 1].toInt() and 0xff).toLong() shl 8) or ((input[EXPAND_START[i] + 2].toInt() and 0xff).toLong() shl 16) - or ((input[EXPAND_START[i] + 3].toInt() and 0xff).toLong() shl 24)) shr EXPAND_SHIFT[i] and MASK[i and 1].toLong() + or ((input[EXPAND_START[i] + 3].toInt() and 0xff).toLong() shl 24) + ) shr EXPAND_SHIFT[i] and MASK[i and 1].toLong() } return output } @@ -477,14 +532,22 @@ internal object Field25519 { } val output = ByteArray(FIELD_LEN) for (i in 0 until LIMB_CNT) { - output[EXPAND_START[i]] = (output[EXPAND_START[i]] - .toLong() or (input[i] and 0xffL)).toByte() - output[EXPAND_START[i] + 1] = (output[EXPAND_START[i] + 1] - .toLong() or (input[i] shr 8 and 0xffL)).toByte() - output[EXPAND_START[i] + 2] = (output[EXPAND_START[i] + 2] - .toLong() or (input[i] shr 16 and 0xffL)).toByte() - output[EXPAND_START[i] + 3] = (output[EXPAND_START[i] + 3] - .toLong() or (input[i] shr 24 and 0xffL)).toByte() + output[EXPAND_START[i]] = ( + output[EXPAND_START[i]] + .toLong() or (input[i] and 0xffL) + ).toByte() + output[EXPAND_START[i] + 1] = ( + output[EXPAND_START[i] + 1] + .toLong() or (input[i] shr 8 and 0xffL) + ).toByte() + output[EXPAND_START[i] + 2] = ( + output[EXPAND_START[i] + 2] + .toLong() or (input[i] shr 16 and 0xffL) + ).toByte() + output[EXPAND_START[i] + 3] = ( + output[EXPAND_START[i] + 3] + .toLong() or (input[i] shr 24 and 0xffL) + ).toByte() } return output } @@ -507,97 +570,97 @@ internal object Field25519 { val t0 = LongArray(LIMB_CNT) val t1 = LongArray(LIMB_CNT) - square(z2, z) // 2 - square(t1, z2) // 4 - square(t0, t1) // 8 - mult(z9, t0, z) // 9 - mult(z11, z9, z2) // 11 - square(t0, z11) // 22 - mult(z2To5Minus1, t0, z9) // 2^5 - 2^0 = 31 - - square(t0, z2To5Minus1) // 2^6 - 2^1 - square(t1, t0) // 2^7 - 2^2 - square(t0, t1) // 2^8 - 2^3 - square(t1, t0) // 2^9 - 2^4 - square(t0, t1) // 2^10 - 2^5 - mult(z2To10Minus1, t0, z2To5Minus1) // 2^10 - 2^0 - - square(t0, z2To10Minus1) // 2^11 - 2^1 - square(t1, t0) // 2^12 - 2^2 + square(z2, z) // 2 + square(t1, z2) // 4 + square(t0, t1) // 8 + mult(z9, t0, z) // 9 + mult(z11, z9, z2) // 11 + square(t0, z11) // 22 + mult(z2To5Minus1, t0, z9) // 2^5 - 2^0 = 31 + + square(t0, z2To5Minus1) // 2^6 - 2^1 + square(t1, t0) // 2^7 - 2^2 + square(t0, t1) // 2^8 - 2^3 + square(t1, t0) // 2^9 - 2^4 + square(t0, t1) // 2^10 - 2^5 + mult(z2To10Minus1, t0, z2To5Minus1) // 2^10 - 2^0 + + square(t0, z2To10Minus1) // 2^11 - 2^1 + square(t1, t0) // 2^12 - 2^2 run { var i = 2 - while (i < 10) { // 2^20 - 2^10 + while (i < 10) { // 2^20 - 2^10 square(t0, t1) square(t1, t0) i += 2 } } - mult(z2To20Minus1, t1, z2To10Minus1) // 2^20 - 2^0 + mult(z2To20Minus1, t1, z2To10Minus1) // 2^20 - 2^0 - square(t0, z2To20Minus1) // 2^21 - 2^1 - square(t1, t0) // 2^22 - 2^2 + square(t0, z2To20Minus1) // 2^21 - 2^1 + square(t1, t0) // 2^22 - 2^2 run { var i = 2 - while (i < 20) { // 2^40 - 2^20 + while (i < 20) { // 2^40 - 2^20 square(t0, t1) square(t1, t0) i += 2 } } - mult(t0, t1, z2To20Minus1) // 2^40 - 2^0 + mult(t0, t1, z2To20Minus1) // 2^40 - 2^0 - square(t1, t0) // 2^41 - 2^1 - square(t0, t1) // 2^42 - 2^2 + square(t1, t0) // 2^41 - 2^1 + square(t0, t1) // 2^42 - 2^2 run { var i = 2 - while (i < 10) { // 2^50 - 2^10 + while (i < 10) { // 2^50 - 2^10 square(t1, t0) square(t0, t1) i += 2 } } - mult(z2To50Minus1, t0, z2To10Minus1) // 2^50 - 2^0 + mult(z2To50Minus1, t0, z2To10Minus1) // 2^50 - 2^0 - square(t0, z2To50Minus1) // 2^51 - 2^1 - square(t1, t0) // 2^52 - 2^2 + square(t0, z2To50Minus1) // 2^51 - 2^1 + square(t1, t0) // 2^52 - 2^2 run { var i = 2 - while (i < 50) { // 2^100 - 2^50 + while (i < 50) { // 2^100 - 2^50 square(t0, t1) square(t1, t0) i += 2 } } - mult(z2To100Minus1, t1, z2To50Minus1) // 2^100 - 2^0 + mult(z2To100Minus1, t1, z2To50Minus1) // 2^100 - 2^0 - square(t1, z2To100Minus1) // 2^101 - 2^1 - square(t0, t1) // 2^102 - 2^2 + square(t1, z2To100Minus1) // 2^101 - 2^1 + square(t0, t1) // 2^102 - 2^2 run { var i = 2 - while (i < 100) { // 2^200 - 2^100 + while (i < 100) { // 2^200 - 2^100 square(t1, t0) square(t0, t1) i += 2 } } - mult(t1, t0, z2To100Minus1) // 2^200 - 2^0 + mult(t1, t0, z2To100Minus1) // 2^200 - 2^0 - square(t0, t1) // 2^201 - 2^1 - square(t1, t0) // 2^202 - 2^2 + square(t0, t1) // 2^201 - 2^1 + square(t1, t0) // 2^202 - 2^2 var i = 2 - while (i < 50) { // 2^250 - 2^50 + while (i < 50) { // 2^250 - 2^50 square(t0, t1) square(t1, t0) i += 2 } - mult(t0, t1, z2To50Minus1) // 2^250 - 2^0 - - square(t1, t0) // 2^251 - 2^1 - square(t0, t1) // 2^252 - 2^2 - square(t1, t0) // 2^253 - 2^3 - square(t0, t1) // 2^254 - 2^4 - square(t1, t0) // 2^255 - 2^5 - mult(out, t1, z11) // 2^255 - 21 + mult(t0, t1, z2To50Minus1) // 2^250 - 2^0 + + square(t1, t0) // 2^251 - 2^1 + square(t0, t1) // 2^252 - 2^2 + square(t1, t0) // 2^253 - 2^3 + square(t0, t1) // 2^254 - 2^4 + square(t1, t0) // 2^255 - 2^5 + mult(out, t1, z11) // 2^255 - 21 } /** diff --git a/zipline-loader/src/commonTest/kotlin/app/cash/zipline/loader/DownloadOnlyFetcherReceiverTest.kt b/zipline-loader/src/commonTest/kotlin/app/cash/zipline/loader/DownloadOnlyFetcherReceiverTest.kt index 7e60c66c1..86974c1bc 100644 --- a/zipline-loader/src/commonTest/kotlin/app/cash/zipline/loader/DownloadOnlyFetcherReceiverTest.kt +++ b/zipline-loader/src/commonTest/kotlin/app/cash/zipline/loader/DownloadOnlyFetcherReceiverTest.kt @@ -35,7 +35,7 @@ class DownloadOnlyFetcherReceiverTest { private val loader = testZiplineLoader( dispatcher = dispatcher, httpClient = httpClient, - nowEpochMs = { 1 } + nowEpochMs = { 1 }, ) private val fileSystem = systemFileSystem @@ -53,10 +53,12 @@ class DownloadOnlyFetcherReceiverTest { assertTrue(fileSystem.exists(downloadDir / testFixtures.alphaSha256Hex)) assertEquals( testFixtures.alphaByteString, - fileSystem.read(downloadDir / testFixtures.alphaSha256Hex) { readByteString() }) + fileSystem.read(downloadDir / testFixtures.alphaSha256Hex) { readByteString() }, + ) assertTrue(fileSystem.exists(downloadDir / testFixtures.bravoSha256Hex)) assertEquals( testFixtures.bravoByteString, - fileSystem.read(downloadDir / testFixtures.bravoSha256Hex) { readByteString() }) + fileSystem.read(downloadDir / testFixtures.bravoSha256Hex) { readByteString() }, + ) } } diff --git a/zipline-loader/src/commonTest/kotlin/app/cash/zipline/loader/FakeZiplineHttpClient.kt b/zipline-loader/src/commonTest/kotlin/app/cash/zipline/loader/FakeZiplineHttpClient.kt index 1574a976a..67a2a6e44 100644 --- a/zipline-loader/src/commonTest/kotlin/app/cash/zipline/loader/FakeZiplineHttpClient.kt +++ b/zipline-loader/src/commonTest/kotlin/app/cash/zipline/loader/FakeZiplineHttpClient.kt @@ -22,7 +22,7 @@ import kotlinx.coroutines.flow.consumeAsFlow import okio.ByteString import okio.IOException -class FakeZiplineHttpClient: ZiplineHttpClient() { +class FakeZiplineHttpClient : ZiplineHttpClient() { var filePathToByteString: Map = mapOf() val webSockets = mutableMapOf>() val log = Channel(capacity = Int.MAX_VALUE) diff --git a/zipline-loader/src/commonTest/kotlin/app/cash/zipline/loader/FastCodeUpdatesTest.kt b/zipline-loader/src/commonTest/kotlin/app/cash/zipline/loader/FastCodeUpdatesTest.kt index 39e538090..d8dc98e8e 100644 --- a/zipline-loader/src/commonTest/kotlin/app/cash/zipline/loader/FastCodeUpdatesTest.kt +++ b/zipline-loader/src/commonTest/kotlin/app/cash/zipline/loader/FastCodeUpdatesTest.kt @@ -133,14 +133,17 @@ class FastCodeUpdatesTest { // confirm >= 500 ms has elapsed assertTrue(testDuration.inWholeMilliseconds >= 500) - assertEquals(listOf( + assertEquals( + listOf( "close socket $wsUrlA", "close socket $wsUrlB", "close socket $wsUrlC", "open socket $wsUrlA", "open socket $wsUrlB", "open socket $wsUrlC", - ), client.log.consumeAsFlow().toList().take(6)) + ), + client.log.consumeAsFlow().toList().take(6), + ) } @Test @@ -176,9 +179,12 @@ class FastCodeUpdatesTest { job.cancel() client.log.close() - assertEquals(listOf( + assertEquals( + listOf( "open socket $wsUrl", "open socket $wsUrl", - ), client.log.consumeAsFlow().toList().take(6)) + ), + client.log.consumeAsFlow().toList().take(6), + ) } } diff --git a/zipline-loader/src/commonTest/kotlin/app/cash/zipline/loader/LoadOrFallbackTest.kt b/zipline-loader/src/commonTest/kotlin/app/cash/zipline/loader/LoadOrFallbackTest.kt index 2576b01cd..e191a1c7b 100644 --- a/zipline-loader/src/commonTest/kotlin/app/cash/zipline/loader/LoadOrFallbackTest.kt +++ b/zipline-loader/src/commonTest/kotlin/app/cash/zipline/loader/LoadOrFallbackTest.kt @@ -110,17 +110,23 @@ class LoadOrFallbackTest { @Test fun successfulNetworkMakesPreviousNetworkPrunable() = runBlocking { assertEquals("apple", tester.success("red", "apple")) - assertEquals(2, tester.countFiles { + assertEquals( + 2, + tester.countFiles { assertEquals("firetruck", tester.success("red", "firetruck")) - }) + }, + ) } @Test fun loadFailureIsPrunable() = runBlocking { assertEquals("apple", tester.success("red", "apple")) - assertEquals(1, tester.countFiles { + assertEquals( + 1, + tester.countFiles { assertEquals("apple", tester.failureCodeLoadFails("red")) - }) + }, + ) assertEquals(-1, tester.prune()) } diff --git a/zipline-loader/src/commonTest/kotlin/app/cash/zipline/loader/LoaderEventsTest.kt b/zipline-loader/src/commonTest/kotlin/app/cash/zipline/loader/LoaderEventsTest.kt index 5d79b7cdd..05203e9ab 100644 --- a/zipline-loader/src/commonTest/kotlin/app/cash/zipline/loader/LoaderEventsTest.kt +++ b/zipline-loader/src/commonTest/kotlin/app/cash/zipline/loader/LoaderEventsTest.kt @@ -61,7 +61,7 @@ class LoaderEventsTest { "mainFunctionEnd red", "applicationLoadSuccess red https://example.com/files/red/red.manifest.zipline.json", ), - eventListener.takeAll(skipServiceEvents = true) + eventListener.takeAll(skipServiceEvents = true), ) } @@ -89,7 +89,7 @@ class LoaderEventsTest { "downloadEnd red https://example.com/files/red/red.manifest.zipline.json", "applicationLoadSkipped red https://example.com/files/red/red.manifest.zipline.json", ), - eventListener.takeAll(skipServiceEvents = true) + eventListener.takeAll(skipServiceEvents = true), ) } @@ -114,7 +114,7 @@ class LoaderEventsTest { "mainFunctionEnd red", "applicationLoadSuccess red https://example.com/files/red/red.manifest.zipline.json", ), - eventListener.takeAll(skipServiceEvents = true) + eventListener.takeAll(skipServiceEvents = true), ) } @@ -140,7 +140,7 @@ class LoaderEventsTest { "mainFunctionEnd red", "applicationLoadSuccess red null", ), - eventListener.takeAll(skipServiceEvents = true) + eventListener.takeAll(skipServiceEvents = true), ) } @@ -170,7 +170,7 @@ class LoaderEventsTest { "mainFunctionEnd red", "applicationLoadSuccess red null", ), - eventListener.takeAll(skipServiceEvents = true) + eventListener.takeAll(skipServiceEvents = true), ) } @@ -200,7 +200,7 @@ class LoaderEventsTest { "mainFunctionEnd red", "applicationLoadSuccess red null", ), - eventListener.takeAll(skipServiceEvents = true) + eventListener.takeAll(skipServiceEvents = true), ) } @@ -232,7 +232,7 @@ class LoaderEventsTest { "mainFunctionEnd red", "applicationLoadSuccess red null", ), - eventListener.takeAll(skipServiceEvents = true) + eventListener.takeAll(skipServiceEvents = true), ) } } diff --git a/zipline-loader/src/commonTest/kotlin/app/cash/zipline/loader/LoaderTester.kt b/zipline-loader/src/commonTest/kotlin/app/cash/zipline/loader/LoaderTester.kt index 25290db6d..ead0cc715 100644 --- a/zipline-loader/src/commonTest/kotlin/app/cash/zipline/loader/LoaderTester.kt +++ b/zipline-loader/src/commonTest/kotlin/app/cash/zipline/loader/LoaderTester.kt @@ -34,7 +34,7 @@ import okio.FileSystem @OptIn(ExperimentalCoroutinesApi::class) class LoaderTester( private val eventListener: EventListener = EventListener.NONE, - private val manifestVerifier: ManifestVerifier = NO_SIGNATURE_CHECKS + private val manifestVerifier: ManifestVerifier = NO_SIGNATURE_CHECKS, ) { val tempDir = FileSystem.SYSTEM_TEMPORARY_DIRECTORY / "okio-${randomToken().hex()}" @@ -65,7 +65,7 @@ class LoaderTester( cache = testZiplineCache( systemFileSystem, cacheDir, - cacheMaxSizeInBytes.toLong() + cacheMaxSizeInBytes.toLong(), ) loader = testZiplineLoader( dispatcher = dispatcher, @@ -77,7 +77,7 @@ class LoaderTester( embeddedDir = embeddedDir, embeddedFileSystem = embeddedFileSystem, ).withCache( - cache + cache, ) } @@ -101,8 +101,8 @@ class LoaderTester( } embeddedFileSystem.write( embeddedDir / getApplicationManifestFileName( - applicationName - ) + applicationName, + ), ) { write(embeddedManifest.manifestBytes) } @@ -125,7 +125,7 @@ class LoaderTester( ) httpClient.filePathToByteString = mapOf( manifestUrl to loadedManifest.manifestBytes, - "$baseUrl/$applicationName/$seed.zipline" to ziplineFileByteString + "$baseUrl/$applicationName/$seed.zipline" to ziplineFileByteString, ) return loader.load( applicationName = applicationName, @@ -152,16 +152,17 @@ class LoaderTester( val seed = "fail" val manifestUrl = "$baseUrl/$applicationName/${getApplicationManifestFileName(applicationName)}" val ziplineFileByteString = testFixtures.createZiplineFile( - LoaderTestFixtures.createJs(seed), "$seed.js" + LoaderTestFixtures.createJs(seed), + "$seed.js", ) httpClient.filePathToByteString = mapOf( - "$baseUrl/$applicationName/$seed.zipline" to ziplineFileByteString + "$baseUrl/$applicationName/$seed.zipline" to ziplineFileByteString, ) loadZiplineFromLastResult(applicationName, manifestUrl) return (zipline.quickJs.evaluate("globalThis.log", "assert.js") as String).removeSuffix( - " loaded\n" + " loaded\n", ) } @@ -189,7 +190,7 @@ class LoaderTester( loadZiplineFromLastResult(applicationName, manifestUrl) return (zipline.quickJs.evaluate("globalThis.log", "assert.js") as String).removeSuffix( - " loaded\n" + " loaded\n", ) } @@ -212,13 +213,13 @@ class LoaderTester( .readByteString() httpClient.filePathToByteString = mapOf( manifestUrl to malformedManifest, - "$baseUrl/$applicationName/$seed.zipline" to ziplineFileByteString + "$baseUrl/$applicationName/$seed.zipline" to ziplineFileByteString, ) loadZiplineFromLastResult(applicationName, manifestUrl) return (zipline.quickJs.evaluate("globalThis.log", "assert.js") as String).removeSuffix( - " loaded\n" + " loaded\n", ) } @@ -241,7 +242,7 @@ class LoaderTester( loadZiplineFromLastResult(applicationName, manifestUrl) return (zipline.quickJs.evaluate("globalThis.log", "assert.js") as String).removeSuffix( - " loaded\n" + " loaded\n", ) } @@ -249,8 +250,9 @@ class LoaderTester( val seed = "broken" val ziplineFileByteString = testFixtures.createZiplineFile( LoaderTestFixtures.createFailureJs( - seed - ), "$seed.js" + seed, + ), + "$seed.js", ) val loadedManifest = LoaderTestFixtures.createRelativeManifest( seed, @@ -262,7 +264,7 @@ class LoaderTester( httpClient.filePathToByteString = mapOf( manifestUrl to loadedManifest.manifestBytes, - "$baseUrl/$applicationName/$seed.zipline" to ziplineFileByteString + "$baseUrl/$applicationName/$seed.zipline" to ziplineFileByteString, ) loadZiplineFromLastResult(applicationName, manifestUrl) @@ -285,7 +287,7 @@ class LoaderTester( httpClient.filePathToByteString = mapOf( manifestUrl to loadedManifest.manifestBytes, - "$baseUrl/$applicationName/$seed.zipline" to ziplineFileByteString + "$baseUrl/$applicationName/$seed.zipline" to ziplineFileByteString, ) loadZiplineFromLastResult(applicationName, manifestUrl) { diff --git a/zipline-loader/src/commonTest/kotlin/app/cash/zipline/loader/ProductionFetcherReceiverTest.kt b/zipline-loader/src/commonTest/kotlin/app/cash/zipline/loader/ProductionFetcherReceiverTest.kt index cc88fcae7..8fe8ebf8b 100644 --- a/zipline-loader/src/commonTest/kotlin/app/cash/zipline/loader/ProductionFetcherReceiverTest.kt +++ b/zipline-loader/src/commonTest/kotlin/app/cash/zipline/loader/ProductionFetcherReceiverTest.kt @@ -78,8 +78,9 @@ class ProductionFetcherReceiverTest { """ |alpha loaded |bravo loaded - |""".trimMargin(), - zipline.quickJs.getLog() + | +""".trimMargin(), + zipline.quickJs.getLog(), ) } @@ -102,8 +103,9 @@ class ProductionFetcherReceiverTest { """ |alpha loaded |bravo loaded - |""".trimMargin(), - zipline.quickJs.getLog() + | +""".trimMargin(), + zipline.quickJs.getLog(), ) } @@ -123,8 +125,9 @@ class ProductionFetcherReceiverTest { """ |alpha loaded |bravo loaded - |""".trimMargin(), - zipline.quickJs.getLog() + | +""".trimMargin(), + zipline.quickJs.getLog(), ) val ziplineFileFromCache = cache.getOrPut("app1", testFixtures.alphaSha256, nowMillis) { diff --git a/zipline-loader/src/commonTest/kotlin/app/cash/zipline/loader/TopologicalSortTest.kt b/zipline-loader/src/commonTest/kotlin/app/cash/zipline/loader/TopologicalSortTest.kt index 8014c87e1..0ec8271ed 100644 --- a/zipline-loader/src/commonTest/kotlin/app/cash/zipline/loader/TopologicalSortTest.kt +++ b/zipline-loader/src/commonTest/kotlin/app/cash/zipline/loader/TopologicalSortTest.kt @@ -50,22 +50,33 @@ class TopologicalSortTest { assertTopologicalSort( unsorted = listOf("a", "b"), sorted = listOf("b", "a"), - "ab" + "ab", ) assertTopologicalSort( unsorted = listOf("b", "c", "d", "a"), sorted = listOf("a", "b", "c", "d"), - "ba", "ca", "db", "dc" + "ba", + "ca", + "db", + "dc", ) assertTopologicalSort( unsorted = listOf("d", "b", "c", "a"), sorted = listOf("a", "b", "c", "d"), - "ba", "ca", "db", "dc" + "ba", + "ca", + "db", + "dc", ) assertTopologicalSort( unsorted = listOf("a", "b", "c", "d", "e"), sorted = listOf("d", "c", "a", "e", "b"), - "be", "bc", "ec", "ac", "cd", "ad" + "be", + "bc", + "ec", + "ac", + "cd", + "ad", ) } diff --git a/zipline-loader/src/commonTest/kotlin/app/cash/zipline/loader/ZiplineLoaderSigningTest.kt b/zipline-loader/src/commonTest/kotlin/app/cash/zipline/loader/ZiplineLoaderSigningTest.kt index 83df15c51..c4a11d645 100644 --- a/zipline-loader/src/commonTest/kotlin/app/cash/zipline/loader/ZiplineLoaderSigningTest.kt +++ b/zipline-loader/src/commonTest/kotlin/app/cash/zipline/loader/ZiplineLoaderSigningTest.kt @@ -26,7 +26,6 @@ import kotlin.test.AfterTest import kotlin.test.BeforeTest import kotlin.test.Test import kotlin.test.assertEquals -import kotlin.test.assertFailsWith import kotlin.test.assertTrue import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.runBlocking @@ -44,7 +43,7 @@ class ZiplineLoaderSigningTest { eventListener = eventListener, manifestVerifier = ManifestVerifier.Builder() .addEd25519("key1", SampleKeys.key1Public) - .build() + .build(), ) private val testFixtures = LoaderTestFixtures() @@ -90,7 +89,7 @@ class ZiplineLoaderSigningTest { "bravo" -> value.copy(sha256 = "wrong content for SHA-256".encodeUtf8().sha256()) else -> value } - } + }, ) val manifest = signer.sign(manifestWithBadChecksum) @@ -123,7 +122,7 @@ class ZiplineLoaderSigningTest { val loadResult = tester.loader.loadOnce("test", manifestUrl) assertEquals( "manifest signature for key key1 did not verify!", - (loadResult as LoadResult.Failure).exception.message + (loadResult as LoadResult.Failure).exception.message, ) val listenerException = eventListener.takeException() assertTrue(listenerException is IllegalStateException) diff --git a/zipline-loader/src/commonTest/kotlin/app/cash/zipline/loader/ZiplineLoaderTest.kt b/zipline-loader/src/commonTest/kotlin/app/cash/zipline/loader/ZiplineLoaderTest.kt index 0505e97e0..39366e70b 100644 --- a/zipline-loader/src/commonTest/kotlin/app/cash/zipline/loader/ZiplineLoaderTest.kt +++ b/zipline-loader/src/commonTest/kotlin/app/cash/zipline/loader/ZiplineLoaderTest.kt @@ -72,7 +72,7 @@ class ZiplineLoaderTest { fun happyPath() = runBlocking { httpClient.filePathToByteString = mapOf( alphaUrl to testFixtures.alphaByteString, - bravoUrl to testFixtures.bravoByteString + bravoUrl to testFixtures.bravoByteString, ) val zipline = loader.loadOrFail("test", testFixtures.manifest) assertEquals( @@ -80,7 +80,8 @@ class ZiplineLoaderTest { """ |alpha loaded |bravo loaded - |""".trimMargin() + | +""".trimMargin(), ) zipline.close() } @@ -90,7 +91,7 @@ class ZiplineLoaderTest { httpClient.filePathToByteString = mapOf( manifestUrl to testFixtures.manifestNoBaseUrlByteString, alphaUrl to testFixtures.alphaByteString, - bravoUrl to testFixtures.bravoByteString + bravoUrl to testFixtures.bravoByteString, ) val zipline = (loader.loadOnce("test", manifestUrl) as LoadResult.Success).zipline assertEquals( @@ -98,7 +99,8 @@ class ZiplineLoaderTest { """ |alpha loaded |bravo loaded - |""".trimMargin() + | +""".trimMargin(), ) zipline.close() } @@ -109,7 +111,7 @@ class ZiplineLoaderTest { httpClient.filePathToByteString = mapOf( manifestUrl to testFixtures.manifestNoBaseUrlByteString, alphaUrl to testFixtures.alphaByteString, - bravoUrl to testFixtures.bravoByteString + bravoUrl to testFixtures.bravoByteString, ) val ziplineColdCache = (loader.loadOnce("test", manifestUrl) as LoadResult.Success).zipline assertEquals( @@ -117,7 +119,8 @@ class ZiplineLoaderTest { """ |alpha loaded |bravo loaded - |""".trimMargin() + | +""".trimMargin(), ) ziplineColdCache.close() @@ -132,7 +135,8 @@ class ZiplineLoaderTest { """ |alpha loaded |bravo loaded - |""".trimMargin() + | +""".trimMargin(), ) ziplineWarmedCache.close() } @@ -159,7 +163,8 @@ class ZiplineLoaderTest { """ |alpha loaded |bravo loaded - |""".trimMargin() + | +""".trimMargin(), ) zipline.close() } @@ -176,7 +181,7 @@ class ZiplineLoaderTest { httpClient.filePathToByteString = mapOf( manifestUrl to testFixtures.manifestNoBaseUrlByteString, alphaUrl to testFixtures.alphaByteString, - bravoUrl to testFixtures.bravoByteString + bravoUrl to testFixtures.bravoByteString, ) loader.download("test", downloadDir, downloadFileSystem, manifestUrl) @@ -184,15 +189,18 @@ class ZiplineLoaderTest { testFixtures.manifest, downloadFileSystem.read(downloadDir / getApplicationManifestFileName("test")) { readByteString() - }) + }, + ) assertTrue(downloadFileSystem.exists(downloadDir / testFixtures.alphaSha256Hex)) assertEquals( testFixtures.alphaByteString, - downloadFileSystem.read(downloadDir / testFixtures.alphaSha256Hex) { readByteString() }) + downloadFileSystem.read(downloadDir / testFixtures.alphaSha256Hex) { readByteString() }, + ) assertTrue(downloadFileSystem.exists(downloadDir / testFixtures.bravoSha256Hex)) assertEquals( testFixtures.bravoByteString, - downloadFileSystem.read(downloadDir / testFixtures.bravoSha256Hex) { readByteString() }) + downloadFileSystem.read(downloadDir / testFixtures.bravoSha256Hex) { readByteString() }, + ) // Load into Zipline. val zipline = loader.loadOrFail("test", testFixtures.manifest) @@ -201,7 +209,8 @@ class ZiplineLoaderTest { """ |alpha loaded |bravo loaded - |""".trimMargin() + | +""".trimMargin(), ) zipline.close() } @@ -218,7 +227,7 @@ class ZiplineLoaderTest { httpClient.filePathToByteString = mapOf( manifestUrl to testFixtures.manifestByteString, alphaUrl to testFixtures.alphaByteString, - bravoUrl to testFixtures.bravoByteString + bravoUrl to testFixtures.bravoByteString, ) loader.download("test", downloadDir, fileSystem, testFixtures.embeddedLoadedManifest) @@ -226,15 +235,18 @@ class ZiplineLoaderTest { assertTrue(fileSystem.exists(downloadDir / getApplicationManifestFileName("test"))) assertDownloadedToEmbeddedManifest( testFixtures.manifest, - fileSystem.read(downloadDir / getApplicationManifestFileName("test")) { readByteString() }) + fileSystem.read(downloadDir / getApplicationManifestFileName("test")) { readByteString() }, + ) assertTrue(fileSystem.exists(downloadDir / testFixtures.alphaSha256Hex)) assertEquals( testFixtures.alphaByteString, - fileSystem.read(downloadDir / testFixtures.alphaSha256Hex) { readByteString() }) + fileSystem.read(downloadDir / testFixtures.alphaSha256Hex) { readByteString() }, + ) assertTrue(fileSystem.exists(downloadDir / testFixtures.bravoSha256Hex)) assertEquals( testFixtures.bravoByteString, - fileSystem.read(downloadDir / testFixtures.bravoSha256Hex) { readByteString() }) + fileSystem.read(downloadDir / testFixtures.bravoSha256Hex) { readByteString() }, + ) } @Test @@ -267,19 +279,25 @@ class ZiplineLoaderTest { ).test { assertEquals( "apple", - ((awaitItem() as LoadResult.Success).zipline.quickJs.evaluate( - "globalThis.log", "assert.js" - ) as String).removeSuffix( - " loaded\n" - ) + ( + (awaitItem() as LoadResult.Success).zipline.quickJs.evaluate( + "globalThis.log", + "assert.js", + ) as String + ).removeSuffix( + " loaded\n", + ), ) assertEquals( "firetruck", - ((awaitItem() as LoadResult.Success).zipline.quickJs.evaluate( - "globalThis.log", "assert.js" - ) as String).removeSuffix( - " loaded\n" - ) + ( + (awaitItem() as LoadResult.Success).zipline.quickJs.evaluate( + "globalThis.log", + "assert.js", + ) as String + ).removeSuffix( + " loaded\n", + ), ) awaitComplete() } diff --git a/zipline-loader/src/commonTest/kotlin/app/cash/zipline/loader/ZiplineManifestTest.kt b/zipline-loader/src/commonTest/kotlin/app/cash/zipline/loader/ZiplineManifestTest.kt index 03e81f019..a94d7f39f 100644 --- a/zipline-loader/src/commonTest/kotlin/app/cash/zipline/loader/ZiplineManifestTest.kt +++ b/zipline-loader/src/commonTest/kotlin/app/cash/zipline/loader/ZiplineManifestTest.kt @@ -39,7 +39,7 @@ class ZiplineManifestTest { dependsOnIds = listOf(), ), ), - mainFunction = "zipline.ziplineMain" + mainFunction = "zipline.ziplineMain", ) val sorted = ZiplineManifest.create( modules = mapOf( @@ -54,7 +54,7 @@ class ZiplineManifestTest { dependsOnIds = listOf("alpha"), ), ), - mainFunction = "zipline.ziplineMain" + mainFunction = "zipline.ziplineMain", ) assertEquals(sorted, unsorted) } @@ -67,9 +67,9 @@ class ZiplineManifestTest { url = "/alpha.zipline", sha256 = "abc123".encodeUtf8(), dependsOnIds = listOf(), - ) + ), ), - mainFunction = "zipline.ziplineMain" + mainFunction = "zipline.ziplineMain", ) val unsortedException = assertFailsWith { empty.copy( @@ -83,13 +83,13 @@ class ZiplineManifestTest { url = "/alpha.zipline", sha256 = "abc123".encodeUtf8(), dependsOnIds = listOf(), - ) - ) + ), + ), ) } assertEquals( "Modules are not topologically sorted and can not be loaded", - unsortedException.message + unsortedException.message, ) } @@ -109,7 +109,7 @@ class ZiplineManifestTest { } assertEquals( "No topological ordering is possible for [alpha]", - selfDependencyException.message + selfDependencyException.message, ) val cyclicalException = assertFailsWith { @@ -125,12 +125,12 @@ class ZiplineManifestTest { sha256 = "abc123".encodeUtf8(), dependsOnIds = listOf("alpha"), ), - ) + ), ) } assertEquals( "No topological ordering is possible for [alpha, bravo]", - cyclicalException.message + cyclicalException.message, ) } @@ -149,7 +149,7 @@ class ZiplineManifestTest { dependsOnIds = listOf("alpha"), ), ), - mainFunction = "zipline.ziplineMain" + mainFunction = "zipline.ziplineMain", ) assertEquals("bravo", manifest.mainModuleId) } @@ -202,7 +202,7 @@ class ZiplineManifestTest { | "version": null |} """.trimMargin(), - prettyPrint(serialized) + prettyPrint(serialized), ) val parsed = serialized.decodeToManifest() @@ -262,7 +262,7 @@ class ZiplineManifestTest { url = "/alpha.zipline", sha256 = "abc123".encodeUtf8(), dependsOnIds = listOf(), - ) + ), ), mainModuleId = "/alpha.zipline", ) diff --git a/zipline-loader/src/commonTest/kotlin/app/cash/zipline/loader/internal/EcdsaP256Test.kt b/zipline-loader/src/commonTest/kotlin/app/cash/zipline/loader/internal/EcdsaP256Test.kt index 435a6fa54..d14f58cbf 100644 --- a/zipline-loader/src/commonTest/kotlin/app/cash/zipline/loader/internal/EcdsaP256Test.kt +++ b/zipline-loader/src/commonTest/kotlin/app/cash/zipline/loader/internal/EcdsaP256Test.kt @@ -39,18 +39,22 @@ class EcdsaP256Test { assertTrue(ecdsaP256.verify(data, SampleKeys.key4HelloWorldsignatureB, SampleKeys.key4Public)) // If the data changes, it doesn't verify. - assertFalse(ecdsaP256.verify( + assertFalse( + ecdsaP256.verify( message = "hello World".encodeUtf8(), signature = SampleKeys.key4HelloWorldsignatureA, - publicKey = SampleKeys.key4Public - )) + publicKey = SampleKeys.key4Public, + ), + ) // If the key changes, it doesn't verify. - assertFalse(ecdsaP256.verify( + assertFalse( + ecdsaP256.verify( message = data, signature = SampleKeys.key4HelloWorldsignatureA, - publicKey = SampleKeys.key5Public - )) + publicKey = SampleKeys.key5Public, + ), + ) } @Test @@ -80,12 +84,12 @@ class EcdsaP256Test { val signature = testcase.sig.decodeHex() if (ecdsaP256.verify(message, signature, publicKey)) { if (testcase.result == "invalid") { - println("FAIL ${testcaseId}: accepting invalid signature") + println("FAIL $testcaseId: accepting invalid signature") if (testcaseId !in knownFailures) unexpectedErrors++ } } else { if (testcase.result == "valid") { - println("FAIL ${testcaseId}: rejecting valid signature") + println("FAIL $testcaseId: rejecting valid signature") if (testcaseId !in knownFailures) unexpectedErrors++ } } diff --git a/zipline-loader/src/commonTest/kotlin/app/cash/zipline/loader/internal/SignaturePayloadTest.kt b/zipline-loader/src/commonTest/kotlin/app/cash/zipline/loader/internal/SignaturePayloadTest.kt index 1fbe0a4e0..aafb4f3a5 100644 --- a/zipline-loader/src/commonTest/kotlin/app/cash/zipline/loader/internal/SignaturePayloadTest.kt +++ b/zipline-loader/src/commonTest/kotlin/app/cash/zipline/loader/internal/SignaturePayloadTest.kt @@ -34,7 +34,7 @@ class SignaturePayloadTest { url = "kotlin_kotlin.zipline", sha256 = "6bd4baa9f46afa62477fec8c9e95528de7539f036d26fc13885177b32fc0d6ab".decodeHex(), dependsOnIds = listOf(), - ) + ), ), mainModuleId = "./kotlin_kotlin.js", mainFunction = "app.cash.prepareApp", @@ -46,12 +46,12 @@ class SignaturePayloadTest { url = "kotlin_kotlin.zipline", sha256 = "6bd4baa9f46afa62477fec8c9e95528de7539f036d26fc13885177b32fc0d6ab".decodeHex(), dependsOnIds = listOf(), - ) + ), ), mainModuleId = "./kotlin_kotlin.js", mainFunction = "app.cash.prepareApp", ).copy( - baseUrl = "https://example.com/base-url/" + baseUrl = "https://example.com/base-url/", ) assertEquals( @@ -68,7 +68,7 @@ class SignaturePayloadTest { url = "kotlin_kotlin.zipline", sha256 = "6bd4baa9f46afa62477fec8c9e95528de7539f036d26fc13885177b32fc0d6ab".decodeHex(), dependsOnIds = listOf(), - ) + ), ), mainModuleId = "./kotlin_kotlin.js", mainFunction = "app.cash.prepareApp", @@ -76,14 +76,14 @@ class SignaturePayloadTest { signatures = mapOf( "sigA" to "0f91508b8451a8ed4eedf723f22613fe", "sigB" to "55a3605081f20817859d494103bc43d7", - ) + ), ) val manifestB = manifestA.copy( signatures = mapOf( "sigA" to "0f91508b8451a8ed4eedf723f22613ff", // Last character is changed. "sigB" to "55a3605081f20817859d494103bc43d8", // Last character is changed. - ) + ), ) assertEquals( @@ -100,7 +100,7 @@ class SignaturePayloadTest { url = "kotlin_kotlin.zipline", sha256 = "6bd4baa9f46afa62477fec8c9e95528de7539f036d26fc13885177b32fc0d6ab".decodeHex(), dependsOnIds = listOf(), - ) + ), ), mainModuleId = "./kotlin_kotlin.js", mainFunction = "app.cash.prepareApp", @@ -113,7 +113,7 @@ class SignaturePayloadTest { // Last character is changed: sha256 = "6bd4baa9f46afa62477fec8c9e95528de7539f036d26fc13885177b32fc0d6aa".decodeHex(), dependsOnIds = listOf(), - ) + ), ), ) @@ -131,7 +131,7 @@ class SignaturePayloadTest { url = "kotlin_kotlin.zipline", sha256 = "6bd4baa9f46afa62477fec8c9e95528de7539f036d26fc13885177b32fc0d6ab".decodeHex(), dependsOnIds = listOf(), - ) + ), ), mainModuleId = "./kotlin_kotlin.js", mainFunction = "app.cash.prepareApp", @@ -155,7 +155,7 @@ class SignaturePayloadTest { url = "kotlin_kotlin.zipline", sha256 = "6bd4baa9f46afa62477fec8c9e95528de7539f036d26fc13885177b32fc0d6ab".decodeHex(), dependsOnIds = listOf(), - ) + ), ), mainModuleId = "./kotlin_kotlin.js", mainFunction = "app.cash.prepareApp", diff --git a/zipline-loader/src/commonTest/kotlin/app/cash/zipline/loader/internal/cache/DatabaseCommonTest.kt b/zipline-loader/src/commonTest/kotlin/app/cash/zipline/loader/internal/cache/DatabaseCommonTest.kt index 9e51296b0..4abbb7236 100644 --- a/zipline-loader/src/commonTest/kotlin/app/cash/zipline/loader/internal/cache/DatabaseCommonTest.kt +++ b/zipline-loader/src/commonTest/kotlin/app/cash/zipline/loader/internal/cache/DatabaseCommonTest.kt @@ -63,7 +63,7 @@ class DatabaseCommonTest { file_state = FileState.DIRTY, size_bytes = 0L, last_used_at_epoch_ms = 1, - fresh_at_epoch_ms = 1 + fresh_at_epoch_ms = 1, ) // Inserting another row with the same sha256_hex should fail! @@ -74,7 +74,7 @@ class DatabaseCommonTest { file_state = FileState.DIRTY, size_bytes = 0L, last_used_at_epoch_ms = 1, - fresh_at_epoch_ms = 1 + fresh_at_epoch_ms = 1, ) } diff --git a/zipline-loader/src/commonTest/kotlin/app/cash/zipline/loader/internal/tink/subtle/Ed25519VerifyTest.kt b/zipline-loader/src/commonTest/kotlin/app/cash/zipline/loader/internal/tink/subtle/Ed25519VerifyTest.kt index 0ee833972..2e8ba6d72 100644 --- a/zipline-loader/src/commonTest/kotlin/app/cash/zipline/loader/internal/tink/subtle/Ed25519VerifyTest.kt +++ b/zipline-loader/src/commonTest/kotlin/app/cash/zipline/loader/internal/tink/subtle/Ed25519VerifyTest.kt @@ -54,12 +54,12 @@ class Ed25519VerifyTest { val verifier = Ed25519Verify(publicKey) if (verifier.verify(sig, msg)) { if (result == "invalid") { - println("FAIL ${tcId}: accepting invalid signature") + println("FAIL $tcId: accepting invalid signature") errors++ } } else { if (result == "valid") { - println("FAIL ${tcId}: rejecting valid signature") + println("FAIL $tcId: rejecting valid signature") errors++ } } diff --git a/zipline-loader/src/commonTest/kotlin/app/cash/zipline/loader/loaderTestsCommon.kt b/zipline-loader/src/commonTest/kotlin/app/cash/zipline/loader/loaderTestsCommon.kt index df136e0f0..a3074ffbc 100644 --- a/zipline-loader/src/commonTest/kotlin/app/cash/zipline/loader/loaderTestsCommon.kt +++ b/zipline-loader/src/commonTest/kotlin/app/cash/zipline/loader/loaderTestsCommon.kt @@ -38,7 +38,11 @@ fun testZiplineLoader( nowEpochMs: () -> Long, eventListener: EventListener = EventListener.NONE, ) = ZiplineLoader( - dispatcher, manifestVerifier, httpClient, eventListener, nowEpochMs + dispatcher, + manifestVerifier, + httpClient, + eventListener, + nowEpochMs, ) fun testZiplineCache( diff --git a/zipline-loader/src/jniMain/kotlin/app/cash/zipline/loader/OkHttpZiplineHttpClient.kt b/zipline-loader/src/jniMain/kotlin/app/cash/zipline/loader/OkHttpZiplineHttpClient.kt index 04debc9d5..5e1d5342c 100644 --- a/zipline-loader/src/jniMain/kotlin/app/cash/zipline/loader/OkHttpZiplineHttpClient.kt +++ b/zipline-loader/src/jniMain/kotlin/app/cash/zipline/loader/OkHttpZiplineHttpClient.kt @@ -33,7 +33,7 @@ import okhttp3.WebSocketListener import okio.ByteString internal class OkHttpZiplineHttpClient( - private val okHttpClient: OkHttpClient + private val okHttpClient: OkHttpClient, ) : ZiplineHttpClient() { override suspend fun download( url: String, @@ -48,7 +48,7 @@ internal class OkHttpZiplineHttpClient( addHeader(name, value) } } - .build() + .build(), ) continuation.invokeOnCancellation { @@ -58,14 +58,14 @@ internal class OkHttpZiplineHttpClient( call.enqueue(object : Callback { override fun onFailure( call: Call, - e: IOException + e: IOException, ) { continuation.resumeWithException(e) } override fun onResponse( call: Call, - response: Response + response: Response, ) { val byteString = response.use { try { @@ -86,7 +86,8 @@ internal class OkHttpZiplineHttpClient( } override suspend fun openDevelopmentServerWebSocket( - url: String, requestHeaders: List>, + url: String, + requestHeaders: List>, ): Flow { val request = Request.Builder() .url(url) diff --git a/zipline-loader/src/jniTest/kotlin/app/cash/zipline/loader/OkHttpZiplineHttpClientTest.kt b/zipline-loader/src/jniTest/kotlin/app/cash/zipline/loader/OkHttpZiplineHttpClientTest.kt index dcc8b07fc..236945a5f 100644 --- a/zipline-loader/src/jniTest/kotlin/app/cash/zipline/loader/OkHttpZiplineHttpClientTest.kt +++ b/zipline-loader/src/jniTest/kotlin/app/cash/zipline/loader/OkHttpZiplineHttpClientTest.kt @@ -43,7 +43,7 @@ class OkHttpZiplineHttpClientTest { fun happyPath(): Unit = runBlocking { server.enqueue( MockResponse() - .setBody("hello") + .setBody("hello"), ) val content = client.download(server.url("/foo").toString(), listOf()) @@ -57,7 +57,7 @@ class OkHttpZiplineHttpClientTest { fun requestHeaders(): Unit = runBlocking { server.enqueue( MockResponse() - .setBody("hello") + .setBody("hello"), ) val content = client.download( @@ -90,7 +90,7 @@ class OkHttpZiplineHttpClientTest { server.enqueue( MockResponse() .setResponseCode(404) - .setBody("hello") + .setBody("hello"), ) val url = server.url("/foo") @@ -102,7 +102,7 @@ class OkHttpZiplineHttpClientTest { @Test fun tearDownWebSocketWhenClosed(): Unit = runBlocking { - val webSocketListener = object: WebSocketListener() { + val webSocketListener = object : WebSocketListener() { override fun onOpen(webSocket: WebSocket, response: Response) { assertEquals(1, okHttpClient.connectionPool.connectionCount()) webSocket.send("reload") @@ -143,7 +143,7 @@ class OkHttpZiplineHttpClientTest { // If there are any HTTP connections in OkHttp, they had better be idle. assertEquals( okHttpClient.connectionPool.idleConnectionCount(), - okHttpClient.connectionPool.connectionCount() + okHttpClient.connectionPool.connectionCount(), ) } } diff --git a/zipline-loader/src/jvmTest/kotlin/app/cash/zipline/loader/internal/EcdsaP256JniTest.kt b/zipline-loader/src/jvmTest/kotlin/app/cash/zipline/loader/internal/EcdsaP256JniTest.kt index db131d155..a237cb5b0 100644 --- a/zipline-loader/src/jvmTest/kotlin/app/cash/zipline/loader/internal/EcdsaP256JniTest.kt +++ b/zipline-loader/src/jvmTest/kotlin/app/cash/zipline/loader/internal/EcdsaP256JniTest.kt @@ -53,25 +53,25 @@ class EcdsaP256JniTest { // Pads out to the full width. assertEquals( "00000000".decodeHex(), - BigInteger("0").toUnsignedFixedWidth(4).toByteString() + BigInteger("0").toUnsignedFixedWidth(4).toByteString(), ) assertEquals( "00000001".decodeHex(), - BigInteger("1").toUnsignedFixedWidth(4).toByteString() + BigInteger("1").toUnsignedFixedWidth(4).toByteString(), ) assertEquals( "000000ff".decodeHex(), - BigInteger("255").toUnsignedFixedWidth(4).toByteString() + BigInteger("255").toUnsignedFixedWidth(4).toByteString(), ) // Leading sign '0' bit is dropped. assertEquals( "7fffffff".decodeHex(), - BigInteger("2147483647").toUnsignedFixedWidth(4).toByteString() + BigInteger("2147483647").toUnsignedFixedWidth(4).toByteString(), ) assertEquals( "ffffffff".decodeHex(), - BigInteger("4294967295").toUnsignedFixedWidth(4).toByteString() + BigInteger("4294967295").toUnsignedFixedWidth(4).toByteString(), ) } @@ -97,4 +97,3 @@ class EcdsaP256JniTest { return keyFactory.generatePublic(keySpec) as ECPublicKey } } - diff --git a/zipline-loader/src/jvmTest/kotlin/app/cash/zipline/loader/internal/tink/subtle/Field25519Test.kt b/zipline-loader/src/jvmTest/kotlin/app/cash/zipline/loader/internal/tink/subtle/Field25519Test.kt index 0cbb4ed45..fad4fce7f 100644 --- a/zipline-loader/src/jvmTest/kotlin/app/cash/zipline/loader/internal/tink/subtle/Field25519Test.kt +++ b/zipline-loader/src/jvmTest/kotlin/app/cash/zipline/loader/internal/tink/subtle/Field25519Test.kt @@ -68,7 +68,7 @@ class Field25519Test { assertEquals( "Subtraction x[i] - y[i]: " + x[i] + "-" + y[i], expectedResult, - result + result, ) } } @@ -100,7 +100,7 @@ class Field25519Test { assertEquals( "Multiplication x[i] * y[i]: " + x[i] + "*" + y[i], expectedResult, - result + result, ) } } @@ -119,7 +119,7 @@ class Field25519Test { assertEquals( "Scalar product x[i] * 10 " + x[i] + "*" + 10, expectedResult, - result + result, ) } } diff --git a/zipline-loader/src/nativeMain/kotlin/app/cash/zipline/loader/URLSessionZiplineHttpClient.kt b/zipline-loader/src/nativeMain/kotlin/app/cash/zipline/loader/URLSessionZiplineHttpClient.kt index d3263d8ec..6dcbfb0e6 100644 --- a/zipline-loader/src/nativeMain/kotlin/app/cash/zipline/loader/URLSessionZiplineHttpClient.kt +++ b/zipline-loader/src/nativeMain/kotlin/app/cash/zipline/loader/URLSessionZiplineHttpClient.kt @@ -21,8 +21,8 @@ import kotlin.native.concurrent.freeze import kotlinx.coroutines.CancellableContinuation import kotlinx.coroutines.suspendCancellableCoroutine import okio.ByteString -import okio.IOException import okio.ByteString.Companion.toByteString +import okio.IOException import platform.Foundation.NSData import platform.Foundation.NSError import platform.Foundation.NSHTTPURLResponse @@ -54,7 +54,7 @@ internal class URLSessionZiplineHttpClient( addValue(value = value, forHTTPHeaderField = name) } }, - completionHandler = completionHandler::invoke.maybeFreeze() + completionHandler = completionHandler::invoke.maybeFreeze(), ) continuation.invokeOnCancellation { @@ -83,7 +83,7 @@ private class CompletionHandler( if (response.statusCode !in 200 until 300) { continuation.resumeWithException( - IOException("failed to fetch $url: ${response.statusCode}") + IOException("failed to fetch $url: ${response.statusCode}"), ) return } diff --git a/zipline-loader/src/nativeMain/kotlin/app/cash/zipline/loader/internal/EcdsaP256.kt b/zipline-loader/src/nativeMain/kotlin/app/cash/zipline/loader/internal/EcdsaP256.kt index 8edb35d6c..9e836fc6b 100644 --- a/zipline-loader/src/nativeMain/kotlin/app/cash/zipline/loader/internal/EcdsaP256.kt +++ b/zipline-loader/src/nativeMain/kotlin/app/cash/zipline/loader/internal/EcdsaP256.kt @@ -58,10 +58,14 @@ class EcdsaP256 : SignatureAlgorithm { valueCallBacks = kCFTypeDictionaryValueCallBacks.ptr, ) CFDictionaryAddValue( - attributes, kSecAttrKeyType, kSecAttrKeyTypeECSECPrimeRandom, + attributes, + kSecAttrKeyType, + kSecAttrKeyTypeECSECPrimeRandom, ) CFDictionaryAddValue( - attributes, kSecAttrKeyClass, kSecAttrKeyClassPublic, + attributes, + kSecAttrKeyClass, + kSecAttrKeyClassPublic, ) memScoped { @@ -93,7 +97,7 @@ class EcdsaP256 : SignatureAlgorithm { require( errorRef.value == null || - CFErrorGetCode(errorRef.value) == errSecVerifyFailed.toLong() + CFErrorGetCode(errorRef.value) == errSecVerifyFailed.toLong(), ) { "failed to verify signature: ${CFErrorGetCode(errorRef.value)}" } @@ -112,7 +116,7 @@ class EcdsaP256 : SignatureAlgorithm { } val nsData = NSData.dataWithBytesNoCopy( bytes = bytesPointer, - length = byteArray.size.convert() + length = byteArray.size.convert(), ) val typeRef = CFBridgingRetain(nsData) as CFDataRef try { diff --git a/zipline-loader/src/nativeMain/kotlin/app/cash/zipline/loader/internal/cache/databaseNative.kt b/zipline-loader/src/nativeMain/kotlin/app/cash/zipline/loader/internal/cache/databaseNative.kt index f359cefa7..103f0412e 100644 --- a/zipline-loader/src/nativeMain/kotlin/app/cash/zipline/loader/internal/cache/databaseNative.kt +++ b/zipline-loader/src/nativeMain/kotlin/app/cash/zipline/loader/internal/cache/databaseNative.kt @@ -38,7 +38,7 @@ internal actual class SqlDriverFactory { extendedConfig = DatabaseConfiguration.Extended( basePath = path.parent!!.toString(), ), - ) + ), ) } } diff --git a/zipline-profiler/src/main/kotlin/app/cash/zipline/profiler/HprofWriter.kt b/zipline-profiler/src/main/kotlin/app/cash/zipline/profiler/HprofWriter.kt index 9be26134e..f099ca2a2 100644 --- a/zipline-profiler/src/main/kotlin/app/cash/zipline/profiler/HprofWriter.kt +++ b/zipline-profiler/src/main/kotlin/app/cash/zipline/profiler/HprofWriter.kt @@ -34,7 +34,7 @@ import okio.utf8Size */ internal class HprofWriter( private val sink: BufferedSink, - private val clock: ProfilerClock = DefaultProfilerClock + private val clock: ProfilerClock = DefaultProfilerClock, ) : Closeable by sink { private val headerTime = clock.currentTimeMillis private val headerNanoTime = clock.nanoTime @@ -57,7 +57,7 @@ internal class HprofWriter( fun writeControlSettings( allocationTraces: Boolean = false, cpuSampling: Boolean = false, - stackTraceDepth: Short = Short.MAX_VALUE + stackTraceDepth: Short = Short.MAX_VALUE, ) { var bitMaskFlags = 0 if (allocationTraces) bitMaskFlags = bitMaskFlags or 0x1 @@ -115,7 +115,7 @@ internal class HprofWriter( fun allocateClassId( className: String, classObjectId: Int, - stackTraceSerialNumber: Int + stackTraceSerialNumber: Int, ): Int { return classIds.getOrPut(className) { val id = classIds.size + 2_000_000 diff --git a/zipline-profiler/src/main/kotlin/app/cash/zipline/profiler/SamplingProfiler.kt b/zipline-profiler/src/main/kotlin/app/cash/zipline/profiler/SamplingProfiler.kt index f96e7912e..22155c65d 100644 --- a/zipline-profiler/src/main/kotlin/app/cash/zipline/profiler/SamplingProfiler.kt +++ b/zipline-profiler/src/main/kotlin/app/cash/zipline/profiler/SamplingProfiler.kt @@ -59,8 +59,10 @@ internal class SamplingProfiler internal constructor( /** Placeholder value for the JavaScript thread. */ private val javaScriptThreadId: Int = nextId++ + /** Placeholder value for JavaScript functions that don't have a proper signature. */ private val javaScriptMethodSignatureStringId: Int + /** Placeholder value for JavaScript functions that don't have a proper class. */ private val javaScriptClassId: Int @@ -80,7 +82,7 @@ internal class SamplingProfiler internal constructor( stackTraceId = nullStackTraceId, threadNameStringId = hprofWriter.allocateStringId("main"), threadGroupNameId = hprofWriter.allocateStringId("main"), - threadParentGroupNameId = hprofWriter.allocateStringId("system") + threadParentGroupNameId = hprofWriter.allocateStringId("system"), ) } diff --git a/zipline-profiler/src/test/kotlin/app/cash/zipline/profiler/SamplingProfilerTest.kt b/zipline-profiler/src/test/kotlin/app/cash/zipline/profiler/SamplingProfilerTest.kt index 7a84a989b..6fb8940aa 100644 --- a/zipline-profiler/src/test/kotlin/app/cash/zipline/profiler/SamplingProfilerTest.kt +++ b/zipline-profiler/src/test/kotlin/app/cash/zipline/profiler/SamplingProfilerTest.kt @@ -25,7 +25,8 @@ internal class SamplingProfilerTest { private val quickJs = QuickJs.create() @Before fun setUp() { - quickJs.evaluate(""" + quickJs.evaluate( + """ |function fib0() { | return 1; |} @@ -65,8 +66,11 @@ internal class SamplingProfilerTest { |function fib9() { | return fib8() + fib7(); |} - """.trimMargin(), "smallFibs.js") - quickJs.evaluate(""" + """.trimMargin(), + "smallFibs.js", + ) + quickJs.evaluate( + """ |function fib10() { | return fib9() + fib8(); |} @@ -111,7 +115,9 @@ internal class SamplingProfilerTest { | return fib19() + fib18(); |} | - """.trimMargin(), "bigFibs.js") + """.trimMargin(), + "bigFibs.js", + ) } @After fun tearDown() { diff --git a/zipline/src/androidMain/kotlin/app/cash/zipline/internal/HostConsole.kt b/zipline/src/androidMain/kotlin/app/cash/zipline/internal/HostConsole.kt index 88264d2dd..bde30920b 100644 --- a/zipline/src/androidMain/kotlin/app/cash/zipline/internal/HostConsole.kt +++ b/zipline/src/androidMain/kotlin/app/cash/zipline/internal/HostConsole.kt @@ -22,7 +22,7 @@ internal actual object HostConsole : Console { when (level) { "warn" -> Log.w("Zipline", message, throwable) "error" -> Log.e("Zipline", message, throwable) - else -> Log.i("Zipline", message, throwable) + else -> Log.i("Zipline", message, throwable) } } } diff --git a/zipline/src/commonMain/kotlin/app/cash/zipline/internal/bridge/CallCodec.kt b/zipline/src/commonMain/kotlin/app/cash/zipline/internal/bridge/CallCodec.kt index 0c60c48e8..6569867a4 100644 --- a/zipline/src/commonMain/kotlin/app/cash/zipline/internal/bridge/CallCodec.kt +++ b/zipline/src/commonMain/kotlin/app/cash/zipline/internal/bridge/CallCodec.kt @@ -60,7 +60,7 @@ internal class CallCodec( internalCall.function, internalCall.args, encodedCall, - encodedServiceNames + encodedServiceNames, ) val callback = nextOutboundCallCallback @@ -85,7 +85,7 @@ internal class CallCodec( internalCall.function, internalCall.args, callJson, - decodedServiceNames + decodedServiceNames, ) return internalCall } diff --git a/zipline/src/commonMain/kotlin/app/cash/zipline/internal/bridge/Endpoint.kt b/zipline/src/commonMain/kotlin/app/cash/zipline/internal/bridge/Endpoint.kt index 02a5baa86..b4fc38364 100644 --- a/zipline/src/commonMain/kotlin/app/cash/zipline/internal/bridge/Endpoint.kt +++ b/zipline/src/commonMain/kotlin/app/cash/zipline/internal/bridge/Endpoint.kt @@ -70,8 +70,8 @@ class Endpoint internal constructor( FlowSerializer( ziplineServiceSerializer>( FlowZiplineService::class, - serializers - ) + serializers, + ), ) } contextual(StateFlow::class) { serializers -> @@ -79,7 +79,7 @@ class Endpoint internal constructor( ziplineServiceSerializer>( StateFlowZiplineService::class, serializers, - ) + ), ) } include(userSerializersModule) @@ -102,11 +102,11 @@ class Endpoint internal constructor( internalCall.suspendCallback != null -> inboundService.callSuspending( internalCall, externalCall, - internalCall.suspendCallback + internalCall.suspendCallback, ) else -> inboundService.call( internalCall, - externalCall + externalCall, ) } } @@ -127,7 +127,7 @@ class Endpoint internal constructor( internal fun bind( name: String, service: T, - adapter: ZiplineServiceAdapter + adapter: ZiplineServiceAdapter, ) { eventListener.bindService(name, service) diff --git a/zipline/src/commonMain/kotlin/app/cash/zipline/internal/bridge/InboundService.kt b/zipline/src/commonMain/kotlin/app/cash/zipline/internal/bridge/InboundService.kt index a0e1d2e8b..d778ab6e0 100644 --- a/zipline/src/commonMain/kotlin/app/cash/zipline/internal/bridge/InboundService.kt +++ b/zipline/src/commonMain/kotlin/app/cash/zipline/internal/bridge/InboundService.kt @@ -124,7 +124,7 @@ internal class InboundService( val encodedResultOrCallback = endpoint.callCodec.encodeResultOrCallback( function, - ResultOrCallback(callback = cancelCallback) + ResultOrCallback(callback = cancelCallback), ) return encodedResultOrCallback.json } diff --git a/zipline/src/commonMain/kotlin/app/cash/zipline/internal/bridge/OutboundCallHandler.kt b/zipline/src/commonMain/kotlin/app/cash/zipline/internal/bridge/OutboundCallHandler.kt index e460d971d..3e1a3509f 100644 --- a/zipline/src/commonMain/kotlin/app/cash/zipline/internal/bridge/OutboundCallHandler.kt +++ b/zipline/src/commonMain/kotlin/app/cash/zipline/internal/bridge/OutboundCallHandler.kt @@ -44,7 +44,12 @@ internal class OutboundCallHandler( */ fun withScope(scope: ZiplineScope): OutboundCallHandler { return OutboundCallHandler( - serviceName, endpoint, adapter, scope, functionsList, serviceState, + serviceName, + endpoint, + adapter, + scope, + functionsList, + serviceState, ) } @@ -77,7 +82,7 @@ internal class OutboundCallHandler( val internalCall = InternalCall( serviceName = serviceName, function = function, - args = argsList + args = argsList, ) val externalCall = endpoint.callCodec.encodeCall(internalCall, service) val callStart = when (service) { @@ -172,8 +177,8 @@ internal class OutboundCallHandler( var closed = false } - private inner class RealSuspendCallback - : SuspendCallback, HasPassByReferenceName, ZiplineScoped { + private inner class RealSuspendCallback : + SuspendCallback, HasPassByReferenceName, ZiplineScoped { lateinit var internalCall: InternalCall lateinit var externalCall: Call lateinit var continuation: Continuation diff --git a/zipline/src/commonMain/kotlin/app/cash/zipline/internal/bridge/ZiplineServiceAdapter.kt b/zipline/src/commonMain/kotlin/app/cash/zipline/internal/bridge/ZiplineServiceAdapter.kt index edd226c09..a9803e017 100644 --- a/zipline/src/commonMain/kotlin/app/cash/zipline/internal/bridge/ZiplineServiceAdapter.kt +++ b/zipline/src/commonMain/kotlin/app/cash/zipline/internal/bridge/ZiplineServiceAdapter.kt @@ -39,7 +39,7 @@ internal abstract class ZiplineServiceAdapter : KSerializer< override val descriptor = contextualSerializer.descriptor abstract fun ziplineFunctions( - serializersModule: SerializersModule + serializersModule: SerializersModule, ): List> abstract fun outboundService( @@ -66,13 +66,13 @@ internal abstract class ZiplineServiceAdapter : KSerializer< } @PublishedApi -internal fun ziplineServiceAdapter() : ZiplineServiceAdapter { +internal fun ziplineServiceAdapter(): ZiplineServiceAdapter { error("unexpected call to ziplineServiceAdapter(): is the Zipline plugin configured?") } @PublishedApi internal fun ziplineServiceAdapter( - ziplineServiceAdapter: ZiplineServiceAdapter -) : ZiplineServiceAdapter { + ziplineServiceAdapter: ZiplineServiceAdapter, +): ZiplineServiceAdapter { return ziplineServiceAdapter } diff --git a/zipline/src/commonMain/kotlin/app/cash/zipline/internal/bridge/calls.kt b/zipline/src/commonMain/kotlin/app/cash/zipline/internal/bridge/calls.kt index 2b772e085..b4b4512a6 100644 --- a/zipline/src/commonMain/kotlin/app/cash/zipline/internal/bridge/calls.kt +++ b/zipline/src/commonMain/kotlin/app/cash/zipline/internal/bridge/calls.kt @@ -163,10 +163,13 @@ internal class RealCallSerializer( serviceName = serviceName, inboundService = inboundService ?: unknownService(), function = function ?: unknownFunction( - serviceName, functionName, inboundService, suspendCallback + serviceName, + functionName, + inboundService, + suspendCallback, ), suspendCallback = suspendCallback, - args = args + args = args, ) } } finally { @@ -179,7 +182,7 @@ internal class RealCallSerializer( return InboundService( service = object : ZiplineService {}, endpoint = endpoint, - functionsList = listOf() + functionsList = listOf(), ) } @@ -262,7 +265,6 @@ internal class ArgsListSerializer( } } - internal class ResultSerializer( internal val successSerializer: KSerializer, ) : KSerializer> { @@ -373,10 +375,10 @@ internal class ResultOrCallbackSerializer( when (val index = decodeElementIndex(descriptor)) { 0 -> callback = decodeSerializableElement(descriptor, 0, cancelCallbackSerializer) 1 -> result = Result.failure( - decodeSerializableElement(descriptor, 1, ThrowableSerializer) + decodeSerializableElement(descriptor, 1, ThrowableSerializer), ) 2 -> result = Result.success( - decodeSerializableElement(descriptor, 2, successSerializer) + decodeSerializableElement(descriptor, 2, successSerializer), ) DECODE_DONE -> break else -> error("Unexpected index: $index") diff --git a/zipline/src/commonMain/kotlin/app/cash/zipline/internal/bridge/internalSerializers.kt b/zipline/src/commonMain/kotlin/app/cash/zipline/internal/bridge/internalSerializers.kt index 1dcad3213..15881617b 100644 --- a/zipline/src/commonMain/kotlin/app/cash/zipline/internal/bridge/internalSerializers.kt +++ b/zipline/src/commonMain/kotlin/app/cash/zipline/internal/bridge/internalSerializers.kt @@ -32,8 +32,8 @@ import kotlinx.serialization.modules.SerializersModule @PublishedApi internal fun SerializersModule.requireContextual( kClass: KClass<*>, - typeArgumentsSerializers: List> -) : KSerializer { + typeArgumentsSerializers: List>, +): KSerializer { val result = getContextual(kClass, typeArgumentsSerializers) ?: error("No contextual serializer for $kClass is registered") return result as KSerializer diff --git a/zipline/src/commonMain/kotlin/app/cash/zipline/internal/bridge/leakCanary.kt b/zipline/src/commonMain/kotlin/app/cash/zipline/internal/bridge/leakCanary.kt index 3cd5d1c1b..117393a3b 100644 --- a/zipline/src/commonMain/kotlin/app/cash/zipline/internal/bridge/leakCanary.kt +++ b/zipline/src/commonMain/kotlin/app/cash/zipline/internal/bridge/leakCanary.kt @@ -25,7 +25,7 @@ internal expect fun trackLeaks( eventListener: EndpointEventListener, serviceName: String, callHandler: OutboundCallHandler, - service: ZiplineService + service: ZiplineService, ) /** diff --git a/zipline/src/commonMain/kotlin/app/cash/zipline/serializers.kt b/zipline/src/commonMain/kotlin/app/cash/zipline/serializers.kt index 24e276fd8..ef64c16c5 100644 --- a/zipline/src/commonMain/kotlin/app/cash/zipline/serializers.kt +++ b/zipline/src/commonMain/kotlin/app/cash/zipline/serializers.kt @@ -54,7 +54,7 @@ import kotlinx.serialization.KSerializer * The caller must call [ZiplineService.close] when they are done with the returned service to * release the held reference. */ -fun ziplineServiceSerializer() : KSerializer { +fun ziplineServiceSerializer(): KSerializer { error("unexpected call to ziplineServiceSerializer(): is the Zipline plugin configured?") } @@ -64,14 +64,14 @@ fun ziplineServiceSerializer() : KSerializer { */ fun ziplineServiceSerializer( kClass: KClass<*>, - typeArgumentsSerializers: List> = emptyList() -) : KSerializer { + typeArgumentsSerializers: List> = emptyList(), +): KSerializer { error("unexpected call to ziplineServiceSerializer(): is the Zipline plugin configured?") } @PublishedApi internal fun ziplineServiceSerializer( - ziplineServiceAdapter: ZiplineServiceAdapter -) : KSerializer { + ziplineServiceAdapter: ZiplineServiceAdapter, +): KSerializer { return ziplineServiceAdapter } diff --git a/zipline/src/commonMain/kotlin/app/cash/zipline/testing/endpoints.kt b/zipline/src/commonMain/kotlin/app/cash/zipline/testing/endpoints.kt index 808b23527..fca302729 100644 --- a/zipline/src/commonMain/kotlin/app/cash/zipline/testing/endpoints.kt +++ b/zipline/src/commonMain/kotlin/app/cash/zipline/testing/endpoints.kt @@ -35,7 +35,11 @@ internal fun newEndpointPair( listenerB: EndpointEventListener = nullEndpointEventListener, ): Pair { val pair = object : Any() { - val a: Endpoint = Endpoint(scope, serializersModule, listenerA, object : CallChannel { + val a: Endpoint = Endpoint( + scope, + serializersModule, + listenerA, + object : CallChannel { override fun serviceNamesArray(): Array { return b.inboundChannel.serviceNamesArray() } @@ -47,7 +51,8 @@ internal fun newEndpointPair( override fun disconnect(instanceName: String): Boolean { return b.inboundChannel.disconnect(instanceName) } - }) + }, + ) val b: Endpoint = Endpoint(scope, serializersModule, listenerB, a.inboundChannel) } diff --git a/zipline/src/engineMain/kotlin/app/cash/zipline/internal/CoroutineEventLoop.kt b/zipline/src/engineMain/kotlin/app/cash/zipline/internal/CoroutineEventLoop.kt index adcad72ec..660f0aabb 100644 --- a/zipline/src/engineMain/kotlin/app/cash/zipline/internal/CoroutineEventLoop.kt +++ b/zipline/src/engineMain/kotlin/app/cash/zipline/internal/CoroutineEventLoop.kt @@ -48,7 +48,7 @@ internal class CoroutineEventLoop( private inner class DelayedJob( val timeoutId: Int, - val delayMillis: Int + val delayMillis: Int, ) : Runnable { var canceled = false var job: Job? = null diff --git a/zipline/src/engineMain/kotlin/app/cash/zipline/internal/quickJsExtensions.kt b/zipline/src/engineMain/kotlin/app/cash/zipline/internal/quickJsExtensions.kt index b0c4e0fd1..2b37f9eb6 100644 --- a/zipline/src/engineMain/kotlin/app/cash/zipline/internal/quickJsExtensions.kt +++ b/zipline/src/engineMain/kotlin/app/cash/zipline/internal/quickJsExtensions.kt @@ -13,7 +13,7 @@ fun QuickJs.getModuleDependencies(): List { val dependencies = Json.decodeFromString>( dependenciesString // If define is never called, dependencies is returned as null - ?: "[]" + ?: "[]", ) return dependencies } @@ -42,7 +42,7 @@ fun QuickJs.loadJsModule(id: String, bytecode: ByteArray) { fun QuickJs.runApplication(mainModuleId: String, mainFunction: String) { evaluate( - script = "require('${mainModuleId}').$mainFunction()", + script = "require('$mainModuleId').$mainFunction()", fileName = "RunApplication.kt", ) } diff --git a/zipline/src/engineTest/kotlin/app/cash/zipline/EndpointPropertiesTest.kt b/zipline/src/engineTest/kotlin/app/cash/zipline/EndpointPropertiesTest.kt index 7275b478a..e8b496906 100644 --- a/zipline/src/engineTest/kotlin/app/cash/zipline/EndpointPropertiesTest.kt +++ b/zipline/src/engineTest/kotlin/app/cash/zipline/EndpointPropertiesTest.kt @@ -94,7 +94,7 @@ internal class EndpointPropertiesTest { data class Bar( val alpha: Boolean, val bravo: String, - val charlie: Baz + val charlie: Baz, ) @Serializable @@ -110,7 +110,7 @@ internal class EndpointPropertiesTest { var result = Bar( alpha = true, bravo = "bingo", - charlie = Baz.BINGO + charlie = Baz.BINGO, ) val service = object : GenericValService { @@ -124,24 +124,30 @@ internal class EndpointPropertiesTest { endpointA.bind>("genericValService", service) val client = endpointB.take>("genericValService") - assertEquals(Bar( + assertEquals( + Bar( alpha = true, bravo = "bingo", - charlie = Baz.BINGO - ), client.foo) + charlie = Baz.BINGO, + ), + client.foo, + ) assertEquals(1, fooCalls) // Confirm every access goes to the source of truth. result = Bar( alpha = false, bravo = "bloop", - charlie = Baz.BLOOP + charlie = Baz.BLOOP, ) - assertEquals(Bar( + assertEquals( + Bar( alpha = false, bravo = "bloop", - charlie = Baz.BLOOP - ), client.foo) + charlie = Baz.BLOOP, + ), + client.foo, + ) assertEquals(2, fooCalls) } @@ -153,7 +159,7 @@ internal class EndpointPropertiesTest { var state = Bar( alpha = true, bravo = "bingo", - charlie = Baz.BINGO + charlie = Baz.BINGO, ) val service = object : GenericVarService { @@ -172,13 +178,16 @@ internal class EndpointPropertiesTest { client.foo = Bar( alpha = false, bravo = "bloop", - charlie = Baz.BLOOP + charlie = Baz.BLOOP, ) assertEquals(1, fooCalls) - assertEquals(Bar( + assertEquals( + Bar( alpha = false, bravo = "bloop", - charlie = Baz.BLOOP - ), state) + charlie = Baz.BLOOP, + ), + state, + ) } } diff --git a/zipline/src/engineTest/kotlin/app/cash/zipline/EndpointTest.kt b/zipline/src/engineTest/kotlin/app/cash/zipline/EndpointTest.kt index b46a72e75..34a2d2a11 100644 --- a/zipline/src/engineTest/kotlin/app/cash/zipline/EndpointTest.kt +++ b/zipline/src/engineTest/kotlin/app/cash/zipline/EndpointTest.kt @@ -22,7 +22,6 @@ import app.cash.zipline.testing.GenericEchoService import app.cash.zipline.testing.SuspendingEchoService import app.cash.zipline.testing.kotlinBuiltInSerializersModule import app.cash.zipline.testing.newEndpointPair -import kotlin.coroutines.suspendCoroutine import kotlin.test.Test import kotlin.test.assertEquals import kotlin.test.assertFailsWith @@ -32,11 +31,9 @@ import kotlinx.coroutines.CancellationException import kotlinx.coroutines.CoroutineDispatcher import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.CoroutineStart.UNDISPATCHED -import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers.Unconfined import kotlinx.coroutines.async import kotlinx.coroutines.channels.Channel -import kotlinx.coroutines.delay import kotlinx.coroutines.launch import kotlinx.coroutines.runBlocking import kotlinx.coroutines.suspendCancellableCoroutine @@ -316,12 +313,12 @@ internal class EndpointTest { assertEquals( listOf(mapOf(), mapOf("one" to 1, "two" to 2)), - mapsClient.genericEcho(mapOf("one" to 1, "two" to 2)) + mapsClient.genericEcho(mapOf("one" to 1, "two" to 2)), ) assertEquals( listOf("x", "hello"), - stringClient.genericEcho("hello") + stringClient.genericEcho("hello"), ) } @@ -388,10 +385,11 @@ internal class EndpointTest { val (endpointA, endpointB) = newEndpointPair(this) - endpointA.bind("serviceA", + endpointA.bind( + "serviceA", object : EchoService { override fun echo(request: EchoRequest) = error("unexpected call") - } + }, ) val client = endpointB.take("serviceA", scope) @@ -404,7 +402,7 @@ internal class EndpointTest { |EchoService serviceA is closed, failed to call: | fun echo(app.cash.zipline.testing.EchoRequest): app.cash.zipline.testing.EchoResponse """.trimMargin(), - exception.message + exception.message, ) } @@ -414,10 +412,11 @@ internal class EndpointTest { val (endpointA, endpointB) = newEndpointPair(this) - endpointA.bind("serviceA", + endpointA.bind( + "serviceA", object : SuspendingEchoService { override suspend fun suspendingEcho(request: EchoRequest) = error("unexpected call") - } + }, ) val client = endpointB.take("serviceA", scope) @@ -430,7 +429,7 @@ internal class EndpointTest { |SuspendingEchoService serviceA is closed, failed to call: | suspend fun suspendingEcho(app.cash.zipline.testing.EchoRequest): app.cash.zipline.testing.EchoResponse """.trimMargin(), - exception.message + exception.message, ) } @@ -442,14 +441,15 @@ internal class EndpointTest { val log = ArrayDeque() - endpointA.bind("service", + endpointA.bind( + "service", object : EchoService { override fun echo(request: EchoRequest) = error("unexpected call") override fun close() { log += "service closed" } - } + }, ) val client = endpointB.take("service", scope) diff --git a/zipline/src/engineTest/kotlin/app/cash/zipline/FinalizationRegistryTest.kt b/zipline/src/engineTest/kotlin/app/cash/zipline/FinalizationRegistryTest.kt index 7d26db9ee..344808d52 100644 --- a/zipline/src/engineTest/kotlin/app/cash/zipline/FinalizationRegistryTest.kt +++ b/zipline/src/engineTest/kotlin/app/cash/zipline/FinalizationRegistryTest.kt @@ -34,7 +34,7 @@ class FinalizationRegistryTest { log.length = 0; return result; }; - """ + """, ) } @@ -59,7 +59,7 @@ class FinalizationRegistryTest { } makeFinalizableObject(); - """.trimIndent() + """.trimIndent(), ) assertEquals( """["heavy object was finalized"]""", @@ -79,7 +79,7 @@ class FinalizationRegistryTest { data: 'this data is owned by the heavy object.' }; registry.register(heavyObject, 'heavy object'); - """.trimIndent() + """.trimIndent(), ) assertEquals( """[]""", @@ -90,7 +90,7 @@ class FinalizationRegistryTest { """ globalThis.anotherProperty = globalThis.heavyObject; delete globalThis.heavyObject; - """.trimIndent() + """.trimIndent(), ) assertEquals( """[]""", @@ -100,7 +100,7 @@ class FinalizationRegistryTest { quickJs.evaluate( """ delete globalThis.anotherProperty; - """.trimIndent() + """.trimIndent(), ) assertEquals( """["registry got heavy object"]""", @@ -127,7 +127,7 @@ class FinalizationRegistryTest { } makeCycleContainingFinalizableObject(); - """.trimIndent() + """.trimIndent(), ) assertEquals( """[]""", @@ -159,7 +159,7 @@ class FinalizationRegistryTest { makeFinalizableObject('red'); makeFinalizableObject('green'); makeFinalizableObject('blue'); - """.trimIndent() + """.trimIndent(), ) assertEquals( """["registry got red","registry got green","registry got blue"]""", @@ -167,7 +167,6 @@ class FinalizationRegistryTest { ) } - @Test fun multipleRegistriesMayBeUsed() { quickJs.evaluate( @@ -189,7 +188,7 @@ class FinalizationRegistryTest { makeFinalizableObject(registryA, 'green'); makeFinalizableObject(registryB, 'blue'); - """.trimIndent() + """.trimIndent(), ) assertEquals( """["registry A got green","registry B got blue"]""", diff --git a/zipline/src/engineTest/kotlin/app/cash/zipline/QuickJsInboundChannelTest.kt b/zipline/src/engineTest/kotlin/app/cash/zipline/QuickJsInboundChannelTest.kt index c993606da..2d1dcf4d8 100644 --- a/zipline/src/engineTest/kotlin/app/cash/zipline/QuickJsInboundChannelTest.kt +++ b/zipline/src/engineTest/kotlin/app/cash/zipline/QuickJsInboundChannelTest.kt @@ -39,7 +39,8 @@ class QuickJsInboundChannelTest { @BeforeTest fun setUp() { - quickJs.evaluate(""" + quickJs.evaluate( + """ globalThis.$inboundChannelName = {}; globalThis.$inboundChannelName.serviceNamesArray = function() { }; @@ -47,16 +48,19 @@ class QuickJsInboundChannelTest { }; globalThis.$inboundChannelName.disconnect = function(instanceName) { }; - """.trimIndent()) + """.trimIndent(), + ) } @Test fun callHappyPath() { - quickJs.evaluate(""" + quickJs.evaluate( + """ globalThis.$inboundChannelName.call = function(callJson) { return 'received call(' + callJson + ') and the call was successful!'; }; - """.trimIndent()) + """.trimIndent(), + ) val inboundChannel = quickJs.getInboundChannel() val result = inboundChannel.call("firstArg") @@ -65,12 +69,14 @@ class QuickJsInboundChannelTest { @Test fun serviceNamesArrayHappyPath() { - quickJs.evaluate(""" + quickJs.evaluate( + """ var callLog = []; globalThis.$inboundChannelName.serviceNamesArray = function() { return ['service one', 'service two']; }; - """.trimIndent()) + """.trimIndent(), + ) val inboundChannel = quickJs.getInboundChannel() val result = inboundChannel.serviceNamesArray() @@ -85,7 +91,8 @@ class QuickJsInboundChannelTest { @Test fun disconnectHappyPath() { - quickJs.evaluate(""" + quickJs.evaluate( + """ var callLog = ""; globalThis.$inboundChannelName.call = function(callJson) { var result = callLog; @@ -96,7 +103,8 @@ class QuickJsInboundChannelTest { callLog += 'disconnect(' + instanceName + ')'; return true; }; - """.trimIndent()) + """.trimIndent(), + ) val inboundChannel = quickJs.getInboundChannel() assertTrue(inboundChannel.disconnect("service one")) @@ -106,9 +114,11 @@ class QuickJsInboundChannelTest { @Test fun noInboundChannelThrows() { - quickJs.evaluate(""" + quickJs.evaluate( + """ delete globalThis.$inboundChannelName; - """.trimIndent()) + """.trimIndent(), + ) val t = assertFailsWith { quickJs.getInboundChannel() diff --git a/zipline/src/engineTest/kotlin/app/cash/zipline/QuickJsInterruptTest.kt b/zipline/src/engineTest/kotlin/app/cash/zipline/QuickJsInterruptTest.kt index 5f879ffa9..2cb7b52c4 100644 --- a/zipline/src/engineTest/kotlin/app/cash/zipline/QuickJsInterruptTest.kt +++ b/zipline/src/engineTest/kotlin/app/cash/zipline/QuickJsInterruptTest.kt @@ -25,12 +25,14 @@ class QuickJsInterruptTest { private val quickJs = QuickJs.create() @BeforeTest fun setUp() { - quickJs.evaluate(""" + quickJs.evaluate( + """ |var fib = function(a) { | if (a < 2) return 1; | return fib(a - 1) + fib(a - 2); |} - """.trimMargin()) + """.trimMargin(), + ) // Set a huge max stack because of the heavy recursion of fib(). quickJs.maxStackSize *= 5 @@ -69,9 +71,12 @@ class QuickJsInterruptTest { } } - assertEquals("interrupted", assertFailsWith { + assertEquals( + "interrupted", + assertFailsWith { quickJs.evaluate("""fib(20)""") - }.message) + }.message, + ) } @Test fun removeInterruptHandler() { diff --git a/zipline/src/engineTest/kotlin/app/cash/zipline/QuickJsOutboundChannelTest.kt b/zipline/src/engineTest/kotlin/app/cash/zipline/QuickJsOutboundChannelTest.kt index ccaffd42d..8f43626ea 100644 --- a/zipline/src/engineTest/kotlin/app/cash/zipline/QuickJsOutboundChannelTest.kt +++ b/zipline/src/engineTest/kotlin/app/cash/zipline/QuickJsOutboundChannelTest.kt @@ -44,9 +44,11 @@ class QuickJsOutboundChannelTest { @Test fun callHappyPath() { callChannel.callResult = "result one" - val callResult = quickJs.evaluate(""" - globalThis.${outboundChannelName}.call('firstArg'); - """.trimIndent()) + val callResult = quickJs.evaluate( + """ + globalThis.$outboundChannelName.call('firstArg'); + """.trimIndent(), + ) assertEquals("result one", callResult) assertEquals(listOf("call(firstArg)"), callChannel.log) } @@ -56,9 +58,11 @@ class QuickJsOutboundChannelTest { callChannel.serviceNamesResult += "service one" callChannel.serviceNamesResult += "service two" - val serviceNames = quickJs.evaluate(""" - globalThis.${outboundChannelName}.serviceNamesArray(); - """.trimIndent()) as Array + val serviceNames = quickJs.evaluate( + """ + globalThis.$outboundChannelName.serviceNamesArray(); + """.trimIndent(), + ) as Array assertContentEquals( arrayOf( "service one", @@ -78,9 +82,11 @@ class QuickJsOutboundChannelTest { fun disconnectHappyPath() { callChannel.disconnectResult = true - val disconnectResult = quickJs.evaluate(""" - globalThis.${outboundChannelName}.disconnect('theInstanceName'); - """.trimIndent()) as Boolean + val disconnectResult = quickJs.evaluate( + """ + globalThis.$outboundChannelName.disconnect('theInstanceName'); + """.trimIndent(), + ) as Boolean assertTrue(disconnectResult) assertEquals( listOf( @@ -96,11 +102,11 @@ class QuickJsOutboundChannelTest { """ |var count = 0; |for (var i = 0; i < 100000; i++) { - | var result = globalThis.${outboundChannelName}.disconnect('theInstanceName'); + | var result = globalThis.$outboundChannelName.disconnect('theInstanceName'); | if (result) count++; |} |count; - """.trimMargin() + """.trimMargin(), ) as Int assertEquals(100000, callChannel.log.size) assertEquals(100000, count) diff --git a/zipline/src/engineTest/kotlin/app/cash/zipline/QuickJsTest.kt b/zipline/src/engineTest/kotlin/app/cash/zipline/QuickJsTest.kt index 5bef3ef78..88d7c7283 100644 --- a/zipline/src/engineTest/kotlin/app/cash/zipline/QuickJsTest.kt +++ b/zipline/src/engineTest/kotlin/app/cash/zipline/QuickJsTest.kt @@ -58,7 +58,9 @@ class QuickJsTest { assertNull(quickJs.evaluate("undefined;")) assertNull(quickJs.evaluate("null;")) - assertContentEquals(arrayOf("test", true, false, 1, 1.123, null, null), - quickJs.evaluate("""["test", true, false, 1, 1.123, undefined, null];""") as Array) + assertContentEquals( + arrayOf("test", true, false, 1, 1.123, null, null), + quickJs.evaluate("""["test", true, false, 1, 1.123, undefined, null];""") as Array, + ) } } diff --git a/zipline/src/engineTest/kotlin/app/cash/zipline/SampleService.kt b/zipline/src/engineTest/kotlin/app/cash/zipline/SampleService.kt index ed7ca2709..a2fe3ad1e 100644 --- a/zipline/src/engineTest/kotlin/app/cash/zipline/SampleService.kt +++ b/zipline/src/engineTest/kotlin/app/cash/zipline/SampleService.kt @@ -30,12 +30,12 @@ import kotlinx.serialization.serializer @Serializable data class SampleRequest( - val message: String + val message: String, ) @Serializable data class SampleResponse( - val message: String + val message: String, ) /** diff --git a/zipline/src/engineTest/kotlin/app/cash/zipline/TuningApisTest.kt b/zipline/src/engineTest/kotlin/app/cash/zipline/TuningApisTest.kt index 18b19431f..3796d800a 100644 --- a/zipline/src/engineTest/kotlin/app/cash/zipline/TuningApisTest.kt +++ b/zipline/src/engineTest/kotlin/app/cash/zipline/TuningApisTest.kt @@ -67,7 +67,7 @@ class TuningApisTest { quickjs.evaluate( """ globalThis.hello = 'hello'; - """ + """, ) } assertEquals(diff.stringsCount, 0L) // Why isn't this 1? @@ -81,7 +81,7 @@ class TuningApisTest { globalThis.hypotenuse = function(a, b) { return Math.sqrt((a * a) + (b * b)); }; - """ + """, ) } assertEquals(diff.jsFunctionsCount, 1L) @@ -96,7 +96,7 @@ class TuningApisTest { quickjs.evaluate( """ globalThis.buffer = new Uint8Array(1024 * 1024); - """ + """, ) } assertTrue(diff.memoryAllocatedSize >= 1024L * 1024L) diff --git a/zipline/src/engineTest/kotlin/app/cash/zipline/ZiplineServiceTest.kt b/zipline/src/engineTest/kotlin/app/cash/zipline/ZiplineServiceTest.kt index 5c50ac2f9..e100e889a 100644 --- a/zipline/src/engineTest/kotlin/app/cash/zipline/ZiplineServiceTest.kt +++ b/zipline/src/engineTest/kotlin/app/cash/zipline/ZiplineServiceTest.kt @@ -130,7 +130,7 @@ internal class ZiplineServiceTest { |EchoService zipline/host-1 is closed, failed to call: | fun echo(app.cash.zipline.testing.EchoRequest): app.cash.zipline.testing.EchoResponse """.trimMargin(), - failure.message + failure.message, ) assertEquals(setOf("factory"), endpointA.serviceNames) } diff --git a/zipline/src/jniMain/kotlin/app/cash/zipline/JniCallChannel.kt b/zipline/src/jniMain/kotlin/app/cash/zipline/JniCallChannel.kt index 45beb1817..05778afb8 100644 --- a/zipline/src/jniMain/kotlin/app/cash/zipline/JniCallChannel.kt +++ b/zipline/src/jniMain/kotlin/app/cash/zipline/JniCallChannel.kt @@ -19,13 +19,13 @@ import app.cash.zipline.internal.bridge.CallChannel internal class JniCallChannel( private val quickJs: QuickJs, - private val instance: Long + private val instance: Long, ) : CallChannel { override fun serviceNamesArray() = serviceNamesArray(quickJs.context, instance) private external fun serviceNamesArray( context: Long, - instance: Long + instance: Long, ): Array override fun call(callJson: String) = @@ -43,6 +43,6 @@ internal class JniCallChannel( private external fun disconnect( context: Long, instance: Long, - instanceName: String + instanceName: String, ): Boolean } diff --git a/zipline/src/jniMain/kotlin/app/cash/zipline/QuickJs.kt b/zipline/src/jniMain/kotlin/app/cash/zipline/QuickJs.kt index eaf144d29..6b51bfd7d 100644 --- a/zipline/src/jniMain/kotlin/app/cash/zipline/QuickJs.kt +++ b/zipline/src/jniMain/kotlin/app/cash/zipline/QuickJs.kt @@ -29,7 +29,7 @@ import java.io.Closeable */ @EngineApi actual class QuickJs private constructor( - internal var context: Long + internal var context: Long, ) : Closeable { actual companion object { init { diff --git a/zipline/src/jniMain/kotlin/app/cash/zipline/QuickJsException.kt b/zipline/src/jniMain/kotlin/app/cash/zipline/QuickJsException.kt index 232a16c90..3dc6fffd1 100644 --- a/zipline/src/jniMain/kotlin/app/cash/zipline/QuickJsException.kt +++ b/zipline/src/jniMain/kotlin/app/cash/zipline/QuickJsException.kt @@ -21,7 +21,7 @@ import java.util.regex.Pattern @Keep // Instruct ProGuard not to strip this type. actual class QuickJsException @JvmOverloads constructor( detailMessage: String, - jsStackTrace: String? = null + jsStackTrace: String? = null, ) : RuntimeException(detailMessage) { init { if (jsStackTrace != null) { @@ -60,9 +60,10 @@ actual class QuickJsException @JvmOverloads constructor( // Splice the JavaScript stack in right above the call to QuickJs. var spliced = false for (stackTraceElement in stackTrace) { - if (!spliced - && stackTraceElement.isNativeMethod - && stackTraceElement.isZipline) { + if (!spliced && + stackTraceElement.isNativeMethod && + stackTraceElement.isZipline + ) { spliced = true for (line in lines) { val jsElement = toStackTraceElement(line) ?: continue @@ -82,8 +83,12 @@ actual class QuickJsException @JvmOverloads constructor( return if (!m.matches()) { null // Nothing interesting on this line. } else { - StackTraceElement(STACK_TRACE_CLASS_NAME, m.group(1), m.group(2), - if (m.groupCount() > 3) m.group(3)!!.toInt() else -1) + StackTraceElement( + STACK_TRACE_CLASS_NAME, + m.group(1), + m.group(2), + if (m.groupCount() > 3) m.group(3)!!.toInt() else -1, + ) } } } diff --git a/zipline/src/jniMain/kotlin/app/cash/zipline/internal/bridge/leakCanaryJni.kt b/zipline/src/jniMain/kotlin/app/cash/zipline/internal/bridge/leakCanaryJni.kt index 0f404c455..f959e761a 100644 --- a/zipline/src/jniMain/kotlin/app/cash/zipline/internal/bridge/leakCanaryJni.kt +++ b/zipline/src/jniMain/kotlin/app/cash/zipline/internal/bridge/leakCanaryJni.kt @@ -24,7 +24,7 @@ internal actual fun trackLeaks( eventListener: EndpointEventListener, serviceName: String, callHandler: OutboundCallHandler, - service: ZiplineService + service: ZiplineService, ) { allReferencesSet += ZiplineServiceReference(eventListener, serviceName, callHandler, service) } @@ -46,7 +46,7 @@ private class ZiplineServiceReference( private val eventListener: EndpointEventListener, private val serviceName: String, private val callHandler: OutboundCallHandler, - service: ZiplineService + service: ZiplineService, ) : PhantomReference(service, allReferencesQueue) { fun afterGc() { allReferencesSet.remove(this) diff --git a/zipline/src/jniTest/kotlin/app/cash/zipline/EventListenerTest.kt b/zipline/src/jniTest/kotlin/app/cash/zipline/EventListenerTest.kt index a6498a839..93a0083aa 100644 --- a/zipline/src/jniTest/kotlin/app/cash/zipline/EventListenerTest.kt +++ b/zipline/src/jniTest/kotlin/app/cash/zipline/EventListenerTest.kt @@ -33,7 +33,8 @@ import org.junit.Test * This test exercises event listeners using QuickJS. */ class EventListenerTest { - @Rule @JvmField val ziplineTestRule = ZiplineTestRule() + @Rule @JvmField + val ziplineTestRule = ZiplineTestRule() private val dispatcher = ziplineTestRule.dispatcher private val eventListener = LoggingEventListener() private val zipline = Zipline.create(dispatcher, eventListener = eventListener) @@ -106,7 +107,7 @@ class EventListenerTest { zipline.bind( "jvmSuspendingEchoService", - jvmSuspendingEchoService + jvmSuspendingEchoService, ) zipline.quickJs.evaluate("testing.app.cash.zipline.testing.callSuspendingEchoService('Eric')") @@ -124,9 +125,12 @@ class EventListenerTest { @Test fun jvmCallIncompatibleJsService() = runBlocking(dispatcher) { zipline.quickJs.evaluate("testing.app.cash.zipline.testing.prepareJsBridges()") - assertThat(assertFailsWith { + assertThat( + assertFailsWith { zipline.take("helloService").echo() - }).hasMessageThat().startsWith(""" + }, + ).hasMessageThat().startsWith( + """ no such method (incompatible API versions?) called service: helloService @@ -136,7 +140,7 @@ class EventListenerTest { fun echo(app.cash.zipline.testing.EchoRequest): app.cash.zipline.testing.EchoResponse fun close(): kotlin.Unit at - """.trimIndent() + """.trimIndent(), ) val name = "helloService" val funName = "fun echo(): app.cash.zipline.testing.EchoResponse" @@ -149,15 +153,18 @@ class EventListenerTest { @Test fun jvmCallUnknownJsService() = runBlocking(dispatcher) { zipline.quickJs.evaluate("testing.app.cash.zipline.testing.initZipline()") - assertThat(assertFailsWith { + assertThat( + assertFailsWith { zipline.take("helloService").echo(EchoRequest("hello")) - }).hasMessageThat().startsWith(""" + }, + ).hasMessageThat().startsWith( + """ no such service (service closed?) called service: helloService available services: zipline/js - """.trimIndent() + """.trimIndent(), ) val name = "helloService" val funName = "fun echo(app.cash.zipline.testing.EchoRequest): app.cash.zipline.testing.EchoResponse" @@ -175,9 +182,11 @@ class EventListenerTest { } zipline.bind("supService", jvmPotatoService) - assertThat(assertFailsWith { + assertThat( + assertFailsWith { zipline.quickJs.evaluate("testing.app.cash.zipline.testing.callSupService('homie')") - }).hasMessageThat().startsWith("app.cash.zipline.ZiplineApiMismatchException: no such method") + }, + ).hasMessageThat().startsWith("app.cash.zipline.ZiplineApiMismatchException: no such method") val name = "supService" val funName = "fun echo(app.cash.zipline.testing.EchoRequest): app.cash.zipline.testing.EchoResponse" @@ -188,9 +197,11 @@ class EventListenerTest { } @Test fun jsCallUnknownJvmService() = runBlocking(dispatcher) { - assertThat(assertFailsWith { + assertThat( + assertFailsWith { zipline.quickJs.evaluate("testing.app.cash.zipline.testing.callSupService('homie')") - }).hasMessageThat().startsWith("app.cash.zipline.ZiplineApiMismatchException: no such service") + }, + ).hasMessageThat().startsWith("app.cash.zipline.ZiplineApiMismatchException: no such service") val name = "supService" val funName = "fun echo(app.cash.zipline.testing.EchoRequest): app.cash.zipline.testing.EchoResponse" diff --git a/zipline/src/jniTest/kotlin/app/cash/zipline/ExceptionsTest.kt b/zipline/src/jniTest/kotlin/app/cash/zipline/ExceptionsTest.kt index 637a31b2d..a2f7399fb 100644 --- a/zipline/src/jniTest/kotlin/app/cash/zipline/ExceptionsTest.kt +++ b/zipline/src/jniTest/kotlin/app/cash/zipline/ExceptionsTest.kt @@ -27,7 +27,8 @@ import org.junit.Rule import org.junit.Test class ExceptionsTest { - @Rule @JvmField val ziplineTestRule = ZiplineTestRule() + @Rule @JvmField + val ziplineTestRule = ZiplineTestRule() private val dispatcher = ziplineTestRule.dispatcher private val zipline = Zipline.create(dispatcher) @@ -44,15 +45,17 @@ class ExceptionsTest { val service = zipline.take("throwingService") - assertThat(assertFailsWith { + assertThat( + assertFailsWith { service.echo(EchoRequest("Jake")) - }.stackTraceToString()).apply { + }.stackTraceToString(), + ).apply { matches( """(?s).*IllegalStateException: boom!""" + """.*at goBoom1""" + """.*at goBoom2""" + """.*at goBoom3""" + - """.*""" + """.*""", ) } } @@ -60,16 +63,18 @@ class ExceptionsTest { @Test fun jsCallJvmServiceThatThrows(): Unit = runBlocking(dispatcher) { zipline.bind("throwingService", JvmThrowingEchoService()) - assertThat(assertFailsWith { + assertThat( + assertFailsWith { zipline.quickJs.evaluate("testing.app.cash.zipline.testing.callThrowingService('homie')") - }.stackTraceToString()).apply { + }.stackTraceToString(), + ).apply { matches( """(?s).*java\.lang\.IllegalStateException: boom!""" + """.*JvmThrowingEchoService\.goBoom1""" + """.*JvmThrowingEchoService\.goBoom2""" + """.*JvmThrowingEchoService\.goBoom3""" + """.*JvmThrowingEchoService\.echo""" + - """.*""" + """.*""", ) } } @@ -80,9 +85,11 @@ class ExceptionsTest { val service = zipline.take("delegatingService") - assertThat(assertFailsWith { + assertThat( + assertFailsWith { service.echo(EchoRequest("Jake")) - }.stackTraceToString()).apply { + }.stackTraceToString(), + ).apply { matches( """(?s).*IllegalStateException: boom!""" + """.*at .*JvmThrowingEchoService\.goBoom1""" + @@ -92,7 +99,7 @@ class ExceptionsTest { """.*at delegate1""" + """.*at delegate2""" + """.*at delegate3""" + - """.*""" + """.*""", ) } } diff --git a/zipline/src/jniTest/kotlin/app/cash/zipline/InterfaceSerializersTest.kt b/zipline/src/jniTest/kotlin/app/cash/zipline/InterfaceSerializersTest.kt index b300846d1..abe86733d 100644 --- a/zipline/src/jniTest/kotlin/app/cash/zipline/InterfaceSerializersTest.kt +++ b/zipline/src/jniTest/kotlin/app/cash/zipline/InterfaceSerializersTest.kt @@ -34,7 +34,8 @@ import org.junit.Test * a weakness in kotlinx.serialization, which is lazy when resolving serializers for interfaces. */ class InterfaceSerializersTest { - @Rule @JvmField val ziplineTestRule = ZiplineTestRule() + @Rule @JvmField + val ziplineTestRule = ZiplineTestRule() private val dispatcher = ziplineTestRule.dispatcher private val zipline = Zipline.create(dispatcher, MessageInterfaceSerializersModule) private val ziplineNoSerializer = Zipline.create(dispatcher) @@ -51,7 +52,7 @@ class InterfaceSerializersTest { @Test fun jvmToJsRequestInterfaceSucceeds() = runBlocking(dispatcher) { zipline.quickJs.evaluate( - "testing.app.cash.zipline.testing.prepareInterfaceSerializersJsBridges()" + "testing.app.cash.zipline.testing.prepareInterfaceSerializersJsBridges()", ) val service = zipline.take("requestInterfaceService") assertThat(service.echo(RealMessageInterface("Andrew"))) @@ -60,7 +61,7 @@ class InterfaceSerializersTest { @Test fun jvmToJsResponseInterfaceSucceeds() = runBlocking(dispatcher) { zipline.quickJs.evaluate( - "testing.app.cash.zipline.testing.prepareInterfaceSerializersJsBridges()" + "testing.app.cash.zipline.testing.prepareInterfaceSerializersJsBridges()", ) val service = zipline.take("responseInterfaceService") assertThat(service.echo("Andrew")) @@ -70,11 +71,11 @@ class InterfaceSerializersTest { @Test fun jsToJvmRequestInterfaceSucceeds() = runBlocking(dispatcher) { zipline.bind( "requestInterfaceService", - JvmMessageInterfaceService() + JvmMessageInterfaceService(), ) val result = zipline.quickJs.evaluate( - "testing.app.cash.zipline.testing.callInterfaceRequest()" + "testing.app.cash.zipline.testing.callInterfaceRequest()", ) assertThat(result).isEqualTo("JVM received an interface, Jesse") } @@ -82,11 +83,11 @@ class InterfaceSerializersTest { @Test fun jsToJvmResponseInterfaceSucceeds() = runBlocking(dispatcher) { zipline.bind( "responseInterfaceService", - JvmMessageInterfaceService() + JvmMessageInterfaceService(), ) val result = zipline.quickJs.evaluate( - "testing.app.cash.zipline.testing.callInterfaceResponse()" + "testing.app.cash.zipline.testing.callInterfaceResponse()", ) assertThat(result).isEqualTo("JVM returned an interface, Jesse") } @@ -94,12 +95,12 @@ class InterfaceSerializersTest { @Test fun jsToJvmInterfaceRequestFailsLate() = runBlocking(dispatcher) { ziplineNoSerializer.bind( "requestInterfaceService", - JvmMessageInterfaceService() + JvmMessageInterfaceService(), ) val exception = assertFailsWith { ziplineNoSerializer.quickJs.evaluate( - "testing.app.cash.zipline.testing.callInterfaceRequest()" + "testing.app.cash.zipline.testing.callInterfaceRequest()", ) } assertThat(exception).hasMessageThat() @@ -109,12 +110,12 @@ class InterfaceSerializersTest { @Test fun jsToJvmInterfaceResponseFailsLate() = runBlocking(dispatcher) { ziplineNoSerializer.bind( "responseInterfaceService", - JvmMessageInterfaceService() + JvmMessageInterfaceService(), ) val exception = assertFailsWith { ziplineNoSerializer.quickJs.evaluate( - "testing.app.cash.zipline.testing.callInterfaceResponse()" + "testing.app.cash.zipline.testing.callInterfaceResponse()", ) } assertThat(exception).hasMessageThat() diff --git a/zipline/src/jniTest/kotlin/app/cash/zipline/LeakedServicesTest.kt b/zipline/src/jniTest/kotlin/app/cash/zipline/LeakedServicesTest.kt index cba098421..1c106b284 100644 --- a/zipline/src/jniTest/kotlin/app/cash/zipline/LeakedServicesTest.kt +++ b/zipline/src/jniTest/kotlin/app/cash/zipline/LeakedServicesTest.kt @@ -27,7 +27,8 @@ import org.junit.Rule import org.junit.Test class LeakedServicesTest { - @Rule @JvmField val ziplineTestRule = ZiplineTestRule() + @Rule @JvmField + val ziplineTestRule = ZiplineTestRule() private val dispatcher = ziplineTestRule.dispatcher private val eventListener = LoggingEventListener() private val zipline = Zipline.create(dispatcher, eventListener = eventListener) diff --git a/zipline/src/jniTest/kotlin/app/cash/zipline/LoadJsModuleTest.kt b/zipline/src/jniTest/kotlin/app/cash/zipline/LoadJsModuleTest.kt index 43ab58888..da34cb37b 100644 --- a/zipline/src/jniTest/kotlin/app/cash/zipline/LoadJsModuleTest.kt +++ b/zipline/src/jniTest/kotlin/app/cash/zipline/LoadJsModuleTest.kt @@ -27,7 +27,8 @@ import org.junit.Test * modules in the standard forms that the Kotlin compiler produces. */ class LoadJsModuleTest { - @Rule @JvmField val ziplineTestRule = ZiplineTestRule() + @Rule @JvmField + val ziplineTestRule = ZiplineTestRule() private val dispatcher = ziplineTestRule.dispatcher private val zipline = Zipline.create(dispatcher) diff --git a/zipline/src/jniTest/kotlin/app/cash/zipline/NewServicesTest.kt b/zipline/src/jniTest/kotlin/app/cash/zipline/NewServicesTest.kt index 85de566d0..da7e7a9da 100644 --- a/zipline/src/jniTest/kotlin/app/cash/zipline/NewServicesTest.kt +++ b/zipline/src/jniTest/kotlin/app/cash/zipline/NewServicesTest.kt @@ -39,7 +39,8 @@ import org.junit.Rule import org.junit.Test class NewSerializersTest { - @Rule @JvmField val ziplineTestRule = ZiplineTestRule() + @Rule @JvmField + val ziplineTestRule = ZiplineTestRule() private val dispatcher = ziplineTestRule.dispatcher private val zipline = Zipline.create(dispatcher, kotlinBuiltInSerializersModule) private val json = zipline.json @@ -187,7 +188,7 @@ class NewSerializersTest { assertSerializersEqual( ListSerializer(String.serializer()), function.argsListSerializer.serializers[0], - listOf("a", "b", "c") + listOf("a", "b", "c"), ) } @@ -370,7 +371,7 @@ class NewSerializersTest { ) as ReturningZiplineFunction<*> assertEquals( RequiresContextualSerializer, - function.argsListSerializer.serializers.first() + function.argsListSerializer.serializers.first(), ) } @@ -386,7 +387,7 @@ class NewSerializersTest { ) as ReturningZiplineFunction<*> assertEquals( RequiresContextualSerializer, - function.resultSerializer.successSerializer + function.resultSerializer.successSerializer, ) } @@ -402,7 +403,7 @@ class NewSerializersTest { ) as SuspendingZiplineFunction<*> assertEquals( suspendCallbackSerializer(RequiresContextualSerializer), - function.suspendCallbackSerializer + function.suspendCallbackSerializer, ) } @@ -411,17 +412,17 @@ class NewSerializersTest { } private fun suspendCallbackSerializer( - resultSerializer: KSerializer + resultSerializer: KSerializer, ): KSerializer> { return ziplineServiceSerializer( SuspendCallback::class, - listOf(resultSerializer) + listOf(resultSerializer), ) } private fun flowSerializer(elementSerializer: KSerializer): KSerializer> { return FlowSerializer( - ziplineServiceSerializer(FlowZiplineService::class, listOf(elementSerializer)) + ziplineServiceSerializer(FlowZiplineService::class, listOf(elementSerializer)), ) } @@ -440,7 +441,7 @@ class NewSerializersTest { // Note: no @Serializable. class RequiresContextual( - val string: String + val string: String, ) object RequiresContextualSerializer : KSerializer { diff --git a/zipline/src/jniTest/kotlin/app/cash/zipline/QuickJsCompileJvmTest.kt b/zipline/src/jniTest/kotlin/app/cash/zipline/QuickJsCompileJvmTest.kt index bf6806928..3836c5492 100644 --- a/zipline/src/jniTest/kotlin/app/cash/zipline/QuickJsCompileJvmTest.kt +++ b/zipline/src/jniTest/kotlin/app/cash/zipline/QuickJsCompileJvmTest.kt @@ -28,7 +28,8 @@ class QuickJsCompileJvmTest { } @Test fun exceptionsInScriptIncludeStackTrace() { - val code = quickJs.compile(""" + val code = quickJs.compile( + """ |f1(); | |function f1() { @@ -38,7 +39,10 @@ class QuickJsCompileJvmTest { |function f2() { | nope(); |} - |""".trimMargin(), "C:\\Documents\\myFile.js") + | +""".trimMargin(), + "C:\\Documents\\myFile.js", + ) val t = assertFailsWith { quickJs.execute(code) } diff --git a/zipline/src/jniTest/kotlin/app/cash/zipline/QuickJsInboundChannelJvmTest.kt b/zipline/src/jniTest/kotlin/app/cash/zipline/QuickJsInboundChannelJvmTest.kt index 19b5f202f..87446a597 100644 --- a/zipline/src/jniTest/kotlin/app/cash/zipline/QuickJsInboundChannelJvmTest.kt +++ b/zipline/src/jniTest/kotlin/app/cash/zipline/QuickJsInboundChannelJvmTest.kt @@ -37,7 +37,8 @@ class QuickJsInboundChannelJvmTest { @Before fun setUp() { - quickJs.evaluate(""" + quickJs.evaluate( + """ globalThis.$inboundChannelName = {}; globalThis.$inboundChannelName.serviceNamesArray = function() { }; @@ -45,7 +46,8 @@ class QuickJsInboundChannelJvmTest { }; globalThis.$inboundChannelName.disconnect = function(instanceName) { }; - """.trimIndent()) + """.trimIndent(), + ) } /** @@ -53,14 +55,17 @@ class QuickJsInboundChannelJvmTest { * that crashes it could throw a JavaScript exception. Confirm such exceptions are reasonable. */ @Test fun inboundChannelThrowsInJavaScript() { - quickJs.evaluate(""" + quickJs.evaluate( + """ function goBoom() { noSuchMethod(); } globalThis.$inboundChannelName.disconnect = function(instanceName) { goBoom(); }; - """.trimIndent(), "explode.js") + """.trimIndent(), + "explode.js", + ) val inboundChannel = quickJs.getInboundChannel() val t = assertFailsWith { inboundChannel.disconnect("service one") diff --git a/zipline/src/jniTest/kotlin/app/cash/zipline/QuickJsJvmTest.kt b/zipline/src/jniTest/kotlin/app/cash/zipline/QuickJsJvmTest.kt index 2864b2545..387334e9e 100644 --- a/zipline/src/jniTest/kotlin/app/cash/zipline/QuickJsJvmTest.kt +++ b/zipline/src/jniTest/kotlin/app/cash/zipline/QuickJsJvmTest.kt @@ -30,7 +30,8 @@ class QuickJsJvmTest { @Test fun exceptionsInScriptIncludeStackTrace() { val t = assertFailsWith { - quickjs.evaluate(""" + quickjs.evaluate( + """ |f1(); | |function f1() { @@ -40,7 +41,10 @@ class QuickJsJvmTest { |function f2() { | nope(); |} - |""".trimMargin(), "test.js") + | +""".trimMargin(), + "test.js", + ) } assertEquals("'nope' is not defined", t.message) assertEquals("JavaScript.f2(test.js:8)", t.stackTrace[0].toString()) @@ -53,7 +57,9 @@ class QuickJsJvmTest { val beforeMillis = System.currentTimeMillis().toDouble() val nowMillis = quickjs.evaluate("Date.now()") as Double val afterMillis = System.currentTimeMillis().toDouble() - assertTrue("$beforeMillis <= $nowMillis <= $afterMillis", - nowMillis in beforeMillis..afterMillis) + assertTrue( + "$beforeMillis <= $nowMillis <= $afterMillis", + nowMillis in beforeMillis..afterMillis, + ) } } diff --git a/zipline/src/jniTest/kotlin/app/cash/zipline/QuickJsOutboundChannelJvmTest.kt b/zipline/src/jniTest/kotlin/app/cash/zipline/QuickJsOutboundChannelJvmTest.kt index 8363a6f38..dcf8f47d4 100644 --- a/zipline/src/jniTest/kotlin/app/cash/zipline/QuickJsOutboundChannelJvmTest.kt +++ b/zipline/src/jniTest/kotlin/app/cash/zipline/QuickJsOutboundChannelJvmTest.kt @@ -45,9 +45,10 @@ class QuickJsOutboundChannelJvmTest { fun jvmExceptionsWithUnifiedStackTrace() { callChannel.disconnectThrow = true val t = assertFailsWith { - quickJs.evaluate(""" + quickJs.evaluate( + """ function f1() { - globalThis.${outboundChannelName}.disconnect('theInstanceName'); + globalThis.$outboundChannelName.disconnect('theInstanceName'); } function f2() { @@ -55,7 +56,9 @@ class QuickJsOutboundChannelJvmTest { } f2(); - """.trimIndent(), "explode.js") + """.trimIndent(), + "explode.js", + ) } assertThat(t) .hasMessageThat() diff --git a/zipline/src/jniTest/kotlin/app/cash/zipline/SealedClassSerializersTest.kt b/zipline/src/jniTest/kotlin/app/cash/zipline/SealedClassSerializersTest.kt index f9856ba6a..79aa2138d 100644 --- a/zipline/src/jniTest/kotlin/app/cash/zipline/SealedClassSerializersTest.kt +++ b/zipline/src/jniTest/kotlin/app/cash/zipline/SealedClassSerializersTest.kt @@ -28,7 +28,8 @@ import org.junit.Rule import org.junit.Test class SealedClassSerializersTest { - @Rule @JvmField val ziplineTestRule = ZiplineTestRule() + @Rule @JvmField + val ziplineTestRule = ZiplineTestRule() private val dispatcher = ziplineTestRule.dispatcher private val zipline = Zipline.create(dispatcher) @@ -43,7 +44,7 @@ class SealedClassSerializersTest { @Test fun sealedClassesEncodeAndDecode() = runBlocking(dispatcher) { val service = zipline.take("sealedClassMessageService") zipline.quickJs.evaluate( - "testing.app.cash.zipline.testing.prepareSealedClassMessageService()" + "testing.app.cash.zipline.testing.prepareSealedClassMessageService()", ) assertThat(service.colorSwap(RedMessage("hello!"))) @@ -57,7 +58,7 @@ class SealedClassSerializersTest { @Test fun sealedClassesFlow(): Unit = runBlocking(dispatcher) { val service = zipline.take("sealedClassMessageService") zipline.quickJs.evaluate( - "testing.app.cash.zipline.testing.prepareSealedClassMessageService()" + "testing.app.cash.zipline.testing.prepareSealedClassMessageService()", ) val sealedMessageFlow = flow { diff --git a/zipline/src/jniTest/kotlin/app/cash/zipline/SerializersTest.kt b/zipline/src/jniTest/kotlin/app/cash/zipline/SerializersTest.kt index d0e2accb9..f2e516567 100644 --- a/zipline/src/jniTest/kotlin/app/cash/zipline/SerializersTest.kt +++ b/zipline/src/jniTest/kotlin/app/cash/zipline/SerializersTest.kt @@ -30,7 +30,8 @@ import org.junit.Rule import org.junit.Test class SerializersTest { - @Rule @JvmField val ziplineTestRule = ZiplineTestRule() + @Rule @JvmField + val ziplineTestRule = ZiplineTestRule() private val dispatcher = ziplineTestRule.dispatcher private val zipline = Zipline.create(dispatcher, AdaptersSerializersModule) private val ziplineRequestOnly = Zipline.create(dispatcher, AdaptersRequestSerializersModule) @@ -49,15 +50,19 @@ class SerializersTest { } @Test fun missingGetReturnValueSerializerFailsFast() = runBlocking(dispatcher) { - assertThat(assertFailsWith { + assertThat( + assertFailsWith { ziplineRequestOnly.take("adaptersService") - }).hasMessageThat().contains("Serializer for class 'AdaptersResponse' is not found.") + }, + ).hasMessageThat().contains("Serializer for class 'AdaptersResponse' is not found.") } @Test fun missingGetParameterSerializerFailsFast() = runBlocking(dispatcher) { - assertThat(assertFailsWith { + assertThat( + assertFailsWith { ziplineResponseOnly.take("adaptersService") - }).hasMessageThat().contains("Serializer for class 'AdaptersRequest' is not found.") + }, + ).hasMessageThat().contains("Serializer for class 'AdaptersRequest' is not found.") } @Test fun presentGetSerializersSucceeds() = runBlocking(dispatcher) { @@ -69,27 +74,31 @@ class SerializersTest { } @Test fun missingSetReturnValueSerializerFailsFast() = runBlocking(dispatcher) { - assertThat(assertFailsWith { + assertThat( + assertFailsWith { ziplineRequestOnly.bind( "adaptersService", - JvmAdaptersService() + JvmAdaptersService(), ) - }).hasMessageThat().contains("Serializer for class 'AdaptersResponse' is not found.") + }, + ).hasMessageThat().contains("Serializer for class 'AdaptersResponse' is not found.") } @Test fun missingSetParameterSerializerFailsFast() = runBlocking(dispatcher) { - assertThat(assertFailsWith { + assertThat( + assertFailsWith { ziplineResponseOnly.bind( "adaptersService", - JvmAdaptersService() + JvmAdaptersService(), ) - }).hasMessageThat().contains("Serializer for class 'AdaptersRequest' is not found.") + }, + ).hasMessageThat().contains("Serializer for class 'AdaptersRequest' is not found.") } @Test fun presentSetSerializersSucceeds() = runBlocking(dispatcher) { zipline.bind( "adaptersService", - JvmAdaptersService() + JvmAdaptersService(), ) assertThat(zipline.quickJs.evaluate("testing.app.cash.zipline.testing.callAdaptersService()")) .isEqualTo("JavaScript received nice adapters, Jesse") diff --git a/zipline/src/jniTest/kotlin/app/cash/zipline/ServiceMemberTest.kt b/zipline/src/jniTest/kotlin/app/cash/zipline/ServiceMemberTest.kt index d395c48f9..0623fa322 100644 --- a/zipline/src/jniTest/kotlin/app/cash/zipline/ServiceMemberTest.kt +++ b/zipline/src/jniTest/kotlin/app/cash/zipline/ServiceMemberTest.kt @@ -33,7 +33,8 @@ import org.junit.Test * [ziplineServiceSerializer]. This test confirms it all works across bridges. */ class ServiceMemberTest { - @Rule @JvmField val ziplineTestRule = ZiplineTestRule() + @Rule @JvmField + val ziplineTestRule = ZiplineTestRule() private val dispatcher = ziplineTestRule.dispatcher private val zipline = Zipline.create(dispatcher, ServiceMemberSerializersModule) diff --git a/zipline/src/jniTest/kotlin/app/cash/zipline/SetTimeoutTest.kt b/zipline/src/jniTest/kotlin/app/cash/zipline/SetTimeoutTest.kt index d6c16a62c..590e70ee9 100644 --- a/zipline/src/jniTest/kotlin/app/cash/zipline/SetTimeoutTest.kt +++ b/zipline/src/jniTest/kotlin/app/cash/zipline/SetTimeoutTest.kt @@ -24,7 +24,8 @@ import org.junit.Rule import org.junit.Test class SetTimeoutTest { - @Rule @JvmField val ziplineTestRule = ZiplineTestRule() + @Rule @JvmField + val ziplineTestRule = ZiplineTestRule() private val dispatcher = ziplineTestRule.dispatcher private val zipline = Zipline.create(dispatcher) @@ -47,7 +48,7 @@ class SetTimeoutTest { }; setTimeout(sayGoodbye, 100); - """ + """, ) assertEquals("hello", zipline.quickJs.evaluate("greeting")) @@ -62,7 +63,7 @@ class SetTimeoutTest { }; setTimeout(doNothing, 100); - """ + """, ) zipline.close() diff --git a/zipline/src/jniTest/kotlin/app/cash/zipline/ThrowableSerializerTest.kt b/zipline/src/jniTest/kotlin/app/cash/zipline/ThrowableSerializerTest.kt index cdb8ec22d..dcffef23d 100644 --- a/zipline/src/jniTest/kotlin/app/cash/zipline/ThrowableSerializerTest.kt +++ b/zipline/src/jniTest/kotlin/app/cash/zipline/ThrowableSerializerTest.kt @@ -32,7 +32,7 @@ class ThrowableSerializerTest { @Test fun happyPath() { val exception = Exception("boom") exception.stackTrace = arrayOf( - StackTraceElement("ThrowableSerializerTest", "goBoom", "test.kt", 5) + StackTraceElement("ThrowableSerializerTest", "goBoom", "test.kt", 5), ) val exceptionJson = """ @@ -55,7 +55,7 @@ class ThrowableSerializerTest { |java.lang.Exception: boom |${'\t'}at ThrowableSerializerTest.goBoom(test.kt:5) """.trimMargin(), - decoded.message + decoded.message, ) } diff --git a/zipline/src/jniTest/kotlin/app/cash/zipline/Utf8Test.kt b/zipline/src/jniTest/kotlin/app/cash/zipline/Utf8Test.kt index ca8e977af..7f4e67f7a 100644 --- a/zipline/src/jniTest/kotlin/app/cash/zipline/Utf8Test.kt +++ b/zipline/src/jniTest/kotlin/app/cash/zipline/Utf8Test.kt @@ -31,7 +31,8 @@ import org.junit.Test * each doesn't mangle content. We've had bugs where non-ASCII characters weren't encoded properly. */ class Utf8Test { - @Rule @JvmField val ziplineTestRule = ZiplineTestRule() + @Rule @JvmField + val ziplineTestRule = ZiplineTestRule() private val dispatcher = ziplineTestRule.dispatcher private val zipline = Zipline.create(dispatcher) private val quickjs = zipline.quickJs @@ -45,19 +46,25 @@ class Utf8Test { } @Test fun nonAsciiInInputAndOutput() = runBlocking(dispatcher) { - assertEquals("(a\uD83D\uDC1Dcdefg, a\uD83D\uDC1Dcdefg)", - quickjs.evaluate("var s = \"a\uD83D\uDC1Dcdefg\"; '(' + s + ', ' + s + ')';")) + assertEquals( + "(a\uD83D\uDC1Dcdefg, a\uD83D\uDC1Dcdefg)", + quickjs.evaluate("var s = \"a\uD83D\uDC1Dcdefg\"; '(' + s + ', ' + s + ')';"), + ) } @Test fun nonAsciiInFileName() = runBlocking(dispatcher) { val t = assertFailsWith { - quickjs.evaluate(""" + quickjs.evaluate( + """ |f1(); | |function f1() { | nope(); |} - |""".trimMargin(), "a\uD83D\uDC1Dcdefg.js") + | +""".trimMargin(), + "a\uD83D\uDC1Dcdefg.js", + ) quickjs.evaluate("formatter.format();") } assertEquals("JavaScript.f1(a\uD83D\uDC1Dcdefg.js:4)", t.stackTrace[0].toString()) @@ -70,13 +77,18 @@ class Utf8Test { } @Test fun nonAsciiOutboundCalls() = runBlocking(dispatcher) { - zipline.bind("formatter", object : Formatter { + zipline.bind( + "formatter", + object : Formatter { override fun format(message: String): String { return "($message, $message)" } - }) - assertEquals("(a\uD83D\uDC1Dcdefg, a\uD83D\uDC1Dcdefg)", - quickjs.evaluate("testing.app.cash.zipline.testing.callFormatter('a\uD83D\uDC1Dcdefg');")) + }, + ) + assertEquals( + "(a\uD83D\uDC1Dcdefg, a\uD83D\uDC1Dcdefg)", + quickjs.evaluate("testing.app.cash.zipline.testing.callFormatter('a\uD83D\uDC1Dcdefg');"), + ) } @Test fun nonAsciiInExceptionThrownInJs() = runBlocking(dispatcher) { @@ -89,11 +101,14 @@ class Utf8Test { } @Test fun nonAsciiInExceptionThrownInJava() = runBlocking(dispatcher) { - zipline.bind("formatter", object : Formatter { + zipline.bind( + "formatter", + object : Formatter { override fun format(message: String): String { throw RuntimeException("a\uD83D\uDC1Dcdefg") } - }) + }, + ) val t = assertFailsWith { quickjs.evaluate("testing.app.cash.zipline.testing.callFormatter('');") } diff --git a/zipline/src/jniTest/kotlin/app/cash/zipline/ZiplineDispatchTest.kt b/zipline/src/jniTest/kotlin/app/cash/zipline/ZiplineDispatchTest.kt index a519c1f6a..20482ec0f 100644 --- a/zipline/src/jniTest/kotlin/app/cash/zipline/ZiplineDispatchTest.kt +++ b/zipline/src/jniTest/kotlin/app/cash/zipline/ZiplineDispatchTest.kt @@ -33,7 +33,8 @@ import org.junit.Test * stacks. Confirm that recursive suspend functions don't crash. */ class ZiplineDispatchTest { - @Rule @JvmField val ziplineTestRule = ZiplineTestRule() + @Rule @JvmField + val ziplineTestRule = ZiplineTestRule() private val dispatcher = ziplineTestRule.dispatcher private val zipline = Zipline.create(dispatcher) @@ -58,28 +59,37 @@ class ZiplineDispatchTest { coroutineScope { async { - schedulerService.schedule(100L, object : SchedulerService.Callback { + schedulerService.schedule( + 100L, + object : SchedulerService.Callback { override suspend fun invoke(): String { channel.send("delay = 100") return "success" } - }) + }, + ) } async { - schedulerService.schedule(0L, object : SchedulerService.Callback { + schedulerService.schedule( + 0L, + object : SchedulerService.Callback { override suspend fun invoke(): String { channel.send("delay = 0") return "success" } - }) + }, + ) } async { - schedulerService.schedule(200L, object : SchedulerService.Callback { + schedulerService.schedule( + 200L, + object : SchedulerService.Callback { override suspend fun invoke(): String { channel.send("delay = 200") return "success" } - }) + }, + ) } } @@ -97,38 +107,50 @@ class ZiplineDispatchTest { coroutineScope { async { - schedulerService.schedule(100L, object : SchedulerService.Callback { + schedulerService.schedule( + 100L, + object : SchedulerService.Callback { override suspend fun invoke(): String { channel.send("delay = 100 before") this@coroutineScope.async { - schedulerService.schedule(200L, object : SchedulerService.Callback { + schedulerService.schedule( + 200L, + object : SchedulerService.Callback { override suspend fun invoke(): String { channel.send("delay = 100 + 200") return "success" } - }) + }, + ) } channel.send("delay = 100 after") return "success" } - }) + }, + ) } async { - schedulerService.schedule(0L, object : SchedulerService.Callback { + schedulerService.schedule( + 0L, + object : SchedulerService.Callback { override suspend fun invoke(): String { channel.send("delay = 0 before") this@coroutineScope.async { - schedulerService.schedule(200L, object : SchedulerService.Callback { + schedulerService.schedule( + 200L, + object : SchedulerService.Callback { override suspend fun invoke(): String { channel.send("delay = 0 + 200") return "success" } - }) + }, + ) } channel.send("delay = 0 after") return "success" } - }) + }, + ) } } diff --git a/zipline/src/jniTest/kotlin/app/cash/zipline/ZiplineTest.kt b/zipline/src/jniTest/kotlin/app/cash/zipline/ZiplineTest.kt index 2b84438cf..41e068bde 100644 --- a/zipline/src/jniTest/kotlin/app/cash/zipline/ZiplineTest.kt +++ b/zipline/src/jniTest/kotlin/app/cash/zipline/ZiplineTest.kt @@ -41,7 +41,8 @@ import org.junit.Rule import org.junit.Test class ZiplineTest { - @Rule @JvmField val ziplineTestRule = ZiplineTestRule() + @Rule @JvmField + val ziplineTestRule = ZiplineTestRule() private val dispatcher = ziplineTestRule.dispatcher private val zipline = Zipline.create(dispatcher) @@ -68,9 +69,11 @@ class ZiplineTest { val service = zipline.take("helloService") zipline.close() - assertThat(assertFailsWith { + assertThat( + assertFailsWith { service.echo(EchoRequest("Jake")) - }).hasMessageThat().isEqualTo("Zipline closed") + }, + ).hasMessageThat().isEqualTo("Zipline closed") } @Test fun jvmCallJsService() = runBlocking(dispatcher) { @@ -116,7 +119,7 @@ class ZiplineTest { zipline.bind( "jvmSuspendingEchoService", - jvmSuspendingEchoService + jvmSuspendingEchoService, ) zipline.quickJs.evaluate("testing.app.cash.zipline.testing.callSuspendingEchoService('Eric')") @@ -141,7 +144,7 @@ class ZiplineTest { zipline.bind( "jvmSuspendingEchoService", - jvmSuspendingEchoService + jvmSuspendingEchoService, ) lock.withPermit { @@ -203,7 +206,7 @@ class ZiplineTest { zipline.bind( "jvmSuspendingEchoService", - jvmSuspendingEchoService + jvmSuspendingEchoService, ) val deferredA = async { @@ -259,9 +262,12 @@ class ZiplineTest { @Test fun jvmCallIncompatibleJsService() = runBlocking(dispatcher) { zipline.quickJs.evaluate("testing.app.cash.zipline.testing.prepareJsBridges()") - assertThat(assertFailsWith { + assertThat( + assertFailsWith { zipline.take("helloService").echo() - }).hasMessageThat().startsWith(""" + }, + ).hasMessageThat().startsWith( + """ no such method (incompatible API versions?) called service: helloService @@ -271,16 +277,19 @@ class ZiplineTest { fun echo(app.cash.zipline.testing.EchoRequest): app.cash.zipline.testing.EchoResponse fun close(): kotlin.Unit at - """.trimIndent() + """.trimIndent(), ) } @Test fun suspendingJvmCallIncompatibleJsService() = runBlocking(dispatcher) { zipline.quickJs.evaluate("testing.app.cash.zipline.testing.prepareJsBridges()") - assertThat(assertFailsWith { + assertThat( + assertFailsWith { zipline.take("helloService").echo() - }).hasMessageThat().startsWith(""" + }, + ).hasMessageThat().startsWith( + """ no such method (incompatible API versions?) called service: helloService @@ -290,16 +299,19 @@ class ZiplineTest { fun echo(app.cash.zipline.testing.EchoRequest): app.cash.zipline.testing.EchoResponse fun close(): kotlin.Unit at - """.trimIndent() + """.trimIndent(), ) } @Test fun jsCallIncompatibleJvmService() = runBlocking(dispatcher) { zipline.bind("supService", JvmPotatoService("sup")) - assertThat(assertFailsWith { + assertThat( + assertFailsWith { zipline.quickJs.evaluate("testing.app.cash.zipline.testing.callSupService('homie')") - }).hasMessageThat().startsWith(""" + }, + ).hasMessageThat().startsWith( + """ app.cash.zipline.ZiplineApiMismatchException: no such method (incompatible API versions?) called service: supService @@ -308,7 +320,7 @@ class ZiplineTest { available functions: fun echo(): app.cash.zipline.testing.EchoResponse fun close(): kotlin.Unit - """.trimIndent() + """.trimIndent(), ) } @@ -320,7 +332,8 @@ class ZiplineTest { .isNull() assertThat(zipline.quickJs.evaluate("testing.app.cash.zipline.testing.suspendingPotatoException") as String?) - .startsWith(""" + .startsWith( + """ ZiplineApiMismatchException: app.cash.zipline.ZiplineApiMismatchException: no such method (incompatible API versions?) called service: jvmSuspendingPotatoService @@ -329,24 +342,26 @@ class ZiplineTest { available functions: fun echo(): app.cash.zipline.testing.EchoResponse fun close(): kotlin.Unit - """.trimIndent() + """.trimIndent(), ) } - @Test fun jvmCallUnknownJsService() = runBlocking(dispatcher) { zipline.quickJs.evaluate("testing.app.cash.zipline.testing.initZipline()") val noSuchService = zipline.take("noSuchService") - assertThat(assertFailsWith { + assertThat( + assertFailsWith { noSuchService.echo(EchoRequest("hello")) - }).hasMessageThat().startsWith(""" + }, + ).hasMessageThat().startsWith( + """ no such service (service closed?) called service: noSuchService available services: zipline/js - """.trimIndent() + """.trimIndent(), ) } @@ -354,22 +369,28 @@ class ZiplineTest { zipline.quickJs.evaluate("testing.app.cash.zipline.testing.initZipline()") val noSuchService = zipline.take("noSuchService") - assertThat(assertFailsWith { + assertThat( + assertFailsWith { noSuchService.suspendingEcho(EchoRequest("hello")) - }).hasMessageThat().startsWith(""" + }, + ).hasMessageThat().startsWith( + """ no such service (service closed?) called service: noSuchService available services: zipline/js - """.trimIndent() + """.trimIndent(), ) } @Test fun jsCallUnknownJvmService() = runBlocking(dispatcher) { - assertThat(assertFailsWith { + assertThat( + assertFailsWith { zipline.quickJs.evaluate("testing.app.cash.zipline.testing.callSupService('homie')") - }).hasMessageThat().startsWith(""" + }, + ).hasMessageThat().startsWith( + """ app.cash.zipline.ZiplineApiMismatchException: no such service (service closed?) called service: supService @@ -377,7 +398,7 @@ class ZiplineTest { zipline/console zipline/event_loop zipline/event_listener - """.trimIndent() + """.trimIndent(), ) } @@ -387,7 +408,8 @@ class ZiplineTest { .isNull() assertThat(zipline.quickJs.evaluate("testing.app.cash.zipline.testing.suspendingPotatoException") as String?) - .startsWith(""" + .startsWith( + """ ZiplineApiMismatchException: app.cash.zipline.ZiplineApiMismatchException: no such service (service closed?) called service: jvmSuspendingPotatoService @@ -395,7 +417,7 @@ class ZiplineTest { zipline/console zipline/event_loop zipline/event_listener - """.trimIndent() + """.trimIndent(), ) } @@ -413,7 +435,7 @@ class ZiplineTest { zipline.bind( "jvmSuspendingEchoService", - jvmSuspendingEchoService + jvmSuspendingEchoService, ) zipline.quickJs.evaluate("testing.app.cash.zipline.testing.callSuspendingEchoService('')") @@ -422,7 +444,7 @@ class ZiplineTest { zipline.quickJs.evaluate("testing.app.cash.zipline.testing.callSuspendingEchoService('')") assertThat( - zipline.quickJs.evaluate("testing.app.cash.zipline.testing.suspendingEchoResult") as String + zipline.quickJs.evaluate("testing.app.cash.zipline.testing.suspendingEchoResult") as String, ).startsWith("ZiplineException: kotlinx.coroutines.JobCancellationException") zipline.quickJs.evaluate("testing.app.cash.zipline.testing.callSuspendingEchoService('')") diff --git a/zipline/src/jniTest/kotlin/app/cash/zipline/ZiplineTestRule.kt b/zipline/src/jniTest/kotlin/app/cash/zipline/ZiplineTestRule.kt index 84fc3bba1..64f5314ea 100644 --- a/zipline/src/jniTest/kotlin/app/cash/zipline/ZiplineTestRule.kt +++ b/zipline/src/jniTest/kotlin/app/cash/zipline/ZiplineTestRule.kt @@ -30,7 +30,11 @@ class ZiplineTestRule : TestRule { private val exceptions = mutableListOf() private val executorService = ThreadPoolExecutor( - 0, 1, 100, TimeUnit.MILLISECONDS, LinkedBlockingQueue() + 0, + 1, + 100, + TimeUnit.MILLISECONDS, + LinkedBlockingQueue(), ) { runnable -> Thread(runnable, "ZiplineTestRule").also { it.uncaughtExceptionHandler = Thread.UncaughtExceptionHandler { _, exception -> diff --git a/zipline/src/jsMain/kotlin/app/cash/zipline/GlobalBridge.kt b/zipline/src/jsMain/kotlin/app/cash/zipline/GlobalBridge.kt index f8f8853ed..81f92ca5f 100644 --- a/zipline/src/jsMain/kotlin/app/cash/zipline/GlobalBridge.kt +++ b/zipline/src/jsMain/kotlin/app/cash/zipline/GlobalBridge.kt @@ -17,7 +17,6 @@ package app.cash.zipline import app.cash.zipline.internal.JsPlatform import app.cash.zipline.internal.bridge.CallChannel -import app.cash.zipline.internal.bridge.inboundChannelName /** * JS-global bindings for implementing a complete JS platform (setTimeout, console), and receiving @@ -55,7 +54,7 @@ internal object GlobalBridge : JsPlatform, CallChannel { log: function() { globalBridge.consoleMessage('log', arguments) }, warn: function() { globalBridge.consoleMessage('warn', arguments) }, }; - """ + """, ) } @@ -107,6 +106,6 @@ internal object GlobalBridge : JsPlatform, CallChannel { private class Job( val handler: dynamic, - val arguments: Array + val arguments: Array, ) } diff --git a/zipline/src/jsMain/kotlin/app/cash/zipline/internal/bridge/leakCanaryJs.kt b/zipline/src/jsMain/kotlin/app/cash/zipline/internal/bridge/leakCanaryJs.kt index 6a3454e0c..0cb00f318 100644 --- a/zipline/src/jsMain/kotlin/app/cash/zipline/internal/bridge/leakCanaryJs.kt +++ b/zipline/src/jsMain/kotlin/app/cash/zipline/internal/bridge/leakCanaryJs.kt @@ -27,7 +27,7 @@ internal val registry = run { new FinalizationRegistry(function(heldValue) { referenceQueue.push(heldValue); }) - """ + """, ) } @@ -35,7 +35,7 @@ internal actual fun trackLeaks( eventListener: EndpointEventListener, serviceName: String, callHandler: OutboundCallHandler, - service: ZiplineService + service: ZiplineService, ) { registry.register(service, ZiplineServiceReference(eventListener, serviceName, callHandler)) } diff --git a/zipline/src/jsMain/kotlin/app/cash/zipline/ziplineJs.kt b/zipline/src/jsMain/kotlin/app/cash/zipline/ziplineJs.kt index cb625f059..c3dc73a48 100644 --- a/zipline/src/jsMain/kotlin/app/cash/zipline/ziplineJs.kt +++ b/zipline/src/jsMain/kotlin/app/cash/zipline/ziplineJs.kt @@ -23,7 +23,6 @@ import app.cash.zipline.internal.bridge.CallChannel import app.cash.zipline.internal.bridge.Endpoint import app.cash.zipline.internal.bridge.EventListenerAdapter import app.cash.zipline.internal.bridge.ZiplineServiceAdapter -import app.cash.zipline.internal.bridge.outboundChannelName import app.cash.zipline.internal.consoleName import app.cash.zipline.internal.eventListenerName import app.cash.zipline.internal.eventLoopName @@ -85,7 +84,7 @@ actual class Zipline internal constructor(userSerializersModule: SerializersModu internal fun bind( name: String, service: T, - adapter: ZiplineServiceAdapter + adapter: ZiplineServiceAdapter, ) { endpoint.bind(name, service, adapter) } diff --git a/zipline/src/jvmTest/kotlin/app/cash/zipline/ConsoleTest.kt b/zipline/src/jvmTest/kotlin/app/cash/zipline/ConsoleTest.kt index c6e273f26..1bc7d8729 100644 --- a/zipline/src/jvmTest/kotlin/app/cash/zipline/ConsoleTest.kt +++ b/zipline/src/jvmTest/kotlin/app/cash/zipline/ConsoleTest.kt @@ -30,7 +30,8 @@ import org.junit.Rule import org.junit.Test class ConsoleTest { - @Rule @JvmField val ziplineTestRule = ZiplineTestRule() + @Rule @JvmField + val ziplineTestRule = ZiplineTestRule() private val dispatcher = ziplineTestRule.dispatcher private val zipline = Zipline.create(dispatcher) @@ -86,7 +87,7 @@ class ConsoleTest { """.*at goBoom2""" + """.*at goBoom3""" + """.*at consoleLogWithThrowable""" + - """.*""" + """.*""", ) val record2 = logRecords.take() diff --git a/zipline/src/nativeMain/kotlin/app/cash/zipline/InboundCallChannel.kt b/zipline/src/nativeMain/kotlin/app/cash/zipline/InboundCallChannel.kt index 35090138d..522dbd28d 100644 --- a/zipline/src/nativeMain/kotlin/app/cash/zipline/InboundCallChannel.kt +++ b/zipline/src/nativeMain/kotlin/app/cash/zipline/InboundCallChannel.kt @@ -39,6 +39,7 @@ internal class InboundCallChannel( val property = JS_NewAtom(context, "serviceNamesArray") val jsResult = JS_Invoke(context, inboundChannel, property, 0, null) + @Suppress("UNCHECKED_CAST") // Our JS implementation returns an Array. val kotlinResult = with(quickJs) { jsResult.toKotlinInstanceOrNull() } as Array diff --git a/zipline/src/nativeMain/kotlin/app/cash/zipline/QuickJs.kt b/zipline/src/nativeMain/kotlin/app/cash/zipline/QuickJs.kt index 13f8d7264..c2968f94f 100644 --- a/zipline/src/nativeMain/kotlin/app/cash/zipline/QuickJs.kt +++ b/zipline/src/nativeMain/kotlin/app/cash/zipline/QuickJs.kt @@ -261,8 +261,11 @@ actual class QuickJs private constructor( } val result = memScoped { val bufferLengthVar = alloc() - val buffer = JS_WriteObject(contextForCompiling, bufferLengthVar.ptr, compiled, - JS_WRITE_OBJ_BYTECODE or JS_WRITE_OBJ_REFERENCE + val buffer = JS_WriteObject( + contextForCompiling, + bufferLengthVar.ptr, + compiled, + JS_WRITE_OBJ_BYTECODE or JS_WRITE_OBJ_REFERENCE, ) val bufferLength = bufferLengthVar.value.toInt() @@ -285,8 +288,11 @@ actual class QuickJs private constructor( @Suppress("UNCHECKED_CAST") // ByteVar and UByteVar have the same bit layout. val bytecodeRef = bytecode.refTo(0) as CValuesRef - val obj = JS_ReadObject(context, bytecodeRef, bytecode.size.convert(), - JS_READ_OBJ_BYTECODE or JS_READ_OBJ_REFERENCE or JS_EVAL_FLAG_STRICT + val obj = JS_ReadObject( + context, + bytecodeRef, + bytecode.size.convert(), + JS_READ_OBJ_BYTECODE or JS_READ_OBJ_REFERENCE or JS_EVAL_FLAG_STRICT, ) if (JS_IsException(obj) != 0) { throwJsException() @@ -327,7 +333,8 @@ actual class QuickJs private constructor( val jsOutboundCallChannel = JS_NewObjectClass(context, outboundCallChannelClassId) if (JS_IsException(jsOutboundCallChannel) != 0 || - JS_SetProperty(context, globalThis, propertyName, jsOutboundCallChannel) <= 0) { + JS_SetProperty(context, globalThis, propertyName, jsOutboundCallChannel) <= 0 + ) { throwJsException() } @@ -402,8 +409,9 @@ actual class QuickJs private constructor( val messageValue = JS_GetPropertyStr(context, exceptionValue, "message") val stackValue = JS_GetPropertyStr(context, exceptionValue, "stack") - val message = JS_ToCString(context, - messageValue.takeUnless { JS_IsUndefined(messageValue) != 0 } ?: exceptionValue + val message = JS_ToCString( + context, + messageValue.takeUnless { JS_IsUndefined(messageValue) != 0 } ?: exceptionValue, )?.toKStringFromUtf8() ?: "" JS_FreeValue(context, messageValue) diff --git a/zipline/src/nativeMain/kotlin/app/cash/zipline/internal/bridge/leakCanaryNative.kt b/zipline/src/nativeMain/kotlin/app/cash/zipline/internal/bridge/leakCanaryNative.kt index c31d66b96..cdb756583 100644 --- a/zipline/src/nativeMain/kotlin/app/cash/zipline/internal/bridge/leakCanaryNative.kt +++ b/zipline/src/nativeMain/kotlin/app/cash/zipline/internal/bridge/leakCanaryNative.kt @@ -21,7 +21,7 @@ internal actual fun trackLeaks( eventListener: EndpointEventListener, serviceName: String, callHandler: OutboundCallHandler, - service: ZiplineService + service: ZiplineService, ) { // TODO: can we implement this with ARC? } diff --git a/zipline/testing/src/commonMain/kotlin/app/cash/zipline/testing/adapters.kt b/zipline/testing/src/commonMain/kotlin/app/cash/zipline/testing/adapters.kt index 4f76f0aca..253a4d541 100644 --- a/zipline/testing/src/commonMain/kotlin/app/cash/zipline/testing/adapters.kt +++ b/zipline/testing/src/commonMain/kotlin/app/cash/zipline/testing/adapters.kt @@ -30,18 +30,18 @@ interface AdaptersService : ZiplineService { // Note that this is not @Serializable. data class AdaptersRequest( - val message: String + val message: String, ) // Note that this is not @Serializable. data class AdaptersResponse( - val message: String + val message: String, ) internal object AdaptersRequestSerializer : KSerializer { override val descriptor = PrimitiveSerialDescriptor( "app.cash.zipline.testing.AdaptersRequestSerializer", - PrimitiveKind.STRING + PrimitiveKind.STRING, ) override fun serialize(encoder: Encoder, value: AdaptersRequest) { @@ -56,7 +56,7 @@ internal object AdaptersRequestSerializer : KSerializer { internal object AdaptersResponseSerializer : KSerializer { override val descriptor = PrimitiveSerialDescriptor( "app.cash.zipline.testing.AdaptersResponseSerializer", - PrimitiveKind.STRING + PrimitiveKind.STRING, ) override fun serialize(encoder: Encoder, value: AdaptersResponse) { diff --git a/zipline/testing/src/commonMain/kotlin/app/cash/zipline/testing/awaitEquals.kt b/zipline/testing/src/commonMain/kotlin/app/cash/zipline/testing/awaitEquals.kt index 95427a196..522314bd1 100644 --- a/zipline/testing/src/commonMain/kotlin/app/cash/zipline/testing/awaitEquals.kt +++ b/zipline/testing/src/commonMain/kotlin/app/cash/zipline/testing/awaitEquals.kt @@ -28,7 +28,7 @@ suspend fun awaitEquals( expected: T?, delay: Duration = Duration.ZERO, attempts: Int = 5, - actual: () -> T? + actual: () -> T?, ) { var actualValue = actual() if (expected == actualValue) return diff --git a/zipline/testing/src/commonMain/kotlin/app/cash/zipline/testing/echo.kt b/zipline/testing/src/commonMain/kotlin/app/cash/zipline/testing/echo.kt index 461837cce..fd72c6eca 100644 --- a/zipline/testing/src/commonMain/kotlin/app/cash/zipline/testing/echo.kt +++ b/zipline/testing/src/commonMain/kotlin/app/cash/zipline/testing/echo.kt @@ -24,10 +24,10 @@ interface EchoService : ZiplineService { @Serializable data class EchoRequest( - val message: String + val message: String, ) @Serializable data class EchoResponse( - val message: String + val message: String, ) diff --git a/zipline/testing/src/commonMain/kotlin/app/cash/zipline/testing/interfaceSerializers.kt b/zipline/testing/src/commonMain/kotlin/app/cash/zipline/testing/interfaceSerializers.kt index 829cf43cd..7b832c12e 100644 --- a/zipline/testing/src/commonMain/kotlin/app/cash/zipline/testing/interfaceSerializers.kt +++ b/zipline/testing/src/commonMain/kotlin/app/cash/zipline/testing/interfaceSerializers.kt @@ -33,13 +33,13 @@ interface MessageInterface { @Serializable data class RealMessageInterface( - override val message: String -): MessageInterface + override val message: String, +) : MessageInterface val MessageInterfaceSerializersModule: SerializersModule = SerializersModule { polymorphic( MessageInterface::class, RealMessageInterface::class, - RealMessageInterface.serializer() + RealMessageInterface.serializer(), ) } diff --git a/zipline/testing/src/commonMain/kotlin/app/cash/zipline/testing/utf8.kt b/zipline/testing/src/commonMain/kotlin/app/cash/zipline/testing/utf8.kt index 6c00fe756..ff811a1ad 100644 --- a/zipline/testing/src/commonMain/kotlin/app/cash/zipline/testing/utf8.kt +++ b/zipline/testing/src/commonMain/kotlin/app/cash/zipline/testing/utf8.kt @@ -20,4 +20,3 @@ import app.cash.zipline.ZiplineService interface Formatter : ZiplineService { fun format(message: String): String? } - diff --git a/zipline/testing/src/engineMain/kotlin/app/cash/zipline/testing/LoggingEventListener.kt b/zipline/testing/src/engineMain/kotlin/app/cash/zipline/testing/LoggingEventListener.kt index 7a7b33647..4725d1175 100644 --- a/zipline/testing/src/engineMain/kotlin/app/cash/zipline/testing/LoggingEventListener.kt +++ b/zipline/testing/src/engineMain/kotlin/app/cash/zipline/testing/LoggingEventListener.kt @@ -32,7 +32,7 @@ class LoggingEventListener : EventListener() { log( service = service, serviceName = name, - log = "bindService $name" + log = "bindService $name", ) } @@ -40,7 +40,7 @@ class LoggingEventListener : EventListener() { log( service = service, serviceName = name, - log = "takeService $name" + log = "takeService $name", ) } @@ -49,7 +49,7 @@ class LoggingEventListener : EventListener() { log( service = call.service, serviceName = call.serviceName, - log = "callStart $callId ${call.serviceName} ${call.function.name} ${call.args}" + log = "callStart $callId ${call.serviceName} ${call.function.name} ${call.args}", ) return callId } @@ -59,21 +59,21 @@ class LoggingEventListener : EventListener() { service = call.service, serviceName = call.serviceName, log = "callEnd $startValue " + - "${call.serviceName} ${call.function.name} ${call.args} ${result.result}" + "${call.serviceName} ${call.function.name} ${call.args} ${result.result}", ) } override fun serviceLeaked(zipline: Zipline, name: String) { log( serviceName = name, - log = "serviceLeaked $name" + log = "serviceLeaked $name", ) } override fun applicationLoadStart(applicationName: String, manifestUrl: String?) { log( applicationName = applicationName, - log = "applicationLoadStart $applicationName $manifestUrl" + log = "applicationLoadStart $applicationName $manifestUrl", ) } @@ -81,22 +81,22 @@ class LoggingEventListener : EventListener() { applicationName: String, manifestUrl: String?, zipline: Zipline, - startValue: Any? + startValue: Any?, ) { log( applicationName = applicationName, - log = "applicationLoadSuccess $applicationName $manifestUrl" + log = "applicationLoadSuccess $applicationName $manifestUrl", ) } override fun applicationLoadSkipped( applicationName: String, manifestUrl: String, - startValue: Any? + startValue: Any?, ) { log( applicationName = applicationName, - log = "applicationLoadSkipped $applicationName $manifestUrl" + log = "applicationLoadSkipped $applicationName $manifestUrl", ) } @@ -104,26 +104,26 @@ class LoggingEventListener : EventListener() { applicationName: String, manifestUrl: String?, exception: Exception, - startValue: Any? + startValue: Any?, ) { log( applicationName = applicationName, exception = exception, - log = "applicationLoadFailed $applicationName $exception" + log = "applicationLoadFailed $applicationName $exception", ) } override fun downloadStart(applicationName: String, url: String) { log( applicationName = applicationName, - log = "downloadStart $applicationName $url" + log = "downloadStart $applicationName $url", ) } override fun downloadEnd(applicationName: String, url: String, startValue: Any?) { log( applicationName = applicationName, - log = "downloadEnd $applicationName $url" + log = "downloadEnd $applicationName $url", ) } @@ -131,12 +131,12 @@ class LoggingEventListener : EventListener() { applicationName: String, url: String, exception: Exception, - startValue: Any? + startValue: Any?, ) { log( applicationName = applicationName, exception = exception, - log = "downloadFailed $applicationName $url $exception" + log = "downloadFailed $applicationName $url $exception", ) } @@ -144,14 +144,14 @@ class LoggingEventListener : EventListener() { log( applicationName = applicationName, exception = exception, - log = "manifestParseFailed $applicationName $url" + log = "manifestParseFailed $applicationName $url", ) } override fun moduleLoadStart(zipline: Zipline, moduleId: String): Any? { log( moduleId = moduleId, - log = "moduleLoadStart $moduleId" + log = "moduleLoadStart $moduleId", ) return null } @@ -159,7 +159,7 @@ class LoggingEventListener : EventListener() { override fun moduleLoadEnd(zipline: Zipline, moduleId: String, startValue: Any?) { log( moduleId = moduleId, - log = "moduleLoadEnd $moduleId" + log = "moduleLoadEnd $moduleId", ) } @@ -291,11 +291,11 @@ class LoggingEventListener : EventListener() { skipServiceEvents: Boolean, skipApplicationEvents: Boolean, skipInternalServices: Boolean, - ) : Boolean { - val skip = (skipModuleEvents && moduleId != null) - || (skipServiceEvents && serviceName != null) - || (skipApplicationEvents && applicationName != null) - || (skipInternalServices && isInternalService) + ): Boolean { + val skip = (skipModuleEvents && moduleId != null) || + (skipServiceEvents && serviceName != null) || + (skipApplicationEvents && applicationName != null) || + (skipInternalServices && isInternalService) return !skip } } diff --git a/zipline/testing/src/jsMain/kotlin/app/cash/zipline/testing/adaptersJs.kt b/zipline/testing/src/jsMain/kotlin/app/cash/zipline/testing/adaptersJs.kt index a4861dbff..6edc40f2a 100644 --- a/zipline/testing/src/jsMain/kotlin/app/cash/zipline/testing/adaptersJs.kt +++ b/zipline/testing/src/jsMain/kotlin/app/cash/zipline/testing/adaptersJs.kt @@ -29,7 +29,7 @@ private val zipline by lazy { Zipline.get(AdaptersSerializersModule) } fun prepareAdaptersJsBridges() { zipline.bind( "adaptersService", - JsAdaptersService() + JsAdaptersService(), ) } diff --git a/zipline/testing/src/jsMain/kotlin/app/cash/zipline/testing/console.kt b/zipline/testing/src/jsMain/kotlin/app/cash/zipline/testing/console.kt index a7e492d3f..f4c0276bd 100644 --- a/zipline/testing/src/jsMain/kotlin/app/cash/zipline/testing/console.kt +++ b/zipline/testing/src/jsMain/kotlin/app/cash/zipline/testing/console.kt @@ -40,7 +40,7 @@ fun consoleLogWithThrowable() { console.error( "3. multiple exceptions", IllegalStateException("number one!"), - IllegalStateException("number two!") + IllegalStateException("number two!"), ) console.error(IllegalStateException("exception first!"), "4. message second") console.info("5. info with exception", IllegalStateException()) diff --git a/zipline/testing/src/jsMain/kotlin/app/cash/zipline/testing/echoJs.kt b/zipline/testing/src/jsMain/kotlin/app/cash/zipline/testing/echoJs.kt index 03506a9a1..fc566abb0 100644 --- a/zipline/testing/src/jsMain/kotlin/app/cash/zipline/testing/echoJs.kt +++ b/zipline/testing/src/jsMain/kotlin/app/cash/zipline/testing/echoJs.kt @@ -18,7 +18,7 @@ package app.cash.zipline.testing import app.cash.zipline.Zipline class JsEchoService( - private val greeting: String + private val greeting: String, ) : EchoService { override fun echo(request: EchoRequest): EchoResponse { return EchoResponse("$greeting from JavaScript, ${request.message}") diff --git a/zipline/testing/src/jsMain/kotlin/app/cash/zipline/testing/incompatibleService.kt b/zipline/testing/src/jsMain/kotlin/app/cash/zipline/testing/incompatibleService.kt index b04e267fd..dda89b6be 100644 --- a/zipline/testing/src/jsMain/kotlin/app/cash/zipline/testing/incompatibleService.kt +++ b/zipline/testing/src/jsMain/kotlin/app/cash/zipline/testing/incompatibleService.kt @@ -6,7 +6,7 @@ import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.launch class JsSuspendingPotatoService( - private val greeting: String + private val greeting: String, ) : SuspendingPotatoService { override suspend fun echo(): EchoResponse { return EchoResponse("$greeting from suspending JavaScript, anonymous") @@ -19,7 +19,7 @@ private val zipline by lazy { Zipline.get() } fun prepareSuspendingPotatoJsBridges() { zipline.bind( "jsSuspendingPotatoService", - JsSuspendingPotatoService("hello") + JsSuspendingPotatoService("hello"), ) } diff --git a/zipline/testing/src/jsMain/kotlin/app/cash/zipline/testing/interfaceSerializersJs.kt b/zipline/testing/src/jsMain/kotlin/app/cash/zipline/testing/interfaceSerializersJs.kt index 9e6ef1c81..06de436a2 100644 --- a/zipline/testing/src/jsMain/kotlin/app/cash/zipline/testing/interfaceSerializersJs.kt +++ b/zipline/testing/src/jsMain/kotlin/app/cash/zipline/testing/interfaceSerializersJs.kt @@ -31,11 +31,11 @@ private val zipline by lazy { Zipline.get(MessageInterfaceSerializersModule) } fun prepareInterfaceSerializersJsBridges() { zipline.bind( "requestInterfaceService", - JsMessageInterfaceService() + JsMessageInterfaceService(), ) zipline.bind( "responseInterfaceService", - JsMessageInterfaceService() + JsMessageInterfaceService(), ) } @@ -50,4 +50,3 @@ fun callInterfaceRequest(): String { val service = zipline.take("requestInterfaceService") return service.echo(RealMessageInterface("Jesse")) } - diff --git a/zipline/testing/src/jsMain/kotlin/app/cash/zipline/testing/leakedServices.kt b/zipline/testing/src/jsMain/kotlin/app/cash/zipline/testing/leakedServices.kt index cc4bd289e..cb4533d5b 100644 --- a/zipline/testing/src/jsMain/kotlin/app/cash/zipline/testing/leakedServices.kt +++ b/zipline/testing/src/jsMain/kotlin/app/cash/zipline/testing/leakedServices.kt @@ -32,4 +32,3 @@ fun triggerLeakDetection() { } catch (ignored: Exception) { } } - diff --git a/zipline/testing/src/jsMain/kotlin/app/cash/zipline/testing/sealedClassSerializersJs.kt b/zipline/testing/src/jsMain/kotlin/app/cash/zipline/testing/sealedClassSerializersJs.kt index 86bfc3684..365df3656 100644 --- a/zipline/testing/src/jsMain/kotlin/app/cash/zipline/testing/sealedClassSerializersJs.kt +++ b/zipline/testing/src/jsMain/kotlin/app/cash/zipline/testing/sealedClassSerializersJs.kt @@ -38,6 +38,6 @@ private val zipline by lazy { Zipline.get() } fun prepareSealedClassMessageService() { zipline.bind( "sealedClassMessageService", - JsSealedClassMessageService() + JsSealedClassMessageService(), ) } diff --git a/zipline/testing/src/jsMain/kotlin/app/cash/zipline/testing/serviceMemberJs.kt b/zipline/testing/src/jsMain/kotlin/app/cash/zipline/testing/serviceMemberJs.kt index e16dfcf1d..838da65b0 100644 --- a/zipline/testing/src/jsMain/kotlin/app/cash/zipline/testing/serviceMemberJs.kt +++ b/zipline/testing/src/jsMain/kotlin/app/cash/zipline/testing/serviceMemberJs.kt @@ -27,7 +27,7 @@ class JsServiceTransformer : ServiceTransformer { private class PrefixingEchoService( private val prefix: String, - private val delegate: EchoService + private val delegate: EchoService, ) : EchoService { override fun echo(request: EchoRequest): EchoResponse { val response = delegate.echo(request) @@ -45,7 +45,6 @@ private val zipline by lazy { Zipline.get(ServiceMemberSerializersModule) } fun prepareServiceMemberJsBridges() { zipline.bind( "serviceTransformer", - JsServiceTransformer() + JsServiceTransformer(), ) } - diff --git a/zipline/testing/src/jsMain/kotlin/app/cash/zipline/testing/suspendingJs.kt b/zipline/testing/src/jsMain/kotlin/app/cash/zipline/testing/suspendingJs.kt index 125028377..293a2636e 100644 --- a/zipline/testing/src/jsMain/kotlin/app/cash/zipline/testing/suspendingJs.kt +++ b/zipline/testing/src/jsMain/kotlin/app/cash/zipline/testing/suspendingJs.kt @@ -23,7 +23,7 @@ import kotlinx.coroutines.sync.Mutex import kotlinx.coroutines.sync.withLock class JsSuspendingEchoService( - private val greeting: String + private val greeting: String, ) : SuspendingEchoService { override suspend fun suspendingEcho(request: EchoRequest): EchoResponse { mutex.withLock { @@ -40,7 +40,7 @@ private val mutex = Mutex(locked = true) fun prepareSuspendingJsBridges() { zipline.bind( "jsSuspendingEchoService", - JsSuspendingEchoService("hello") + JsSuspendingEchoService("hello"), ) } diff --git a/zipline/testing/src/jsMain/kotlin/app/cash/zipline/testing/throwingJs.kt b/zipline/testing/src/jsMain/kotlin/app/cash/zipline/testing/throwingJs.kt index 7daf5f311..5c34a5c70 100644 --- a/zipline/testing/src/jsMain/kotlin/app/cash/zipline/testing/throwingJs.kt +++ b/zipline/testing/src/jsMain/kotlin/app/cash/zipline/testing/throwingJs.kt @@ -33,7 +33,7 @@ class JsThrowingEchoService : EchoService { } class JsDelegatingEchoService( - private val delegate: EchoService + private val delegate: EchoService, ) : EchoService { override fun echo(request: EchoRequest): EchoResponse { return delegate3(request) diff --git a/zipline/testing/src/jsMain/kotlin/app/cash/zipline/testing/utf8Js.kt b/zipline/testing/src/jsMain/kotlin/app/cash/zipline/testing/utf8Js.kt index 783f99a9d..ec7e16136 100644 --- a/zipline/testing/src/jsMain/kotlin/app/cash/zipline/testing/utf8Js.kt +++ b/zipline/testing/src/jsMain/kotlin/app/cash/zipline/testing/utf8Js.kt @@ -21,20 +21,26 @@ private val zipline by lazy { Zipline.get() } @JsExport fun prepareNonAsciiInputAndOutput() { - zipline.bind("formatter", object : Formatter { + zipline.bind( + "formatter", + object : Formatter { override fun format(message: String): String { return "($message, $message)" } - }) + }, + ) } @JsExport fun prepareNonAsciiThrower() { - zipline.bind("formatter", object : Formatter { + zipline.bind( + "formatter", + object : Formatter { override fun format(message: String): String { throw Exception("a🐝cdefg") } - }) + }, + ) } @JsExport