How to use File.shouldNotBeEmpty method of io.kotest.matchers.file.matchers class

Best Kotest code snippet using io.kotest.matchers.file.matchers.File.shouldNotBeEmpty

ArgumentsTest.kt

Source:ArgumentsTest.kt Github

copy

Full Screen

1package de.qualersoft.robotframework.gradleplugin.utils2import io.kotest.assertions.assertSoftly3import io.kotest.core.spec.style.AnnotationSpec4import io.kotest.matchers.Matcher5import io.kotest.matchers.MatcherResult6import io.kotest.matchers.collections.shouldHaveElementAt7import io.kotest.matchers.collections.shouldHaveSize8import io.kotest.matchers.should9import io.kotest.matchers.shouldNot10import java.io.File11class ArgumentsTest : AnnotationSpec() {12  private lateinit var sut: Arguments13  @BeforeEach14  fun setupTest() {15    sut = Arguments()16  }17  @Test18  fun givenNewArgumentsThenResultIsEmpty() {19    sut.shouldBeEmpty()20  }21  @Test22  fun whenAddingAnOptionalFileOfNullThenResultIsEmpty() {23    sut.addOptionalFile(null, "a")24    sut.shouldBeEmpty()25  }26  @Test27  fun whenAddingAnOptionalNonNullFileThenResultIsNotEmpty() {28    sut.addOptionalFile(File("./test"), "a")29    assertSoftly {30      sut.shouldNotBeEmpty()31      val arr = sut.toArray()32      arr.shouldHaveSize(2)33      arr.shouldHaveElementAt(0, "a")34      arr.shouldHaveElementAt(1, File("./test").path)35    }36  }37  @Test38  fun whenAddingNullFileThenItsConvertedToNone() {39    sut.addFileToArguments(null, "f")40    assertSoftly {41      sut.shouldNotBeEmpty()42      val arr = sut.toArray()43      arr.shouldHaveSize(2)44      arr.shouldHaveElementAt(0, "f")45      arr.shouldHaveElementAt(1, "NONE")46    }47  }48  @Test49  fun whenAddingNonEmptyFileThenItWillBeInResult() {50    sut.addFileToArguments(File("./test"), "f")51    assertSoftly {52      sut.shouldNotBeEmpty()53      val arr = sut.toArray()54      arr.shouldHaveSize(2)55      arr.shouldHaveElementAt(0, "f")56      arr.shouldHaveElementAt(1, File("./test").path)57    }58  }59  @Test60  fun whenAddingEmptyFileThenItsNotInResult() {61    sut.addFileToArguments(File(""), "f")62    sut.shouldBeEmpty()63  }64  @Test65  fun whenAddingNullStringThenItsNotInResult() {66    sut.addNonEmptyStringToArguments(null, "s")67    sut.shouldBeEmpty()68  }69  @Test70  fun whenAddingEmptyStringThenItsNotInResult() {71    sut.addNonEmptyStringToArguments("", "s")72    sut.shouldBeEmpty()73  }74  @Test75  fun whenAddingNonEmptyStringThenItsInResult() {76    sut.addNonEmptyStringToArguments("notEmpty", "s")77    assertSoftly {78      sut.shouldNotBeEmpty()79      val arr = sut.toArray()80      arr.shouldHaveSize(2)81      arr.shouldHaveElementAt(0, "s")82      arr.shouldHaveElementAt(1, "notEmpty")83    }84  }85  @Test86  fun whenAddingEmptyMapThenItsNotInResult() {87    sut.addMapToArguments(mapOf(), "m")88    sut.shouldBeEmpty()89  }90  @Test91  fun whenAddingMapThenItsInResult() {92    sut.addMapToArguments(mapOf("key" to "val"), "m")93    assertSoftly {94      sut.shouldNotBeEmpty()95      val arr = sut.toArray()96      arr.shouldHaveSize(2)97      arr.shouldHaveElementAt(0, "m")98      arr.shouldHaveElementAt(1, "key:val")99    }100  }101  @Test102  fun whenAddingMultiMapThenItsInResult() {103    sut.addMapToArguments(mapOf("key1" to "val1", "key2" to "val2"), "m")104    assertSoftly {105      sut.shouldNotBeEmpty()106      val arr = sut.toArray()107      arr.shouldHaveSize(4)108      arr.shouldHaveElementAt(0, "m")109      arr.shouldHaveElementAt(1, "key1:val1")110      arr.shouldHaveElementAt(2, "m")111      arr.shouldHaveElementAt(3, "key2:val2")112    }113  }114  @Test115  fun whenAddingNullFlagThenItsNotInResult() {116    sut.addFlagToArguments(null, "b")117    sut.shouldBeEmpty()118  }119  @Test120  fun whenAddingFalseFlagThenItsNotInResult() {121    sut.addFlagToArguments(false, "b")122    sut.shouldBeEmpty()123  }124  @Test125  fun whenAddingTrueFlagThenItsInResult() {126    sut.addFlagToArguments(true, "b")127    assertSoftly {128      sut.shouldNotBeEmpty()129      val arr = sut.toArray()130      arr.shouldHaveSize(1)131      arr.shouldHaveElementAt(0, "b")132    }133  }134  @Test135  fun whenAddingOptionalNullStringThenItsNotInResult() {136    sut.addStringToArguments(null, "s")137    sut.shouldBeEmpty()138  }139  @Test140  fun whenAddingOptionalEmptyStringThenItsInResult() {141    sut.addStringToArguments("", "s")142    assertSoftly {143      sut.shouldNotBeEmpty()144      val arr = sut.toArray()145      arr.shouldHaveSize(2)146      arr.shouldHaveElementAt(0, "s")147      arr.shouldHaveElementAt(1, "")148    }149  }150  @Test151  fun whenAddingOptionalNonEmptyStringThenItsInResult() {152    sut.addStringToArguments("NotEmpty", "s")153    assertSoftly {154      sut.shouldNotBeEmpty()155      val arr = sut.toArray()156      arr.shouldHaveSize(2)157      arr.shouldHaveElementAt(0, "s")158      arr.shouldHaveElementAt(1, "NotEmpty")159    }160  }161  @Test162  fun whenAddNullStringListThenItsNotInResult() {163    sut.addListToArguments(null as String?, "s")164    sut.shouldBeEmpty()165  }166  @Test167  fun whenAddStringListThenItsInResult() {168    sut.addListToArguments("aString", "s")169    assertSoftly {170      sut.shouldNotBeEmpty()171      val arr = sut.toArray()172      arr.shouldHaveSize(2)173      arr.shouldHaveElementAt(0, "s")174      arr.shouldHaveElementAt(1, "aString")175    }176  }177  @Test178  fun whenAddingMultiStringListThenEachIsInResult() {179    sut.addListToArguments("str1, str2", "s")180    assertSoftly {181      sut.shouldNotBeEmpty()182      val arr = sut.toArray()183      arr.shouldHaveSize(4)184      arr.shouldHaveElementAt(0, "s")185      arr.shouldHaveElementAt(1, "str1")186      arr.shouldHaveElementAt(2, "s")187      arr.shouldHaveElementAt(3, "str2")188    }189  }190  @Test191  fun whenAddingNullListThenItsNotInResult() {192    sut.addListToArguments(null as List<String?>?, "ls")193    sut.shouldBeEmpty()194  }195  @Test196  fun whenAddingEmptyListThenItsNotInResult() {197    sut.addListToArguments(listOf(), "ls")198    sut.shouldBeEmpty()199  }200  @Test201  fun whenAddingListWithNullThenItsNotInResult() {202    sut.addListToArguments(listOf<String?>(null), "ls")203    sut.shouldBeEmpty()204  }205  @Test206  fun whenAddingListWithEmptyThenItsNotInResult() {207    sut.addListToArguments(listOf(""), "ls")208    sut.shouldBeEmpty()209  }210  @Test211  fun whenAddingListThenItsInResult() {212    sut.addListToArguments(listOf("str"), "ls")213    assertSoftly {214      sut.shouldNotBeEmpty()215      val arr = sut.toArray()216      arr.shouldHaveSize(2)217      arr.shouldHaveElementAt(0, "ls")218      arr.shouldHaveElementAt(1, "str")219    }220  }221  @Test222  fun whenAddingListWithMoreElemsThenEachIsInResult() {223    sut.addListToArguments(listOf("str1", "str2"), "ls")224    assertSoftly {225      sut.shouldNotBeEmpty()226      val arr = sut.toArray()227      arr.shouldHaveSize(4)228      arr.shouldHaveElementAt(0, "ls")229      arr.shouldHaveElementAt(1, "str1")230      arr.shouldHaveElementAt(2, "ls")231      arr.shouldHaveElementAt(3, "str2")232    }233  }234  @Test235  fun whenAddingNullFileListThenItsNotInResult() {236    sut.addFileListToArguments(null, "fl")237    sut.shouldBeEmpty()238  }239  @Test240  fun whenAddingEmptyFileListThenItsNotInResult() {241    sut.addFileListToArguments(listOf(), "fl")242    sut.shouldBeEmpty()243  }244  @Test245  fun whenAddingFileListWithEmptyFileThenItsNotInResult() {246    sut.addFileListToArguments(listOf(File("")), "fl")247    sut.shouldBeEmpty()248  }249  @Test250  fun whenAddingFileListWithFileThenItsInResult() {251    sut.addFileListToArguments(listOf(File("./test")), "fl")252    assertSoftly {253      sut.shouldNotBeEmpty()254      val arr = sut.toArray()255      arr.shouldHaveSize(2)256      arr.shouldHaveElementAt(0, "fl")257      arr.shouldHaveElementAt(1, File("./test").path)258    }259  }260  // <editor-fold desc="Helper extensions">261  private fun beEmpty() = object : Matcher<Arguments> {262    override fun test(value: Arguments) = MatcherResult(263      value.toArray().isEmpty(),264      "Arguments $value should be empty",265      "String $value should not be empty"266    )267  }268  private fun Arguments.shouldBeEmpty() = this should beEmpty()269  private fun Arguments.shouldNotBeEmpty() = this shouldNot beEmpty()270  // </editor-fold>271}...

Full Screen

Full Screen

OmniJacocoFileAdapterTest.kt

Source:OmniJacocoFileAdapterTest.kt Github

copy

Full Screen

1package org.jesperancinha.plugins.omni.reporter.domain.reports2import io.kotest.matchers.nulls.shouldNotBeNull3import io.kotest.matchers.string.shouldEndWith4import io.kotest.matchers.string.shouldHaveMinLength5import io.kotest.matchers.string.shouldNotBeEmpty6import io.kotest.matchers.string.shouldStartWith7import io.kotest.matchers.types.shouldBeInstanceOf8import org.jesperancinha.plugins.omni.reporter.processors.ReportType9import org.jesperancinha.plugins.omni.reporter.utils.toFile10import org.junit.jupiter.api.Test11internal class OmniJacocoFileAdapterTest {12    @Test13    fun `should generate itg jacoco report`() {14        val jacocoItg = javaClass.getResource("/jacoco.formats/jacoco-itg.xml")15        jacocoItg.shouldNotBeNull()16        val rootJacocoItg = javaClass.getResource("/jacoco.formats")17        rootJacocoItg.shouldNotBeNull()18        val reportFileAdapter = ReportType.createReportFileAdapter(19            jacocoItg.toFile(),20            false,21            rootJacocoItg.toFile(),22            rootJacocoItg.toFile()23        )24        reportFileAdapter.shouldBeInstanceOf<OmniJacocoFileAdapter>()25        val generatePayload = reportFileAdapter.generatePayload(false, listOf(rootJacocoItg.toFile()))26        generatePayload.shouldNotBeEmpty()27        generatePayload.shouldHaveMinLength(10)28        generatePayload.shouldStartWith("<")29        generatePayload.shouldEndWith(">")30    }31    @Test32    fun `should generate pbr jacoco report`() {33        val jacocoItg = javaClass.getResource("/jacoco.formats/jacoco-pbr.xml")34        jacocoItg.shouldNotBeNull()35        val rootJacocoItg = javaClass.getResource("/jacoco.formats")36        rootJacocoItg.shouldNotBeNull()37        val reportFileAdapter = ReportType.createReportFileAdapter(38            jacocoItg.toFile(),39            false,40            rootJacocoItg.toFile(),41            rootJacocoItg.toFile()42        )43        reportFileAdapter.shouldBeInstanceOf<OmniJacocoFileAdapter>()44        val generatePayload = reportFileAdapter.generatePayload(false, listOf(rootJacocoItg.toFile()))45        generatePayload.shouldNotBeEmpty()46        generatePayload.shouldHaveMinLength(10)47        generatePayload.shouldStartWith("<")48        generatePayload.shouldEndWith(">")49    }50    @Test51    fun `should generate pjs jacoco report`() {52        val jacocoItg = javaClass.getResource("/jacoco.formats/jacoco-pjs.xml")53        jacocoItg.shouldNotBeNull()54        val rootJacocoItg = javaClass.getResource("/jacoco.formats")55        rootJacocoItg.shouldNotBeNull()56        val reportFileAdapter = ReportType.createReportFileAdapter(57            jacocoItg.toFile(),58            false,59            rootJacocoItg.toFile(),60            rootJacocoItg.toFile()61        )62        reportFileAdapter.shouldBeInstanceOf<OmniJacocoFileAdapter>()63        val generatePayload = reportFileAdapter.generatePayload(false, listOf(rootJacocoItg.toFile()))64        generatePayload.shouldNotBeEmpty()65        generatePayload.shouldHaveMinLength(10)66        generatePayload.shouldStartWith("<")67        generatePayload.shouldEndWith(">")68    }69    @Test70    fun `should generate report with correct paths`() {71        val resource = javaClass.getResource("/multi-module")72        resource.shouldNotBeNull()73        val jacocoResource = javaClass.getResource("/multi-module/vertx-module/target/site/jacoco/jacoco.xml")74        jacocoResource.shouldNotBeNull()75        val buildResource = javaClass.getResource("/multi-module/vertx-module/target")76        buildResource.shouldNotBeNull()77        val srcResource = javaClass.getResource("/multi-module/vertx-module/src/main/java/")78        srcResource.shouldNotBeNull()79        val reportFileAdapter = ReportType.createReportFileAdapter(80            jacocoResource.toFile(),81            false,82            resource.toFile(),83            buildResource.toFile()84        )85        reportFileAdapter.shouldNotBeNull()86        reportFileAdapter.shouldBeInstanceOf<OmniJacocoFileAdapter>()87        val generatePayload = reportFileAdapter.generatePayload(false, listOf(srcResource.toFile()))88        generatePayload.shouldNotBeNull()89    }90}...

Full Screen

Full Screen

TestCSVExporter.kt

Source:TestCSVExporter.kt Github

copy

Full Screen

1/*2 * Copyright (C) 2010-2022, Danilo Pianini and contributors3 * listed, for each module, in the respective subproject's build.gradle.kts file.4 *5 * This file is part of Alchemist, and is distributed under the terms of the6 * GNU General Public License, with a linking exception,7 * as described in the file LICENSE in the Alchemist distribution's top directory.8 */9package it.unibo.alchemist.test10import io.kotest.core.spec.style.FreeSpec11import io.kotest.matchers.file.shouldExist12import io.kotest.matchers.nulls.shouldNotBeNull13import io.kotest.matchers.shouldBe14import io.kotest.matchers.string.shouldContain15import io.kotest.matchers.string.shouldNotBeEmpty16import it.unibo.alchemist.loader.InitializedEnvironment17import it.unibo.alchemist.loader.export.exporters.CSVExporter18import it.unibo.alchemist.model.interfaces.Position19import it.unibo.alchemist.testsupport.createSimulation20import it.unibo.alchemist.testsupport.loadAlchemist21import it.unibo.alchemist.testsupport.runInCurrentThread22import java.io.File23class TestCSVExporter<T, P : Position<P>> : FreeSpec({24    "CSV files" - {25        val initialized: InitializedEnvironment<T, P> = loadAlchemist("testCSVExporter.yml")26        initialized.createSimulation().runInCurrentThread()27        initialized.exporters.size shouldBe 128        val exporter = getCSVExporter(initialized)29        val outputFile = File(exporter.exportPath)30            .listFiles()31            ?.find { it.name.startsWith("00-testing_csv_export_") && it.extension == exporter.fileExtension }32        "should exist when CSV export is enabled" {33            outputFile.shouldNotBeNull()34            outputFile.shouldExist()35        }36        "header should be like \"var1 = val1, var2 = val2\"" {37            val fileContents = requireNotNull(outputFile).readText()38            val match = Regex("([^\\s=,]+)\\s*=\\s*([^,\\s]+)").findAll(fileContents).toList()39            require(match.isNotEmpty()) {40                "Unmatched header regex in ${outputFile.absolutePath}:\n$fileContents"41            }42        }43    }44    "column order should replicate" {45        val initialized: InitializedEnvironment<T, P> = loadAlchemist("testCSVExportColumnAlignment.yml")46        initialized.createSimulation().runInCurrentThread()47        val exporter = getCSVExporter(initialized)48        // Get the first line of the output produce by CSVExporter49        val exporterFirstLine = File(exporter.exportPath).listFiles()50            ?.first { it.name.startsWith("column-alignment") }51            ?.readLines()52            ?.dropWhile { !it.contains("d c b a") } // remove the lines before the column names53            ?.drop(1) // I am not interested in column head54            ?.first()55        exporterFirstLine.shouldNotBeNull()56        exporterFirstLine.shouldNotBeEmpty()57        exporterFirstLine.shouldContain("0 1 2 3")58    }59}) {60    /* common utility functions */61    companion object {62        fun <T, P : Position<P>> getCSVExporter(environment: InitializedEnvironment<T, P>): CSVExporter<T, P> {63            val exporter = environment.exporters.first()64            require(exporter is CSVExporter) {65                "Invalid exporter type '${exporter::class.simpleName}'"66            }67            return exporter68        }69    }70}...

Full Screen

Full Screen

TestGraphStream.kt

Source:TestGraphStream.kt Github

copy

Full Screen

1/*2 * Copyright (C) 2010-2020, Danilo Pianini and contributors3 * listed in the main project's alchemist/build.gradle.kts file.4 *5 * This file is part of Alchemist, and is distributed under the terms of the6 * GNU General Public License, with a linking exception,7 * as described in the file LICENSE in the Alchemist distribution's top directory.8 */9package it.unibo.alchemist.test10import io.kotest.core.spec.style.FreeSpec11import io.kotest.matchers.collections.shouldNotBeEmpty12import io.kotest.matchers.doubles.shouldBeLessThan13import io.kotest.matchers.ints.shouldBeExactly14import io.kotest.matchers.ints.shouldBeGreaterThan15import it.unibo.alchemist.loader.LoadAlchemist16import org.kaikikm.threadresloader.ResourceLoader17class TestGraphStream : FreeSpec({18    "the lobster deployment should" - {19        val environment = LoadAlchemist.from(ResourceLoader.getResource("graphstream/testlobster.yml"))20            .getDefault<Nothing, Nothing>()21            .environment22        "displace all nodes" - {23            environment.nodeCount shouldBeExactly 40024            "with neighbors closer than non-neighbors" {25                environment.nodes.forEach { node ->26                    val neighborhood = environment.getNeighborhood(node)27                    val averageDistances = environment.nodes.asSequence()28                        .groupBy { it in neighborhood }29                        .mapValues { (_, nodes) ->30                            nodes.asSequence()31                                .map { environment.getDistanceBetweenNodes(node, it) }32                                .average()33                        }34                    2 * averageDistances[true]!! shouldBeLessThan averageDistances[false]!!35                }36            }37        }38        "create links" - {39            val neighborhoods = environment.nodes40                .map { environment.getNeighborhood(it).neighbors }41            neighborhoods.forEach { it.shouldNotBeEmpty() }42            "asymmetrically" {43                println(neighborhoods)44                neighborhoods.map { it.size }.toSet().size shouldBeGreaterThan 245            }46        }47    }48})...

Full Screen

Full Screen

TestEffectLoading.kt

Source:TestEffectLoading.kt Github

copy

Full Screen

1/*2 * Copyright (C) 2010-2022, Danilo Pianini and contributors3 * listed, for each module, in the respective subproject's build.gradle.kts file.4 *5 * This file is part of Alchemist, and is distributed under the terms of the6 * GNU General Public License, with a linking exception,7 * as described in the file LICENSE in the Alchemist distribution's top directory.8 */9@file:Suppress("DEPRECATION")10package it.unibo.alchemist.test11import io.kotest.core.spec.style.StringSpec12import io.kotest.engine.spec.tempfile13import io.kotest.matchers.file.shouldBeAFile14import io.kotest.matchers.file.shouldExist15import io.kotest.matchers.file.shouldNotBeEmpty16import io.kotest.matchers.nulls.beNull17import io.kotest.matchers.nulls.shouldNotBeNull18import io.kotest.matchers.shouldBe19import io.kotest.matchers.shouldNot20import it.unibo.alchemist.boundary.gui.effects.DrawBidimensionalGaussianLayersGradient21import it.unibo.alchemist.boundary.gui.effects.EffectSerializationFactory22import org.kaikikm.threadresloader.ResourceLoader23import java.io.File24class TestEffectLoading : StringSpec(25    {26        "effects with layers should be (de)serializable" {27            val target = DrawBidimensionalGaussianLayersGradient()28            val tempFile = tempfile()29            EffectSerializationFactory.effectToFile(tempFile, target)30            println(tempFile.readText())31            tempFile.shouldExist()32            tempFile.shouldBeAFile()33            tempFile.shouldNotBeEmpty()34            EffectSerializationFactory.effectsFromFile(tempFile).shouldNotBeNull()35        }36        "legacy effects with layers should be deserializable" {37            val target = ResourceLoader.getResource("layer.json")38            target shouldNot beNull()39            val file = File(target.file)40            file.shouldExist()41            file.shouldNotBeEmpty()42            file.shouldBeAFile()43            val effects = EffectSerializationFactory.effectsFromFile(file)44            effects.shouldNotBeNull()45            effects.size shouldBe 446        }47    }48)...

Full Screen

Full Screen

TestWebsiteCodeSnippets.kt

Source:TestWebsiteCodeSnippets.kt Github

copy

Full Screen

1import io.kotest.core.spec.style.FreeSpec2import io.kotest.matchers.collections.beEmpty3import io.kotest.matchers.collections.shouldBeEmpty4import io.kotest.matchers.collections.shouldNotBeEmpty5import io.kotest.matchers.nulls.beNull6import io.kotest.matchers.nulls.shouldNotBeNull7import io.kotest.matchers.shouldNot8import it.unibo.alchemist.util.ClassPathScanner9import it.unibo.alchemist.core.implementations.Engine10import it.unibo.alchemist.loader.LoadAlchemist11/*12 * Copyright (C) 2010-2021, Danilo Pianini and contributors13 * listed in the main project's alchemist/build.gradle.kts file.14 *15 * This file is part of Alchemist, and is distributed under the terms of the16 * GNU General Public License, with a linking exception,17 * as described in the file LICENSE in the Alchemist distribution's top directory.18 */19class TestWebsiteCodeSnippets : FreeSpec(20    {21        val allSpecs = ClassPathScanner.resourcesMatching(".*", "website-snippets")22            .also { it shouldNot beEmpty() }23            .onEach { it shouldNot beNull() }24        allSpecs.forEach { url ->25            "snippet ${url.path.split("/").last()} should load correctly" - {26                val environment = LoadAlchemist.from(url).getDefault<Any, Nothing>().environment27                environment.shouldNotBeNull()28                if (url.readText().contains("deployments:")) {29                    "and have deployed nodes" {30                        environment.shouldNotBeEmpty()31                        environment.nodes shouldNot beEmpty()32                    }33                } else {34                    "and be empty" {35                        environment.shouldBeEmpty()36                    }37                }38                "and execute a few steps without errors" {39                    Engine(environment, 100L).apply { play() }.run()40                }41            }42        }43    }44)...

Full Screen

Full Screen

processMatchers.kt

Source:processMatchers.kt Github

copy

Full Screen

1package dev.adamko.kxstsgen.util2import io.kotest.assertions.asClue3import io.kotest.assertions.withClue4import io.kotest.matchers.ints.shouldBeExactly5import io.kotest.matchers.nulls.shouldNotBeNull6import io.kotest.matchers.string.shouldContainIgnoringCase7import io.kotest.matchers.string.shouldNotBeEmpty8import io.kotest.matchers.string.shouldNotContain9import java.nio.file.Path10import kotlin.coroutines.CoroutineContext11import kotlin.io.path.createDirectory12import kotlin.io.path.createTempDirectory13import kotlin.io.path.createTempFile14import kotlin.io.path.exists15import kotlin.io.path.invariantSeparatorsPathString16import kotlin.io.path.writeText17import kotlinx.coroutines.CoroutineName18import kotlinx.coroutines.Dispatchers19import kotlinx.coroutines.SupervisorJob20import kotlinx.coroutines.withContext21private val processContext: CoroutineContext =22  Dispatchers.IO + SupervisorJob() + CoroutineName("TscCompile")23private val tempDir: Path by lazy {24  createTempDirectory().resolveSibling("kxstsgen").apply {25    if (!exists()) createDirectory()26    println("""Test output dir file:///${this.invariantSeparatorsPathString}""")27  }28}29suspend fun String?.shouldTypeScriptCompile(): String = withContext(processContext) {30  val src = this@shouldTypeScriptCompile31  src.shouldNotBeNull()32  val file: Path = createTempFile(33    directory = tempDir,34    prefix = src.filter { it.isLetterOrDigit() }.take(20),35    suffix = ".ts",36  )37  file.writeText(src)38  val (process, output) = typescriptCompile(file)39  output.joinToString("\n").asClue { log ->40    withClue("exit code should be 0") { process shouldBeExactly 0 }41    log.shouldNotBeEmpty()42    log shouldContainIgnoringCase "npx: installed"43    log shouldNotContain "error TS"44  }45  src46}...

Full Screen

Full Screen

DirectoryTests.kt

Source:DirectoryTests.kt Github

copy

Full Screen

1package msw.server.core.common2import io.kotest.assertions.throwables.shouldNotThrowAny3import io.kotest.assertions.throwables.shouldThrow4import io.kotest.core.spec.style.FunSpec5import io.kotest.matchers.booleans.shouldBeTrue6import io.kotest.matchers.collections.shouldNotBeEmpty7import io.kotest.matchers.nulls.shouldNotBeNull8import java.io.File9class DirectoryTests : FunSpec({10    test("A directory called '$exists' should not fail the instantiation of a Directory class") {11        shouldNotThrowAny {12            Directory(exists)13        }14    }15    test("A directory called '$existsNot' should fail the instantiation of a Directory class") {16        shouldThrow<IllegalArgumentException> {17            Directory(existsNot)18        }19    }20    test("A directory called '$create' should be created when instantiating Directory(path, true)") {21        shouldNotThrowAny {22            Directory(create, true)23        }24        File(create).exists().shouldBeTrue()25    }26    test("A directory called '$existsNot' should not fail the instantiation Directory(path, require = false)") {27        shouldNotThrowAny {28            Directory(existsNot, require = false)29        }30    }31    test("A directory called '$exists' should contain some files obtainable via Directory(path).list()") {32        val files: Array<String>? = shouldNotThrowAny {33            Directory(exists).list()34        }35        files.shouldNotBeNull()36        files.shouldNotBeEmpty()37    }38})...

Full Screen

Full Screen

File.shouldNotBeEmpty

Using AI Code Generation

copy

Full Screen

1    import io.kotest.matchers.file.matchers.shouldNotBeEmpty2    import io.kotest.matchers.file.matchers.shouldBeEmpty3    import io.kotest.matchers.file.matchers.shouldBeHidden4    import io.kotest.matchers.file.matchers.shouldBeReadable5    import io.kotest.matchers.file.matchers.shouldBeWritable6    import io.kotest.matchers.file.matchers.shouldBeExecutable7    import io.kotest.matchers.file.matchers.shouldHaveExtension8    import io.kotest.matchers.file.matchers.shouldHaveName9    import io.kotest.matchers.file.matchers.shouldHaveParent10    import io.kotest.matchers.file.matchers.shouldHaveParentDirectory11    import io.kotest.matchers.file.matchers.shouldHaveParentPath12    import io.kotest.matchers.file.matchers.shouldHavePath13    import io.kotest.matchers.file.matchers.shouldHaveNameStartingWith14    import io.kotest

Full Screen

Full Screen

File.shouldNotBeEmpty

Using AI Code Generation

copy

Full Screen

1File("myFile.txt").shouldNotBeEmpty()2File("myFile.txt").shouldBeEmpty()3File("myFile.txt").shouldHaveExtension("txt")4File("myFile.txt").shouldHaveName("myFile.txt")5File("myFile.txt").shouldHaveParent("myFile.txt")6File("myFile.txt").shouldHavePath("myFile.txt")7File("myFile.txt").shouldHaveSize(100)8File("myFile.txt").shouldHaveText("myFile.txt")9File("myFile.txt").shouldHaveTextIgnoringCase("myFile.txt")10File("myFile.txt").shouldHaveTextStartingWith("myFile.txt")11File("myFile.txt").shouldHaveTextEndingWith("myFile.txt")12File("myFile.txt").shouldHaveTextContaining("myFile.txt")13File("myFile.txt").shouldHaveTextMatching("myFile.txt")14File("myFile.txt").shouldHaveTextMatching("myFile.txt")

Full Screen

Full Screen

File.shouldNotBeEmpty

Using AI Code Generation

copy

Full Screen

1    File("somefile").shouldNotBeEmpty()2    File("somefile").shouldBeExecutable()3    File("somefile").shouldBeReadable()4    File("somefile").shouldBeWritable()5    File("somefile").shouldBeHidden()6    File("somefile").shouldNotBeHidden()7    File("somefile").shouldBeSymlink()8    File("somefile").shouldNotBeSymlink()9    File("somefile").shouldBeAbsolute()10    File("somefile").shouldNotBeAbsolute()11    File("somefile").shouldBeRelative()12    File("somefile").shouldNotBeRelative()13    File("somefile").shouldBeFile()14    File("somefile").shouldNotBeFile()15    File("somefile").shouldBeDirectory()

Full Screen

Full Screen

File.shouldNotBeEmpty

Using AI Code Generation

copy

Full Screen

1    import io.kotest.matchers.file.shouldNotBeEmpty2    class FileExtensionTest : StringSpec() {3        init {4            "file should not be empty" {5                val file = File("test.txt")6                file.shouldNotBeEmpty()7            }8        }9    }

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful