use of org.lflang.DefaultErrorReporter in project lingua-franca by lf-lang.
the class TestBase method configure.
/**
* Configure a test by applying the given configurator and return a
* generator context. Also, if the given level is less than
* `TestLevel.BUILD`, add a `no-compile` flag to the generator context. If
* the configurator was not applied successfully, throw an AssertionError.
*
* @param test the test to configure.
* @param configurator The configurator to apply to the test.
* @param level The level of testing in which the generator context will be
* used.
* @return a generator context with a fresh resource, unaffected by any AST
* transformation that may have occured in other tests.
* @throws IOException if there is any file access problem
*/
private LFGeneratorContext configure(LFTest test, Configurator configurator, TestLevel level) throws IOException {
var context = new MainContext(LFGeneratorContext.Mode.STANDALONE, CancelIndicator.NullImpl, (m, p) -> {
}, new Properties(), true, fileConfig -> new DefaultErrorReporter());
var r = resourceSetProvider.get().getResource(URI.createFileURI(test.srcFile.toFile().getAbsolutePath()), true);
if (r.getErrors().size() > 0) {
test.result = Result.PARSE_FAIL;
throw new AssertionError("Test did not parse correctly.");
}
fileAccess.setOutputPath(FileConfig.findPackageRoot(test.srcFile, s -> {
}).resolve(FileConfig.DEFAULT_SRC_GEN_DIR).toString());
test.context = context;
test.fileConfig = new FileConfig(r, FileConfig.getSrcGenRoot(fileAccess), context.useHierarchicalBin());
// Set the no-compile flag the test is not supposed to reach the build stage.
if (level.compareTo(TestLevel.BUILD) < 0) {
context.getArgs().setProperty("no-compile", "");
}
addExtraLfcArgs(context.getArgs());
// Update the test by applying the configuration. E.g., to carry out an AST transformation.
if (configurator != null && !configurator.configure(test)) {
test.result = Result.CONFIG_FAIL;
throw new AssertionError("Test configuration unsuccessful.");
}
return context;
}
use of org.lflang.DefaultErrorReporter in project lingua-franca by lf-lang.
the class LinguaFrancaDependencyAnalysisTest method circularInstantiation.
/**
* Check that circular instantiations are detected.
*/
@Test
public void circularInstantiation() throws Exception {
// Java 17:
// String testCase = """
// target C;
//
// reactor X {
// reaction() {=
// //
// =}
// p = new Y();
// }
//
// reactor Y {
// q = new X();
// }
// """
// Java 11:
String testCase = String.join(System.getProperty("line.separator"), "target C;", "", "reactor X {", " reaction() {=", " //", " =}", " p = new Y();", "}", "", "reactor Y {", " q = new X();", "}");
Model model = parser.parse(testCase);
Assertions.assertNotNull(model);
ModelInfo info = new ModelInfo();
info.update(model, new DefaultErrorReporter());
Assertions.assertTrue(info.instantiationGraph.hasCycles() == true, "Did not detect cyclic instantiation.");
}
use of org.lflang.DefaultErrorReporter in project lingua-franca by lf-lang.
the class LinguaFrancaDependencyAnalysisTest method cyclicDependency.
/**
* Check that circular dependencies between reactions are detected.
*/
@Test
public void cyclicDependency() throws Exception {
// Java 17:
// String testCase = """
// target C;
//
// reactor Clock {
// timer t(0, 10 msec);
// input x:int;
// output y:int;
// reaction(t) -> y {=
//
// =}
// reaction(x) -> y {=
//
// =}
// }
//
// reactor A {
// input x:int;
// output y:int;
// reaction(x) -> y {=
//
// =}
// }
//
// main reactor Loop {
// c = new Clock();
// a = new A();
// c.y -> a.x;
// a.y -> c.x;
// }
// """
// Java 11:
String testCase = String.join(System.getProperty("line.separator"), "target C;", "", "reactor Clock {", " timer t(0, 10 msec);", " input x:int;", " output y:int;", " reaction(t) -> y {=", " ", " =}", " reaction(x) -> y {=", " ", " =}", "}", "", "reactor A {", " input x:int;", " output y:int;", " reaction(x) -> y {=", " ", " =}", "}", "", "main reactor Loop {", " c = new Clock();", " a = new A();", " c.y -> a.x;", " a.y -> c.x;", "}");
Model model = parser.parse(testCase);
Assertions.assertNotNull(model);
Instantiation mainDef = null;
TreeIterator<EObject> it = model.eResource().getAllContents();
while (it.hasNext()) {
EObject obj = it.next();
if (!(obj instanceof Reactor)) {
continue;
}
Reactor reactor = (Reactor) obj;
if (reactor.isMain()) {
// Creating an definition for the main reactor because
// there isn't one.
mainDef = LfFactory.eINSTANCE.createInstantiation();
mainDef.setName(reactor.getName());
mainDef.setReactorClass(reactor);
}
}
ReactorInstance instance = new ReactorInstance(toDefinition(mainDef.getReactorClass()), new DefaultErrorReporter());
Assertions.assertFalse(instance.getCycles().isEmpty());
}
Aggregations