Skip to content

Commit

Permalink
excludeTests
Browse files Browse the repository at this point in the history
  • Loading branch information
andreaTP committed Oct 8, 2023
1 parent d061aa8 commit bf8fa82
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 8 deletions.
13 changes: 12 additions & 1 deletion runtime/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,18 @@
</execution>
</executions>
<configuration>
<wastToProcess>i32.wast,i64.wast</wastToProcess>
<wastToProcess>
i32.wast,
i64.wast,
return.wast
</wastToProcess>
<excludedTests>
SpecV1ReturnTest.test6,
SpecV1ReturnTest.test7,
SpecV1ReturnTest.test9,
SpecV1ReturnTest.test49,
SpecV1ReturnTest.test55
</excludedTests>
</configuration>
</plugin>
</plugins>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import com.github.javaparser.ast.CompilationUnit;
import com.github.javaparser.ast.Modifier;
import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration;
import com.github.javaparser.ast.body.MethodDeclaration;
import com.github.javaparser.ast.body.VariableDeclarator;
import com.github.javaparser.ast.expr.Expression;
Expand Down Expand Up @@ -40,7 +41,7 @@ public JavaTestGen(Log log, File baseDir, File sourceTargetFolder) {

private String INSTANCE_NAME = "instance";

public void generate(File specFile, File wasmFilesFolder) {
public void generate(File specFile, File wasmFilesFolder, List<String> excludedTests) {
Wast wast;
try {
wast = mapper.readValue(specFile, Wast.class);
Expand All @@ -56,6 +57,7 @@ public void generate(File specFile, File wasmFilesFolder) {

// all the imports
// junit imports
cu.addImport("org.junit.Ignore");
cu.addImport("org.junit.Test");
cu.addImport("org.junit.Assert.assertEquals", true, false);
cu.addImport("org.junit.Assert.assertThrows", true, false);
Expand All @@ -79,6 +81,8 @@ public void generate(File specFile, File wasmFilesFolder) {
int testNumber = 0;
int moduleInstantiationNumber = 0;
for (var cmd: wast.getCommands()) {
var excludedMethods = excludedTests.stream().filter(t -> t.startsWith(testName)).map(t -> t.replace(testName + ".", "")).collect(Collectors.toList());

switch (cmd.getType()) {
case MODULE:
testClass.addFieldWithInitializer(
Expand All @@ -88,8 +92,7 @@ public void generate(File specFile, File wasmFilesFolder) {
break;
case ASSERT_RETURN:
case ASSERT_TRAP:
method = testClass.addMethod("test" + testNumber++, Modifier.Keyword.PUBLIC);
method.addAnnotation("Test");
method = createTestMethod(testClass, testNumber++, excludedMethods);

var varName = escapedCamelCase(cmd.getAction().getField());
var fieldExport = generateFieldExport(varName, cmd, (moduleInstantiationNumber - 1));
Expand All @@ -103,8 +106,7 @@ public void generate(File specFile, File wasmFilesFolder) {
break;
case ASSERT_INVALID:
case ASSERT_MALFORMED:
method = testClass.addMethod("test" + testNumber++, Modifier.Keyword.PUBLIC);
method.addAnnotation("Test");
method = createTestMethod(testClass, testNumber++, excludedMethods);

for (var expr: generateAssertThrows(cmd, wasmFilesFolder)) {
method.getBody().get().addStatement(expr);
Expand All @@ -117,6 +119,17 @@ public void generate(File specFile, File wasmFilesFolder) {
dest.saveAll();
}

private MethodDeclaration createTestMethod(ClassOrInterfaceDeclaration testClass, int testNumber, List<String> excludedTests) {
var methodName = "test" + testNumber;
var method = testClass.addMethod("test" + testNumber, Modifier.Keyword.PUBLIC);
if (excludedTests.contains(methodName)) {
method.addAnnotation("Ignore");
}
method.addAnnotation("Test");

return method;
}

private Optional<Expression> generateFieldExport(String varName, Command cmd, int instanceNumber) {
if (cmd.getAction() != null && cmd.getAction().getField() != null) {
var declarator = new VariableDeclarator()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

import java.io.File;
import java.util.List;
import java.util.stream.Collectors;

import static com.dylibso.chicory.maven.Constants.SPEC_JSON;

Expand Down Expand Up @@ -71,12 +72,22 @@ public class TestGenMojo extends AbstractMojo {
@Parameter(required = true)
private List<String> wastToProcess;

/**
* Exclude list for tests that are still failing.
*/
@Parameter(required = false, defaultValue = "[]")
private List<String> excludedTests;

/**
* The current Maven project.
*/
@Parameter(property = "project", required = true, readonly = true)
private MavenProject project;

private List<String> clean(List<String> in) {
return in.stream().map(t -> t.replace("\n", "").replace("\r", "").trim()).collect(Collectors.toList());
}

@Override
public void execute() throws MojoExecutionException {
JavaParserMavenUtils.makeJavaParserLogToMavenOutput(getLog());
Expand All @@ -95,14 +106,14 @@ public void execute() throws MojoExecutionException {
wast2Json.fetch();

// generate the tests
for (var spec: wastToProcess) {
for (var spec: clean(wastToProcess)) {
log.debug("TestGen processing " + spec);
var wastFile = testsuiteFolder.toPath().resolve(spec).toFile();
if (!wastFile.exists()) {
throw new IllegalArgumentException("Wast file " + wastFile.getAbsolutePath() + " not found");
}
var wasmFilesFolder = wast2Json.execute(testsuiteFolder.toPath().resolve(spec).toFile());
testGen.generate(wasmFilesFolder.toPath().resolve(SPEC_JSON).toFile(), wasmFilesFolder);
testGen.generate(wasmFilesFolder.toPath().resolve(SPEC_JSON).toFile(), wasmFilesFolder, clean(excludedTests));
}
} catch (Exception e) {
throw new RuntimeException(e);
Expand Down

0 comments on commit bf8fa82

Please sign in to comment.