Commit 83a04e63 authored by Johannes Mey's avatar Johannes Mey
Browse files

move first test to gradle

parent f2055430
......@@ -22,8 +22,8 @@ dependencies {
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.4.0'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.4.0'
compile group: 'net.sf.beaver', name: 'beaver-rt', version: '0.9.11'
// compile group: 'org.apache.logging.log4j', name: 'log4j-api', version: '2.10.0'
// compile group: 'org.apache.logging.log4j', name: 'log4j-core', version: '2.10.0'
compile group: 'org.apache.logging.log4j', name: 'log4j-api', version: '2.10.0'
compile group: 'org.apache.logging.log4j', name: 'log4j-core', version: '2.10.0'
}
sourceSets {
......@@ -100,5 +100,6 @@ jastadd {
test {
outputs.upToDateWhen { false }
useJUnitPlatform()
}
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="INFO">
<Appenders>
<Console name="Console" target="SYSTEM_OUT">
<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
</Console>
</Appenders>
<Loggers>
<Root level="info">
<AppenderRef ref="Console"/>
</Root>
</Loggers>
</Configuration>
\ No newline at end of file
*.out
\ No newline at end of file
package org.jastadd.relast.tests.errors;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.jastadd.relast.compiler.Compiler;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import java.io.File;
import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Paths;
public class Errors {
private static final Logger logger = LogManager.getLogger(Errors.class);
static String readFile(String path, Charset encoding)
throws IOException {
byte[] encoded = Files.readAllBytes(Paths.get(path));
return new String(encoded, encoding);
}
static int exec(Class klass, String[] args, File err) throws IOException,
InterruptedException {
String javaHome = System.getProperty("java.home");
String javaBin = javaHome + File.separator + "bin" + File.separator + "java";
String classpath = System.getProperty("java.class.path");
String className = klass.getName();
String[] newArgs = new String[args.length + 4];
newArgs[0] = javaBin;
newArgs[1] = "-cp";
newArgs[2] = classpath;
newArgs[3] = className;
System.arraycopy(args, 0, newArgs, 4, args.length);
ProcessBuilder builder = new ProcessBuilder(newArgs);
builder.redirectError(err);
Process process = builder.start();
process.waitFor();
return process.exitValue();
}
@Test
void test1() throws IOException {
String inFile = "./src/test/jastadd/errors/Errors.relast";
String outFile = "./src/test/jastadd/errors/Errors.out";
String expectedFile = "./src/test/jastadd/errors/Errors.expected";
try {
System.out.println(System.getProperty("user.dir"));
int returnValue = exec(Compiler.class, new String[]{inFile}, new File(outFile));
Assertions.assertEquals(1, returnValue, "Relast did not return with value 1");
} catch (IOException | InterruptedException e) {
e.printStackTrace();
}
String out = readFile(outFile, Charset.defaultCharset());
String expected = readFile(expectedFile, Charset.defaultCharset());
Assertions.assertEquals(out, expected);
logger.info("'relast Errors.relast' returned \n{}", out);
}
@Test
void test2() throws IOException {
String inFile = "./src/test/jastadd/errors/Inheritance.relast";
String outFile = "./src/test/jastadd/errors/Inheritance.out";
String expectedFile = "./src/test/jastadd/errors/Inheritance.expected";
try {
System.out.println(System.getProperty("user.dir"));
int returnValue = exec(Compiler.class, new String[]{inFile}, new File(outFile));
Assertions.assertEquals(1, returnValue, "Relast did not return with value 1");
} catch (IOException | InterruptedException e) {
e.printStackTrace();
}
String out = readFile(outFile, Charset.defaultCharset());
String expected = readFile(expectedFile, Charset.defaultCharset());
Assertions.assertEquals(out, expected);
logger.info("'relast Inheritance.relast' returned \n{}", out);
}
}
all: build-jar test
build-jar:
(cd ../../ && ./gradlew jar)
test:
java -jar ../../build/libs/relast.jar Errors.relast 2> Errors.out || true
diff Errors.out Errors.expected
java -jar ../../build/libs/relast.jar Inheritance.relast 2> Inheritance.out || true
diff Inheritance.out Inheritance.expected
@echo "#"
@echo "# ERROR TESTS OK"
@echo "#"
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