Commit 637fe8ba authored by Johannes Mey's avatar Johannes Mey
Browse files

move final tests to gradle/junit

parent 66f9729b
......@@ -10,4 +10,7 @@ src/test/jastadd/relations/Relations.jadd
src/test/jastadd/lowerbounds/LowerBounds.ast
src/test/jastadd/lowerbounds/LowerBounds.jadd
src/test/jastadd/multiple/Multiple.ast
src/test/jastadd/multiple/Multiple.jadd
\ No newline at end of file
src/test/jastadd/multiple/Multiple.jadd
src/test/jastadd/resolver/Resolver.ast
src/test/jastadd/resolver/Resolver.jadd
src/test/jastadd/resolver/ResolverRefResolver.jadd
\ No newline at end of file
......@@ -179,6 +179,28 @@ task compileMultipleTest(type: JavaExec, group: 'verification') {
args '--o=src/test/java-gen/', '--package=multiple.ast', 'src/test/jastadd/multiple/Multiple.ast', 'src/test/jastadd/multiple/Multiple.jadd', 'src/test/jastadd/Utils.jadd'
}
task preprocessResolverTest(type: JavaExec, group: 'verification') {
doFirst {
delete 'src/test/jastadd/resolver/Resolver.ast', 'src/test/jastadd/resolver/Resolver.jadd'
}
classpath = sourceSets.main.runtimeClasspath
main = 'org.jastadd.relast.compiler.Compiler'
args 'src/test/jastadd/resolver/Resolver.relast', '--file', '--grammarName=src/test/jastadd/resolver/Resolver', '--resolverHelper'
}
task compileResolverTest(type: JavaExec, group: 'verification') {
doFirst {
delete 'src/test/java-gen/resolver'
}
classpath = sourceSets.main.runtimeClasspath
main = 'org.jastadd.JastAdd'
args '--o=src/test/java-gen/', '--package=resolver.ast', 'src/test/jastadd/resolver/Resolver.ast', 'src/test/jastadd/resolver/Resolver.jadd', 'src/test/jastadd/resolver/ResolverUtils.jadd', 'src/test/jastadd/resolver/ResolverRefResolver.jadd', 'src/test/jastadd/resolver/MyRefResolver.jadd', 'src/test/jastadd/Utils.jadd'
}
test {
outputs.upToDateWhen { false }
......@@ -194,4 +216,7 @@ test.dependsOn compileLowerBoundsTest
compileLowerBoundsTest.dependsOn preprocessLowerBoundsTest
test.dependsOn compileMultipleTest
compileMultipleTest.dependsOn preprocessMultipleTest
\ No newline at end of file
compileMultipleTest.dependsOn preprocessMultipleTest
test.dependsOn compileResolverTest
compileResolverTest.dependsOn preprocessResolverTest
\ No newline at end of file
......@@ -6,10 +6,5 @@ aspect MyRewrites {
return root().findNamedElement(id);
}
refine RefResolverStubs eq A.resolveRel2(String id) {
// default to context-independent name resolution
return resolveNamedElement(id);
}
}
aspect Utils {
public String NamedElement.toString() {
return getName();
}
inh Root ASTNode.root();
eq Root.getA(int i).root() = this;
......
import AST.*;
import java.util.*;
package org.jastadd.relast.tests;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import resolver.ast.A;
import resolver.ast.B;
import resolver.ast.NamedElement;
import resolver.ast.Root;
import static org.junit.jupiter.api.Assertions.assertSame;
@SuppressWarnings("ArraysAsListWithZeroOrOneArgument")
public class All extends AbstractTests {
class ResolverHelper {
private Root r;
private A a1;
private A a2;
......@@ -11,27 +19,20 @@ public class All extends AbstractTests {
private B b2;
private B b3;
public static void main(String args[]) {
new All().test();
}
public void test() {
testNameRes1();
}
/**
* rel A.Di1 -> B;
*/
private void testNameRes1() {
@Test
void testNameRes1() {
setup();
a1.setRel1(NamedElement.createRef("b2"));
System.out.println("Rel 1 of a1 has type " + a1.getRel1().getClass().getSimpleName());
assertSame(a1.getRel1(), b2);
}
private void setup() {
@BeforeEach
void setup() {
r = new Root();
a1 = new A("a1");
a2 = new A("a2");
......
all:
cd ../ && ./gradlew jar
cd valid && make test
cd errors && make test
cd multipleFiles && make test
cd resolverHelper && make test
/AST/*
/Relations.ast
Relations.jadd
AllRefResolver.jadd
public class AbstractTests {
protected void assertException() {
check(false, "should throw exception");
}
protected void assertTrue(boolean b) {
check(b, "value should be true (is false)");
}
protected void assertFalse(boolean b) {
check(!b, "value should be flase (is true)");
}
protected void assertNull(Object obj) {
check(obj == null, "Object not null: " + obj);
}
protected void assertSame(Object o1, Object o2) {
check(o1 == o2, "Objects not same: " + o1 + ", " + o2);
}
protected void assertEquals(Object o1, Object o2) {
check(o1.equals(o2), "Objects not equals: " + o1 + ", " + o2);
}
protected void check(boolean b, String message) {
if (!b) {
throw new RuntimeException(message);
}
}
}
\ No newline at end of file
Root ::= A* B*;
abstract NamedElement ::= <Name:String>;
A : NamedElement ::= <_impl_Rel1:NamedElement> <_impl_Rel2:NamedElement>;
B : NamedElement;
__unresolvedRoot : Root ::= <__token:String>;
__unresolvedNamedElement : NamedElement ::= <__token:String>;
__unresolvedA : A ::= <__token:String>;
__unresolvedB : B ::= <__token:String>;
import java.util.ArrayList;
import java.util.Collections;
aspect RelAstAPI {
public A.A(String Name) {
setName(Name);
}
public __unresolvedA.__unresolvedA(String Name, String __token) {
setName(Name);
set__token(__token);
}
// rel A.Rel1 -> NamedElement
public NamedElement A.getRel1() {
if (get_impl_Rel1() != null && get_impl_Rel1().unresolved()) {
set_impl_Rel1(resolveRel1(get_impl_Rel1().asUnresolvedNamedElement().get__token()));
}
return get_impl_Rel1();
}
public void A.setRel1(NamedElement o) {
assertNotNull(o);
set_impl_Rel1(o);
}
// rel A.Rel2 -> NamedElement
public NamedElement A.getRel2() {
if (get_impl_Rel2() != null && get_impl_Rel2().unresolved()) {
set_impl_Rel2(resolveRel2(get_impl_Rel2().asUnresolvedNamedElement().get__token()));
}
return get_impl_Rel2();
}
public void A.setRel2(NamedElement o) {
assertNotNull(o);
set_impl_Rel2(o);
}
public boolean ASTNode.violatesLowerBounds() {
return !getLowerBoundsViolations().isEmpty();
}
public java.util.List<Pair<ASTNode, String>> ASTNode.getLowerBoundsViolations() {
ArrayList<Pair<ASTNode, String>> list = new ArrayList<>();
computeLowerBoundsViolations(list);
return list;
}
public void ASTNode.computeLowerBoundsViolations(java.util.List<Pair<ASTNode, String>> list) {
for (int i = 0; i < getNumChildNoTransform(); i++) {
getChildNoTransform(i).computeLowerBoundsViolations(list);
}
}
public void A.computeLowerBoundsViolations(java.util.List<Pair<ASTNode, String>> list) {
if (getRel1() == null) {
list.add(new Pair<>(this, "Rel1"));
}
if (getRel2() == null) {
list.add(new Pair<>(this, "Rel2"));
}
super.computeLowerBoundsViolations(list);
}
public class Pair<T1, T2> {
public final T1 _1;
public final T2 _2;
public Pair(T1 _1, T2 _2) {
ASTNode.assertNotNull(_1);
ASTNode.assertNotNull(_2);
this._1 = _1;
this._2 = _2;
}
public boolean equals(Object other) {
if (other instanceof Pair) {
Pair<?,?> p = (Pair<?,?>) other;
return _1.equals(p._1) && _2.equals(p._2);
} else {
return false;
}
}
public int hashCode() {
return 31*_1.hashCode() + _2.hashCode();
}
}
public static void ASTNode.assertNotNull(Object obj) {
if (obj == null) {
throw new NullPointerException();
}
}
}
all: build-jar test
test: clean test1
@echo "#"
@echo "# RESOLVER HELPER TESTS OK"
@echo "#"
build-jar:
(cd ../../ && ./gradlew jar)
test1:
java -jar ../../build/libs/relast.jar Grammar.relast --file --grammarName=Relations --resolverHelper
java -jar ../../tools/jastadd2.jar --package=AST --rewrite=cnta Relations.ast Relations.jadd AllRefResolver.jadd MyRefResolver.jadd Utils.jadd
javac AST/*.java Relations.java
java Relations
clean:
rm -rf AST
rm -f *.class
rm -f *.ast
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment