Skip to main content

module lang::java::tests::BasicM3Tests

rascal-0.43.0
org.rascalmpl.java-air-1.0.3

Regression tests and backward compatibility tests for AST construction and M3 extraction for Java

Usage​

import lang::java::tests::BasicM3Tests;

Dependencies​

import util::Reflective;
import List;
import Message;
import IO;
import util::FileSystem;
import util::Math;
import ValueIO;
import Node;
import String;
import lang::java::m3::Core;
import lang::java::m3::AST;

function unpackExampleProject​

Unpack a test source zip in a temporary folder for downstream analysis.

loc unpackExampleProject(str name, loc projectZip)

function compareM3s​

Comparison and simplistic differential diagnosis between two M3 models

bool compareM3s(M3 a, M3 b)

Tests

test junitM3RemainedTheSame​


test bool junitM3RemainedTheSame() {
reference = readBinaryValueFile(#M3, junitBinaryM3);
root = junitProject;
models = createM3sFromFiles(find(root + "src", "java"),
sourcePath = junitSourcePath,
classPath = junitClassPath,
javaVersion = JLS13());
result = composeJavaM3(|project://junit4|, models);

if (OVERWRITE) {
writeBinaryValueFile(junitBinaryM3, result);
}

return compareM3s(reference, result);
}

test snakesM3RemainedTheSame​


test bool snakesM3RemainedTheSame() {
reference = readBinaryValueFile(#M3, snakesAndLaddersBinaryM3);
root = snakesAndLaddersProject;

models = createM3sFromFiles(find(root + "src", "java"),
sourcePath = snakesSourcePath,
classPath = snakesClassPath,
javaVersion = JLS13());
result = composeJavaM3(|project://snakes-and-ladders/|, models);

if (OVERWRITE) {
writeBinaryValueFile(snakesAndLaddersBinaryM3, result);
}

return compareM3s(reference, result);
}

test junitASTsRemainedTheSame​

  
test bool junitASTsRemainedTheSame() {
reference = readBinaryValueFile(#set[Declaration], junitBinaryASTs);
root = junitProject;

asts = createAstsFromFiles(find(root + "src", "java"), true,
sourcePath = junitSourcePath,
classPath = junitClassPath,
javaVersion = JLS13());

// Because java.lang.SecurityManager no longer exists in JLS13 and we are compiling
// an older version of Junit4, we get unresolved decl's for all things related to SecurityManager.
astNodeSpecification(asts, checkNameResolution=true, checkSourceLocation=true);

if (OVERWRITE) {
writeBinaryValueFile(junitBinaryASTs, asts);
}

return reference == asts;
}

test snakesASTsRemainedTheSame​

        
test bool snakesASTsRemainedTheSame() {
reference = readBinaryValueFile(#set[Declaration], snakesAndLaddersBinaryAST);

root = snakesAndLaddersProject;

asts = createAstsFromFiles(find(root + "src", "java"), true,
sourcePath = junitSourcePath,
classPath = junitClassPath,
javaVersion = JLS13());

astNodeSpecification(asts, checkNameResolution=true, checkSourceLocation=true);

if (OVERWRITE) {
writeBinaryValueFile(snakesAndLaddersBinaryAST, asts);
}

return reference == asts;
}

test hamcrestJarM3RemainedTheSame​


test bool hamcrestJarM3RemainedTheSame() {
reference = readBinaryValueFile(#M3, hamcrestBinaryM3);

// move to a location that is the same on all build machines
targetJar = |tmp:///| + hamcrestJar.file;
copy(hamcrestJar, targetJar, overwrite=true);

result = createM3FromJar(targetJar);
if (OVERWRITE) {
writeBinaryValueFile(hamcrestBinaryM3, result);
}
return compareM3s(reference, result);
}