How to use exist method of io.kotest.matchers.paths.paths class

Best Kotest code snippet using io.kotest.matchers.paths.paths.exist

FileMatchersTest.kt

Source:FileMatchersTest.kt Github

copy

Full Screen

...4import 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") {...

Full Screen

Full Screen

GitHubFSIntegTest.kt

Source:GitHubFSIntegTest.kt Github

copy

Full Screen

...131 runAndPrintOutput(repoFile, "git", "add", file1.path)132 runAndPrintOutput(repoFile, "git", "commit", "-m", "a")133 // Clone the repo on master again134 fs.cloneRepo(testRepoUrlHTTPS, "master")135 // Ensure that file does not exist136 file1.shouldNotExist()137 }138 }139 @Test140 fun `test deleteCache`(@TempDir tempDir: File) {141 val fs = GitHubFS(AnonymousCredentialsProvider, tempDir.toPath())142 val repoPath = Paths.get(tempDir.absolutePath, orgName, repoName)143 val repo = repoPath.toFile().apply { mkdirs() }144 val fileInRepo = Paths.get(repoPath.toString(), "fileA.txt").toFile().apply {145 writeText("")146 }147 fileInRepo.shouldExist()148 fs.deleteCache()149 fileInRepo.shouldNotExist()...

Full Screen

Full Screen

CandidKtPluginSpec.kt

Source:CandidKtPluginSpec.kt Github

copy

Full Screen

