Commit 27131db7 authored by Fred Eisele's avatar Fred Eisele
Browse files

gradle runs tests

parent 9f8ff47c
......@@ -8,6 +8,7 @@ import org.babeloff.plugins.antlr.Antlr4Task
apply plugin: 'java'
apply plugin: 'maven'
apply plugin: 'application'
apply plugin: 'idea'
apply plugin: 'eclipse'
......@@ -16,6 +17,8 @@ group = 'net.catdata'
project.ext.versionFile = file('gradle/version.properties')
mainClassName = "catdata.ide.IDE"
task loadVersion {
project.version = ProjectVersion.read(logger, versionFile)
}
......@@ -81,7 +84,7 @@ task antlrGen (type: Antlr4Task) {
lexerGrammar = file("${project.rootDir}/src/main/antlr/catdata/aql/grammar/AqlLexerRules.g4")
parserGrammar = file("${project.rootDir}/src/main/antlr/catdata/aql/grammar/AqlParser.g4")
module = "catdata.aql.grammar"
targetDir = file("${project.buildDir}/generated-src/antlr/main/catdata/aql/grammar")
targetDir = file("${project.buildDir}/generated-src/java/catdata/aql/grammar")
visitor = false
listener = true
}
......@@ -89,7 +92,7 @@ task antlrGen (type: Antlr4Task) {
compileJava.dependsOn antlrGen
wrapper {
gradleVersion = '4.10'
gradleVersion = '4.10.1'
distributionUrl = "https://services.gradle.org/distributions/gradle-$gradleVersion-all.zip"
}
......@@ -97,28 +100,34 @@ wrapper {
sourceSets {
main {
java {
srcDirs = ['src/main/java','build/generated-src/antlr']
srcDirs = ['src/main/java','build/generated-src/java']
}
resources {
srcDirs = ["${project.projectDir}/resources"]
}
}
test {
java {
srcDirs = ['test/java']
srcDirs = ["${project.projectDir}/src/test/java"]
}
resources {
srcDirs = ["${project.projectDir}/resources"]
}
}
}
idea {
module {
generatedSourceDirs += file("${project.buildDir}/generated-src/antlr/main")
generatedSourceDirs += file("${project.buildDir}/generated-src/java")
downloadJavadoc = true
downloadSources = false
}
}
repositories {
maven { url "https://nexus.isis.vanderbilt.edu/repository/maven-releases" }
maven { url "https://nexus.isis.vanderbilt.edu/repository/maven-snapshots" }
mavenCentral()
mavenCentral()
maven { url "https://nexus.isis.vanderbilt.edu/repository/maven-releases" }
maven { url "https://nexus.isis.vanderbilt.edu/repository/maven-snapshots" }
}
dependencies {
......@@ -146,7 +155,8 @@ dependencies {
'junit:junit:4.12'
)
testImplementation(
'org.junit.jupiter:junit-jupiter-api:5.3.1'
'org.junit.jupiter:junit-jupiter-api:5.3.1',
'org.junit.jupiter:junit-jupiter-params:5.3.1'
)
testRuntimeOnly(
'org.junit.jupiter:junit-jupiter-engine:5.3.1',
......
......@@ -30,10 +30,13 @@ class ProjectVersion {
}
Properties versionProps = new Properties()
versionFile.withInputStream { stream -> versionProps.load(stream) }
new ProjectVersion(versionProps.year.toInteger(),
ProjectVersion pv = new ProjectVersion(
versionProps.year.toInteger(),
versionProps.month.toInteger(),
versionProps.day.toInteger(),
versionProps.release.toBoolean())
logger.quiet 'the version specified is: ' + pv.toString()
return pv;
}
@Override
......
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.1-all.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
......@@ -84,7 +84,9 @@ public class Examples {
if (url == null) {
URL l = ClassLoader.getSystemResource("examples");
if (l == null) {
new RuntimeException("Cannot locate examples").printStackTrace();
final String classpath = System.getProperty("java.class.path");
final String[] classpathEntries = classpath.split(File.pathSeparator);
new RuntimeException("Cannot locate 'examples' from : " + classpath).printStackTrace();
HashMap<Language, List<Example>> ret = new HashMap<>();
for (Language ll : Language.values()) {
ret.put(ll, new LinkedList<>());
......
package catdata.aql;
import catdata.Program;
import catdata.aql.exp.AqlEnv;
import catdata.aql.exp.AqlMultiDriver;
import catdata.aql.exp.AqlParserFactory;
import catdata.aql.exp.Exp;
import catdata.ide.Examples;
import catdata.ide.Language;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
import java.util.stream.Stream;
import static org.junit.jupiter.api.Assertions.fail;
public class AqlExampleTest {
@ParameterizedTest
@MethodSource("loadExamples")
public void testSourceText(String description, String src) {
System.out.println("testing example: " + description);
try {
final Program<Exp<?>> prog = AqlParserFactory.getParser().parseProgram(src);
final AqlMultiDriver driver = new AqlMultiDriver(prog, new String[1], null);
driver.start();
final AqlEnv lastEnv = driver.env;
if (lastEnv.exn != null) {
throw lastEnv.exn;
}
} catch (Exception e) {
final String msg = new StringBuilder()
.append("Test failed for test case '")
.append(description)
.append("' \n")
.append(src)
.append("'.\n")
.append(e.getStackTrace())
.toString();
// System.out.println( msg );
fail(msg);
}
}
public static Stream<Arguments> loadExamples() {
return Examples.getExamples(Language.AQL).stream()
.map(example -> Arguments.of(example.getName(), example.getText()));
}
}
......@@ -2,7 +2,7 @@ package catdata.aql;
import catdata.Program;
import catdata.Util;
import catdata.aql.exp.AqlParser;
import catdata.aql.exp.AqlParserFactory;
import catdata.aql.exp.AqlEnv;
import catdata.aql.exp.AqlMultiDriver;
import catdata.aql.exp.Exp;
......@@ -20,52 +20,5 @@ import org.junit.jupiter.api.Test;
public class AqlTest {
// This duplicated some of AqlTester, but as headless unit tests.
@Test
public void testAqlExamples() {
for (Example e : Examples.getExamples(Language.AQL)) {
System.out.println("testing example: " + e.getName());
testSourceText("example: " + e.getName(), e.getText());
}
}
/////////////////////////////////////////////////////////////////////////////////
//
// helpers
//
/////////////////////////////////////////////////////////////////////////////////
public void testSourceText(String description, String src) {
try {
Program<Exp<?>> prog = AqlParser.getParser().parseProgram(src);
testAqlMultiDriver(prog);
} catch (Exception e) {
fail("Test failed for test case '" + description + "'.");
// e.printStackTrace();
System.out.println("Test failed for test case '" + description + "'.\n" + e.getStackTrace());
fail("Test failed for test case '" + description + "'.\n" + e.getStackTrace());
}
}
// TODO Code is similar to that in AqlTester and AqlCmdLine; refactor.
public Program<Exp<?>> parseFileOrNull(String fileName) {
try (FileReader r = new FileReader(fileName)) {
String src = Util.readFile(r);
Program<Exp<?>> prog = AqlParser.getParser().parseProgram(src);
return prog;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
// TODO Code is similar to that in AqlTester and AqlCmdLine; refactor.
public void testAqlMultiDriver(Program<Exp<?>> prog) {
AqlMultiDriver driver = new AqlMultiDriver(prog, new String[1], null);
driver.start();
AqlEnv lastEnv = driver.env;
if (lastEnv.exn != null) {
throw lastEnv.exn;
}
}
}
Markdown is supported
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