Best Kotest code snippet using io.kotest.matchers.paths.names
AbstractDependencyNavigatorTest.kt
Source:AbstractDependencyNavigatorTest.kt
...54 private val testProject by lazy { testResult.getProject(PROJECT_ID)!! }55 protected val navigator by lazy { testResult.dependencyNavigator }56 init {57 "scopeNames" should {58 "return the scope names of a project" {59 navigator.scopeNames(testProject) should containExactlyInAnyOrder("compile", "test")60 }61 }62 "directDependencies" should {63 "return the direct dependencies of a project" {64 navigator.directDependencies(testProject, "test").map { it.id } should containSequenceExactly(65 Identifier("Maven:org.scalacheck:scalacheck_2.12:1.13.5"),66 Identifier("Maven:org.scalatest:scalatest_2.12:3.0.4")67 )68 }69 "return an empty sequence for an unknown scope" {70 navigator.directDependencies(testProject, "unknownScope") should beEmptySequence()71 }72 }73 "scopeDependencies" should {74 "return a map with scopes and their dependencies for a project" {75 val scopeDependencies = navigator.scopeDependencies(testProject)76 scopeDependencies.keys should containExactlyInAnyOrder("compile", "test")77 scopeDependencies["compile"] shouldNotBeNull {78 this should haveSize(17)79 this should containAll(80 Identifier("Maven:com.typesafe.akka:akka-actor_2.12:2.5.6"),81 Identifier("Maven:org.scala-lang:scala-reflect:2.12.2"),82 Identifier("Maven:org.scala-lang:scala-library:2.12.3")83 )84 }85 scopeDependencies["test"] shouldNotBeNull {86 this should haveSize(6)87 this should containAll(88 Identifier("Maven:org.scalacheck:scalacheck_2.12:1.13.5"),89 Identifier("Maven:org.scalactic:scalactic_2.12:3.0.4")90 )91 }92 }93 "return a map with scopes and their direct dependencies by using maxDepth = 1" {94 val scopeDependencies = navigator.scopeDependencies(testProject, maxDepth = 1)95 scopeDependencies["compile"] shouldNotBeNull {96 this should haveSize(7)97 this shouldNot contain(Identifier("Maven:com.typesafe.akka:akka-actor_2.12:2.5.6"))98 }99 }100 "return a map with scopes and their dependencies up to a given maxDepth" {101 val scopeDependencies = navigator.scopeDependencies(testProject, maxDepth = 2)102 scopeDependencies["compile"] shouldNotBeNull {103 this should haveSize(14)104 this shouldNot contain(105 Identifier("Maven:org.scala-lang.modules:scala-java8-compat_2.12:0.8.0")106 )107 }108 }109 "return a map with scopes and their dependencies with filter criteria" {110 val matchedIds = mutableSetOf<Identifier>()111 val scopeDependencies = navigator.scopeDependencies(testProject) { node ->112 matchedIds += node.id113 node.id.namespace == "com.typesafe.akka"114 }115 scopeDependencies["compile"] shouldNotBeNull {116 this should containExactlyInAnyOrder(117 Identifier("Maven:com.typesafe.akka:akka-actor_2.12:2.5.6"),118 Identifier("Maven:com.typesafe.akka:akka-stream_2.12:2.5.6")119 )120 }121 matchedIds should haveSize(23)122 }123 }124 "dependenciesForScope" should {125 "return an empty set for an unknown scope" {126 navigator.dependenciesForScope(testProject, "unknownScope") should beEmpty()127 }128 "return the dependencies of a specific scope" {129 val compileDependencies = navigator.dependenciesForScope(testProject, "compile")130 compileDependencies should haveSize(17)131 compileDependencies should containAll(132 Identifier("Maven:com.typesafe.akka:akka-actor_2.12:2.5.6"),133 Identifier("Maven:org.scala-lang:scala-reflect:2.12.2"),134 Identifier("Maven:org.scala-lang:scala-library:2.12.3")135 )136 }137 "return the dependencies of a specific scope up to a given maxDepth" {138 val compileDependencies = navigator.dependenciesForScope(testProject, "compile", maxDepth = 2)139 compileDependencies should haveSize(14)140 compileDependencies shouldNot contain(141 Identifier("Maven:org.scala-lang.modules:scala-java8-compat_2.12:0.8.0")142 )143 }144 "return the dependencies of a specific scope with filter criteria" {145 val akkaDependencies = navigator.dependenciesForScope(testProject, "compile") { node ->146 "akka" in node.id.namespace147 }148 akkaDependencies.shouldContainExactlyInAnyOrder(149 Identifier("Maven:com.typesafe.akka:akka-actor_2.12:2.5.6"),150 Identifier("Maven:com.typesafe.akka:akka-stream_2.12:2.5.6")151 )152 }153 }154 "packageDependencies" should {155 "return the dependencies of an existing package in a project" {156 val pkgId = Identifier("Maven:com.typesafe.akka:akka-stream_2.12:2.5.6")157 val dependencies = navigator.packageDependencies(testProject, pkgId)158 dependencies should containExactlyInAnyOrder(159 Identifier("Maven:com.typesafe:ssl-config-core_2.12:0.2.2"),160 Identifier("Maven:com.typesafe.akka:akka-actor_2.12:2.5.6"),161 Identifier("Maven:org.scala-lang.modules:scala-java8-compat_2.12:0.8.0"),162 Identifier("Maven:org.reactivestreams:reactive-streams:1.0.1")163 )164 }165 "return an empty set for the dependencies of a non-existing package" {166 val pkgId = Identifier("Maven:com.typesafe.akka:akka-actor_2.12:2.5.7")167 val dependencies = navigator.packageDependencies(testProject, pkgId)168 dependencies should beEmpty()169 }170 "support a maxDepth filter" {171 val pkgId = Identifier("Maven:com.typesafe.akka:akka-stream_2.12:2.5.6")172 val dependencies = navigator.packageDependencies(testProject, pkgId, maxDepth = 1)173 dependencies should containExactlyInAnyOrder(174 Identifier("Maven:com.typesafe:ssl-config-core_2.12:0.2.2"),175 Identifier("Maven:com.typesafe.akka:akka-actor_2.12:2.5.6"),176 Identifier("Maven:org.reactivestreams:reactive-streams:1.0.1")177 )178 }179 "support a DependencyMatcher" {180 val pkgId = Identifier("Maven:com.typesafe.akka:akka-stream_2.12:2.5.6")181 val dependencies = navigator.packageDependencies(testProject, pkgId) { node ->182 node.id.namespace.startsWith("com.typesafe")183 }184 dependencies should containExactlyInAnyOrder(185 Identifier("Maven:com.typesafe:ssl-config-core_2.12:0.2.2"),186 Identifier("Maven:com.typesafe.akka:akka-actor_2.12:2.5.6")187 )188 }189 }190 "getShortestPaths" should {191 "return the shortest paths for a project" {192 val paths = navigator.getShortestPaths(testProject)193 paths.keys should haveSize(2)194 paths["compile"] shouldNotBeNull {195 this should containExactlyEntries(196 Identifier("Maven:ch.qos.logback:logback-classic:1.2.3") to emptyList(),...
ApplicationConfigTest.kt
Source:ApplicationConfigTest.kt
...76 pingConfig.pingServer shouldBe "1.1.1.1"77 pingConfig.timeout shouldBe 100078 }79 @Test80 fun `Exit application, when forbidden service names are used`() {81 Mockito.mockStatic(Runtime::class.java).use {82 val runtimeMock = mock<Runtime>()83 it.`when`<Any> { Runtime.getRuntime() }.thenReturn(runtimeMock)84 whenever(Runtime.getRuntime()).thenReturn(runtimeMock)85 shouldThrow<Exception> {86 ApplicationConfig(87 loggerMock,88 Paths.get(javaClass.getResource("/forbidden-service-name.conf").toURI())89 )90 .userConfig91 }92 verify(loggerMock).error(any<() -> Any?>())93 verify(runtimeMock).exit(ArgumentMatchers.intThat { exitCode -> exitCode != 0 })94 }...
JsMinifier - class.kt
Source:JsMinifier - class.kt
1package org.gradlewebtools.minify.minifier.js2import io.kotest.assertions.throwables.shouldThrow3import io.kotest.core.spec.IsolationMode4import io.kotest.core.spec.style.AnnotationSpec5import io.kotest.matchers.collections.shouldHaveSize6import io.kotest.matchers.shouldBe7import org.gradle.api.GradleException8import java.io.BufferedReader9import java.io.File10import java.io.FileReader11import java.nio.file.Files12import java.nio.file.Path13import java.nio.file.Paths14import java.util.stream.Collectors15class `JsMinifier - class` : AnnotationSpec() {16 override fun isolationMode() = IsolationMode.InstancePerTest17 var testProjectDir: File = Files.createTempDirectory("test_gradle_project_dir").toFile().apply {18 afterSpec {19 deleteRecursively()20 }21 }22 @Test23 fun minifyFile() {24 val jsMinifier = JsMinifier()25 val dst = File(testProjectDir, "dst")26 dst.mkdir()27 jsMinifier.minify(File("src/test/resources/js"), dst)28 val files = dst.walk().toList().filterNot { it.path.endsWith("dst") }29 files shouldHaveSize 330 val subDir = File(dst, "sub")31 val subFiles = subDir.walk().toList().filterNot { it.path.endsWith("sub") }32 subFiles shouldHaveSize 133 }34 @Test35 fun minifyFileWithoutRenaming() {36 val jsMinifier = JsMinifier()37 jsMinifier.minifierOptions.originalFileNames = true38 val dst = File(testProjectDir, "dst")39 dst.mkdir()40 jsMinifier.minify(File("src/test/resources/js"), dst)41 val files = dst.walk().toList().filter { it.path.endsWith("dst/js.min.js") }42 files shouldHaveSize 043 }44 @Test45 fun minifyFileWithSourceMaps() {46 val jsMinifier = JsMinifier()47 jsMinifier.minifierOptions.createSourceMaps = true48 val dst = File(testProjectDir, "dst")49 dst.mkdir()50 jsMinifier.minify(File("src/test/resources/js"), dst)51 val files = Files.list(Paths.get(dst.absolutePath + "/")).collect(Collectors.toList())52 files shouldHaveSize 353 val minifiedJs = files.stream()54 .filter { path: Path? -> path!!.toFile().name.endsWith(".min.js") }55 .collect(Collectors.toList())56 minifiedJs shouldHaveSize 157 val path = minifiedJs[0]58 val lines = BufferedReader(FileReader(path!!.toFile())).lines().collect(Collectors.toList())59 lines[lines.size - 1] shouldBe "//# sourceMappingURL=" + path.fileName + ".map"60 val subDir = files.stream().filter { p: Path? -> p!!.toFile().name.endsWith("sub") }.findFirst().orElse(null)61 val subFiles = Files.list(subDir).collect(Collectors.toList())62 subFiles shouldHaveSize 263 }64 @Test65 fun minifyFileWithError() {66 val jsMinifier = JsMinifier()67 jsMinifier.minifierOptions.createSourceMaps = true68 val dst = File(testProjectDir, "dst")69 dst.mkdir()70 shouldThrow<GradleException> {71 jsMinifier.minify(File("src/test/resources/errors/js"), dst)72 }73 val files = Files.list(Paths.get(dst.absolutePath + "/")).collect(Collectors.toList())74 files shouldHaveSize 075 jsMinifier.report.errors shouldHaveSize 176 jsMinifier.report.warnings shouldHaveSize 077 }78 @Test79 fun minifyEmptyFile() {80 val jsMinifier = JsMinifier()81 val src = File(testProjectDir, "empty")82 src.mkdir()83 val empty = File(src, "empty.js")84 empty.createNewFile()85 val dst = File(testProjectDir, "dst")86 dst.mkdir()87 jsMinifier.minify(src, dst)88 val files = Files.list(Paths.get(dst.absolutePath + "/")).collect(Collectors.toList())89 files shouldHaveSize 190 }91}...
CacheTests.kt
Source:CacheTests.kt
...85 checkRemapping()86 }87 "clear cache" {88 checkUsingCache()89 // Ensure that some cache names remain unchanged90 val cacheJarsDir = project.projectDir.resolve("$CacheDir/$CacheJarsDir")91 val cacheJars = cacheJarsDir.listFiles()!!92 // Clear `AdditionalPlugins`93 cacheJars.filter { it.name.startsWith("AdditionalPlugins") }.forEach { it.delete() }94 checkRemapping()95 val newCacheJars = cacheJarsDir.listFiles()!!96 // Only `AdditionalPlugins` re-cached97 newCacheJars.filter { new ->98 // Filter out names that do not exist in the old `cacheJars`99 cacheJars.none { old -> new == old }100 }.forEachAsClue { it.name.shouldStartWith("AdditionalPlugins") }101 }102})...
LangTest.kt
Source:LangTest.kt
1package com.github.durun.nitron.test2import com.github.durun.nitron.core.config.AntlrParserConfig3import com.github.durun.nitron.core.config.LangConfig4import com.github.durun.nitron.core.config.loader.NitronConfigLoader5import com.github.durun.nitron.core.parser.antlr.ParserStore6import io.kotest.assertions.throwables.shouldNotThrowAny7import io.kotest.core.spec.style.FreeSpec8import io.kotest.core.spec.style.freeSpec9import io.kotest.inspectors.forAll10import io.kotest.matchers.collections.shouldBeIn11import io.kotest.matchers.collections.shouldContainAll12import io.kotest.matchers.collections.shouldHaveAtLeastSize13import io.kotest.matchers.paths.shouldBeReadable14import io.kotest.mpp.log15import java.nio.file.Path16import java.nio.file.Paths17import kotlin.io.path.toPath18class LangTest : FreeSpec({19 val configPath = Paths.get("config/nitron.json")20 NitronConfigLoader.load(configPath).langConfig21 .filter { (_, config) -> config.parserConfig is AntlrParserConfig }22 .forEach { (lang, config) -> include(langTestFactory(lang, config)) }23})24fun langTestFactory(lang: String, config: LangConfig) = freeSpec {25 "config for $lang (${config.fileName})" - {26 val parser = ParserStore.getOrNull(config.parserConfig)27 val parserConfig = config.parserConfig as AntlrParserConfig28 "grammar files exist" {29 val files = parserConfig.grammarFilePaths + parserConfig.utilJavaFilePaths30 log { "${config.fileName}: files=$files" }31 files shouldHaveAtLeastSize 132 files.forAll {33 it.shouldBeReadable()34 }35 }36 "defines parser settings" {37 shouldNotThrowAny {38 ParserStore.getOrThrow(config.parserConfig)39 }40 }41 "defines start rule" {42 val startRule = parserConfig.startRule43 log { "${config.fileName}: startRule=$startRule" }44 startRule shouldBeIn parser!!.antlrParser.ruleNames45 }46 "defines at least 1 extension of sourcecode" {47 val extensions = config.extensions48 log { "${config.fileName}: extensions=$extensions" }49 extensions shouldHaveAtLeastSize 150 }51 "uses correct rule/token name" {52 val usedRules: List<String> = (53 config.processConfig.normalizeConfig.ignoreRules +54 config.processConfig.normalizeConfig.mapping.keys +55 config.processConfig.normalizeConfig.indexedMapping.keys +56 config.processConfig.splitConfig.splitRules57 )58 .flatMap { it.split('/').filter(String::isNotEmpty) }59 .filterNot { it.contains(Regex("[^a-zA-Z]")) }60 val antlrParser = parser!!.antlrParser61 val allowedRules = antlrParser.ruleNames + antlrParser.tokenTypeMap.keys62 runCatching {63 allowedRules shouldContainAll usedRules64 }.onFailure {65 println("see: ${parserConfig.grammarFilePaths.map(Path::normalize)}")66 val errorSymbols = (usedRules - allowedRules)67 config.fileUri.toURL().readText().lineSequence().forEachIndexed { index, line ->68 val file = config.fileUri.toPath()69 val lineNo = index + 170 errorSymbols.filter { line.contains(it) }.forEach {71 println("""$file:$lineNo: "$it" is not defined""")72 }73 }74 }.getOrThrow()75 }76 }77}...
AllureTestReporterTest.kt
Source:AllureTestReporterTest.kt
...13@Order(1)14class AllureTestReporterTest : WordSpec() {15 private val mapper = ObjectMapper().registerModule(KotlinModule())16 private fun findTestFile(name: String): JsonNode {17 val names = Paths.get("./build/allure-results").toFile().listFiles()18 .filter { it.name.endsWith(".json") }19 .map { mapper.readTree(it) }20 .map { it.get("name").textValue() }21 return Paths.get("./build/allure-results").toFile().listFiles()22 .filter { it.name.endsWith(".json") }23 .map { mapper.readTree(it) }24 .first { it.get("name").textValue() == name }25 }26 init {27 "AllureTestReporter" should {28 "write out data" {29 val json = findTestFile("Given: a given When: another when Then: a final then")30 json["name"].textValue() shouldBe "Given: a given When: another when Then: a final then"31 json["fullName"].textValue() shouldBe "Given: a given When: another when Then: a final then"...
IOSpec.kt
Source:IOSpec.kt
1package com.github.rougsig.core2import io.kotest.core.datatest.forAll3import io.kotest.core.spec.style.FunSpec4import io.kotest.matchers.file.shouldBeADirectory5import io.kotest.matchers.file.shouldBeAFile6import io.kotest.matchers.file.shouldExist7import io.kotest.matchers.shouldBe8import kotlinx.coroutines.runBlocking9import java.io.ByteArrayInputStream10import java.io.ByteArrayOutputStream11import java.io.File12import java.io.PrintStream13import java.nio.file.Paths14abstract class IOSpec(15 private val resourcesPath: String,16 private val testFun: IOEnvironment.() -> Unit17) : FunSpec({18 val projectRoot = File(".").absoluteFile.parent19 val resourcesDir = Paths.get(projectRoot, "src/test/resources", resourcesPath).toFile()20 context("File IO tests") {21 val inputDir = File("${resourcesDir.absoluteFile}/input")22 inputDir.shouldExist()23 inputDir.shouldBeADirectory()24 val outputDir = File("${resourcesDir.absoluteFile}/output")25 outputDir.shouldExist()26 val testNames = inputDir.listFiles()27 .map { it.nameWithoutExtension.removePrefix("input") }28 forAll(testNames) { testName: String ->29 val input = File("${inputDir.absoluteFile}/input${testName}.txt")30 input.shouldExist()31 input.shouldBeAFile()32 val output = File("${outputDir.absoluteFile}/output${testName}.txt")33 output.shouldExist()34 output.shouldBeAFile()35 val baos = ByteArrayOutputStream()36 runBlocking {37 // Set the same as hackerrank timeout limit38 // https://www.hackerrank.com/environment/languages39 withTimeoutOrInterrupt(4000L) {40 IOEnvironment(ByteArrayInputStream(input.readBytes()), PrintStream(baos)).testFun()41 }42 }43 val actual = baos.toString().trim().trimIndent()44 val expected = output.readText().trim().trimIndent()45 actual.shouldBe(expected)46 }47 }48})...
GenericParserTest.kt
Source:GenericParserTest.kt
1package com.github.durun.nitron.core.parser.antlr2import com.github.durun.nitron.core.config.AntlrParserConfig3import com.github.durun.nitron.core.config.loader.NitronConfigLoader4import io.kotest.assertions.throwables.shouldNotThrowAny5import io.kotest.core.spec.style.FreeSpec6import io.kotest.core.spec.style.freeSpec7import io.kotest.matchers.collections.shouldHaveAtLeastSize8import java.nio.file.Paths9class GenericParserTest : FreeSpec({10 val configPath = Paths.get("config/nitron.json")11 val config = NitronConfigLoader.load(configPath)12 include(13 tests(14 "javascript",15 config.langConfig["javascript"]!!.parserConfig as AntlrParserConfig,16 src = """console.log("Hello");"""17 )18 )19})20private fun tests(name: String, config: AntlrParserConfig, src: String) = freeSpec {21 val parser = ParserStore.getOrThrow(config)22 name - {23 "init" {24 shouldNotThrowAny {25 println(parser)26 }27 }28 "antlrParser" {29 val antlr = shouldNotThrowAny {30 parser.antlrParser31 }32 antlr.ruleNames shouldHaveAtLeastSize 133 antlr.tokenTypeMap.entries shouldHaveAtLeastSize 134 }35 "parse" {36 println("parsing source: $src")37 val tree = shouldNotThrowAny {38 parser.parse(src.reader(), config.startRule)39 }40 println(tree.toInfoString(parser.antlrParser))41 }42 }43}...
names
Using AI Code Generation
1val path = Paths.get( " /home/kotest " )2path.shouldBe( aDirectory())3path.shouldBe( aRegularFile())4path.shouldBe( anExistingFile())5path.shouldBe( aReadableFile())6path.shouldBe( aWritableFile())7path.shouldBe( aHiddenFile())8path.shouldBe( aSymbolicLink())9path.shouldBe( aRealFile())10path.shouldBe( aFileWithSize( 1000 ))11path.shouldBe( aFileWithSize( greaterThan ( 1000 )))12path.shouldBe( aFileWithSize( lessThan ( 1000 )))13path.shouldBe( aFileWithSize( between ( 1000 , 2000 )))14path.shouldBe( aFileWithSize( not ( between ( 1000 , 2000 ))))15path.shouldBe( aFileWithSize( not ( greaterThan ( 1000 ))))16path.shouldBe( aFileWithSize( not ( lessThan ( 1000 ))))17path.shouldBe( aFileWithSize( not ( equalTo ( 1000 ))))18path.shouldBe( aFileWithSize( equalTo ( 1000 )))19path.shouldBe( aFileWithSize( lessThan ( 1000 )))20path.shouldBe( aFileWithSize( greaterThan ( 1000 )))21path.shouldBe( aFileWithSize( between ( 1000 , 2000 )))22path.shouldBe( aFileWithSize( not ( between ( 1000 , 2000 ))))23path.shouldBe( aFileWithSize( not ( greaterThan ( 1000 ))))24path.shouldBe( aFileWithSize( not ( lessThan ( 1000 ))))25path.shouldBe( aFileWithSize( not ( equalTo ( 1000 ))))26path.shouldBe( aFileWithSize( equalTo ( 1000 )))27path.shouldBe( aFileWithSize( lessThan ( 1000 )))28path.shouldBe( aFileWithSize( greaterThan ( 1000 )))29path.shouldBe( aFileWithSize( between ( 1000 , 2000 )))30path.shouldBe( aFileWithSize( not ( between ( 1000 , 2000 ))))31path.shouldBe( aFileWithSize( not ( greaterThan ( 1000 ))))32path.shouldBe( aFileWithSize( not ( lessThan ( 100
names
Using AI Code Generation
1fun Path.shouldBeADirectory() = this should beADirectory()2fun Path.shouldNotBeADirectory() = this shouldNot beADirectory()3fun Path.shouldBeADirectory(message: String) = this should beADirectory(message)4fun Path.shouldNotBeADirectory(message: String) = this shouldNot beADirectory(message)5fun Path.shouldBeADirectory(message: () -> String) = this should beADirectory(message)6fun Path.shouldNotBeADirectory(message: () -> String) = this shouldNot beADirectory(message)7fun Path.shouldBeAFile() = this should beAFile()8fun Path.shouldNotBeAFile() = this shouldNot beAFile()9fun Path.shouldBeAFile(message: String) = this should beAFile(message)10fun Path.shouldNotBeAFile(message: String) = this shouldNot beAFile(message)11fun Path.shouldBeAFile(message: () -> String) = this should beAFile(message)12fun Path.shouldNotBeAFile(message: () -> String) = this shouldNot beAFile(message)13fun Path.shouldBeAbsolute() = this should beAbsolute()14fun Path.shouldNotBeAbsolute() = this shouldNot beAbsolute()15fun Path.shouldBeAbsolute(message: String) = this should beAbsolute(message)16fun Path.shouldNotBeAbsolute(message: String) = this shouldNot beAbsolute(message)17fun Path.shouldBeAbsolute(message: () -> String) = this should beAbsolute(message)
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!