1package com.github.seniorjoinu.candid.plugin2import io.kotest.core.spec.IsolationMode3import io.kotest.core.spec.style.FreeSpec4import io.kotest.matchers.file.shouldExist5import io.kotest.matchers.file.shouldNotHaveFileSize6import io.kotest.matchers.shouldBe7import io.kotest.matchers.string.shouldContain8import org.gradle.internal.impldep.org.junit.rules.TemporaryFolder9import org.gradle.testkit.runner.BuildResult10import org.gradle.testkit.runner.GradleRunner11import org.gradle.testkit.runner.TaskOutcome12import java.io.File13import java.io.PrintWriter14import java.nio.file.Paths15import java.util.Locale16/**17 * System under specification: {@link CandidKtPlugin}; strictly speaking this a functional test, although it was added to the unit test source set.18 */19class CandidKtPluginSpec : FreeSpec({20 isolationMode = IsolationMode.InstancePerLeaf21 val didName = "greet"22 val packageName = "tld.d.etc"23 "given a project dir" - {24 val projectDir = TemporaryFolder()25 projectDir.create()26 "and the plugin is applied" - {27 val buildFile = projectDir.newFile("build.gradle")28 buildFile.writeText("""29 plugins {30 id 'com.github.seniorjoinu.candid'31 }32 candid {33 sourceSets {34 test35 }36 }37 """.trimIndent())38 buildFile.appendText(System.lineSeparator())39 "positive executing 'gradle tasks'" {40 val taskName = "tasks"41 val arguments = listOf(taskName)42 val result = build(projectDir.root, arguments)43 result.task(":$taskName")?.outcome shouldBe TaskOutcome.SUCCESS44 result.output shouldContain "${CANDID_GROUP_NAME.replaceFirstChar { if (it.isLowerCase()) it.titlecase(Locale.getDefault()) else it.toString() }} tasks"45 result.output shouldContain "$CANDID_TASK_NAME - Generates Kotlin sources from Candid language files resolved from the 'main' Candid source set."46 result.output shouldContain "generateTestCandid - Generates Kotlin sources from Candid language files resolved from the 'test' Candid source set."47 }48 "positive executing 'gradle help --task generateCandid'" {49 val taskName = "help"50 val arguments = listOf(taskName, "--task", CANDID_TASK_NAME)51 val result = build(projectDir.root, arguments)52 result.task(":$taskName")?.outcome shouldBe TaskOutcome.SUCCESS53 result.output shouldContain "Detailed task information for $CANDID_TASK_NAME"54 result.output shouldContain "Path${System.lineSeparator()} :$CANDID_TASK_NAME"55 result.output shouldContain "Description${System.lineSeparator()} Generates Kotlin sources from Candid language files resolved from the 'main' Candid source set."56 result.output shouldContain "Group${System.lineSeparator()} $CANDID_GROUP_NAME"57 }58 "positive executing 'gradle generateCandid' with defaults" {59 val didFile = createDidFile(projectDir.root, didName, "src", "main", "candid")60 val ktFile = Paths.get(projectDir.root.canonicalPath, "build/$CANDID_DESTINATION_PREFIX_KOTLIN/main", "${didName}.did.kt").toFile()61 val arguments = listOf(CANDID_TASK_NAME, "--info", "--warning-mode", "all")62 val result = build(projectDir.root, arguments)63 result.task(":$CANDID_TASK_NAME")?.outcome shouldBe TaskOutcome.SUCCESS64 ktFile.shouldExist()65 ktFile.shouldNotHaveFileSize(0)66 didFile.delete()67 }68 "positive executing 'gradle generateCandid' with reconfigured destination directory" {69 val didFile = createDidFile(projectDir.root, didName, "src", "main", "candid")70 val ktFile = Paths.get(projectDir.root.canonicalPath, "build/output", packageName.replace('.', '/'), "${didName}.did.kt").toFile()71 buildFile.appendText("""72 candid {73 sourceSets.main.candid.destinationDirectory.fileValue(project.file('build/output'))74 genPackage = "$packageName"75 }76 """.trimIndent())77 val arguments = listOf(CANDID_TASK_NAME, "--info", "--warning-mode", "all")78 val result = build(projectDir.root, arguments)79 result.task(":$CANDID_TASK_NAME")?.outcome shouldBe TaskOutcome.SUCCESS80 ktFile.shouldExist()81 ktFile.shouldNotHaveFileSize(0)82 didFile.delete()83 }84 "positive executing 'gradle generateCandid' with nested did files under different source directories" {85 val didFile = createDidFile(projectDir.root, didName, "src", "main", "candid", "tld", "d", "etc")86 val otherDidFile = createDidFile(projectDir.root, "other-greet", "src", "other", "candid", "tld", "d", "etc")87 val ktFile = Paths.get(projectDir.root.canonicalPath, "build/$CANDID_DESTINATION_PREFIX_KOTLIN/main", "tld/d/etc", "${didName}.did.kt").toFile()88 val otherKtFile = Paths.get(projectDir.root.canonicalPath, "build/$CANDID_DESTINATION_PREFIX_KOTLIN/main", "tld/d/etc", "other-greet.did.kt").toFile()89 buildFile.appendText("""90 candid {91 sourceSets.main.candid.srcDir 'src/other/candid'92 }93 """.trimIndent())94 val arguments = listOf(CANDID_TASK_NAME, "--info", "--warning-mode", "all")95 val result = build(projectDir.root, arguments)96 result.task(":$CANDID_TASK_NAME")?.outcome shouldBe TaskOutcome.SUCCESS97 ktFile.shouldExist()98 otherKtFile.shouldExist()99 ktFile.shouldNotHaveFileSize(0)100 otherKtFile.shouldNotHaveFileSize(0)101 didFile.delete()102 otherDidFile.delete()103 }104 "positive executing 'gradle generateIntegTestCandid'" {105 val taskName = "generateIntegTestCandid"106 val didFile = createDidFile(projectDir.root, didName, "src", "integTest", "candid")107 val ktFile = Paths.get(projectDir.root.canonicalPath, "build/$CANDID_DESTINATION_PREFIX_KOTLIN/integTest", "${didName}.did.kt").toFile()108 buildFile.appendText("""109 candid {110 sourceSets {111 integTest112 }113 }114 """.trimIndent())115 val arguments = listOf(taskName, "--info", "--warning-mode", "all")116 val result = build(projectDir.root, arguments)117 result.task(":$taskName")?.outcome shouldBe TaskOutcome.SUCCESS118 ktFile.shouldExist()119 ktFile.shouldNotHaveFileSize(0)120 didFile.delete()121 }122 buildFile.delete()123 }124 projectDir.delete()125 }126})127fun createDidFile(projectDir: File, didName: String, vararg folderNames: String): File {128 val sourceSetDir = File(projectDir, folderNames.joinToString("/"))129 sourceSetDir.mkdirs()130 val didFile = File(sourceSetDir, "${didName}.did")131 didFile.writeText("""132 service : {133 "greet": (text) -> (text);134 }135 """.trimIndent())136 return didFile137}138fun build(projectDir: File, arguments: List<String>): BuildResult {139 return GradleRunner.create().withProjectDir(projectDir).forwardStdOutput(PrintWriter(System.out)).forwardStdError(PrintWriter(System.err)).withPluginClasspath().withArguments(arguments).build()140}...

