Skip to content

Commit

Permalink
Global fmt configuration and wrap lines in README
Browse files Browse the repository at this point in the history
  • Loading branch information
rickie committed May 21, 2022
1 parent f8119a4 commit 52c1d9e
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 49 deletions.
9 changes: 0 additions & 9 deletions error-prone-contrib/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -216,15 +216,6 @@
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>com.coveo</groupId>
<artifactId>fmt-maven-plugin</artifactId>
<configuration>
<additionalSourceDirectories>
<additionalSourceDirectory>${basedir}/src/test/resources</additionalSourceDirectory>
</additionalSourceDirectories>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
Expand Down
3 changes: 3 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,9 @@
<artifactId>fmt-maven-plugin</artifactId>
<version>2.18</version>
<configuration>
<additionalSourceDirectories>
<additionalSourceDirectory>${basedir}/src/test/resources</additionalSourceDirectory>
</additionalSourceDirectories>
<forkMode>never</forkMode>
</configuration>
</plugin>
Expand Down
2 changes: 1 addition & 1 deletion refaster-runner/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<artifactId>refaster-runner</artifactId>

<name>Picnic :: Error Prone Support :: Refaster Runner</name>
<description>Apply Refaster templates found on the classpath.</description>
<description>Applies Refaster templates found on the classpath.</description>

<dependencies>
<dependency>
Expand Down
79 changes: 49 additions & 30 deletions refaster-test-support/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,58 +4,77 @@ This package provides utilities to validate Refaster template collections.

## What does this module do?

These utilities allow for validating the rewrites performed by Refaster templates, or absence thereof. Each collection
of Refaster templates is applied to an input file and the result of that should match the provided output file.
These utilities allow for validating the rewrites performed by Refaster
templates, or absence thereof. Each collection of Refaster templates is applied
to an input file and the result of that should match the provided output file.

This extension ensures that each Refaster template has a test and has a match at the expected place. If a test is
missing, an error is reported in the test's console. This way, the developer has some guidance on how to write tests and
This extension ensures that each Refaster template has a test and has a match at
the expected place. If a test is missing, an error is reported in the test's
console. This way, the developer has some guidance on how to write tests and
assurance that every template is tested.

## How to test a collection of Refaster templates?

In summary, to test Refaster templates using the `RefasterCollectionTestUtil`, one should create an input and output
file. The Refaster templates from the collection are applied on the input file and should exactly match the content of
In summary, to test Refaster templates using the `RefasterCollectionTestUtil`,
one should create an input and output file. The Refaster templates from the
collection are applied on the input file and should exactly match the content of
the provided output file.

To test Refaster templates, one can create a (parameterized) test for every class containing the Refaster templates to
invoke the `RefasterCollectionTestUtil`. A class that contains one or more Refaster templates is called a Refaster
template collection. This test utility applies the Refaster templates in the collection to a provided input file, and
expects the result to exactly match the contents of a provided output file.
To test Refaster templates, one can create a (parameterized) test for every
class containing the Refaster templates to invoke the
`RefasterCollectionTestUtil`. A class that contains one or more Refaster
templates is called a Refaster template collection. This test utility applies
the Refaster templates in the collection to a provided input file, and expects
the result to exactly match the contents of a provided output file.

To adopt this setup, the following requirements have to be met:

- Create a class with a (parameterized) test method that calls
the `RefasterCollectionTestUtil#validateTemplateCollection` and passes the collection(s) to validate. The Refaster
template collection must match the naming convention `<TemplateCollectionName>Templates.java`.
- An input file matching the naming convention `<TemplateCollectionName>TemplatesTestInput.java` is added for every
the `RefasterCollectionTestUtil#validateTemplateCollection` and passes the
collection(s) to validate. The Refaster template collection must match the
naming convention `<TemplateCollectionName>Templates.java`.
- An input file matching the naming convention
`<TemplateCollectionName>TemplatesTestInput.java` is added for every template
collection.
- An output file matching the naming convention
`<TemplateCollectionName>TemplatesTestOutput.java` file is added for every
template collection.
- An output file matching the naming convention `<TemplateCollectionName>TemplatesTestOutput.java`
file is added for every template collection.
- For each Refaster template in the collection, the input and output file must contain a method. The name of the method
is equal to the name of the Refaster template prefixed with `test` (e.g. `test<RefasterTemplateClassName>`).
- The method contains at least one expression that matches the `@BeforeTemplate` of one specific Refaster template. As
a result, the output file contains the same method with an updated expression, matching the content of
the `@AfterTemplate`. Additionally, incorrect matches of _other_ Refaster templates in the method are flagged.
- For each Refaster template in the collection, the input and output file must
contain a method. The name of the method is equal to the name of the Refaster
template prefixed with `test` (e.g. `test<RefasterTemplateClassName>`).
- The method contains at least one expression that matches the `@BeforeTemplate`
of one specific Refaster template. As a result, the output file contains the
same method with an updated expression, matching the content of the
`@AfterTemplate`. Additionally, incorrect matches of _other_ Refaster
templates in the method are flagged.

As a result from these tests, unexpected output will be shown in the console.

An example of a folder structure for such a setup is as follows:

```
main/java/
tech.picnic.errorprone.refastertemplates
└── ExampleTemplates.java -- Contains multiple Refaster templates.
└── Example1Template
└── Example2Template
main/
java/
tech.picnic.errorprone.refastertemplates
└── ExampleTemplates.java -- Contains multiple Refaster templates.
└── Example1Template
└── Example2Template
test/
java/
└── tech.picnic.errorprone.refastertemplates
└── RefasterCollectionTest.java -- Here the test invokes `RefasterCollectionTestUtil#validateTemplateCollection`.
└── RefasterCollectionTest.java
-- Here the test invokes
-- `RefasterCollectionTestUtil#validateTemplateCollection`.
resources/
└── tech.picnic.errorprone.refastertemplates
└── ExampleTemplatesTestInput.java -- Contains a class named `ExampleTemplatesTest` and
two methods named `testExample1Template` and `testExample2Template`.
└── ExampleTemplatesTestOutput.java -- Contains a class named `ExampleTemplatesTest` and
two methods named `testExample1Template` and `testExample2Template`.
└── ExampleTemplatesTestInput.java
-- Contains a class named `ExampleTemplatesTest` and
-- two methods named `testExample1Template` and
-- `testExample2Template`.
└── ExampleTemplatesTestOutput.java
-- Contains a class named `ExampleTemplatesTest` and
-- two methods named `testExample1Template` and
-- `testExample2Template`.
```

9 changes: 0 additions & 9 deletions refaster-test-support/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -85,15 +85,6 @@
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>com.coveo</groupId>
<artifactId>fmt-maven-plugin</artifactId>
<configuration>
<additionalSourceDirectories>
<additionalSourceDirectory>${basedir}/src/test/resources</additionalSourceDirectory>
</additionalSourceDirectories>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
Expand Down

0 comments on commit 52c1d9e

Please sign in to comment.