forked from openrewrite/rewrite
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Printable Recipe Datatables (openrewrite#4087)
* Added method to export datatable information as csv to RecipeRun class * Wrapped column value in quotes to escape commas in value * Refactored streams to iterative loops. Log exceptions through Execution Context error handler * Added formatCsv method. Added logic to ensure directories exist before creating files * Refactored export logic to be more testable. Added test for csv printing logic
- Loading branch information
1 parent
1970a34
commit aff81a8
Showing
2 changed files
with
107 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
rewrite-core/src/test/java/org/openrewrite/RecipeRunTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package org.openrewrite; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.openrewrite.table.SourcesFileResults; | ||
import org.openrewrite.test.RewriteTest; | ||
import org.openrewrite.text.FindAndReplace; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.openrewrite.test.SourceSpecs.text; | ||
|
||
public class RecipeRunTest implements RewriteTest { | ||
@Test | ||
void printDatatable() { | ||
rewriteRun( | ||
recipeSpec -> recipeSpec.recipe(new FindAndReplace("replace_me", "replacement", null, null, null, null, null)) | ||
.afterRecipe(recipeRun -> { | ||
StringBuilder output = new StringBuilder(); | ||
final String dataTableName = SourcesFileResults.class.getName(); | ||
RecipeRun.exportCsv(new InMemoryExecutionContext(), recipeRun.getDataTable(dataTableName), | ||
s -> output.append(s).append("\n"), recipeRun.getDataTableRows(dataTableName)); | ||
assertThat(output.toString()).isEqualTo(""" | ||
"Source path before the run","Source path after the run","Parent of the recipe that made changes","Recipe that made changes","Estimated time saving","Cycle" | ||
"The source path of the file before the run.","A recipe may modify the source path. This is the path after the run.","In a hierarchical recipe, the parent of the recipe that made a change. Empty if this is the root of a hierarchy or if the recipe is not hierarchical at all.","The specific recipe that made a change.","An estimated effort that a developer to fix manually instead of using this recipe, in unit of seconds.","The recipe cycle in which the change was made." | ||
"file.txt","file.txt","","org.openrewrite.text.FindAndReplace","300","1" | ||
"""); | ||
}), text(""" | ||
replace_me | ||
""", """ | ||
replacement | ||
""")); | ||
} | ||
} |