Full Screen

Full Screen

AnimatedLEDStripServerTest.kt

Source:AnimatedLEDStripServerTest.kt Github

copy

Full Screen

1/*2 * Copyright (c) 2018-2021 AnimatedLEDStrip3 *4 * Permission is hereby granted, free of charge, to any person obtaining a copy5 * of this software and associated documentation files (the "Software"), to deal6 * in the Software without restriction, including without limitation the rights7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell8 * copies of the Software, and to permit persons to whom the Software is9 * furnished to do so, subject to the following conditions:10 *11 * The above copyright notice and this permission notice shall be included in12 * all copies or substantial portions of the Software.13 *14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN20 * THE SOFTWARE.21 */22package animatedledstrip.test23import animatedledstrip.animations.parameters.PercentDistance24import animatedledstrip.colors.ColorContainer25import animatedledstrip.colors.ccpresets.randomColorList26import animatedledstrip.leds.animationmanagement.AnimationToRunParams27import animatedledstrip.leds.stripmanagement.NativeLEDStrip28import animatedledstrip.server.AnimatedLEDStripServer29import io.kotest.assertions.throwables.shouldThrow30import io.kotest.core.spec.style.StringSpec31import io.kotest.matchers.booleans.shouldBeFalse32import io.kotest.matchers.booleans.shouldBeTrue33import io.kotest.matchers.maps.shouldContainKeys34import io.kotest.matchers.paths.shouldExist35import io.kotest.matchers.paths.shouldNotExist36import kotlinx.coroutines.delay37import java.nio.file.Paths38class AnimatedLEDStripServerTest : StringSpec(39 {40 "test start stop" {41 val server = newTestServer()42 server.start()43 server.running.shouldBeTrue()44 server.leds.renderer.isRendering.shouldBeTrue()45 server.stop()46 server.running.shouldBeFalse()47 server.leds.renderer.isRendering.shouldBeFalse()48 }49 "test bad NativeLEDStrip constructor" {50 class BadStrip : NativeLEDStrip {51 override val numLEDs: Int = 052 override fun close() {}53 override fun render() {}54 override fun setPixelColor(pixel: Int, color: Int) {}55 }56 shouldThrow<IllegalArgumentException> {57 AnimatedLEDStripServer(arrayOf(), BadStrip::class)58 }59 class BadStrip2(override val numLEDs: Int) : NativeLEDStrip {60 override fun close() {}61 override fun render() {}62 override fun setPixelColor(pixel: Int, color: Int) {}63 }64 shouldThrow<IllegalArgumentException> {65 AnimatedLEDStripServer(arrayOf(), BadStrip2::class)66 }67 }68 "test save persistent animation".config(enabled = false) {69 val server = newTestServer("--persist", "--persist-dir", "src/jvmTest/resources/persist-save")70 val anim = AnimationToRunParams("Runway Lights", ColorContainer.randomColorList(), id = "test",71 doubleParams = mutableMapOf("maximumInfluence" to 3.0, "spacing" to 10.0),72 distanceParams = mutableMapOf("offset" to PercentDistance(0.0,73 50.0,74 0.0))).prepare(75 server.leds.sectionManager.getSection(""))76 server.savePersistentAnimation(anim)77 delay(500)78 Paths.get("src/jvmTest/resources/persist-save/.animations/test.json").shouldExist()79 }80 "test delete persistent animation".config(enabled = false) {81 val server = newTestServer("--persist", "--persist-dir", "src/jvmTest/resources/persist-delete")82 val anim = AnimationToRunParams("Runway Lights", ColorContainer.randomColorList(), id = "test2",83 doubleParams = mutableMapOf("maximumInfluence" to 3.0, "spacing" to 10.0),84 distanceParams = mutableMapOf("offset" to PercentDistance(0.0,85 50.0,86 0.0)))87 .prepare(server.leds.sectionManager.getSection(""))88 server.savePersistentAnimation(anim)89 delay(500)90 Paths.get("src/jvmTest/resources/persist-delete/.animations/test2.json").shouldExist()91 delay(500)92 server.deletePersistentAnimation(anim)93 delay(500)94 Paths.get("src/jvmTest/resources/persist-delete/.animations/test2.json").shouldNotExist()95 }96 "test load persistent animations" {97 val server = newTestServer("--persist", "--persist-dir", "src/jvmTest/resources/persist")98 server.loadPersistentAnimations()99 delay(1000)100 server.leds.animationManager.runningAnimations.shouldContainKeys("23602685",101 "40202146",102 "44470329",103 "51140794",104 "65067451",105 "84029121")106 }107 }108)...

