Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Windows path Issues in Coko tests #836

Merged
merged 5 commits into from
Apr 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,7 @@ import org.junit.jupiter.params.provider.MethodSource
import java.nio.file.Files
import java.nio.file.Path
import java.util.stream.Stream
import kotlin.io.path.Path
import kotlin.io.path.absolute
import kotlin.io.path.div
import kotlin.io.path.isRegularFile
import kotlin.io.path.*
import kotlin.streams.asSequence
import kotlin.test.*

Expand Down Expand Up @@ -223,19 +220,19 @@ class CpgOptionGroupTest {
val topTestDirResource =
CpgOptionGroupTest::class.java.classLoader.getResource("cli-test-directory")
assertNotNull(topTestDirResource)
topTestDir = Path(topTestDirResource.path)
topTestDir = topTestDirResource.toURI().toPath()
assertNotNull(topTestDir) // TODO: why is this necessary

val testDir1Resource =
CpgOptionGroupTest::class.java.classLoader.getResource("cli-test-directory/dir1")
assertNotNull(testDir1Resource)
testDir1 = Path(testDir1Resource.path)
testDir1 = testDir1Resource.toURI().toPath()
assertNotNull(testDir1)

val testDir2Resource =
CpgOptionGroupTest::class.java.classLoader.getResource("cli-test-directory/dir2")
assertNotNull(testDir2Resource)
testDir2 = Path(testDir2Resource.path)
testDir2 = testDir2Resource.toURI().toPath()
assertNotNull(testDir2)

val testFile1Resource =
Expand All @@ -244,7 +241,7 @@ class CpgOptionGroupTest {
.classLoader
.getResource("cli-test-directory/file1.java")
assertNotNull(testFile1Resource)
testFile1 = Path(testFile1Resource.path)
testFile1 = testFile1Resource.toURI().toPath()
assertNotNull(testFile1)

allFiles = Files.walk(topTestDir).asSequence().filter { it.isRegularFile() }.toList()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ class FollowsEvaluationTest {

val testFileResource = classLoader.getResource("FollowsEvaluationTest/SimpleFollows.java")
assertNotNull(testFileResource)
testFile = Path(testFileResource.path)
testFile = testFileResource.toURI().toPath()

val fooInstance = FooModel()
val barInstance = BarModel()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import de.fraunhofer.aisec.codyze.specificationLanguages.coko.core.dsl.op
import de.fraunhofer.aisec.codyze.specificationLanguages.coko.core.dsl.signature
import org.junit.jupiter.api.BeforeAll
import org.junit.jupiter.api.Test
import kotlin.io.path.Path
import kotlin.io.path.toPath
import kotlin.test.assertEquals
import kotlin.test.assertNotNull

Expand Down Expand Up @@ -94,7 +94,7 @@ class ImplementationDslTest {

val testFileResource = classLoader.getResource("ImplementationDslTest/SimpleJavaFile.java")
assertNotNull(testFileResource)
val testFile = Path(testFileResource.path)
val testFile = testFileResource.toURI().toPath()
backend = CokoCpgBackend(config = createCpgConfiguration(testFile))
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,11 @@ class NeverEvaluationTest {

val violationFileResource = classLoader.getResource("NeverEvaluationTest/NeverViolation.java")
assertNotNull(violationFileResource)
violationFile = Path(violationFileResource.path)
violationFile = violationFileResource.toURI().toPath()

val passFileResource = classLoader.getResource("NeverEvaluationTest/NeverPass.java")
assertNotNull(passFileResource)
passFile = Path(passFileResource.path)
passFile = passFileResource.toURI().toPath()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class OnlyEvaluationTest {

val testFileResource = classLoader.getResource("OnlyEvaluationTest/SimpleOnly.java")
assertNotNull(testFileResource)
testFile = Path(testFileResource.path)
testFile = testFileResource.toURI().toPath()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ class CodyzeCliTest : KoinTest {
val pathConfigFileResource =
CodyzeCliTest::class.java.classLoader.getResource("config-files/path-config.json")
assertNotNull(pathConfigFileResource)
pathConfigFile = Path(pathConfigFileResource.path)
pathConfigFile = pathConfigFileResource.toURI().toPath()
assertTrue(pathConfigFile.exists())

val correctConfigFileResource =
Expand All @@ -121,19 +121,19 @@ class CodyzeCliTest : KoinTest {
.classLoader
.getResource("config-files/correct-config.json")
assertNotNull(correctConfigFileResource)
correctConfigFile = Path(correctConfigFileResource.path)
correctConfigFile = correctConfigFileResource.toURI().toPath()
assertTrue(correctConfigFile.exists())

val specMarkResource =
CodyzeCliTest::class.java.classLoader.getResource("config-files/spec/spec.mark")
assertNotNull(specMarkResource)
specMark = Path(specMarkResource.path)
specMark = specMarkResource.toURI().toPath()
assertTrue(specMark.exists())

val specMark2Resource =
CodyzeCliTest::class.java.classLoader.getResource("config-files/spec2.mark")
assertNotNull(specMark2Resource)
spec2Mark = Path(specMark2Resource.path)
spec2Mark = specMark2Resource.toURI().toPath()
assertTrue(spec2Mark.exists())
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class CokoCpgIntegrationTest {
.getResource("IntegrationTests/CokoCpg/Main.java"),
CokoCpgIntegrationTest::class.java.classLoader
.getResource("IntegrationTests/CokoCpg/SimpleOrder.java")
).map { Path(it.path) }.also { assertEquals(2, it.size) }
).map { it.toURI().toPath() }.also { assertEquals(2, it.size) }

val cpgConfiguration =
CPGConfiguration(
Expand Down Expand Up @@ -72,7 +72,7 @@ class CokoCpgIntegrationTest {
.getResource("IntegrationTests/CokoCpg/orderFull.codyze.kts"),
CokoCpgIntegrationTest::class.java.classLoader
.getResource("IntegrationTests/CokoCpg/followedByFull.codyze.kts")
).map { Path(it.path) }.also { assertEquals(2, it.size) }
).map { it.toURI().toPath() }.also { assertEquals(2, it.size) }

val cokoConfiguration =
CokoConfiguration(
Expand Down Expand Up @@ -102,7 +102,7 @@ class CokoCpgIntegrationTest {
.getResource("IntegrationTests/CokoCpg/followedByTwoFiles/followedByImplementations.codyze.kts"),
CokoCpgIntegrationTest::class.java.classLoader
.getResource("IntegrationTests/CokoCpg/followedByTwoFiles/followedByModels.codyze.kts")
).map { Path(it.path) }.also { assertEquals(2, it.size) }
).map { it.toURI().toPath() }.also { assertEquals(2, it.size) }

val cokoConfiguration =
CokoConfiguration(
Expand Down Expand Up @@ -221,7 +221,7 @@ class CokoCpgIntegrationTest {
fun `test coko with cpg backend without good findings`() {
val specFiles = listOfNotNull(
CokoCpgIntegrationTest::class.java.classLoader.getResource("IntegrationTests/CokoCpg/orderFull.codyze.kts"),
).map { Path(it.path) }.also { assertEquals(1, it.size) }
).map { it.toURI().toPath() }.also { assertEquals(1, it.size) }

val cokoConfiguration =
CokoConfiguration(
Expand Down Expand Up @@ -252,7 +252,7 @@ class CokoCpgIntegrationTest {
)
val permutations = fileMap.permutate()
for (p in permutations) {
val (specFiles, fileNames) = p.map { Path(it.path) }.map { it to it.fileName }.unzip()
val (specFiles, fileNames) = p.map { it.toURI().toPath() }.map { it to it.fileName }.unzip()
stream.add(
Arguments.of(
specFiles,
Expand All @@ -278,7 +278,7 @@ class CokoCpgIntegrationTest {
)
val permutations = fileMap.permutate()
for (p in permutations) {
val (specFiles, fileNames) = p.map { Path(it.path) }.map { it to it.fileName }.unzip()
val (specFiles, fileNames) = p.map { it.toURI().toPath() }.map { it to it.fileName }.unzip()
stream.add(
Arguments.of(
specFiles,
Expand Down Expand Up @@ -306,7 +306,7 @@ class CokoCpgIntegrationTest {
)
val permutations = fileMap.permutate()
for (p in permutations) {
val (specFiles, fileNames) = p.map { Path(it.path) }.map { it to it.fileName }.unzip()
val (specFiles, fileNames) = p.map { it.toURI().toPath() }.map { it to it.fileName }.unzip()
stream.add(
Arguments.of(
specFiles,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ import org.koin.test.KoinTest
import org.koin.test.junit5.KoinTestExtension
import java.nio.file.Files
import java.nio.file.Path
import kotlin.io.path.Path
import kotlin.io.path.div
import kotlin.io.path.isRegularFile
import kotlin.io.path.toPath
import kotlin.streams.asSequence
import kotlin.test.*

Expand Down Expand Up @@ -103,15 +103,15 @@ class CokoOptionGroupTest : KoinTest {
val topTestDirResource =
CokoOptionGroupTest::class.java.classLoader.getResource("cli-test-directory")
assertNotNull(topTestDirResource)
topTestDir = Path(topTestDirResource.path)
topTestDir = topTestDirResource.toURI().toPath()

val testDir3SpecResource =
CokoOptionGroupTest::class
.java
.classLoader
.getResource("cli-test-directory/dir3-spec")
assertNotNull(testDir3SpecResource)
testDir3Spec = Path(testDir3SpecResource.path)
testDir3Spec = testDir3SpecResource.toURI().toPath()

allFiles = Files.walk(topTestDir).asSequence().filter { it.isRegularFile() }.toList()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import org.junit.jupiter.api.BeforeAll
import org.junit.jupiter.api.Test
import java.nio.file.Path
import kotlin.io.path.Path
import kotlin.io.path.toPath
import kotlin.test.assertContains
import kotlin.test.assertEquals
import kotlin.test.assertNotNull
Expand Down Expand Up @@ -58,7 +59,7 @@ class ValidationTest {
.classLoader
.getResource("cli-test-directory/dir3-spec")
assertNotNull(testDir3SpecResource)
testDir3Spec = Path(testDir3SpecResource.path)
testDir3Spec = testDir3SpecResource.toURI().toPath()
}
}
}