Skip to content

Commit

Permalink
update compile-testing dep from 0.19 to 0.21.0 (#49)
Browse files Browse the repository at this point in the history
Additional `--add-exports` JVM args were needed for testing.

See: google/compile-testing#222
  • Loading branch information
mikewacker authored May 8, 2023
1 parent f28ef2e commit 95a1c4a
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 25 deletions.
37 changes: 24 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class ImmutableRectangle implements Rectangle {

- `./gradlew -Dorg.gradle.debug=true --no-daemon :immutable-example:clean :immutable-example:compileJava`
- From there, you can attach a debugger to Gradle.
- If you use the [Gradle Error Prone plugin][net.ltgt.errorprone],
- If you use the [Gradle Error Prone plugin][net.ltgt.errorprone] with JDK 16+,
you will also need to [add some JVM args](gradle.properties).
- You could also debug a test written with [Compile Testing][com.google.testing.compile].

Expand Down Expand Up @@ -197,16 +197,18 @@ Here is how the annotation processor for `@Immutable` consumes this infrastructu

For end-to-end-testing, Google's [Compile Testing][com.google.testing.compile] framework is used.

Source files are stored in resource folders:
### Setup (JDK 16+)

- Example source files live in the [`test`][resources/test] folder:
- `Rectangle.java`
- `ColoredRectangle.java`
- `Empty.java`
- The expected generated source files live in the [`generated/test`][resources/generated/test] folder:
- `ImmutableRectangle.java`
- `ImmutableColoredRectangle.java`
- `ImmutableEmpty.java`
To use Compile Testing with JDK 16+, you must add these lines to [`build.gradle`](immutable-processor/build.gradle):

```groovy
test {
// See: https://github.com/google/compile-testing/issues/222
jvmArgs '--add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED'
jvmArgs '--add-exports=jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED'
jvmArgs '--add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED'
}
```

### Compiling the Code

Expand Down Expand Up @@ -236,9 +238,7 @@ By default, it expects that the compilation will succeed.
See this snippet from [`ImmutableProcessorTest`][ImmutableProcessorTest], where a compilation failure is expected:

````java
private void error(String sourcePath) {
TestCompiler.create().expectingCompilationFailure().compile(sourcePath);
}
TestCompiler.create().expectingCompilationFailure().compile(sourcePath);
````

Compile Testing also provides fluent assertions. Here is the static import to use those assertions:
Expand All @@ -247,6 +247,17 @@ Compile Testing also provides fluent assertions. Here is the static import to us
import static com.google.testing.compile.CompilationSubject.assertThat;
```

Source files are stored in resource folders:

- Example source files live in the [`test`][resources/test] folder:
- `Rectangle.java`
- `ColoredRectangle.java`
- `Empty.java`
- The expected generated source files live in the [`generated/test`][resources/generated/test] folder:
- `ImmutableRectangle.java`
- `ImmutableColoredRectangle.java`
- `ImmutableEmpty.java`

## Unit Testing

Many design decisions were made with testability in mind. Case in point, most classes have a corresponding test class.
Expand Down
4 changes: 3 additions & 1 deletion immutable-processor/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,7 @@ dependencies {

test {
// See: https://github.com/google/compile-testing/issues/222
jvmArgs '--add-opens=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED'
jvmArgs '--add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED'
jvmArgs '--add-exports=jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED'
jvmArgs '--add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED'
}
20 changes: 10 additions & 10 deletions versions.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,26 @@ com.fasterxml.jackson.core:jackson-databind:2.15.0 (4 constraints: 8e4063b5)
com.google.auto.service:auto-service-annotations:1.0.1 (1 constraints: 0405f135)
com.google.code.findbugs:jsr305:3.0.2 (2 constraints: 5117f460)
com.google.dagger:dagger:2.46 (1 constraints: e0040131)
com.google.errorprone:error_prone_annotations:2.11.0 (3 constraints: 0c228121)
com.google.errorprone:error_prone_annotations:2.11.0 (3 constraints: 10228b21)
com.google.guava:failureaccess:1.0.1 (1 constraints: 140ae1b4)
com.google.guava:guava:31.1-jre (6 constraints: be5a2c95)
com.google.guava:guava:31.1-jre (6 constraints: 785ba0cd)
com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava (1 constraints: bd17c918)
com.google.j2objc:j2objc-annotations:1.3 (2 constraints: 9316c710)
javax.inject:javax.inject:1 (2 constraints: 490ee940)
net.ltgt.gradle.incap:incap:1.0.0 (1 constraints: 0305f035)
org.checkerframework:checker-qual:3.12.0 (3 constraints: 14226d22)
org.checkerframework:checker-qual:3.26.0 (4 constraints: 8e34586c)
org.immutables:value-annotations:2.9.3 (1 constraints: 10051336)

[Test dependencies]
com.fasterxml.jackson.datatype:jackson-datatype-guava:2.15.0 (2 constraints: f1138982)
com.fasterxml.jackson.datatype:jackson-datatype-jdk8:2.15.0 (2 constraints: f1138982)
com.google.auto:auto-common:0.11 (1 constraints: e711f5e8)
com.google.auto.value:auto-value:1.7.4 (1 constraints: 1f1221fb)
com.google.auto.value:auto-value-annotations:1.7.4 (1 constraints: 640a29b9)
com.google.auto:auto-common:1.2.1 (1 constraints: 17120ffb)
com.google.auto.value:auto-value:1.10 (1 constraints: e711f8e8)
com.google.auto.value:auto-value-annotations:1.8.1 (1 constraints: 620a29b9)
com.google.guava:guava-testlib:31.1-jre (1 constraints: 47069c47)
com.google.testing.compile:compile-testing:0.19 (1 constraints: de04f630)
com.google.truth:truth:1.1 (1 constraints: b71111d7)
junit:junit:4.13.2 (3 constraints: 4b2a7bb3)
com.google.testing.compile:compile-testing:0.21.0 (1 constraints: 35052a3b)
com.google.truth:truth:1.1.3 (1 constraints: 18120efb)
junit:junit:4.13.2 (3 constraints: 4d2a9db3)
net.bytebuddy:byte-buddy:1.14.4 (2 constraints: c016a64f)
net.bytebuddy:byte-buddy-agent:1.14.4 (1 constraints: 440b42de)
org.assertj:assertj-core:3.24.2 (1 constraints: 3d05473b)
Expand All @@ -39,4 +39,4 @@ org.junit.platform:junit-platform-engine:1.9.3 (2 constraints: c01943f4)
org.mockito:mockito-core:5.3.1 (1 constraints: 0b050e36)
org.objenesis:objenesis:3.3 (1 constraints: b20a14bd)
org.opentest4j:opentest4j:1.2.0 (2 constraints: cd205b49)
org.ow2.asm:asm:9.0 (1 constraints: 030aa6a4)
org.ow2.asm:asm:9.1 (1 constraints: 040aa7a4)
2 changes: 1 addition & 1 deletion versions.props
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ com.google.auto.service:* = 1.0.1
com.google.dagger:* = 2.46
com.google.errorprone:error_prone_core = 2.18.0
com.google.guava:* = 31.1-jre
com.google.testing.compile:compile-testing = 0.19
com.google.testing.compile:compile-testing = 0.21.0
javax.inject:javax.inject = 1
net.ltgt.gradle.incap:* = 1.0.0
org.assertj:assertj-core = 3.24.2
Expand Down

0 comments on commit 95a1c4a

Please sign in to comment.