Commit 9101a324 authored by René Schöne's avatar René Schöne
Browse files

using packaged preprocessor-testing

- adapt syntax for specifying tests
parent 45b7d167
buildscript {
repositories {
maven {
name "gitlab-maven"
url "https://git-st.inf.tu-dresden.de/api/v4/groups/jastadd/-/packages/maven"
}
}
dependencies {
classpath 'org.jastadd.preprocessor:testing:0.2.13-28'
}
}
import org.jastadd.preprocessor.testing.plugin.PreprocessorPlugin
import org.jastadd.preprocessor.testing.plugin.RelastTest
//file:noinspection HardCodedStringLiteral
plugins {
id 'java'
......@@ -5,10 +20,10 @@ plugins {
id 'application'
id 'idea'
id 'maven-publish'
id 'org.jastadd.relast.plugin'
id 'org.jastadd' version '1.14.5'
}
import org.jastadd.relast.plugin.RelastTest
apply plugin: PreprocessorPlugin
java.toolchain.languageVersion = JavaLanguageVersion.of(11)
......@@ -177,18 +192,30 @@ publishing {
}
task firstRelationsRun(type: RelastTest) {
relastFiles 'src/test/jastadd/relations/Relations.relast'
grammarName = 'src/test/jastadd/relations/Relations'
useJastAddNames = true
packageName = 'relations.ast'
moreInputFiles 'src/test/jastadd/Utils.jadd', 'src/test/jastadd/relations/Relations.jrag'
relast {
inputFiles = [file('src/test/jastadd/relations/Relations.relast')]
grammarName = 'src/test/jastadd/relations/Relations'
useJastAddNames = true
noResolverHelper = true
}
jastadd {
packageName = 'relations.ast'
inputFiles = [file('src/test/jastadd/Utils.jadd'),
file('src/test/jastadd/relations/Relations.jrag')]
}
}
task secondRelationsRun(type: RelastTest, dependsOn: firstRelationsRun) {
relastFiles 'src/test/jastadd/relations/Relations.ast'
grammarName = 'src/test/jastadd/relations/Relations2'
useJastAddNames = true
packageName = 'ignored'
relast {
inputFiles = [file('src/test/jastadd/relations/Relations.ast')]
grammarName = 'src/test/jastadd/relations/Relations2'
useJastAddNames = true
noResolverHelper = true
}
jastadd {
skipRun = true
packageName = 'ignored'
}
doLast {
delete fileTree('src/test/java-gen/ignored')
......@@ -197,131 +224,200 @@ task secondRelationsRun(type: RelastTest, dependsOn: firstRelationsRun) {
}
task compileConstructorTest(type: RelastTest) {
relastFiles 'src/test/jastadd/constructors/Constructors.relast'
grammarName = 'src/test/jastadd/constructors/Constructors'
packageName = 'constructors.ast'
moreInputFiles 'src/test/jastadd/constructors/Constructors.jrag'
relast {
inputFiles = [file('src/test/jastadd/constructors/Constructors.relast')]
grammarName = 'src/test/jastadd/constructors/Constructors'
noResolverHelper = true
}
jastadd {
packageName = 'constructors.ast'
inputFiles = [file('src/test/jastadd/constructors/Constructors.jrag')]
}
}
task compileDefaultNamesTest(type: RelastTest) {
relastFiles 'src/test/jastadd/relations/Relations.relast'
grammarName = 'src/test/jastadd/relations/Relations3'
packageName = 'defaultnames.ast'
moreInputFiles 'src/test/jastadd/Utils.jadd', 'src/test/jastadd/relations/Relations.jrag'
relast {
inputFiles = [file('src/test/jastadd/relations/Relations.relast')]
grammarName = 'src/test/jastadd/relations/Relations3'
useJastAddNames = false
verbose = true
noResolverHelper = true
}
jastadd {
packageName = 'defaultnames.ast'
inputFiles = [file('src/test/jastadd/Utils.jadd'),
file('src/test/jastadd/relations/Relations.jrag')]
}
}
task compileDefaultNamesResolverTest(type: RelastTest) {
relastFiles 'src/test/jastadd/resolver/Resolver.relast'
grammarName = 'src/test/jastadd/resolver/Resolver2'
resolverHelper = true
packageName = 'defaultnames.resolver.ast'
moreInputFiles 'src/test/jastadd/Utils.jadd',
'src/test/jastadd/resolver/ResolverUtils.jadd',
'src/test/jastadd/resolver/MyRefResolver.jadd'
relast {
inputFiles = [file('src/test/jastadd/resolver/Resolver.relast')]
grammarName = 'src/test/jastadd/resolver/Resolver2'
useJastAddNames = false
}
jastadd {
packageName = 'defaultnames.resolver.ast'
inputFiles = [file('src/test/jastadd/Utils.jadd'),
file('src/test/jastadd/resolver/ResolverUtils.jadd'),
file('src/test/jastadd/resolver/MyRefResolver.jadd')]
}
}
task compileLowerBoundsTest(type: RelastTest) {
relastFiles 'src/test/jastadd/lowerbounds/LowerBounds.relast'
grammarName = 'src/test/jastadd/lowerbounds/LowerBounds'
useJastAddNames = true
packageName = 'lowerbounds.ast'
moreInputFiles 'src/test/jastadd/Utils.jadd'
relast {
inputFiles = [file('src/test/jastadd/lowerbounds/LowerBounds.relast')]
grammarName = 'src/test/jastadd/lowerbounds/LowerBounds'
useJastAddNames = true
noResolverHelper = true
}
jastadd {
packageName = 'lowerbounds.ast'
inputFiles = [file('src/test/jastadd/Utils.jadd')]
}
}
task compileMultipleTest(type: RelastTest) {
relastFiles 'src/test/jastadd/multiple/Part1.relast',
'src/test/jastadd/multiple/Part2.relast',
'src/test/jastadd/multiple/Part3.relast'
grammarName = 'src/test/jastadd/multiple/Multiple'
useJastAddNames = true
packageName = 'multiple.ast'
moreInputFiles 'src/test/jastadd/Utils.jadd'
relast {
inputFiles = [file('src/test/jastadd/multiple/Part1.relast'),
file('src/test/jastadd/multiple/Part2.relast'),
file('src/test/jastadd/multiple/Part3.relast')]
grammarName = 'src/test/jastadd/multiple/Multiple'
useJastAddNames = true
noResolverHelper = true
}
jastadd {
packageName = 'multiple.ast'
inputFiles = [file('src/test/jastadd/Utils.jadd')]
}
}
task compileMultipleMixedTest(type: RelastTest) {
relastFiles 'src/test/jastadd/multiple-mixed/Part1.relast',
'src/test/jastadd/multiple-mixed/Part2.relast',
'src/test/jastadd/multiple-mixed/Part3.relast'
grammarName = 'src/test/jastadd/multiple/Multiple'
useJastAddNames = true
packageName = 'mixed.multiple.ast'
moreInputFiles 'src/test/jastadd/Utils.jadd'
relast {
inputFiles = [file('src/test/jastadd/multiple-mixed/Part1.relast'),
file('src/test/jastadd/multiple-mixed/Part2.relast'),
file('src/test/jastadd/multiple-mixed/Part3.relast')]
grammarName = 'src/test/jastadd/multiple/Multiple'
useJastAddNames = true
noResolverHelper = true
}
jastadd {
packageName = 'mixed.multiple.ast'
inputFiles = [file('src/test/jastadd/Utils.jadd')]
}
}
task compileResolverTest(type: RelastTest) {
relastFiles 'src/test/jastadd/resolver/Resolver.relast'
grammarName = 'src/test/jastadd/resolver/Resolver'
useJastAddNames = true
resolverHelper = true
packageName = 'resolver.ast'
moreInputFiles 'src/test/jastadd/Utils.jadd',
'src/test/jastadd/resolver/ResolverUtils.jadd',
'src/test/jastadd/resolver/MyRefResolver.jadd'
relast {
inputFiles = [file('src/test/jastadd/resolver/Resolver.relast')]
grammarName = 'src/test/jastadd/resolver/Resolver'
useJastAddNames = true
}
jastadd {
packageName = 'resolver.ast'
inputFiles = [file('src/test/jastadd/Utils.jadd'),
file('src/test/jastadd/resolver/ResolverUtils.jadd'),
file('src/test/jastadd/resolver/MyRefResolver.jadd')]
}
}
task compileResolver2Test(type: RelastTest) {
relastFiles 'src/test/jastadd/resolver2/Resolver.relast'
grammarName = 'src/test/jastadd/resolver2/Resolver'
useJastAddNames = true
resolverHelper = true
packageName = 'resolver2.ast'
moreInputFiles 'src/test/jastadd/Utils.jadd',
'src/test/jastadd/resolver2/ResolverUtils.jadd',
'src/test/jastadd/resolver2/MyRefResolver.jadd'
relast {
inputFiles = [file('src/test/jastadd/resolver2/Resolver.relast')]
grammarName = 'src/test/jastadd/resolver2/Resolver'
useJastAddNames = true
}
jastadd {
packageName = 'resolver2.ast'
inputFiles = [file('src/test/jastadd/Utils.jadd'),
file('src/test/jastadd/resolver2/ResolverUtils.jadd'),
file('src/test/jastadd/resolver2/MyRefResolver.jadd')]
}
}
task compileListNamesTest(type: RelastTest) {
relastFiles 'src/test/jastadd/listnames/ListNames.relast'
grammarName = 'src/test/jastadd/listnames/ListNames'
useJastAddNames = true
jastAddList = 'ListyMcListface'
listClass = 'java.util.LinkedList'
packageName = 'listnames.ast'
moreInputFiles 'src/test/jastadd/Utils.jadd'
relast {
inputFiles = [file('src/test/jastadd/listnames/ListNames.relast')]
grammarName = 'src/test/jastadd/listnames/ListNames'
useJastAddNames = true
noResolverHelper = true
listClass = 'java.util.LinkedList'
}
jastadd {
jastAddList = 'ListyMcListface'
packageName = 'listnames.ast'
inputFiles = [file('src/test/jastadd/Utils.jadd')]
}
}
task compileSerializerTest(type: RelastTest) {
relastFiles 'src/test/jastadd/serializer/Serializer.relast'
grammarName = 'src/test/jastadd/serializer/Serializer'
useJastAddNames = true
serializer = 'jackson'
packageName = 'serializer.ast'
moreInputFiles 'src/test/jastadd/Utils.jadd'
relast {
inputFiles = [file('src/test/jastadd/serializer/Serializer.relast')]
grammarName = 'src/test/jastadd/serializer/Serializer'
useJastAddNames = true
serializer = 'jackson'
noResolverHelper = true
}
jastadd {
packageName = 'serializer.ast'
inputFiles = [file('src/test/jastadd/Utils.jadd')]
}
}
task compileSerializerDefaultNamesTest(type: RelastTest) {
relastFiles 'src/test/jastadd/serializer-names/Serializer.relast'
grammarName = 'src/test/jastadd/serializer-names/Serializer'
serializer = 'jackson'
packageName = 'defaultnames.serializer.ast'
moreInputFiles 'src/test/jastadd/Utils.jadd'
relast {
inputFiles = [file('src/test/jastadd/serializer-names/Serializer.relast')]
grammarName = 'src/test/jastadd/serializer-names/Serializer'
serializer = 'jackson'
useJastAddNames = false
verbose = true
noResolverHelper = true
}
jastadd {
packageName = 'defaultnames.serializer.ast'
inputFiles = [file('src/test/jastadd/Utils.jadd')]
}
}
task compileSerializerPointerTest(type: RelastTest) {
resolverHelper = true
relastFiles 'src/test/jastadd/serializer-pointer/Serializer.relast'
grammarName = 'src/test/jastadd/serializer-pointer/Serializer'
serializer = 'jackson-json-pointer'
packageName = 'pointer.serializer.ast'
moreInputFiles 'src/test/jastadd/Utils.jadd'
relast {
inputFiles = [file('src/test/jastadd/serializer-pointer/Serializer.relast')]
grammarName = 'src/test/jastadd/serializer-pointer/Serializer'
serializer = 'jackson-json-pointer'
useJastAddNames = false
}
jastadd {
packageName = 'pointer.serializer.ast'
inputFiles = [file('src/test/jastadd/Utils.jadd')]
}
}
task compileSerializerManualTest(type: RelastTest) {
resolverHelper = true
relastFiles 'src/test/jastadd/serializer-manual/Serializer.relast'
grammarName = 'src/test/jastadd/serializer-manual/Serializer'
serializer = 'jackson-manual-references'
packageName = 'manual.serializer.ast'
moreInputFiles 'src/test/jastadd/Utils.jadd', 'src/test/jastadd/serializer-manual/JsonPointer.jrag'
relast {
inputFiles = [file('src/test/jastadd/serializer-manual/Serializer.relast')]
grammarName = 'src/test/jastadd/serializer-manual/Serializer'
serializer = 'jackson-manual-references'
useJastAddNames = false
}
jastadd {
packageName = 'manual.serializer.ast'
inputFiles = [file('src/test/jastadd/Utils.jadd'),
file('src/test/jastadd/serializer-manual/JsonPointer.jrag')]
}
}
task compileSerializerManualRelativeTest(type: RelastTest) {
resolverHelper = true
relastFiles 'src/test/jastadd/serializer-manual-relative/Serializer.relast'
grammarName = 'src/test/jastadd/serializer-manual-relative/Serializer'
serializer = 'jackson-manual-references'
packageName = 'manual.relative.serializer.ast'
moreInputFiles 'src/test/jastadd/Utils.jadd', 'src/test/jastadd/serializer-manual-relative/JsonPointer.jrag'
relast {
inputFiles = [file('src/test/jastadd/serializer-manual-relative/Serializer.relast')]
grammarName = 'src/test/jastadd/serializer-manual-relative/Serializer'
serializer = 'jackson-manual-references'
useJastAddNames = false
}
jastadd {
packageName = 'manual.relative.serializer.ast'
inputFiles = [file('src/test/jastadd/Utils.jadd'),
file('src/test/jastadd/serializer-manual-relative/JsonPointer.jrag')]
}
}
task cleanTestGen(type: Delete) {
......
package org.jastadd.relast.plugin;
import org.gradle.api.Plugin;
import org.gradle.api.Project;
import org.gradle.api.Task;
import org.gradle.api.tasks.TaskCollection;
import java.util.Set;
/**
* Plugin for RelAst-Test.
*
* @author rschoene - Initial contribution
*/
public class RelastPlugin implements Plugin<Project> {
private Task testTask;
@Override
public void apply(Project project) {
Set<Task> tasks = project.getTasksByName("test", false);
// there should be only one task "test"
testTask = tasks.iterator().next();
TaskCollection<RelastTest> relastTests = project.getTasks().withType(RelastTest.class);
relastTests.forEach(this::setupRelastTest);
relastTests.whenTaskAdded(this::setupRelastTest);
}
private void setupRelastTest(RelastTest relastTest) {
testTask.dependsOn(relastTest);
relastTest.setGroup("verification");
}
}
package org.jastadd.relast.plugin;
import org.gradle.api.DefaultTask;
import org.gradle.api.Project;
import org.gradle.api.file.FileCollection;
import org.gradle.api.plugins.JavaPlugin;
import org.gradle.api.tasks.SourceSet;
import org.gradle.api.tasks.SourceSetContainer;
import org.gradle.api.tasks.TaskAction;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
/**
* RelAst Test Task
*
* @author rschoene - Initial contribution
*/
@SuppressWarnings({"unused", "WeakerAccess"})
public class RelastTest extends DefaultTask {
// general options
private boolean verbose = false;
// pre-process options
private List<String> relastFiles = new ArrayList<>();
private boolean useJastAddNames;
private boolean resolverHelper;
private boolean writeToFile = true;
private String grammarName;
private String listClass;
private String jastAddList;
private String serializer;
// compile options
private boolean runJastAdd = true;
private String outputDir = "src/test/java-gen/";
private String packageName;
private List<String> moreInputFiles = new ArrayList<>();
public boolean isVerbose() {
return verbose;
}
public void setVerbose(boolean verbose) {
this.verbose = verbose;
}
// pre-process options
public List<String> getRelastFiles() {
return relastFiles;
}
public void relastFiles(String relastFile) {
this.relastFiles.add(relastFile);
}
public void relastFiles(String[] relastFilesArray) {
this.relastFiles = Arrays.asList(relastFilesArray);
}
public boolean isUseJastAddNames() {
return useJastAddNames;
}
public void setUseJastAddNames(boolean useJastAddNames) {
this.useJastAddNames = useJastAddNames;
}
public boolean isResolverHelper() {
return resolverHelper;
}
public void setResolverHelper(boolean resolverHelper) {
this.resolverHelper = resolverHelper;
}
public boolean isWriteToFile() {
return writeToFile;
}
public void setWriteToFile(boolean writeToFile) {
this.writeToFile = writeToFile;
}
public String getGrammarName() {
return grammarName;
}
public void setGrammarName(String grammarName) {
this.grammarName = grammarName;
}
public String getListClass() {
return listClass;
}
public void setListClass(String listClass) {
this.listClass = listClass;
}
public String getJastAddList() {
return jastAddList;
}
public void setJastAddList(String jastAddList) {
this.jastAddList = jastAddList;
}
public String getSerializer() {
return serializer;
}
public void setSerializer(String serializer) {
this.serializer = serializer;
}
// compile options
public boolean isRunJastAdd() {
return runJastAdd;
}
public void setRunJastAdd(boolean runJastAdd) {
this.runJastAdd = runJastAdd;
}
public String getOutputDir() {
return outputDir;
}
public void setOutputDir(String outputDir) {
this.outputDir = outputDir;
}
public String getPackageName() {
return packageName;
}
public void setPackageName(String packageName) {
this.packageName = packageName;
}
public List<String> getMoreInputFiles() {
return moreInputFiles;
}
public void moreInputFiles(String f) {
this.moreInputFiles.add(f);
}
public void moreInputFiles(String[] fileArray) {
this.moreInputFiles.addAll(Arrays.asList(fileArray));
}
private boolean isSet(String option) {
return option != null && !option.isEmpty();
}
private String[] genSuffixes = {".ast", ".jadd", "RefResolver.jadd", "ResolverStubs.jrag", "Serializer.jadd"};
@TaskAction
void runTest() {
setGroup("verification");
setDescription("Runs a relast test");
Project project = getProject();
if (isVerbose()) {
System.out.println("Running relast test");
System.out.println("relast files: " + getRelastFiles());
System.out.println("Deleting files");
}
// first, delete generated files
List<String> genFiles = new ArrayList<>();
for (String suffix : genSuffixes) {
genFiles.add(getGrammarName() + suffix);
}
if (isVerbose()) {
System.out.println("gen files: " + genFiles);
}
project.delete(deleteSpec -> {
deleteSpec.delete(genFiles);
if (isSet(getPackageName())) {
deleteSpec.delete(Paths.get(getOutputDir(), getPackageName()));
}
});
if (isVerbose()) {
System.out.println("Pre processing, running relast");
}
// then, run relast pre processing
project.getPlugins().withType(JavaPlugin.class, javaPlugin -> {
SourceSetContainer sourceSets = (SourceSetContainer) project.getProperties().get("sourceSets");
FileCollection runtimeClasspath = sourceSets.getByName(SourceSet.MAIN_SOURCE_SET_NAME).getRuntimeClasspath();
project.javaexec(javaExecSpec -> {
javaExecSpec.setClasspath(runtimeClasspath);
javaExecSpec.setMain("org.jastadd.relast.compiler.Compiler");
List<Object> args = new ArrayList<>(getRelastFiles());
args.add("--quiet");
if (isWriteToFile()) {
args.add("--file");
}
if (isUseJastAddNames()) {
args.add("--useJastAddNames");
}
if (isResolverHelper()) {
args.add("--resolverHelper");
}
if (isSet(getJastAddList())) {
args.add("--jastAddList=" + getJastAddList());
}
if (isSet(getListClass())) {
args.add("--listClass=" + getListClass());
}
if (isSet(getSerializer())) {
args.add("--serializer=" + getSerializer());
}
args.add("--grammarName=" + getGrammarName());
if (isVerbose()) {
System.out.println("Start relast with args: " + args);
}
javaExecSpec.args(args);
});
});
if (isRunJastAdd()) {
if (isVerbose()) {