-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add check for compilation in test case
- Loading branch information
1 parent
3b7bae9
commit a1914e7
Showing
3 changed files
with
29 additions
and
24 deletions.
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
codegen/src/test/java/org/web3j/codegen/GeneraterTestUtils.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,25 @@ | ||
package org.web3j.codegen; | ||
|
||
import javax.tools.*; | ||
import java.io.IOException; | ||
import java.util.Collections; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
public class GeneraterTestUtils { | ||
|
||
public static void verifyGeneratedCode(String sourceFile) throws IOException { | ||
JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); | ||
DiagnosticCollector<JavaFileObject> diagnostics = new DiagnosticCollector<>(); | ||
|
||
try (StandardJavaFileManager fileManager = | ||
compiler.getStandardFileManager(diagnostics, null, null)) { | ||
Iterable<? extends JavaFileObject> compilationUnits = | ||
fileManager.getJavaFileObjectsFromStrings( | ||
Collections.singletonList(sourceFile)); | ||
JavaCompiler.CompilationTask task = | ||
compiler.getTask(null, fileManager, diagnostics, null, null, compilationUnits); | ||
assertTrue(task.call(), "Generated contract contains compile time error"); | ||
} | ||
} | ||
} |
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
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