Best Kotest code snippet using io.kotest.matchers.file.matchers.beRelative
ScanCodeResultParserTest.kt
Source:ScanCodeResultParserTest.kt
...26import io.kotest.matchers.collections.beEmpty27import io.kotest.matchers.collections.containExactlyInAnyOrder28import io.kotest.matchers.collections.haveSize29import io.kotest.matchers.collections.shouldBeIn30import io.kotest.matchers.file.beRelative31import io.kotest.matchers.should32import io.kotest.matchers.shouldBe33import io.kotest.matchers.string.shouldContain34import java.io.File35import java.time.Instant36import org.ossreviewtoolkit.model.LicenseFinding37import org.ossreviewtoolkit.model.ScanSummary38import org.ossreviewtoolkit.model.TextLocation39import org.ossreviewtoolkit.model.readTree40import org.ossreviewtoolkit.utils.spdx.SpdxConstants41import org.ossreviewtoolkit.utils.test.transformingCollectionMatcher42@Suppress("LargeClass")43class ScanCodeResultParserTest : FreeSpec({44 "generateSummary()" - {45 "for ScanCode 2.2.1 should" - {46 "properly summarize license findings" {47 val resultFile = File("src/test/assets/scancode-2.2.1_esprima-2.7.3.json")48 val result = resultFile.readTree()49 val summary = generateSummary(Instant.now(), Instant.now(), SpdxConstants.NONE, result)50 summary should containLicensesExactly(51 "BSD-2-Clause",52 "BSD-3-Clause",53 "GPL-1.0+",54 "LGPL-2.0+",55 "MIT"56 )57 summary should containLocationsForLicenseExactly(58 "BSD-2-Clause",59 TextLocation("LICENSE.BSD", 3, 21),60 TextLocation("bin/esparse.js", 5, 23),61 TextLocation("bin/esvalidate.js", 5, 23),62 TextLocation("esprima.js", 4, 22),63 TextLocation("test/benchmarks.js", 4, 22),64 TextLocation("test/browser-tests.js", 4, 22),65 TextLocation("test/check-complexity.js", 4, 22),66 TextLocation("test/check-version.js", 6, 24),67 TextLocation("test/downstream.js", 4, 22),68 TextLocation("test/grammar-tests.js", 4, 22),69 TextLocation("test/profile.js", 4, 22),70 TextLocation("test/regression-tests.js", 4, 22),71 TextLocation("test/unit-tests.js", 4, 22),72 TextLocation("test/utils/create-testcases.js", 4, 22),73 TextLocation("test/utils/error-to-object.js", 4, 22),74 TextLocation("test/utils/evaluate-testcase.js", 4, 22),75 TextLocation("tools/generate-fixtures.js", 3, 19)76 )77 summary should containLocationsForLicenseExactly(78 "BSD-3-Clause",79 TextLocation("bower.json", 20, 20),80 TextLocation("package.json", 37, 37),81 TextLocation("test/3rdparty/jquery.mobile-1.4.2.js", 1910),82 TextLocation("test/3rdparty/yui-3.12.0.js", 4)83 )84 summary should containLocationsForLicenseExactly(85 "GPL-1.0+",86 TextLocation("test/3rdparty/jquery-1.9.1.js", 10),87 TextLocation("test/3rdparty/jquery.mobile-1.4.2.js", 8),88 TextLocation("test/3rdparty/jquery.mobile-1.4.2.js", 233),89 TextLocation("test/3rdparty/jquery.mobile-1.4.2.js", 832),90 TextLocation("test/3rdparty/jquery.mobile-1.4.2.js", 1522, 1523),91 TextLocation("test/3rdparty/jquery.mobile-1.4.2.js", 1538, 1539),92 TextLocation("test/3rdparty/jquery.mobile-1.4.2.js", 14001)93 )94 summary should containLocationsForLicenseExactly(95 "LGPL-2.0+",96 TextLocation("test/3rdparty/mootools-1.4.5.js", 28),97 TextLocation("test/3rdparty/mootools-1.4.5.js", 4718)98 )99 summary should containLocationsForLicenseExactly(100 "MIT",101 TextLocation("test/3rdparty/angular-1.2.5.js", 4),102 TextLocation("test/3rdparty/backbone-1.1.0.js", 5),103 TextLocation("test/3rdparty/benchmark.js", 6),104 TextLocation("test/3rdparty/jquery-1.9.1.js", 9),105 TextLocation("test/3rdparty/jquery-1.9.1.js", 10),106 TextLocation("test/3rdparty/jquery-1.9.1.js", 3690),107 TextLocation("test/3rdparty/jquery.mobile-1.4.2.js", 7),108 TextLocation("test/3rdparty/jquery.mobile-1.4.2.js", 8),109 TextLocation("test/3rdparty/jquery.mobile-1.4.2.js", 232),110 TextLocation("test/3rdparty/jquery.mobile-1.4.2.js", 233),111 TextLocation("test/3rdparty/jquery.mobile-1.4.2.js", 831),112 TextLocation("test/3rdparty/jquery.mobile-1.4.2.js", 832),113 TextLocation("test/3rdparty/jquery.mobile-1.4.2.js", 1522, 1523),114 TextLocation("test/3rdparty/jquery.mobile-1.4.2.js", 1538, 1539),115 TextLocation("test/3rdparty/jquery.mobile-1.4.2.js", 1910),116 TextLocation("test/3rdparty/jquery.mobile-1.4.2.js", 14000),117 TextLocation("test/3rdparty/jquery.mobile-1.4.2.js", 14001),118 TextLocation("test/3rdparty/mootools-1.4.5.js", 21),119 TextLocation("test/3rdparty/mootools-1.4.5.js", 29),120 TextLocation("test/3rdparty/mootools-1.4.5.js", 542),121 TextLocation("test/3rdparty/mootools-1.4.5.js", 723),122 TextLocation("test/3rdparty/mootools-1.4.5.js", 807),123 TextLocation("test/3rdparty/mootools-1.4.5.js", 861),124 TextLocation("test/3rdparty/mootools-1.4.5.js", 991),125 TextLocation("test/3rdparty/mootools-1.4.5.js", 1202),126 TextLocation("test/3rdparty/mootools-1.4.5.js", 1457),127 TextLocation("test/3rdparty/mootools-1.4.5.js", 1584),128 TextLocation("test/3rdparty/mootools-1.4.5.js", 1701),129 TextLocation("test/3rdparty/mootools-1.4.5.js", 1881),130 TextLocation("test/3rdparty/mootools-1.4.5.js", 3043),131 TextLocation("test/3rdparty/mootools-1.4.5.js", 4103),132 TextLocation("test/3rdparty/mootools-1.4.5.js", 4322),133 TextLocation("test/3rdparty/mootools-1.4.5.js", 4514),134 TextLocation("test/3rdparty/mootools-1.4.5.js", 4715),135 TextLocation("test/3rdparty/mootools-1.4.5.js", 4999),136 TextLocation("test/3rdparty/mootools-1.4.5.js", 5180),137 TextLocation("test/3rdparty/mootools-1.4.5.js", 5350),138 TextLocation("test/3rdparty/mootools-1.4.5.js", 5463),139 TextLocation("test/3rdparty/mootools-1.4.5.js", 5542),140 TextLocation("test/3rdparty/mootools-1.4.5.js", 5657),141 TextLocation("test/3rdparty/mootools-1.4.5.js", 5937),142 TextLocation("test/3rdparty/mootools-1.4.5.js", 6027),143 TextLocation("test/3rdparty/mootools-1.4.5.js", 6110),144 TextLocation("test/3rdparty/mootools-1.4.5.js", 6158),145 TextLocation("test/3rdparty/mootools-1.4.5.js", 6234),146 TextLocation("test/3rdparty/mootools-1.4.5.js", 6341),147 TextLocation("test/3rdparty/underscore-1.5.2.js", 4)148 )149 }150 "properly summarize copyright findings" {151 val resultFile = File("src/test/assets/scancode-2.2.1_esprima-2.7.3.json")152 val result = resultFile.readTree()153 val summary = generateSummary(Instant.now(), Instant.now(), SpdxConstants.NONE, result)154 summary should containCopyrightsExactly(155 "(c) 2007-2008 Steven Levithan" to156 listOf(TextLocation("test/3rdparty/mootools-1.4.5.js", 1881, 1883)),157 "(c) 2009-2013 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors Underscore" to158 listOf(TextLocation("test/3rdparty/underscore-1.5.2.js", 2, 4)),159 "(c) 2010-2011 Jeremy Ashkenas, DocumentCloud Inc." to160 listOf(TextLocation("test/3rdparty/backbone-1.1.0.js", 3, 6)),161 "(c) 2010-2014 Google, Inc. http://angularjs.org" to162 listOf(TextLocation("test/3rdparty/angular-1.2.5.js", 2, 4)),163 "(c) 2011-2013 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors Backbone" to164 listOf(TextLocation("test/3rdparty/backbone-1.1.0.js", 3, 6)),165 "Copyright (c) 2005-2007 Sam Stephenson" to166 listOf(TextLocation("test/3rdparty/mootools-1.4.5.js", 27, 29)),167 "Copyright (c) 2006 Dean Edwards, GNU Lesser General Public" to168 listOf(TextLocation("test/3rdparty/mootools-1.4.5.js", 27, 29)),169 "Copyright (c) 2006-2012 Valerio Proietti" to170 listOf(TextLocation("test/3rdparty/mootools-1.4.5.js", 23)),171 "Copyright (c) 2010 Cowboy Ben Alman" to listOf(172 TextLocation("test/3rdparty/jquery.mobile-1.4.2.js", 1521, 1523),173 TextLocation("test/3rdparty/jquery.mobile-1.4.2.js", 1537, 1539)174 ),175 "Copyright (c) jQuery Foundation, Inc. and Contributors" to listOf(176 TextLocation("LICENSE.BSD", 1),177 TextLocation("bin/esparse.js", 3),178 TextLocation("bin/esvalidate.js", 3),179 TextLocation("esprima.js", 2),180 TextLocation("test/benchmarks.js", 2),181 TextLocation("test/browser-tests.js", 2),182 TextLocation("test/check-complexity.js", 2),183 TextLocation("test/check-version.js", 4),184 TextLocation("test/downstream.js", 2),185 TextLocation("test/grammar-tests.js", 2),186 TextLocation("test/profile.js", 2),187 TextLocation("test/regression-tests.js", 2),188 TextLocation("test/unit-tests.js", 2),189 TextLocation("test/utils/create-testcases.js", 2),190 TextLocation("test/utils/error-to-object.js", 2),191 TextLocation("test/utils/evaluate-testcase.js", 2),192 TextLocation("tools/generate-fixtures.js", 2)193 ),194 "Copyright 2005, 2012 jQuery Foundation, Inc." to195 listOf(TextLocation("test/3rdparty/jquery-1.9.1.js", 8, 10)),196 "Copyright 2010, 2014 jQuery Foundation, Inc." to197 listOf(TextLocation("test/3rdparty/jquery.mobile-1.4.2.js", 6, 8)),198 "Copyright 2010-2012 Mathias Bynens" to199 listOf(TextLocation("test/3rdparty/benchmark.js", 2, 6)),200 "Copyright 2012 jQuery Foundation" to201 listOf(TextLocation("test/3rdparty/jquery-1.9.1.js", 3688, 3691)),202 "Copyright 2013 Yahoo! Inc." to203 listOf(TextLocation("test/3rdparty/yui-3.12.0.js", 2, 3)),204 "Copyright 2013 jQuery Foundation" to listOf(205 TextLocation("test/3rdparty/jquery.mobile-1.4.2.js", 231, 233),206 TextLocation("test/3rdparty/jquery.mobile-1.4.2.js", 830, 832),207 TextLocation("test/3rdparty/jquery.mobile-1.4.2.js", 13999, 14001)208 ),209 "copyright (c) 2012 Scott Jehl, Paul Irish, Nicholas Zakas." to210 listOf(TextLocation("test/3rdparty/jquery.mobile-1.4.2.js", 1910, 1911)),211 "copyright Robert Kieffer" to212 listOf(TextLocation("test/3rdparty/benchmark.js", 2, 6))213 )214 }215 }216 "for ScanCode 2.9.7 should" - {217 "get correct counts" {218 val resultFile = File("src/test/assets/scancode-2.9.7_mime-types-2.1.18.json")219 val result = resultFile.readTree()220 val summary = generateSummary(Instant.now(), Instant.now(), SpdxConstants.NONE, result)221 summary.licenseFindings.size shouldBe 4222 summary.copyrightFindings.size shouldBe 4223 summary.issues should beEmpty()224 }225 "properly summarize license findings" {226 val resultFile = File("src/test/assets/scancode-2.9.7_aws-java-sdk-core-1.11.160.json")227 val result = resultFile.readTree()228 val actualFindings = generateSummary(Instant.now(), Instant.now(), SpdxConstants.NONE, result)229 .licenseFindings230 actualFindings.distinctBy { it.license } should haveSize(1)231 actualFindings should haveSize(517)232 actualFindings.toList().subList(0, 10).map { it.location } should containExactlyInAnyOrder(233 TextLocation("com/amazonaws/AbortedException.java", 4, 13),234 TextLocation("com/amazonaws/AmazonClientException.java", 4, 13),235 TextLocation("com/amazonaws/AmazonServiceException.java", 4, 13),236 TextLocation("com/amazonaws/AmazonWebServiceClient.java", 4, 13),237 TextLocation("com/amazonaws/AmazonWebServiceRequest.java", 4, 13),238 TextLocation("com/amazonaws/AmazonWebServiceResponse.java", 4, 13),239 TextLocation("com/amazonaws/AmazonWebServiceResult.java", 4, 13),240 TextLocation("com/amazonaws/ApacheHttpClientConfig.java", 4, 13),241 TextLocation("com/amazonaws/ClientConfiguration.java", 4, 13),242 TextLocation("com/amazonaws/ClientConfigurationFactory.java", 4, 13)243 )244 }245 "properly summarize copyright findings" {246 val resultFile = File("src/test/assets/scancode-2.9.7_aws-java-sdk-core-1.11.160.json")247 val result = resultFile.readTree()248 val actualFindings = generateSummary(Instant.now(), Instant.now(), SpdxConstants.NONE, result)249 .copyrightFindings250 actualFindings.mapTo(mutableSetOf()) { it.statement } should containExactlyInAnyOrder(251 "Copyright (c) 2016 Amazon.com, Inc.",252 "Copyright (c) 2016. Amazon.com, Inc.",253 "Copyright 2010-2017 Amazon.com, Inc.",254 "Copyright 2011-2017 Amazon Technologies, Inc.",255 "Copyright 2011-2017 Amazon.com, Inc.",256 "Copyright 2012-2017 Amazon Technologies, Inc.",257 "Copyright 2012-2017 Amazon.com, Inc.",258 "Copyright 2013-2017 Amazon Technologies, Inc.",259 "Copyright 2013-2017 Amazon.com, Inc.",260 "Copyright 2014-2017 Amazon Technologies, Inc.",261 "Copyright 2014-2017 Amazon.com, Inc.",262 "Copyright 2015-2017 Amazon Technologies, Inc.",263 "Copyright 2015-2017 Amazon.com, Inc.",264 "Copyright 2016-2017 Amazon.com, Inc.",265 "Portions copyright 2006-2009 James Murty."266 )267 }268 }269 "for ScanCode 3.0.2 should" - {270 "get correct counts" {271 val resultFile = File("src/test/assets/scancode-3.0.2_mime-types-2.1.18.json")272 val result = resultFile.readTree()273 val summary = generateSummary(Instant.now(), Instant.now(), SpdxConstants.NONE, result)274 summary.licenseFindings.size shouldBe 4275 summary.copyrightFindings.size shouldBe 4276 summary.issues should beEmpty()277 }278 }279 "for ScanCode 3.2.1rc2 should" - {280 "properly parse license expressions" {281 val resultFile = File("src/test/assets/scancode-3.2.1rc2_h2database-1.4.200.json")282 val result = resultFile.readTree()283 val summary = generateSummary(Instant.now(), Instant.now(), SpdxConstants.NONE, result)284 summary.licenseFindings should containExactlyInAnyOrder(285 LicenseFinding(286 license = "(MPL-2.0 OR EPL-1.0) AND LicenseRef-scancode-proprietary-license",287 location = TextLocation("h2/src/main/org/h2/table/Column.java", 2, 3),288 score = 20.37f289 ),290 LicenseFinding(291 license = "LicenseRef-scancode-public-domain",292 location = TextLocation("h2/src/main/org/h2/table/Column.java", 317),293 score = 70.0f294 )295 )296 }297 "properly parse absolute paths" {298 val resultFile = File("src/test/assets/scancode-3.2.1rc2_spring-javaformat-checkstyle-0.0.15.json")299 val result = resultFile.readTree()300 val summary = generateSummary(Instant.now(), Instant.now(), SpdxConstants.NONE, result)301 val fileExtensions = listOf("html", "java", "txt")302 summary.licenseFindings.forAll {303 val file = File(it.location.path)304 file should beRelative()305 file.extension shouldBeIn fileExtensions306 }307 }308 }309 "for output format 1.0.0 should" - {310 "get correct counts" {311 val resultFile = File("src/test/assets/scancode-output-format-1.0.0_mime-types-2.1.18.json")312 val result = resultFile.readTree()313 val summary = generateSummary(Instant.now(), Instant.now(), SpdxConstants.NONE, result)314 summary.licenseFindings.size shouldBe 5315 summary.copyrightFindings.size shouldBe 4316 summary.issues should beEmpty()317 }318 "properly summarize license findings" {...
FileMatchersTest.kt
Source:FileMatchersTest.kt
...3import 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"))...
matchers.kt
Source:matchers.kt
...145 value.isAbsolute,146 { "File $value should be absolute" },147 { "File $value should not be absolute" })148}149fun File.shouldBeRelative() = this should beRelative()150fun File.shouldNotBeRelative() = this shouldNot beRelative()151fun beRelative(): Matcher<File> = object : Matcher<File> {152 override fun test(value: File): MatcherResult =153 MatcherResult(154 !value.isAbsolute,155 { "File $value should be relative" },156 { "File $value should not be relative" })157}158infix fun File.shouldHaveFileSize(size: Long) = this should haveFileSize(size)159infix fun File.shouldNotHaveFileSize(size: Long) = this shouldNot haveFileSize(size)160fun haveFileSize(size: Long): Matcher<File> = object : Matcher<File> {161 override fun test(value: File): MatcherResult = MatcherResult(162 value.length() == size,163 { "File $value should have size $size" },164 { "File $value should not have size $size" }165 )...
paths.kt
Source:paths.kt
...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" }...
beRelative
Using AI Code Generation
1"file should be relative to" {2val file = File("somefile.txt")3file shouldBe beRelative(File("somedir"))4}5"file should be hidden" {6val file = File("somefile.txt")7file shouldBe beHidden()8}9"file should be absolute" {10val file = File("somefile.txt")11file shouldBe beAbsolute()12}13"file should be a file" {14val file = File("somefile.txt")15file shouldBe beFile()16}17"file should be a directory" {18val file = File("somedir")19file shouldBe beDirectory()20}21"file should be readable" {22val file = File("somefile.txt")23file shouldBe beReadable()24}25"file should be writable" {26val file = File("somefile.txt")27file shouldBe beWritable()28}29"file should have extension" {30val file = File("somefile.txt")31file shouldBe haveExtension("txt")32}33"file should have name" {34val file = File("somefile.txt")35file shouldBe haveName("somefile.txt")36}37"file should have name starting with" {38val file = File("somefile.txt")39file shouldBe haveNameStartingWith("somefile")40}41"file should have name ending with" {42val file = File("somefile.txt")43file shouldBe haveNameEndingWith("txt")44}45"file should have name containing" {46val file = File("somefile
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!!