How to use containFile method of io.kotest.matchers.file.matchers class

Best Kotest code snippet using io.kotest.matchers.file.matchers.containFile

matchers.kt

Source:matchers.kt Github

copy

Full Screen

...120 shouldBeADirectory()121 shouldBeAbsolute()122 shouldNotBeEmpty()123 }124 // executable, hidden, readable, smaller, writeable, containFile, extension, path, ...125 LocalDate.now().shouldBeToday()126 // before/after, within, same, between, have year/month/day/hour/...127 LocalTime.now().shouldHaveSameHoursAs(LocalTime.now())128 // before/after/between, sameMinute/Seconds/Nanos129 }130 it("numbers") {131 1 shouldBeLessThan 2132 1 shouldBeLessThanOrEqual 1 // Int-based; returns this133 1 shouldBeLessThanOrEqualTo 1 // Comparble-based; void134 1 shouldBeEqualComparingTo 1 // Comparable-based135 1.shouldBeBetween(0, 2)136 1 shouldBeInRange 0..2137 0.shouldBeZero()138 1.shouldBePositive()...

Full Screen

Full Screen

paths.kt

Source:paths.kt Github

copy

Full Screen

...130 value.toFile().canonicalPath == value.toFile().path,131 { "File $value should be canonical" },132 { "File $value should not be canonical" })133}134infix fun Path.shouldContainFile(name: String) = this should containFile(name)135infix fun Path.shouldNotContainFile(name: String) = this shouldNot containFile(name)136fun containFile(name: String) = object : Matcher<Path> {137 override fun test(value: Path): MatcherResult {138 val contents = Files.list(value).map { it.fileName.toString() }.toList()139 val passed = Files.isDirectory(value) && contents.contains(name)140 return MatcherResult(141 passed,142 { "Directory $value should contain a file with filename $name (detected ${contents.size} other files)" },143 { "Directory $value should not contain a file with filename $name" })144 }145}146infix fun Path.shouldBeLarger(other: Path) = this.toFile() should beLarger(other.toFile())147infix fun Path.shouldBeLarger(other: File) = this.toFile() should beLarger(other)148infix fun Path.shouldNotBeLarger(other: Path) = this.toFile() shouldNot beLarger(other.toFile())149infix fun Path.shouldNotBeLarger(other: File) = this.toFile() shouldNot beLarger(other)150fun beLarger(other: Path): Matcher<Path> = object : Matcher<Path> {151 override fun test(value: Path): MatcherResult {152 val sizea = Files.size(value)153 val sizeb = Files.size(other)154 return MatcherResult(155 sizea > sizeb,156 { "Path $value ($sizea bytes) should be larger than $other ($sizeb bytes)" },157 { "Path $value ($sizea bytes) should not be larger than $other ($sizeb bytes)"})158 }159}160infix fun Path.shouldBeSmaller(other: Path) = this should beSmaller(other)161infix fun Path.shouldBeSmaller(other: File) = this should beSmaller(other.toPath())162infix fun Path.shouldNotBeSmaller(other: Path) = this shouldNot beSmaller(other)163infix fun Path.shouldNotBeSmaller(other: File) = this shouldNot beSmaller(other.toPath())164fun beSmaller(other: Path): Matcher<Path> = object : Matcher<Path> {165 override fun test(value: Path): MatcherResult {166 val sizea = Files.size(value)167 val sizeb = Files.size(other)168 return MatcherResult(169 sizea < sizeb,170 { "Path $value ($sizea bytes) should be smaller than $other ($sizeb bytes)" },171 { "Path $value ($sizea bytes) should not be smaller than $other ($sizeb bytes)" })172 }173}174infix fun Path.shouldContainFileDeep(name: String) = this should containFileDeep(name)175infix fun Path.shouldNotContainFileDeep(name: String) = this shouldNot containFileDeep(name)176fun containFileDeep(name: String): Matcher<Path> = object : Matcher<Path> {177 private fun fileExists(dir: Path): Boolean {178 val contents = Files.list(dir).toList()179 val (dirs, files) = contents.partition { Files.isDirectory(it) }180 return files.map { it.fileName.toString() }.contains(name) || dirs.any(::fileExists)181 }182 override fun test(value: Path): MatcherResult = MatcherResult(183 fileExists(value),184 { "Path $name should exist in $value" },185 { "Path $name should not exist in $value" }186 )187}188fun Path.shouldContainFiles(vararg files: String) = this should containFiles(files.asList())189fun Path.shouldNotContainFiles(vararg files: String) = this shouldNot containFiles(files.asList())190fun containFiles(names: List<String>) = object : Matcher<Path> {191 override fun test(value: Path): MatcherResult {192 val files = Files.list(value).toList().map { it.fileName.toString() }193 val existingFiles = names.intersect(files)194 val nonExistingFiles = names.subtract(existingFiles)195 return MatcherResult(196 nonExistingFiles.isEmpty(),197 { buildMessage(value, nonExistingFiles, false) },198 {199 buildMessage(value, existingFiles, true)200 })201 }202 private fun buildMessage(path: Path, fileList: Set<String>, isNegative: Boolean): String {203 val fileString = if (fileList.size > 1) "Files" else "File"204 val negativeWord = if (isNegative) " not" else ""...

Full Screen

Full Screen

containFile

Using AI Code Generation

copy

Full Screen

1val file = File("/tmp/test.txt")2file should containFile("test.txt")3val file = File("/tmp/test.txt")4file should containFile("test.txt")5val file = File("/tmp/test.txt")6file should containFile("test.txt")7val file = File("/tmp/test.txt")8file should containFile("test.txt")9val file = File("/tmp/test.txt")10file should containFile("test.txt")11val file = File("/tmp/test.txt")12file should containFile("test.txt")13val file = File("/tmp/test.txt")14file should containFile("test.txt")15val file = File("/tmp/test.txt")16file should containFile("test.txt")17val file = File("/tmp/test.txt")18file should containFile("test.txt")19val file = File("/tmp/test.txt")20file should containFile("test.txt")21val file = File("/tmp/test.txt")22file should containFile("test.txt")23val file = File("/tmp/test.txt")24file should containFile("test.txt")25val file = File("/tmp/test.txt")26file should containFile("test.txt")27val file = File("/tmp/test.txt")28file should containFile("test.txt")

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