Best Kotest code snippet using io.kotest.matchers.file.matchers.File.shouldBeAbsolute
FileMatchersTest.kt
Source:FileMatchersTest.kt  
1package com.sksamuel.kotest.matchers.file2import io.kotest.assertions.throwables.shouldThrow3import io.kotest.core.spec.style.FunSpec4import io.kotest.matchers.file.aDirectory5import io.kotest.matchers.file.aFile6import io.kotest.matchers.file.beAbsolute7import io.kotest.matchers.file.beRelative8import io.kotest.matchers.file.exist9import io.kotest.matchers.file.haveExtension10import io.kotest.matchers.file.shouldBeADirectory11import io.kotest.matchers.file.shouldBeAFile12import io.kotest.matchers.file.shouldBeAbsolute13import io.kotest.matchers.file.shouldBeEmptyDirectory14import io.kotest.matchers.file.shouldBeRelative15import io.kotest.matchers.file.shouldBeSymbolicLink16import io.kotest.matchers.file.shouldExist17import io.kotest.matchers.file.shouldHaveExtension18import io.kotest.matchers.file.shouldHaveParent19import io.kotest.matchers.file.shouldHaveSameStructureAs20import io.kotest.matchers.file.shouldHaveSameStructureAndContentAs21import io.kotest.matchers.file.shouldNotBeADirectory22import io.kotest.matchers.file.shouldNotBeAFile23import io.kotest.matchers.file.shouldNotBeEmptyDirectory24import io.kotest.matchers.file.shouldNotBeSymbolicLink25import io.kotest.matchers.file.shouldNotExist26import io.kotest.matchers.file.shouldNotHaveExtension27import io.kotest.matchers.file.shouldNotHaveParent28import io.kotest.matchers.file.shouldStartWithPath29import io.kotest.matchers.file.startWithPath30import io.kotest.matchers.paths.shouldBeLarger31import io.kotest.matchers.paths.shouldBeSmaller32import io.kotest.matchers.paths.shouldBeSymbolicLink33import io.kotest.matchers.paths.shouldContainFile34import io.kotest.matchers.paths.shouldContainFileDeep35import io.kotest.matchers.paths.shouldContainFiles36import io.kotest.matchers.paths.shouldHaveParent37import io.kotest.matchers.paths.shouldNotBeSymbolicLink38import io.kotest.matchers.paths.shouldNotContainFile39import io.kotest.matchers.paths.shouldNotContainFileDeep40import io.kotest.matchers.paths.shouldNotContainFiles41import io.kotest.matchers.paths.shouldNotHaveParent42import io.kotest.matchers.should43import io.kotest.matchers.shouldBe44import io.kotest.matchers.shouldNot45import io.kotest.matchers.string.shouldEndWith46import io.kotest.matchers.string.shouldMatch47import java.io.File48import java.nio.file.Files49import java.nio.file.Paths50import org.apache.commons.lang3.SystemUtils.IS_OS_WINDOWS51@Suppress("BlockingMethodInNonBlockingContext")52class FileMatchersTest : FunSpec() {53  init {54    test("relative() should match only relative files") {55      File("sammy/boy") shouldBe beRelative()56      File("sammy/boy").shouldBeRelative()57    }58    test("absolute() should match only absolute files") {59      val root = if (IS_OS_WINDOWS) "C:/" else "/"60      File("${root}sammy/boy") shouldBe beAbsolute()61      File("${root}sammy/boy").shouldBeAbsolute()62    }63    test("startWithPath() should only match files that start with the given path") {64      File("sammy/boy") should startWithPath("sammy")65      File("sammy/boy") should startWithPath(Paths.get("sammy"))66      File("/sammy/boy") should startWithPath("${File.separator}sammy")67      File("/sammy/boy") should startWithPath(Paths.get("/sammy"))68      File("/sammy/boy").shouldStartWithPath("${File.separator}sammy")69      File("/sammy/boy").shouldStartWithPath(Paths.get("/sammy"))70    }71    test("exist() file matcher") {72      val file = Files.createTempFile("test", "test").toFile()73      file should exist()74      shouldThrow<AssertionError> {75        File("qweqwewqewqewee") should exist()76      }.message shouldBe "File qweqwewqewqewee should exist"77      file.shouldExist()78      shouldThrow<AssertionError> {79        file.shouldNotExist()80      }81      file.delete()82    }83    test("haveExtension") {84      val file = Files.createTempFile("test", ".test").toFile()85      file should haveExtension(".test")86      file shouldNot haveExtension(".wibble")87      shouldThrow<AssertionError> {88        file should haveExtension(".jpeg")89      }.message.shouldEndWith("with one of .jpeg")90      shouldThrow<AssertionError> {91        file.shouldHaveExtension(".jpeg")92      }.message.shouldEndWith("with one of .jpeg")93      file.shouldHaveExtension(".test")94      file.shouldNotHaveExtension(".wibble")95      file.delete()96    }97    test("aFile() file matcher") {98      val file = Files.createTempFile("test", "test").toFile()99      file shouldBe aFile()100      file.shouldBeAFile()101      shouldThrow<AssertionError> {102        file shouldBe aDirectory()103      }104      shouldThrow<AssertionError> {105        file.shouldNotBeAFile()106      }107      shouldThrow<AssertionError> {108        file.shouldBeADirectory()109      }110      file.delete()111    }112    test("aDirectory() file matcher") {113      val dir = Files.createTempDirectory("testdir").toFile()114      dir shouldBe aDirectory()115      dir.shouldBeADirectory()116      shouldThrow<AssertionError> {117        dir shouldBe aFile()118      }119      shouldThrow<AssertionError> {120        dir.shouldNotBeADirectory()121      }122      shouldThrow<AssertionError> {123        dir shouldBe aFile()124      }125    }126    test("directory should be empty (deprecated)") {127      val dir = Files.createTempDirectory("testdir").toFile()128      dir.shouldBeEmptyDirectory()129      dir.resolve("testfile.txt").writeBytes(byteArrayOf(1, 2, 3))130      dir.shouldNotBeEmptyDirectory()131    }132    test("directory should be empty") {133      val dir = Files.createTempDirectory("testdir").toFile()134      dir.shouldBeEmptyDirectory()135      dir.resolve("testfile.txt").writeBytes(byteArrayOf(1, 2, 3))136      dir.shouldNotBeEmptyDirectory()137    }138    test("directory contains file matching predicate") {139      val dir = Files.createTempDirectory("testdir")140      dir.resolve("a").toFile().createNewFile()141      dir.resolve("b").toFile().createNewFile()142      dir.shouldContainFile("a")143      dir.shouldNotContainFile("c")144      shouldThrow<AssertionError> {145        dir.shouldContainFile("c")146      }.message?.shouldMatch("^Directory .+ should contain a file with filename c \\(detected 2 other files\\)$".toRegex())147    }148    test("beSmaller should compare file sizes") {149      val dir = Files.createTempDirectory("testdir")150      Files.write(dir.resolve("a"), byteArrayOf(1, 2))151      Files.write(dir.resolve("b"), byteArrayOf(1, 2, 3))152      dir.resolve("a").shouldBeSmaller(dir.resolve("b"))153      shouldThrow<AssertionError> {154        dir.resolve("b").shouldBeSmaller(dir.resolve("a"))155      }.message shouldBe "Path ${dir.resolve("b")} (3 bytes) should be smaller than ${dir.resolve("a")} (2 bytes)"156    }157    test("beLarger should compare file sizes") {158      val dir = Files.createTempDirectory("testdir")159      Files.write(dir.resolve("a"), byteArrayOf(1, 2, 3))160      Files.write(dir.resolve("b"), byteArrayOf(1, 2))161      dir.resolve("a").shouldBeLarger(dir.resolve("b"))162      shouldThrow<AssertionError> {163        dir.resolve("b").shouldBeLarger(dir.resolve("a"))164      }.message shouldBe "File ${dir.resolve("b")} (2 bytes) should be larger than ${dir.resolve("a")} (3 bytes)"165    }166    test("containsFileDeep should find file deep") {167      val rootFileName = "super_dooper_hyper_file_root"168      val innerFileName = "super_dooper_hyper_file_inner"169      val nonExistentFileName = "super_dooper_hyper_non_existent_file"170      val rootDir = Files.createTempDirectory("testdir")171      val innerDir = Files.createDirectories(rootDir.resolve("innerfolder"))172      Files.write(rootDir.resolve(rootFileName), byteArrayOf(1, 2, 3))173      Files.write(innerDir.resolve(innerFileName), byteArrayOf(1, 2, 3))174      rootDir.shouldContainFileDeep(rootFileName)175      rootDir.shouldContainFileDeep(innerFileName)176      shouldThrow<AssertionError> {177        rootDir.shouldContainFileDeep(nonExistentFileName)178      }.message shouldBe "Path $nonExistentFileName should exist in $rootDir"179      shouldThrow<AssertionError> {180        rootDir.shouldNotContainFileDeep(rootFileName)181      }.message shouldBe "Path $rootFileName should not exist in $rootDir"182    }183    test("shouldContainFiles should check if files exists") {184      val testDir = Files.createTempDirectory("testdir")185      Files.write(testDir.resolve("a.txt"), byteArrayOf(1, 2, 3))186      Files.write(testDir.resolve("b.gif"), byteArrayOf(1, 2, 3))187      Files.write(testDir.resolve("c.doc"), byteArrayOf(1, 2, 3))188      testDir.shouldContainFiles("a.txt", "b.gif", "c.doc")189      testDir.shouldNotContainFiles("d.txt", "e.gif", "f.doc")190      shouldThrow<AssertionError> {191        testDir.shouldContainFiles("d.txt")192      }.message shouldBe "File d.txt should exist in $testDir"193      shouldThrow<AssertionError> {194        testDir.shouldContainFiles("d.txt", "e.gif")195      }.message shouldBe "Files d.txt, e.gif should exist in $testDir"196      shouldThrow<AssertionError> {197        testDir.shouldNotContainFiles("a.txt")198      }.message shouldBe "File a.txt should not exist in $testDir"199      shouldThrow<AssertionError> {200        testDir.shouldNotContainFiles("a.txt", "b.gif")201      }.message shouldBe "Files a.txt, b.gif should not exist in $testDir"202    }203    test("shouldBeSymbolicLink should check if file is symbolic link").config(enabled = isNotWindowsOrIsWindowsElevated()) {204      val testDir = Files.createTempDirectory("testdir")205      val existingFile = Files.write(testDir.resolve("original.txt"), byteArrayOf(1, 2, 3, 4))206      val existingFileAsFile = existingFile.toFile()207      val link = Files.createSymbolicLink(testDir.resolve("a.txt"), existingFile)208      val linkAsFile = link.toFile()209      link.shouldBeSymbolicLink()210      linkAsFile.shouldBeSymbolicLink()211      existingFile.shouldNotBeSymbolicLink()212      existingFileAsFile.shouldNotBeSymbolicLink()213    }214    test("shouldHaveParent should check if file has any parent with given name") {215      val testDir = Files.createTempDirectory("testdir")216      val subdir = Files.createDirectory(testDir.resolve("sub_testdir"))217      val file = Files.write(subdir.resolve("a.txt"), byteArrayOf(1, 2, 3, 4))218      val fileAsFile = file.toFile()219      file.shouldHaveParent(testDir.toFile().name)220      file.shouldHaveParent(subdir.toFile().name)221      file.shouldNotHaveParent("super_hyper_long_random_file_name")222      fileAsFile.shouldHaveParent(testDir.toFile().name)223      fileAsFile.shouldHaveParent(subdir.toFile().name)224      fileAsFile.shouldNotHaveParent("super_hyper_long_random_file_name")225    }226    test("shouldHaveSameStructureAs and shouldHaveSameStructureAndContentAs two file trees") {227      val testDir = Files.createTempDirectory("testdir")228      val expectDir = File("$testDir/expect").apply {229        File("$this/a.txt").createWithContent(byteArrayOf(1, 2, 3))230        File("$this/b.txt").createWithContent(byteArrayOf(1, 2, 3, 4))231        File("$this/subfolder/b.txt").createWithContent(byteArrayOf(1, 2, 3, 4))232        File("$this/subfolder/subfolder-two/c.txt").createWithContent(byteArrayOf(1, 2))233      }234      val actualDir = File("$testDir/actual").apply {235        File("$this/a.txt").createWithContent(byteArrayOf(1, 2, 3))236        File("$this/b.txt").createWithContent(byteArrayOf(1, 2, 3, 4))237        File("$this/subfolder/b.txt").createWithContent(byteArrayOf(1, 2, 3, 4))238        File("$this/subfolder/subfolder-two/c.txt").createWithContent(byteArrayOf(1, 2))239      }240      expectDir shouldHaveSameStructureAs actualDir241      expectDir shouldHaveSameStructureAndContentAs actualDir242      File("$expectDir/z.txt").createWithContent(byteArrayOf(1, 2, 3))243      shouldThrow<AssertionError> { expectDir shouldHaveSameStructureAs actualDir }244      shouldThrow<AssertionError> { expectDir shouldHaveSameStructureAndContentAs actualDir }245      File("$actualDir/z.txt").createWithContent(byteArrayOf(1, 2, 3, 4))246      expectDir shouldHaveSameStructureAs actualDir247      shouldThrow<AssertionError> { expectDir shouldHaveSameStructureAndContentAs actualDir }248    }249    test("shouldHaveSameStructureAs with filter should check if two file trees are the same and files have the same content") {250      val testDir = Files.createTempDirectory("testdir")251      val expectDir = File("$testDir/expect").apply {252        File("$this/a.txt").createWithContent("a/b")253        File("$this/b.txt").createWithContent("b/c")254        File("$this/subfolder/b.txt").createWithContent("b/c")255        File("$this/subfolder/subfolder-two/c.txt").createWithContent("c/d")256        File("$this/z.txt").createWithContent("z")257      }258      val actualDir = File("$testDir/actual").apply {259        File("$this/a.txt").createWithContent("a/b")260        File("$this/b.txt").createWithContent("b/c")261        File("$this/subfolder/b.txt").createWithContent("b/c")262        File("$this/subfolder/subfolder-two/c.txt").createWithContent("c/d")263        File("$this/z.txt").createWithContent("zz")264      }265      expectDir.shouldHaveSameStructureAs(actualDir, filterLhs = { it.name == "z.txt" })266      expectDir.shouldHaveSameStructureAs(actualDir, filterRhs = { it.name == "z.txt" })267    }268    test("shouldHaveSameStructureAndContentAs with compare and filter should check if two file trees are the same and files have the same content") {269      val testDir = Files.createTempDirectory("testdir")270      val expectDir = File("$testDir/expect").apply {271        File("$this/a.txt").createWithContent("a/b")272        File("$this/b.txt").createWithContent("b/c")273        File("$this/subfolder/b.txt").createWithContent("b/c")274        File("$this/subfolder/subfolder-two/c.txt").createWithContent("c/d")275      }276      val actualDir = File("$testDir/actual").apply {277        File("$this/a.txt").createWithContent("a/b")278        File("$this/b.txt").createWithContent("b\\c")279        File("$this/subfolder/b.txt").createWithContent("b\\c")280        File("$this/subfolder/subfolder-two/c.txt").createWithContent("c\\d")281      }282      expectDir.shouldHaveSameStructureAs(actualDir) { a, b ->283        a.isFile && b.isFile && a.readText() == b.readText().replace("\\", "/")284      }285      expectDir.shouldHaveSameStructureAndContentAs(actualDir, filterLhs = { it.name != "a.txt" })286      expectDir.shouldHaveSameStructureAndContentAs(actualDir, filterRhs = { it.name != "a.txt" })287    }288  }289}290private fun File.createWithContent(content: String) {291  this.parentFile.mkdirs()292  createNewFile()293  writeText(content)294}295private fun File.createWithContent(content: ByteArray) {296  this.parentFile.mkdirs()297  createNewFile()298  writeBytes(content)299}300private fun isNotWindowsOrIsWindowsElevated(): Boolean {301  return if (!IS_OS_WINDOWS) {302    true303  } else {304    try {305      val p = Runtime.getRuntime().exec("""reg query "HKU\S-1-5-19"""")306      p.waitFor()307      0 == p.exitValue()308    } catch (ex: Exception) {309      println("Failed to determine if process had elevated permissions, assuming it does not.")310      false311    }312  }313}...matchers.kt
Source:matchers.kt  
1package tutorial.kotest2import io.kotest.assertions.throwables.shouldThrow3import io.kotest.assertions.throwables.shouldThrowAny4import io.kotest.assertions.throwables.shouldThrowExactly5import io.kotest.core.spec.style.DescribeSpec6import io.kotest.core.test.AssertionMode7import io.kotest.matchers.booleans.shouldBeTrue8import io.kotest.matchers.collections.shouldBeIn9import io.kotest.matchers.collections.shouldBeOneOf10import io.kotest.matchers.collections.shouldBeSameSizeAs11import io.kotest.matchers.collections.shouldBeSingleton12import io.kotest.matchers.collections.shouldBeSmallerThan13import io.kotest.matchers.collections.shouldBeSorted14import io.kotest.matchers.collections.shouldBeUnique15import io.kotest.matchers.collections.shouldContain16import io.kotest.matchers.collections.shouldContainAll17import io.kotest.matchers.collections.shouldContainAnyOf18import io.kotest.matchers.collections.shouldContainDuplicates19import io.kotest.matchers.collections.shouldContainExactly20import io.kotest.matchers.collections.shouldContainExactlyInAnyOrder21import io.kotest.matchers.collections.shouldContainInOrder22import io.kotest.matchers.collections.shouldContainNull23import io.kotest.matchers.collections.shouldEndWith24import io.kotest.matchers.collections.shouldHaveAtLeastSize25import io.kotest.matchers.collections.shouldHaveLowerBound26import io.kotest.matchers.collections.shouldHaveSingleElement27import io.kotest.matchers.collections.shouldHaveSize28import io.kotest.matchers.collections.shouldHaveUpperBound29import io.kotest.matchers.collections.shouldNotContainAnyOf30import io.kotest.matchers.collections.shouldNotHaveElementAt31import io.kotest.matchers.collections.shouldStartWith32import io.kotest.matchers.comparables.shouldBeEqualComparingTo33import io.kotest.matchers.comparables.shouldBeLessThanOrEqualTo34import io.kotest.matchers.date.shouldBeToday35import io.kotest.matchers.date.shouldHaveSameHoursAs36import io.kotest.matchers.doubles.Percentage37import io.kotest.matchers.doubles.beNaN38import io.kotest.matchers.doubles.plusOrMinus39import io.kotest.matchers.doubles.shouldBeNaN40import io.kotest.matchers.doubles.shouldNotBeNaN41import io.kotest.matchers.equality.shouldBeEqualToComparingFields42import io.kotest.matchers.equality.shouldBeEqualToComparingFieldsExcept43import io.kotest.matchers.equality.shouldBeEqualToIgnoringFields44import io.kotest.matchers.equality.shouldBeEqualToUsingFields45import io.kotest.matchers.file.shouldBeADirectory46import io.kotest.matchers.file.shouldBeAbsolute47import io.kotest.matchers.file.shouldExist48import io.kotest.matchers.file.shouldNotBeEmpty49import io.kotest.matchers.ints.beOdd50import io.kotest.matchers.ints.shouldBeBetween51import io.kotest.matchers.ints.shouldBeInRange52import io.kotest.matchers.ints.shouldBeLessThan53import io.kotest.matchers.ints.shouldBeLessThanOrEqual54import io.kotest.matchers.ints.shouldBeOdd55import io.kotest.matchers.ints.shouldBePositive56import io.kotest.matchers.ints.shouldBeZero57import io.kotest.matchers.iterator.shouldBeEmpty58import io.kotest.matchers.iterator.shouldHaveNext59import io.kotest.matchers.maps.shouldBeEmpty60import io.kotest.matchers.maps.shouldContain61import io.kotest.matchers.maps.shouldContainAll62import io.kotest.matchers.maps.shouldContainExactly63import io.kotest.matchers.maps.shouldContainKey64import io.kotest.matchers.nulls.shouldBeNull65import io.kotest.matchers.nulls.shouldNotBeNull66import io.kotest.matchers.shouldBe67import io.kotest.matchers.shouldNot68import io.kotest.matchers.shouldNotBe69import io.kotest.matchers.string.beEmpty70import io.kotest.matchers.string.shouldBeBlank71import io.kotest.matchers.string.shouldBeEmpty72import io.kotest.matchers.string.shouldBeEqualIgnoringCase73import io.kotest.matchers.string.shouldBeInteger74import io.kotest.matchers.string.shouldBeLowerCase75import io.kotest.matchers.string.shouldBeUpperCase76import io.kotest.matchers.string.shouldContain77import io.kotest.matchers.string.shouldContainADigit78import io.kotest.matchers.string.shouldContainIgnoringCase79import io.kotest.matchers.string.shouldContainOnlyDigits80import io.kotest.matchers.string.shouldContainOnlyOnce81import io.kotest.matchers.string.shouldEndWith82import io.kotest.matchers.string.shouldHaveLength83import io.kotest.matchers.string.shouldHaveLineCount84import io.kotest.matchers.string.shouldHaveMaxLength85import io.kotest.matchers.string.shouldHaveMinLength86import io.kotest.matchers.string.shouldHaveSameLengthAs87import io.kotest.matchers.string.shouldMatch88import io.kotest.matchers.string.shouldNotBeEmpty89import io.kotest.matchers.string.shouldStartWith90import io.kotest.matchers.throwable.shouldHaveCause91import io.kotest.matchers.throwable.shouldHaveCauseInstanceOf92import io.kotest.matchers.throwable.shouldHaveCauseOfType93import io.kotest.matchers.throwable.shouldHaveMessage94import io.kotest.matchers.types.shouldBeInstanceOf95import io.kotest.matchers.types.shouldBeSameInstanceAs96import io.kotest.matchers.types.shouldBeTypeOf97import io.kotest.matchers.uri.shouldHaveHost98import io.kotest.matchers.uri.shouldHavePort99import io.kotest.matchers.uri.shouldHaveScheme100import java.io.File101import java.net.URI102import java.time.LocalDate103import java.time.LocalTime104// https://kotest.io/docs/assertions/core-matchers.html105class MatchersTest : DescribeSpec({106    describe("general") {107        it("basics") {108            (1 == 1).shouldBeTrue()109            (2 + 2) shouldBe 4110            val foo: Any = "foobar"111            foo.shouldBeTypeOf<String>() shouldContain "fo"112            "".shouldBeEmpty()113            "x".shouldNot(beEmpty()) // manually negate114            "x".shouldNotBeEmpty() // reusable115            URI("https://tba") shouldHaveHost "tba"116            URI("https://tba:81") shouldHavePort 81117            URI("https://tba") shouldHaveScheme "https"118            File("/").apply {119                shouldExist()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()139            1.shouldBeOdd()140            (1.2).shouldBe(1.20001.plusOrMinus(Percentage(20.0)))141            (1.2).shouldNotBeNaN()142        }143        it("strings") {144            // generic: "abc" shouldBe "abc"145            "aBc" shouldBeEqualIgnoringCase "abc"146            "".shouldBeEmpty()147            " ".shouldBeBlank() // empty or whitespace148            "abc" shouldContain ("b")149            "aBc" shouldContainIgnoringCase "bc"150            "x-a-x" shouldContain """\-[a-z]\-""".toRegex()151            "-a-" shouldMatch """\-[a-z]\-""".toRegex()152            "abc" shouldStartWith ("a")153            "abc" shouldEndWith ("c")154            "ab aa" shouldContainOnlyOnce "aa"155            "abc".shouldBeLowerCase()156            "ABC".shouldBeUpperCase()157            "abc" shouldHaveLength 3158            "a\nb" shouldHaveLineCount 2159            "ab" shouldHaveMinLength 1 shouldHaveMaxLength 3160            "abc" shouldHaveSameLengthAs "foo"161            "1".shouldBeInteger()162            "12".shouldContainOnlyDigits()163            "abc1".shouldContainADigit() // at least one164        }165        it("types") {166            @Connotation167            open class SuperType()168            class SubType : SuperType()169            val sameRef = SuperType()170            sameRef.shouldBeSameInstanceAs(sameRef)171            val superType: SuperType = SubType()172            superType.shouldBeTypeOf<SubType>() // exact runtime match (SuperType won't work!)173            superType.shouldBeInstanceOf<SuperType>() // T or below174//            SubType().shouldHaveAnnotation(Connotation::class)175            val nullable: String? = null176            nullable.shouldBeNull()177        }178        it("collections") {179            emptyList<Int>().iterator().shouldBeEmpty()180            listOf(1).iterator().shouldHaveNext()181            listOf(1, 2) shouldContain 1 // at least182            listOf(1, 2) shouldContainExactly listOf(1, 2) // in-order; not more183            listOf(1, 2) shouldContainExactlyInAnyOrder listOf(2, 1) // out-order; not more184            listOf(0, 3, 0, 4, 0).shouldContainInOrder(3, 4) // possible items in between185            listOf(1) shouldNotContainAnyOf listOf(2, 3) // black list186            listOf(1, 2, 3) shouldContainAll listOf(3, 2) // out-order; more187            listOf(1, 2, 3).shouldBeUnique() // no duplicates188            listOf(1, 2, 2).shouldContainDuplicates() // at least one duplicate189            listOf(1, 2).shouldNotHaveElementAt(1, 3)190            listOf(1, 2) shouldStartWith 1191            listOf(1, 2) shouldEndWith 2192            listOf(1, 2) shouldContainAnyOf listOf(2, 3)193            val x = SomeType(1)194            x shouldBeOneOf listOf(x) // by reference/instance195            x shouldBeIn listOf(SomeType(1)) // by equality/structural196            listOf(1, 2, null).shouldContainNull()197            listOf(1) shouldHaveSize 1198            listOf(1).shouldBeSingleton() // size == 1199            listOf(1).shouldBeSingleton {200                it.shouldBeOdd()201            }202            listOf(1).shouldHaveSingleElement {203                beOdd().test(it).passed() // have to return a boolean here :-/204            }205            listOf(2, 3) shouldHaveLowerBound 1 shouldHaveUpperBound 4206            listOf(1) shouldBeSmallerThan listOf(1, 2)207            listOf(1) shouldBeSameSizeAs listOf(2)208            listOf(1, 2) shouldHaveAtLeastSize 1209            listOf(1, 2).shouldBeSorted()210            mapOf(1 to "a").shouldContain(1, "a") // at least this211            mapOf(1 to "a") shouldContainAll mapOf(1 to "a") // at least those212            mapOf(1 to "a") shouldContainExactly mapOf(1 to "a") // not more213            mapOf(1 to "a") shouldContainKey 1214            emptyMap<Any, Any>().shouldBeEmpty()215        }216        it("exceptions") {217            class SubException() : Exception()218            Exception("a") shouldHaveMessage "a" // same (not contains!)219            Exception("abc").message shouldContain "b"220            Exception("", Exception()).shouldHaveCause()221            Exception("symptom", Exception("cause")).shouldHaveCause {222                it.message shouldBe "cause"223            }224            Exception("", SubException()).shouldHaveCauseInstanceOf<Exception>() // T or subclass225            Exception("", SubException()).shouldHaveCauseOfType<SubException>() // exactly T226            shouldThrow<Exception> { // type or subtype227                throw SubException()228            }229            shouldThrowExactly<Exception> { // exactly that type (no subtype!)230                throw Exception()231            }232            shouldThrowAny { // don't care which233                throw Exception()234            }235        }236    }237    describe("advanced") {238        it("selective matcheres") {239            data class Foo(val p1: Int, val p2: Int)240            val foo1 = Foo(1, 1)241            val foo2 = Foo(1, 2)242            foo1.shouldBeEqualToUsingFields(foo2, Foo::p1)243            foo1.shouldBeEqualToIgnoringFields(foo2, Foo::p2)244            class Bar(val p1: Int, val p2: Int) // not a data class! no equals.245            val bar1a = Bar(1, 1)246            val bar1b = Bar(1, 1)247            bar1a shouldNotBe bar1b248            bar1a shouldBeEqualToComparingFields bar1b // "fake equals" (ignoring private properties)249            bar1a.shouldBeEqualToComparingFields(bar1b, false) // explicitly also check private props250            val bar2 = Bar(1, 2)251            bar1a.shouldBeEqualToComparingFieldsExcept(bar2, Bar::p2)252        }253    }254    // channels255    // concurrent, futures256    // result, optional257    // threads258    // reflection259    // statistic, regex260})261private data class SomeType(val value: Int = 1)262private annotation class Connotation...paths.kt
Source:paths.kt  
1package io.kotest.matchers.paths2import io.kotest.matchers.Matcher3import io.kotest.matchers.MatcherResult4import io.kotest.matchers.file.beLarger5import io.kotest.matchers.file.beEmptyDirectory6import io.kotest.matchers.file.containNFiles7import io.kotest.matchers.should8import io.kotest.matchers.shouldBe9import io.kotest.matchers.shouldNot10import io.kotest.matchers.shouldNotBe11import java.io.File12import java.nio.file.Files13import java.nio.file.Path14import kotlin.streams.toList15infix fun Path.shouldStartWithPath(file: File) = this should startWithPath(file)16infix fun Path.shouldNotStartWithPath(file: File) = this shouldNot startWithPath(file)17infix fun Path.shouldStartWithPath(prefix: String) = this should startWithPath(prefix)18infix fun Path.shouldNotStartWithPath(prefix: String) = this shouldNot startWithPath(prefix)19infix fun Path.shouldStartWithPath(path: Path) = this should startWithPath(path)20infix fun Path.shouldNotStartWithPath(path: Path) = this shouldNot startWithPath(path)21fun startWithPath(path: Path) = startWithPath(path.toString())22fun startWithPath(file: File) = startWithPath(file.toPath())23fun startWithPath(prefix: String) = object : Matcher<Path> {24   override fun test(value: Path): MatcherResult = MatcherResult(25      value.toString().startsWith(prefix),26      { "Path $value should start with $prefix" },27      { "Path $value should not start with $prefix" })28}29fun Path.shouldExist() = this should exist()30fun Path.shouldNotExist() = this shouldNot exist()31fun exist() = object : Matcher<Path> {32   override fun test(value: Path) =33      MatcherResult(34         Files.exists(value),35         { "Path $value should exist" },36         { "Path $value should not exist" })37}38infix fun Path.shouldHaveFileSize(size: Long) = this should haveFileSize(size)39infix fun Path.shouldNotHaveFileSize(size: Long) = this shouldNot haveFileSize(size)40fun haveFileSize(size: Long): Matcher<Path> = object : Matcher<Path> {41   override fun test(value: Path): MatcherResult = MatcherResult(42      Files.size(value) == size,43      { "Path $value should have size $size" },44      { "Path $value should not have size $size" })45}46fun Path.shouldBeADirectory() = this should aDirectory()47fun Path.shouldNotBeADirectory() = this shouldNot aDirectory()48fun aDirectory(): Matcher<Path> = object : Matcher<Path> {49   override fun test(value: Path): MatcherResult = MatcherResult(50      Files.isDirectory(value),51      { "File $value should be a directory" },52      { "File $value should not be a directory" })53}54fun Path.shouldBeAFile() = this should aFile()55fun Path.shouldNotBeAFile() = this shouldNot aFile()56fun aFile(): Matcher<Path> = object : Matcher<Path> {57   override fun test(value: Path): MatcherResult = MatcherResult(58      !Files.isDirectory(value),59      { "File $value should be a directory" },60      { "File $value should not be a directory" })61}62fun Path.shouldBeAbsolute() = this should beAbsolute()63fun Path.shouldNotBeAbsolute() = this shouldNot beAbsolute()64fun beAbsolute(): Matcher<Path> = object : Matcher<Path> {65   override fun test(value: Path): MatcherResult =66      MatcherResult(67         value.isAbsolute,68         { "Path $value should be absolute" },69         { "Path $value should not be absolute" })70}71fun Path.shouldBeRelative() = this should beRelative()72fun Path.shouldNotBeRelative() = this shouldNot beRelative()73fun beRelative(): Matcher<Path> = object : Matcher<Path> {74   override fun test(value: Path): MatcherResult =75      MatcherResult(76         !value.isAbsolute,77         { "Path $value should be relative" },78         { "Path $value should not be relative" })79}80fun Path.shouldBeReadable() = this should beReadable()81fun Path.shouldNotBeReadable() = this shouldNot beReadable()82fun beReadable(): Matcher<Path> = object : Matcher<Path> {83   override fun test(value: Path): MatcherResult =84      MatcherResult(85         Files.isReadable(value),86         { "Path $value should be readable" },87         { "Path $value should not be readable" }88      )89}90fun Path.shouldBeWriteable() = this should beWriteable()91fun Path.shouldNotBeWriteable() = this shouldNot beWriteable()92fun beWriteable(): Matcher<Path> = object : Matcher<Path> {93   override fun test(value: Path): MatcherResult =94      MatcherResult(95         Files.isWritable(value),96         { "Path $value should be writeable" },97         { "Path $value should not be writeable" }98      )99}100fun Path.shouldBeExecutable() = this should beExecutable()101fun Path.shouldNotBeExecutable() = this shouldNot beExecutable()102fun beExecutable(): Matcher<Path> = object : Matcher<Path> {103   override fun test(value: Path): MatcherResult = MatcherResult(104      Files.isExecutable(value),105      { "Path $value should be executable" },106      { "Path $value should not be executable" }107   )108}109infix fun Path.shouldContainNFiles(n: Int) = this.toFile() shouldBe containNFiles(n)110infix fun Path.shouldNotContainNFiles(n: Int) = this.toFile() shouldNotBe containNFiles(n)111@Deprecated(message ="checks if a directory is empty. Deprecated since 4.3.", replaceWith = ReplaceWith("shouldBeEmptyDirectory()"))112fun Path.shouldBeNonEmptyDirectory() = this.toFile() shouldNot beEmptyDirectory()113@Deprecated(message ="checks if a directory is not empty. Deprecated since 4.3.", replaceWith = ReplaceWith("shouldBeNonEmptyDirectory()"))114fun Path.shouldNotBeNonEmptyDirectory() = this.toFile() should beEmptyDirectory()115fun Path.shouldBeEmptyDirectory() = this.toFile() should beEmptyDirectory()116fun Path.shouldNotBeEmptyDirectory() = this.toFile() shouldNot beEmptyDirectory()117fun Path.shouldBeHidden() = this should beHidden()118fun Path.shouldNotBeHidden() = this shouldNot beHidden()119fun beHidden(): Matcher<Path> = object : Matcher<Path> {120   override fun test(value: Path): MatcherResult =121      MatcherResult(122         Files.isHidden(value),123         { "Path $value should be hidden" },124         { "Path $value should not be hidden" })125}126fun Path.shouldBeCanonical() = this should beCanonicalPath()127fun Path.shouldNotBeCanonical() = this shouldNot beCanonicalPath()128fun beCanonicalPath(): Matcher<Path> = object : Matcher<Path> {129   override fun test(value: Path): MatcherResult = MatcherResult(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 ""205      val filesString = fileList.sorted().joinToString(", ")206      return "$fileString $filesString should$negativeWord exist in $path"207   }208}209fun Path.shouldBeSymbolicLink() = this should beSymbolicLink()210fun Path.shouldNotBeSymbolicLink() = this shouldNot beSymbolicLink()211fun beSymbolicLink() = object : Matcher<Path> {212   override fun test(value: Path) = MatcherResult(213      Files.isSymbolicLink(value),214      { "Path $value should be a symbolic link" },215      { "Path $value should not be a symbolic link" }216   )217}218infix fun Path.shouldHaveParent(name: String) = this should haveParent(name)219infix fun Path.shouldNotHaveParent(name: String) = this shouldNot haveParent(name)220fun haveParent(name: String) = object : Matcher<Path> {221   private fun isParentEqualExpected(parent: Path?): Boolean {222      if (parent == null) return false223      return parent.fileName?.toString() == name || isParentEqualExpected(parent.parent)224   }225   override fun test(value: Path) = MatcherResult(226      isParentEqualExpected(value.parent),227      { "Path $value should have parent $name" },228      { "Path $value should not have parent $name" }229   )230}...LocationsKtTest.kt
Source:LocationsKtTest.kt  
1package com.bkahlert.kommons2import io.kotest.inspectors.shouldForAll3import io.kotest.matchers.collections.shouldContain4import io.kotest.matchers.collections.shouldContainExactly5import io.kotest.matchers.collections.shouldContainExactlyInAnyOrder6import io.kotest.matchers.collections.shouldHaveSize7import io.kotest.matchers.collections.shouldNotContain8import io.kotest.matchers.paths.shouldBeADirectory9import io.kotest.matchers.paths.shouldBeAFile10import io.kotest.matchers.paths.shouldBeAbsolute11import io.kotest.matchers.paths.shouldExist12import io.kotest.matchers.paths.shouldNotExist13import io.kotest.matchers.should14import io.kotest.matchers.shouldBe15import org.junit.jupiter.api.Nested16import org.junit.jupiter.api.Test17import org.junit.jupiter.api.io.TempDir18import java.nio.file.Path19import java.nio.file.attribute.PosixFilePermission20import kotlin.io.path.getPosixFilePermissions21import kotlin.io.path.pathString22import kotlin.time.Duration23import kotlin.time.Duration.Companion.days24import kotlin.time.Duration.Companion.hours25import kotlin.time.Duration.Companion.minutes26class LocationsKtTest {27    @Nested28    inner class DefaultLocations {29        @Test30        fun paths() = tests {31            listOf(32                Locations.Default.Work,33                Locations.Default.Home,34                Locations.Default.Temp,35                Locations.Default.JavaHome,36            ).shouldForAll {37                it.shouldBeAbsolute()38                it.shouldExist()39                it.shouldBeADirectory()40            }41        }42    }43    @Nested44    inner class RandomPath {45        @Test46        fun `should create inside receiver path`(@TempDir tempDir: Path) = tests {47            tempDir.randomPath().isSubPathOf(tempDir) shouldBe true48        }49        @Test50        fun `should not exist`(@TempDir tempDir: Path) = tests {51            tempDir.randomPath().shouldNotExist()52        }53    }54    @Nested55    inner class RandomDirectory {56        @Test57        fun `should create inside receiver path`(@TempDir tempDir: Path) = tests {58            tempDir.randomDirectory().isSubPathOf(tempDir) shouldBe true59        }60        @Test61        fun `should create directory`(@TempDir tempDir: Path) = tests {62            tempDir.randomDirectory().shouldBeADirectory()63        }64        @Test65        fun `should create directory inside non-existent parent`(@TempDir tempDir: Path) = tests {66            tempDir.randomPath().randomDirectory().shouldBeADirectory()67        }68    }69    @Nested70    inner class RandomFile {71        @Test72        fun `should create inside receiver path`(@TempDir tempDir: Path) = tests {73            tempDir.randomFile().isSubPathOf(tempDir) shouldBe true74        }75        @Test76        fun `should create regular file`(@TempDir tempDir: Path) = tests {77            tempDir.randomFile().shouldBeAFile()78        }79        @Test80        fun `should create regular file inside non-existent parent`(@TempDir tempDir: Path) = tests {81            tempDir.randomPath().randomFile().shouldBeAFile()82        }83    }84    @Nested85    inner class TempDirectory {86        @Test87        fun `should create inside temp directory`() {88            tempDir().deleteOnExit().isSubPathOf(Locations.Default.Temp) shouldBe true89        }90        @Test91        fun `should create directory`() {92            tempDir().deleteOnExit().shouldBeADirectory()93        }94        @Test95        fun `should have exclusive rights`() {96            tempDir().deleteOnExit().getPosixFilePermissions() shouldContainExactly setOf(97                PosixFilePermission.OWNER_READ,98                PosixFilePermission.OWNER_WRITE,99                PosixFilePermission.OWNER_EXECUTE100            )101        }102        @Test103        fun `should create directory inside receiver path`(@TempDir tempDir: Path) = tests {104            tempDir.tempDir() should {105                it.isSubPathOf(tempDir) shouldBe true106                it.shouldBeADirectory()107                it.getPosixFilePermissions() shouldContainExactly setOf(108                    PosixFilePermission.OWNER_READ,109                    PosixFilePermission.OWNER_WRITE,110                    PosixFilePermission.OWNER_EXECUTE111                )112            }113        }114        @Test115        fun `should create directory inside non-existent parent`(@TempDir tempDir: Path) = tests {116            val nonExistentParent = tempDir.randomPath()117            nonExistentParent.tempDir() should {118                it.isSubPathOf(nonExistentParent) shouldBe true119                it.shouldBeADirectory()120                it.getPosixFilePermissions() shouldContainExactly setOf(121                    PosixFilePermission.OWNER_READ,122                    PosixFilePermission.OWNER_WRITE,123                    PosixFilePermission.OWNER_EXECUTE124                )125            }126        }127    }128    @Nested129    inner class TempFile {130        @Test131        fun `should create inside temp directory`() {132            tempFile().deleteOnExit().isSubPathOf(Locations.Default.Temp) shouldBe true133        }134        @Test135        fun `should create file`() {136            tempFile().deleteOnExit().shouldBeAFile()137        }138        @Test139        fun `should have exclusive rights`() {140            tempFile().deleteOnExit().getPosixFilePermissions() shouldContainExactly setOf(141                PosixFilePermission.OWNER_READ,142                PosixFilePermission.OWNER_WRITE,143                PosixFilePermission.OWNER_EXECUTE144            )145        }146        @Test147        fun `should create file inside receiver path`(@TempDir tempDir: Path) = tests {148            tempDir.tempFile() should {149                it.isSubPathOf(tempDir) shouldBe true150                it.shouldBeAFile()151                it.getPosixFilePermissions() shouldContainExactly setOf(152                    PosixFilePermission.OWNER_READ,153                    PosixFilePermission.OWNER_WRITE,154                    PosixFilePermission.OWNER_EXECUTE155                )156            }157        }158        @Test159        fun `should create file inside non-existent parent`(@TempDir tempDir: Path) = tests {160            val nonExistentParent = tempDir.randomPath()161            nonExistentParent.tempFile() should {162                it.isSubPathOf(nonExistentParent) shouldBe true163                it.shouldBeAFile()164                it.getPosixFilePermissions() shouldContainExactly setOf(165                    PosixFilePermission.OWNER_READ,166                    PosixFilePermission.OWNER_WRITE,167                    PosixFilePermission.OWNER_EXECUTE168                )169            }170        }171    }172    @Nested173    inner class RunWithTempDir {174        @Test175        fun `should run inside temp dir`() {176            val tempDir: Path = runWithTempDir {177                this should {178                    it.isSubPathOf(Locations.Default.Temp) shouldBe true179                    it.shouldBeADirectory()180                }181                this182            }183            tempDir.shouldNotExist()184        }185    }186    @Nested187    inner class AutoCleanup {188        @Test189        fun `should delete if empty`(@TempDir tempDir: Path) = tests {190            tempDir.cleanUp(Duration.ZERO, 0).shouldNotExist()191        }192        @Test193        fun `should keep at most specified number of files`(@TempDir tempDir: Path) = tests {194            (1..10).forEach { _ -> tempDir.tempFile() }195            tempDir.listDirectoryEntriesRecursively() shouldHaveSize 10196            tempDir.cleanUp(Duration.ZERO, 5).listDirectoryEntriesRecursively() shouldHaveSize 5197        }198        @Test199        fun `should not delete if less files than maximum`(@TempDir tempDir: Path) = tests {200            (1..10).forEach { _ -> tempDir.tempFile() }201            tempDir.listDirectoryEntriesRecursively() shouldHaveSize 10202            tempDir.cleanUp(Duration.ZERO, 100).listDirectoryEntriesRecursively() shouldHaveSize 10203        }204        @Test205        fun `should not delete files younger than specified age`(@TempDir tempDir: Path) = tests {206            val a = tempDir.tempFile("a").apply { age = 30.minutes }207            val b = tempDir.tempFile("b").apply { age = 1.5.hours }208            tempDir.tempFile("c").apply { age = 1.days }209            tempDir.cleanUp(2.hours, 0).listDirectoryEntriesRecursively().map { it.pathString }.shouldContainExactlyInAnyOrder(210                a.pathString,211                b.pathString212            )213        }214        @Test215        fun `should delete empty directories`(@TempDir tempDir: Path) = tests {216            val emptyDir = tempDir.tempDir("empty")217            val file = tempDir.tempFile()218            tempDir.cleanUp(2.hours, 0).listDirectoryEntriesRecursively().map { it.pathString } should {219                it shouldNotContain emptyDir.pathString220                it shouldContain file.pathString221            }222        }223    }224}...File.shouldBeAbsolute
Using AI Code Generation
1@file:Suppress("UnstableApiUsage")2import io.kotest.matchers.file.shouldBeAbsolute3import io.kotest.matchers.file.shouldBeDirectory4import io.kotest.matchers.file.shouldBeFile5import io.kotest.matchers.file.shouldBeRelative6import io.kotest.matchers.file.shouldBeSymbolicLink7import io.kotest.matchers.file.shouldBeWritable8import io.kotest.matchers.file.shouldExist9import io.kotest.matchers.file.shouldHaveExtension10import io.kotest.matchers.file.shouldHaveName11import io.kotest.matchers.file.shouldHaveParent12import io.kotest.matchers.file.shouldHaveParentNamed13import io.kotest.matchers.file.shouldHaveSize14import io.kotest.matchers.file.shouldHaveTheSameTextualContentAs15import io.kotest.matchers.file.shouldNotBeAbsolute16import io.kotest.matchers.file.shouldNotBeDirectory17import io.kotest.matchers.file.shouldNotBeFile18import io.kotest.matchers.file.shouldNotBeRelative19import io.kotest.matchers.file.shouldNotBeSymbolicLink20import io.kotest.matchers.file.shouldNotBeWritable21import io.kotest.matchers.file.shouldNotExist22import io.kotest.matchers.file.shouldNotHaveExtension23import io.kotest.matchers.file.shouldNotHaveName24import io.kotest.matchers.file.shouldNotHaveParent25import io.kotest.matchers.file.shouldNotHaveParentNamed26import io.kotest.matchers.file.shouldNotHaveSize27import io.kotest.matchers.file.shouldNotHaveTheSameTextualContentAs28import io.kotest.matchers.file.shouldNotStartWithPath29import io.kotest.matchers.file.shouldStartWithPath30import io.kotest.matchers.file.shouldWrite31import io.kotest.matchers.file.shouldWriteLines32import io.kotest.matchers.file.shouldWriteLinesWithSeparators33import io.kotest.matchers.file.shouldWriteText34import io.kotest.matchers.file.shouldWriteTextWithSeparators35import io.kotest.matchers.file.shouldWriteWithSeparators36import io.kotest.matchers.file.shouldWriteWithSeparatorsAndTrailingNewLine37import io.kotest.matchers.file.shouldWriteWithTrailingNewLine38import io.kotest.matchers.file.shouldWriteWithoutFile.shouldBeAbsolute
Using AI Code Generation
1file.shouldBeAbsolute()2file.shouldBeRelative()3file.shouldBeReadable()4file.shouldBeWritable()5file.shouldBeExecutable()6file.shouldBeHidden()7file.shouldBeHidden()8file.shouldBeHidden()9file.shouldBeHidden()10file.shouldBeHidden()11file.shouldBeHidden()12file.shouldBeHidden()13file.shouldBeHidden()14file.shouldBeHidden()File.shouldBeAbsolute
Using AI Code Generation
1File( "C:\\Users\\user" ).shouldBeAbsolute()2File( "C:\\Users\\user" ).shouldBeRelative()3File( "C:\\Users\\user" ).shouldBeHidden()4File( "C:\\Users\\user" ).shouldBeReadable()5File( "C:\\Users\\user" ).shouldBeWritable()6File( "C:\\Users\\user" ).shouldBeExecutable()7File( "C:\\Users\\user" ).shouldBeHidden()8File( "C:\\Users\\user" ).shouldBeHidden()9File( "C:\\Users\\user" ).shouldBeHidden()10File( "C:\\Users\\user" ).shouldBeHidden()11File( "C:\\Users\\user" ).shouldBeHidden()12File( "C:\\Users\\user" ).shouldBeHidden()13File( "C:\\Users\\user" ).shouldBeHidden()14File( "C:\\Users\\user" ).shouldBeHidden()15File( "C:\\Users\\user" ).shouldBeHidden()File.shouldBeAbsolute
Using AI Code Generation
1File("C:\\path\\to\\file.txt").shouldBeAbsolute()2File("file.txt").shouldNotBeAbsolute()3File("/path/to/file.txt").shouldBeAbsolute()4File("/path/to/file.txt").shouldNotBeAbsolute()5File("C:\\path\\to\\file.txt").shouldNotBeRelative()6File("file.txt").shouldBeRelative()7File("/path/to/file.txt").shouldNotBeRelative()8File("/path/to/file.txt").shouldBeRelative()9File("C:\\path\\to\\file.txt").shouldNotBeEmpty()10File("file.txt").shouldBeEmpty()11File("/path/to/file.txt").shouldNotBeEmpty()12File("/path/to/file.txt").shouldBeEmpty()13File("C:\\path\\to\\file.txt").shouldNotBeHidden()14File("file.txt").shouldBeHidden()15File("/path/to/file.txt").shouldNotBeHidden()16File("/path/to/file.txt").shouldBeHidden()17File("C:\\path\\to\\file.txt").shouldNotBeReadable()18File("file.txt").shouldBeReadable()19File("/path/to/file.txt").shouldNotBeReadable()20File("/path/to/file.txt").shouldBeReadable()21File("C:\\path\\to\\file.txt").shouldNotBeWritable()22File("file.txt").shouldBeWritable()23File("/path/to/file.txt").shouldNotBeWritable()24File("/path/to/file.txt").shouldBeWritable()25File("C:\\path\\to\\file.txt").shouldNotBeExecutable()26File("file.txt").shouldBeExecutable()27File("/path/to/file.txt").shouldNotBeExecutable()28File("/path/to/file.txt").shouldBeExecutable()29File("C:\\path\\to\\file.txt").shouldNotBeHidden()30File("file.txt").shouldBeHidden()31File("/path/to/fileFile.shouldBeAbsolute
Using AI Code Generation
1fun `test file should be absolute`() {2    File("C:\\test.txt").shouldBeAbsolute()3}4fun `test file should be relative`() {5    File("test.txt").shouldBeRelative()6}7fun `test file should be readable`() {8    File("C:\\test.txt").shouldBeReadable()9}10fun `test file should be writable`() {11    File("C:\\test.txt").shouldBeWritable()12}13fun `test file should be executable`() {14    File("C:\\test.txt").shouldBeExecutable()15}16fun `test file should be hidden`() {17    File("C:\\test.txt").shouldBeHidden()18}19fun `test file should be symlink`() {20    File("C:\\test.txt").shouldBeSymlink()21}22fun `test file should be hidden`() {23    File("C:\\test.txt").shouldBeHidden()24}25fun `test file should be symlink`() {26    File("C:\\test.txt").shouldBeSymlink()27}28fun `test file should be hidden`() {29    File("C:\\test.txt").shouldBeHidden()30}31fun `test file should be symlink`() {32    File("C:\\test.txt").shouldBeSymlink()33}34fun `test file should be hidden`()File.shouldBeAbsolute
Using AI Code Generation
1File("c:/users/john").shouldBeAbsolute()2File("/users/john").shouldBeAbsolute()3File("users/john").shouldNotBeAbsolute()4File("c:/users/john").shouldBeDirectory()5File("c:/users/john/myfile.txt").shouldNotBeDirectory()6File("c:/users/john/myfile.txt").shouldBeExecutable()7File("c:/users/john/myfile.txt").shouldNotBeExecutable()8File("c:/users/john/myfile.txt").shouldBeHidden()9File("c:/users/john/myfile.txt").shouldNotBeHidden()10File("c:/users/john/myfile.txt").shouldBeReadable()11File("c:/users/john/myfile.txt").shouldNotBeReadable()12File("c:/users/john").shouldNotBeRelative()13File("users/john").shouldBeRelative()14File("c:/users/john/myfile.txt").shouldBeWritable()15File("c:/users/john/myfile.txt").shouldNotBeWritable()16File("c:/users/john/myfile.txt").shouldHaveExtension("txt")17File("c:/users/john/myfile.txt").shouldNotHaveExtension("txt")18File("c:/users/john/myfile.txt").shouldHaveName("myfile.txt")19File("c:/users/john/myfile.txt").shouldNotHaveName("myfile.txt")20File("c:/users/john/myfile.txt").shouldHaveParent("c:/users/john")21File("c:/users/john/myfile.txt").shouldNotHaveParent("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!!
