15
15
16
16
package com.toasttab.protokt
17
17
18
+ import com.google.common.base.CaseFormat.LOWER_CAMEL
19
+ import com.google.common.base.CaseFormat.LOWER_UNDERSCORE
20
+ import com.google.protobuf.compiler.PluginProtos
21
+ import com.toasttab.protokt.gradle.ProtoktExtension
18
22
import com.toasttab.protokt.testing.util.ProcessOutput.Src.ERR
19
23
import com.toasttab.protokt.testing.util.projectRoot
20
24
import com.toasttab.protokt.testing.util.runCommand
21
- import org.junit.jupiter.api.Disabled
22
25
import org.junit.jupiter.api.Test
23
26
import java.io.ByteArrayOutputStream
24
27
import java.io.File
25
- import java.nio.file.Paths
28
+ import java.nio.file.Path
29
+ import kotlin.reflect.KClass
30
+ import kotlin.reflect.full.declaredMemberProperties
26
31
27
32
class MainTest {
28
33
@Test
29
- @Disabled // Enable this test if you want to step through the code generator
30
34
fun `step through code generation with debugger` () {
31
35
generatedFile.delete()
32
36
37
+ val ext =
38
+ ProtoktExtension ().apply {
39
+ // set any plugin options here
40
+ }
41
+
33
42
listOf (
34
- " protoc" ,
43
+ System .getenv( " PROTOC_PATH " ) ? : " protoc" ,
35
44
" --plugin=protoc-gen-custom=$binGenerator " ,
36
45
" --custom_out=." , // ignored
37
46
" -I$codegenTestingProto " ,
38
47
" -I$runtimeResources " ,
48
+ " -I$includeProtos " ,
49
+ buildPluginOptions(ext),
39
50
" $testProto "
40
51
).joinToString(" " )
41
52
.runCommand(
42
- Paths .get(projectRoot )
53
+ projectRoot.toPath( )
43
54
).orFail(" Failed to generate code generator request" , ERR )
44
55
45
56
val out = ByteArrayOutputStream ()
46
57
main(generatedFile.readBytes(), out )
47
- println (out .toString())
58
+ PluginProtos .CodeGeneratorResponse .parseFrom(out .toByteArray())
59
+ .fileList
60
+ .forEach {
61
+ println (it.name)
62
+ println (it.content)
63
+ }
48
64
}
49
65
}
50
66
67
+ private fun buildPluginOptions (extension : ProtoktExtension ) =
68
+ " --custom_opt=" +
69
+ extension::class .declaredMemberProperties
70
+ .filter { it.returnType.classifier as KClass <* > == Boolean ::class }
71
+ .joinToString(" ," ) {
72
+ LOWER_CAMEL .to(LOWER_UNDERSCORE , it.name) + " =${it.call(extension)} "
73
+ }
74
+
51
75
private val codegenTestingResources =
52
- Paths .get (
76
+ Path .of (
53
77
" protokt-codegen" , " src" , " test" , " resources" ,
54
78
" com" , " toasttab" , " protokt" , " codegen" , " testing"
55
79
)
@@ -58,22 +82,25 @@ private val binGenerator =
58
82
File (codegenTestingResources.toFile(), " bin-generator" )
59
83
60
84
private val codegenTestingProto =
61
- Paths .get (
85
+ Path .of (
62
86
" protokt-codegen" , " src" , " test" , " proto" ,
63
- " com " , " toasttab" , " protokt" , " codegen" , " testing"
87
+ " toasttab" , " protokt" , " codegen" , " testing"
64
88
)
65
89
66
90
private val testProto =
67
91
File (codegenTestingProto.toFile(), " test.proto" )
68
92
69
93
private val runtimeResources =
70
- Paths .get (" protokt-runtime" , " src" , " main" , " resources" )
94
+ Path .of (" protokt-runtime" , " src" , " main" , " resources" )
71
95
72
96
private val generatedFile =
73
97
File (
74
98
projectRoot,
75
- Paths .get (
99
+ Path .of (
76
100
" protokt-codegen" , " src" , " test" , " resources" ,
77
101
" com" , " toasttab" , " protokt" , " test-proto-bin-request.bin"
78
102
).toString()
79
103
)
104
+
105
+ private val includeProtos =
106
+ File (projectRoot, " protokt-codegen/build/extracted-include-protos/main" )
0 commit comments