google / google/compile-testing

Unable to create resource content in code.

Open
#52 0 comments 0 reactions 0 assignees View on GitHub
P3 type=enhancement
Dominant language
Java
Stars
722
Forks
129
Avg merge
11m
Merged PRs (30d)
4

Description

`StringSourceJavaFileObject` (via `forSourceString`) assumes I'm creating a `SOURCE` object when I want to create an `OTHER` (resource file).

In `@AutoService` you use actual resources as the expected generated content. I prefer to keep both the originating source and generated sources in the actual test so everything is in one place.

``` java
String source = ""
+ "package com.example;\n"
+ "\n"
+ "import com.example.auto.resource.thingy.AutoResourceThingy;\n"
+ "\n"
+ "@AutoResourceThingy\n"
+ "public class Example {}";
JavaFileObject sourceFile = JavaFileObjects.forSourceString("com.example.Example", source);

JavaFileObject expectedSource =
JavaFileObjects.forSourceString("META-INF/thingy/com.example.Example",
"THINGY!");

ASSERT.about(javaSource()).that(sourceFile)
.processedWith(autoResourceThingy())
.compilesWithoutError()
.and()
.generatesFiles(expectedSource);
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.