Skip to content

Commit

Permalink
feat: capture Kotlin comments
Browse files Browse the repository at this point in the history
fixes: #2418
  • Loading branch information
stuartwdouglas committed Oct 2, 2024
1 parent b51e3b3 commit a2635f1
Show file tree
Hide file tree
Showing 7 changed files with 117 additions and 37 deletions.
16 changes: 16 additions & 0 deletions internal/integration/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,22 @@ func VerifyKubeState(check func(ctx context.Context, t testing.TB, namespace str
}
}

// VerifySchema lets you test the current schema
func VerifySchema(check func(ctx context.Context, t testing.TB, sch *schemapb.Schema)) Action {
return func(t testing.TB, ic TestContext) {
sch, err := ic.Controller.GetSchema(ic, connect.NewRequest(&ftlv1.GetSchemaRequest{}))
if err != nil {
t.Errorf("failed to get schema: %v", err)
return
}
if err != nil {
t.Errorf("failed to deserialize schema: %v", err)
return
}
check(ic.Context, t, sch.Msg.GetSchema())
}
}

// Fail expects the next action to Fail.
func Fail(next Action, msg string, args ...any) Action {
return func(t testing.TB, ic TestContext) {
Expand Down
2 changes: 1 addition & 1 deletion internal/integration/harness.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ func run(t *testing.T, actionsOrOptions ...ActionOrOption) {
err = ftlexec.Command(ctx, log.Debug, rootDir, "just", "build", "ftl").RunBuffered(ctx)
assert.NoError(t, err)
}
if opts.requireJava || slices.Contains(opts.languages, "java") {
if opts.requireJava || slices.Contains(opts.languages, "java") || slices.Contains(opts.languages, "kotlin") {
err = ftlexec.Command(ctx, log.Debug, rootDir, "just", "build-java", "-DskipTests", "-B").RunBuffered(ctx)
assert.NoError(t, err)
}
Expand Down
27 changes: 25 additions & 2 deletions jvm-runtime/ftl-runtime/kotlin/build-parent/pom.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>xyz.block.ftl</groupId>
Expand All @@ -10,7 +11,9 @@
<artifactId>ftl-build-parent-kotlin</artifactId>
<packaging>pom</packaging>
<name>Ftl Kotlin Build Parent POM</name>
<description>This pom.xml can be used as a parent pom to inherit all required configuration to build a FTL Kotlin app.</description>
<description>This pom.xml can be used as a parent pom to inherit all required configuration to build a FTL Kotlin
app.
</description>

<dependencies>
<dependency>
Expand All @@ -28,6 +31,26 @@
<artifactId>kotlin-maven-plugin</artifactId>
<version>${kotlin.version}</version>
<executions>
<execution>
<id>kapt</id>
<goals>
<goal>kapt</goal>
</goals>
<configuration>
<sourceDirs>
<sourceDir>src/main/kotlin</sourceDir>
<sourceDir>src/main/java</sourceDir>
</sourceDirs>
<annotationProcessorPaths>
<!-- Specify your annotation processors here. -->
<annotationProcessorPath>
<groupId>xyz.block.ftl</groupId>
<artifactId>ftl-java-runtime</artifactId>
<version>${project.version}</version>
</annotationProcessorPath>
</annotationProcessorPaths>
</configuration>
</execution>
<execution>
<id>compile</id>
<goals>
Expand Down
38 changes: 38 additions & 0 deletions jvm-runtime/jvm_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@
package ftl_test

import (
"context"
"strings"
"testing"
"time"

"github.com/alecthomas/assert/v2"

schemapb "github.com/TBD54566975/ftl/backend/protos/xyz/block/ftl/v1/schema"
"github.com/TBD54566975/ftl/go-runtime/ftl"
in "github.com/TBD54566975/ftl/internal/integration"

Expand Down Expand Up @@ -166,6 +169,41 @@ func TestGradle(t *testing.T) {
}),
)
}
func TestSchemaComments(t *testing.T) {
in.Run(t,
in.WithJavaBuild(),
in.CopyModuleWithLanguage("gomodule", "go"),
in.CopyModuleWithLanguage("javamodule", "java"),
in.CopyModuleWithLanguage("kotlinmodule", "kotlin"),
in.Deploy("gomodule"),
in.Deploy("javamodule"),
in.Deploy("kotlinmodule"),
in.VerifySchema(func(ctx context.Context, t testing.TB, sch *schemapb.Schema) {
javaOk := false
kotlinOk := false
for _, module := range sch.Modules {
if module.Name == "gomodule" {
continue
}
for _, decl := range module.Decls {
if decl.GetVerb() != nil {
for _, comment := range decl.GetVerb().GetComments() {
if strings.Contains(comment, "JAVA COMMENT") {
javaOk = true
}
if strings.Contains(comment, "KOTLIN COMMENT") {
kotlinOk = true
}
}
}
}
}
assert.True(t, javaOk, "java comment not found")
assert.True(t, kotlinOk, "kotlin comment not found")

}),
)
}

func PairedTest(name string, testFunc func(module string) in.Action) []in.SubTest {
return []in.SubTest{
Expand Down
64 changes: 31 additions & 33 deletions jvm-runtime/testdata/go/gomodule/types.ftl.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ public void sinkVerb(String input, SinkVerbClient sinkVerbClient) {
public String sourceVerb(SourceVerbClient sourceVerbClient) {
return sourceVerbClient.call();
}

/**
* JAVA COMMENT
*/
@Export
@Verb
public void errorEmptyVerb(ErrorEmptyVerbClient client) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ fun sourceVerb(sourceVerbClient: SourceVerbClient): String {
return sourceVerbClient.call()
}

/**
* KOTLIN COMMENT
*/
@Export
@Verb
fun errorEmptyVerb(client: ErrorEmptyVerbClient) {
Expand Down

0 comments on commit a2635f1

Please sign in to comment.