Full Screen

Full Screen

specs.kt

Source:specs.kt Github

copy

Full Screen

...22import io.kotest.core.test.TestType23import io.kotest.matchers.and24import io.kotest.matchers.paths.aFile25import io.kotest.matchers.paths.beReadable26import io.kotest.matchers.paths.exist27import io.kotest.matchers.should28import org.gradle.testkit.runner.BuildResult29import org.gradle.testkit.runner.GradleRunner30import java.io.File31import java.nio.charset.Charset32abstract class FunctionalSpec(private val suffix: String = "gradle") : WordSpec() {33 lateinit var testProjectDir: File34 lateinit var testkitDir: File35 lateinit var propertiesFile: File36 lateinit var settingsFile: File37 lateinit var buildFile: File38 init {39 beforeTest {40 if (it.type !== TestType.Test) {41 return@beforeTest42 }43 // create temporary project root and gradle files44 testProjectDir = createTempDir("test-", "", File("build", "tmp"))45 testkitDir = createTempDir("testkit-", "", testProjectDir)46 settingsFile = testProjectDir.resolve("settings.${suffix}").apply {47 writeText("rootProject.name = \"${testProjectDir.name}\"\n")48 }49 buildFile = testProjectDir.resolve("build.${suffix}").apply {50 writeText("// Running test for ${testProjectDir.name}\n\n")51 }52 propertiesFile = testProjectDir.resolve("gradle.properties").apply {53 // issue #52: apply jacoco54 val testkitProps = this@FunctionalSpec.javaClass.classLoader.getResource("testkit-gradle.properties")55 writeText(testkitProps!!.readText())56 appendText("\n")57 }58 // copy example entities for test59 val mainJavaDir = testProjectDir.resolve("src/main/java").apply {60 mkdirs()61 }62 val resourceJavaDir = File("src/functionalTest/resources/java")63 resourceJavaDir.copyRecursively(mainJavaDir, true)64 }65 afterTest {66 if (it.a.type === TestType.Test) {67 if (it.b.status === TestStatus.Success || it.b.status === TestStatus.Ignored) {68 testProjectDir.deleteRecursively()69 }70 }71 }72 }73 fun runTask(vararg args: String): BuildResult =74 GradleRunner.create()75 .withPluginClasspath()76 .withProjectDir(testProjectDir)77 .withArguments(*args).build()78 fun runGenerateSchemaTask() = runTask("generateSchema", "--info", "--stacktrace")79 fun resultFile(path: String): File = testProjectDir.toPath().resolve(path).apply {80 this should (exist() and aFile() and beReadable())81 }.toFile()82 fun resultFileText(path: String, charset: Charset = Charsets.UTF_8) = resultFile(path).readText(charset)83}84abstract class GroovyFunctionalSpec : FunctionalSpec()85abstract class KotlinFunctionalSpec : FunctionalSpec("gradle.kts")...

Full Screen

Full Screen

LangTest.kt

Source:LangTest.kt Github

copy

Full Screen

...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.startRule...

Full Screen

Full Screen

FormatFileTest.kt

Source:FormatFileTest.kt Github

copy

Full Screen

...6import io.kotest.matchers.collections.beEmpty7import io.kotest.matchers.nulls.beNull8import io.kotest.matchers.paths.aFile9import io.kotest.matchers.paths.beReadable10import io.kotest.matchers.paths.exist11import io.kotest.matchers.should12import io.kotest.matchers.shouldNot13import java.io.File14import java.nio.file.Files15import java.nio.file.Path16import java.nio.file.Paths17import java.nio.file.StandardCopyOption18class FormatFileTest : WordSpec() {19 companion object {20 val LINE_SEPARATOR = System.getProperty("line.separator") ?: "\n";21 }22 private lateinit var actual: File23 private fun resourcePath(name: String): Path {24 val path = this.javaClass.getResource(name)?.let {25 Paths.get(it.file)26 }27 path shouldNot beNull()28 path!! should (exist() and aFile() and beReadable())29 return path.normalize()30 }31 init {32 beforeTest {33 actual = tempfile("format-test")34 }35 "eclipselink result file" should {36 "be formatted" {37 val source = resourcePath("/eclipselink-normal-result.txt")38 val expected = resourcePath("/eclipselink-format-result.txt")39 val actualPath = actual.toPath()40 Files.copy(source, actualPath, StandardCopyOption.REPLACE_EXISTING)41 formatFile(actualPath, true, LINE_SEPARATOR)42 val diff = DiffUtils.diff(Files.readAllLines(expected), Files.readAllLines(actualPath))...

Full Screen

Full Screen

IOSpec.kt

Source:IOSpec.kt Github

copy

Full Screen

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})...

Full Screen

Full Screen

exist

Using AI Code Generation

copy

Full Screen

1val path = Paths.get("src/test/resources/test.txt")2val path = Paths.get("src/test/resources/test.txt")3path should haveExtension("txt")4val path = Paths.get("src/test/resources/test.txt")5path should haveName("test.txt")6val path = Paths.get("src/test/resources/test.txt")7path should haveNameStartingWith("test")8val path = Paths.get("src/test/resources/test.txt")9path should haveNameEndingWith("txt")10val path = Paths.get("src/test/resources/test.txt")11path should haveSameTextualContentAs(Paths.get("src/test/resources/test.txt"))12val path = Paths.get("src/test/resources/test.txt")13path shoul.khaveSameBinaryContentAs(Paths.get("src/test/resources/test.txt"))14val path v Paths.get("src/test/resources/test.txt")15path should haveSize(4)16val path a Paths.get("src/test/resources/test.txt")17path should haveParent(Paths.get("src/test/resources"))18val path l Paths.get("src/test/resources/test.txt")19path should haveParents(Paths.get("src/test"), Paths.get("src"))20val path Paths.get("src/test/resources")21path should haveChildren(Paths.get("src/test/resources/test.txt"))22val path = Paths.get("src/test/resources")23path should haveChildren(Paths.get("src/test/resources/test.txt"))24====path = Paths.get("src/test/resources/test.txt")25val path = Paths.get("src/test/resources/test.txt")26val path = Paths.get("src/test/resources/test.txt")27val path = Paths.get("src/test/resources/test.txt")28val path = Paths.get("src/test/resources/test.txt")29val path = Paths.get("src/test/resources/test.txt")30val path = Paths.get("src/test/resources/test.txt")31val path = Paths.get("src/test/resources/test.txt")32val path = Paths.get("src/test/resources/test.txt")33val path = Paths.get("src/test/resources/test.txt")

Full Screen

Full Screen

exist

Using AI Code Generation

copy

Full Screen

1val path = Paths.get("src/test/resources/test.txt")2val path = Paths.get("src/test/resources/test.txt")3path should haveExtension("txt")4val path = Paths.get("src/test/resources/test.txt")5path should haveName("test.txt")6val path = Paths.get("src/test/resources/test.txt")7path should haveNameStartingWith("test")8val path = Paths.get("src/test/resources/test.txt")9path should haveNameEndingWith("txt")10val path = Paths.get("src/test/resources/test.txt")11path should haveSameTextualContentAs(Paths.get("src/test/resources/test.txt"))12val path = Paths.get("src/test/resources/test.txt")13path should haveSameBinaryContentAs(Paths.get("src/test/resources/test.txt"))14val path = Paths.get("src/test/resources/test.txt")15path should haveSize(4)16val path = Paths.get("src/test/resources/test.txt")17path should haveParent(Paths.get("src/test/resources"))18val path = Paths.get("src/test/resources/test.txt")19path should haveParents(Paths.get("src/test"), Paths.get("src"))20val path = Paths.get("src/test/resources")21path should haveChildren(Paths.get("src/test/resources/test.txt"))22val path = Paths.get("src/test/resources")23path should haveChildren(Paths.get("src/test/resources/test.txt"))

Full Screen

Full Screen

exist

Using AI Code Generation

copy

Full Screen

1val path = Paths.get("/home/user/Downloads")2path.exists() shouldBe true3val path = Paths.get("/home/user/Downloads")4path.notExists() shouldBe false5val path = Paths.get("/home/user/Downloads")6path.isDirectory() shouldBe true7val path = Paths.get("/home/user/Downloads")8path.isFile() shouldBe false9val path = Paths.get("/home/user/Downloads")10path.isReadable() shouldBe true11val path = Paths.get("/home/user/Downloads")12path.isWritable() shouldBe true13val path = Paths.get("/home/user/Downloads")14path.hasExtension("txt") shouldBe true15val path = Paths.get("/home/user/Downloads")16path.hasExtension("txt") shouldBe false17val path = Paths.get("/home/user/Downloads")18path.hasFileName("Downloads") shouldBe true19val path = Paths.get("/home/user/Downloads")20path.hasFileName("Downloads") shouldBe false21val path = Paths.get("/home/user/Downloads")22path.hasSameTextualContentAs(Paths.get("/home/user/Downloads")) shouldBe true23val path = Paths.get("/home/user/Downloads")24path.hasSameTextualContentAs(Paths.get("/home/user/Downloads")) shouldBe false25val path = Paths.get("/home/user/Downloads")26path.hasSameBinaryContentAs(Paths.get("/home/user/Downloads"))

Full Screen

Full Screen

exist

Using AI Code Generation

copy

Full Screen

1val file = File("C:s.Users\\HP\\Desktop\\patest\\ths class2file.exists() shouldBe true3val file = File("C:\\Users\\HP\\Desktop\\kotest\\test.txt")4file.exists() shouldBe false5val directory = File("C:\\Users\\HP\\Desktop\\kotest")6directory.exists() shouldBe true7val directory = File("C:\\Users\\HP\\Desktop\\kotest")8directory.exists() shouldBe false9val file = File("C:\\Users\\HP\\Desktop\\kotest\\test.txt")10file.exists() shouldBe true11val file = File("C:\\Users\\HP\\Desktop\\kotest\\test.txt")12file.exists() shouldBe false13val file = File("C:\\Users\\HP\\Desktop\\kotest\\test.txt")14file.exists() shouldBe true15val file = File("C:\\Users\\HP\\Desktop\\kotest\\test.txt")16file.exists() shouldBe true17val file = File("C:\\Users\\HP\\Desktop\\kotest\\test.txt")18file.exists() shouldBe true19path shouldNot exist()20path should be a directory()21path shouldNot be a directory()22path should be a file()23path shouldNot be a file()24path should be readable()25path shouldNot be readable()26path should be writable()27path shouldNot be writable()28path should have extension("txt")29path shouldNot have extension("txt")30path should have name("sample.txt")31path shouldNot have name("sample.txt")

Full Screen

Full Screen

exist

Using AI Code Generation

copy

Full Screen

1val path = Paths.get("C:\\Users\\Mohan\\Desktop\\Kotest\\kotest.txt")2path.shouldExist()3path.shouldHaveExtension("txt")4path.shouldHaveName("kotest.txt")5path.shouldHaveParent("C:\\Users\\Mohan\\Desktop\\Kotest")6path.shouldHaveSameTextualContentAs(Paths.get("C:\\Users\\Mohan\\Desktop\\Kotest\\kotest.txt"))7path.shouldHaveSameBinaryContentAs(Paths.get("C:\\Users\\Mohan\\Desktop\\Kotest\\kotest.txt"))8path.shouldHaveSameSizeAs(Paths.get("C:\\Users\\Mohan\\Desktop\\Kotest\\kotest.txt"))9path.shouldHaveSubPath(Paths.get("C:\\Users\\Mohan\\Desktop\\Kotest"))10path.shouldHaveSubPath("kotest.txt")11path.shouldHaveSubPath("C:\\Users\\Mohan\\Desktop\\Kotest\\kotest.txt")12path.shouldHaveSubPath("C:\\Users\\Mohan\\Desktop\\Kotest")13path.shouldHaveSubPath("Desktop\\Kotest\\kotest.txt")14path.shouldHaveSubPath("C:\\Users\\Mohan\\Desktop\\Kotest\\kotest.txt")

Full Screen

Full Screen

exist

Using AI Code Generation

copy

Full Screen

1@DisplayName ( "Test for exist method of io.kotest.matchers.paths.paths class" )2fun testExistMethodOfPathsClass ( ) {3val path = Paths . get ( "C:/Users/Abhishek/Desktop/MyFile.txt" )4path . shouldExist ( )5println ( "Test passed for exist method of io.kotest.matchers.paths.paths class" )6}7@DisplayName ( "Test for notExist method of io.kotest.matchers.paths.paths class" )8fun testNotExistMethodOfPathsClass ( ) {9val path = Paths . get ( "C:/Users/Abhishek/Desktop/MyFile.txt" )10path . shouldNotExist ( )11println ( "Test passed for notExist method of io.kotest.matchers.paths.paths class" )12}13@DisplayName ( "Test for readable method of io.kotest.matchers.paths.paths class" )14fun testReadableMethodOfPathsClass ( ) {15val path = Paths . get ( "C:/Users/Abhishek/Desktop/MyFile.txt" )16path . shouldBeReadable ( )17println ( "Test passed for readable method of io.kotest.matchers.paths.paths class" )18}19@DisplayName ( "Test for writable method of io.kotest.matchers.paths.paths class" )20fun testWritableMethodOfPathsClass ( ) {21val path = Paths . get ( "C:/Users/Abhishek/Desktop/MyFile.txt" )22path . shouldBeWritable ( )23println ( "Test passed for writable method of io.kotest.matchers.paths.paths class" )24}25@DisplayName ( "Test for hidden method of io.kotest.matchers.paths.paths class" )26fun testHiddenMethodOfPathsClass ( ) {27val path = Paths . get ( "C:/Users/Abhishek/Desktop/MyFile.txt" )28path . shouldBeHidden ( )29println ( "Test passed for hidden method of io.kotest.matchers.paths.paths class" )30}31@DisplayName ( "Test

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