Skip to content

Commit 63a2108

Browse files
committed
use extracted code
1 parent a08c667 commit 63a2108

File tree

1 file changed

+7
-75
lines changed

1 file changed

+7
-75
lines changed

openapi-processor-core/src/testInt/kotlin/io/openapiprocessor/core/CompileExpectedSpec.kt

Lines changed: 7 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -6,92 +6,24 @@
66
package io.openapiprocessor.core
77

88
import io.kotest.core.spec.style.StringSpec
9+
import io.kotest.engine.spec.tempdir
910
import io.kotest.matchers.booleans.shouldBeTrue
1011
import io.openapiprocessor.core.parser.ParserType
1112
import io.openapiprocessor.test.*
12-
import java.io.ByteArrayOutputStream
13-
import java.io.OutputStream
14-
import java.net.URI
15-
import java.nio.file.Path
16-
import java.util.*
17-
import javax.tools.*
1813

1914

2015
class CompileExpectedSpec: StringSpec({
2116

22-
class MemoryFile(name: String, kind: JavaFileObject.Kind)
23-
: SimpleJavaFileObject(URI("string:///${name}"), kind) {
24-
25-
override fun openOutputStream(): OutputStream {
26-
return ByteArrayOutputStream()
27-
}
28-
}
29-
30-
class MemoryFileManager(fileManager: StandardJavaFileManager)
31-
: ForwardingJavaFileManager<StandardJavaFileManager>(fileManager) {
32-
33-
override fun getJavaFileForOutput(
34-
location: JavaFileManager.Location,
35-
className: String,
36-
kind: JavaFileObject.Kind,
37-
sibling: FileObject
38-
): JavaFileObject {
39-
return MemoryFile(className, kind)
40-
}
41-
42-
fun getJavaFileObjectsFromPaths(paths: Iterable<Path>): Iterable<JavaFileObject> {
43-
return fileManager.getJavaFileObjectsFromPaths(paths)
44-
}
45-
}
46-
4717
for (testSet in sources()) {
4818
"compile - $testSet".config(enabled = true) {
49-
val itemsReader = TestItemsReader(ResourceReader(CompileExpectedSpec::class.java))
50-
51-
val source = testSet.name
52-
val sourcePath = "/tests/$source"
53-
54-
val compilePaths = mutableListOf<Path>()
55-
56-
// stuff used by all tests
57-
compilePaths.add(Path.of("src/testInt/resources/compile/Generated.java"))
58-
compilePaths.add(Path.of("src/testInt/resources/compile/Mapping.java"))
59-
compilePaths.add(Path.of("src/testInt/resources/compile/Parameter.java"))
60-
61-
var expected = itemsReader.read(sourcePath, "outputs.yaml").items
62-
expected = expected.filter { ! it.endsWith("properties") }
63-
val expectedFileNames = expected.map { it.replaceFirst("<model>", "_${testSet.modelType}_") }
64-
expectedFileNames.forEach {
65-
compilePaths.add(Path.of("src/testInt/resources${sourcePath}/$it"))
66-
}
67-
68-
if (itemsReader.exists(sourcePath, "compile.yaml")) {
69-
val additionalFileNames = itemsReader.read(sourcePath, "compile.yaml").items
70-
71-
additionalFileNames.forEach {
72-
if (it.startsWith("not ")) {
73-
compilePaths.remove(Path.of("src/testInt/resources/${it.substring(4)}"))
74-
} else {
75-
compilePaths.add(Path.of("src/testInt/resources/$it"))
76-
}
77-
}
78-
}
79-
80-
val diagnostics = DiagnosticCollector<JavaFileObject>()
81-
val compiler = ToolProvider.getSystemJavaCompiler()
82-
val manager = MemoryFileManager(compiler.getStandardFileManager(diagnostics, null, null))
19+
val folder = tempdir()
20+
val reader = ResourceReader(CompileExpectedSpec::class.java)
8321

84-
val options = listOf<String>()
85-
val compilationUnit = manager.getJavaFileObjectsFromPaths(compilePaths)
86-
val task = compiler.getTask(null, manager, diagnostics, options, null, compilationUnit)
87-
val success = task.call()
88-
if(!success) {
89-
for (diagnostic in diagnostics.diagnostics) {
90-
println("CompileSpec: compile error at ${diagnostic.source.name}:${diagnostic.lineNumber}, ${diagnostic.getMessage(Locale.ENGLISH)}")
91-
}
92-
}
22+
val testFiles = TestFilesNative(folder, reader)
9323

94-
success.shouldBeTrue()
24+
TestSetCompiler(testSet, testFiles)
25+
.run()
26+
.shouldBeTrue()
9527
}
9628
}
9729
})

0 commit comments

Comments
 (0)