Search in sources :

Example 26 with SemanticConditionList

use of abs.frontend.analyser.SemanticConditionList in project abstools by abstools.

the class ASTBasedABSTestRunnerGeneratorTest method testGenerateTestRunner.

@Test
public final void testGenerateTestRunner() {
    final Model model;
    try {
        model = Main.parseString(ABS_UNIT + TEST_CODE, true);
    } catch (Exception e) {
        throw new IllegalStateException("Cannot parse test code", e);
    }
    ABSTestRunnerGenerator generator = new ASTBasedABSTestRunnerGenerator(model);
    ByteArrayOutputStream stream = new ByteArrayOutputStream();
    PrintStream print = new PrintStream(stream);
    generator.generateTestRunner(print);
    String runner = stream.toString();
    try {
        Model result = Main.parseString(ABS_UNIT + TEST_CODE + runner, true);
        StringBuilder parseErrors = new StringBuilder();
        if (result.hasParserErrors()) {
            parseErrors.append("Syntactic errors: ");
            List<ParserError> es = result.getParserErrors();
            parseErrors.append(es.size());
            parseErrors.append("\n");
            for (ParserError e : es) {
                parseErrors.append(e.getHelpMessage());
                parseErrors.append("\n");
            }
        }
        assertFalse("Generated code must not have parse error: " + parseErrors, result.hasParserErrors());
        StringBuilder errors = new StringBuilder();
        if (result.hasErrors()) {
            SemanticConditionList el = result.getErrors();
            errors.append("Semantic errors: ");
            errors.append(el.getErrorCount());
            errors.append("\n");
            for (SemanticCondition error : el) {
                errors.append(error.getHelpMessage());
                errors.append("\n");
            }
        }
        assertFalse("Generated code must not have semantic error: " + errors, result.hasErrors());
        result.typeCheck();
        assertFalse("Generated code must not have type error", result.hasTypeErrors());
        assertThat("Has one module that has the name 'AbsUnit.TestRunner' and a main block", result.getModuleDecls(), hasItem(new ModuleMatcher()));
    } catch (Exception e) {
        fail("Cannot throw an exception ");
    }
}
Also used : PrintStream(java.io.PrintStream) ParserError(abs.frontend.parser.ParserError) SemanticCondition(abs.frontend.analyser.SemanticCondition) ByteArrayOutputStream(java.io.ByteArrayOutputStream) SemanticConditionList(abs.frontend.analyser.SemanticConditionList) Model(abs.frontend.ast.Model) Test(org.junit.Test)

Example 27 with SemanticConditionList

use of abs.frontend.analyser.SemanticConditionList in project abstools by abstools.

the class ParFnAppTest method tooFewArgsForFuncParam.

@Test
public void tooFewArgsForFuncParam() {
    Model m = parse("apply(tooMany)(0);", applyFunction(), "def Int tooMany(Int i, Int j) = 0;");
    m.expandPartialFunctions();
    SemanticConditionList conditions = m.typeCheck();
    assertTrue(conditions.containsErrors());
}
Also used : SemanticConditionList(abs.frontend.analyser.SemanticConditionList) Model(abs.frontend.ast.Model) Test(org.junit.Test)

Example 28 with SemanticConditionList

use of abs.frontend.analyser.SemanticConditionList in project abstools by abstools.

the class LocationTypeTests method testAwaitFail.

@Test
public void testAwaitFail() {
    LocationType lt = LocationType.INFER;
    Model m = assertParseOkStdLib("interface T { Unit foo(); } class C { T t = null; Unit bar() { await t!foo(); }}");
    // This line is essential to trigger the NPE!
    assertFalse(m.hasErrors());
    LocationTypeInferrerExtension ltie = new LocationTypeInferrerExtension(m);
    ltie.setDefaultType(lt);
    ltie.setLocationTypingPrecision(LocationTypingPrecision.CLASS_LOCAL_FAR);
    m.registerTypeSystemExtension(ltie);
    m.getErrors();
    SemanticConditionList e = m.typeCheck();
}
Also used : LocationTypeInferrerExtension(abs.frontend.typechecker.locationtypes.infer.LocationTypeInferrerExtension) SemanticConditionList(abs.frontend.analyser.SemanticConditionList) Model(abs.frontend.ast.Model) LocationType(abs.frontend.typechecker.locationtypes.LocationType) Test(org.junit.Test) FrontendTest(abs.frontend.FrontendTest)

Example 29 with SemanticConditionList

use of abs.frontend.analyser.SemanticConditionList in project abstools by abstools.

the class LocationTypeTests method assertLocationTypeErrorOnly.

private void assertLocationTypeErrorOnly(String code) {
    Model m = assertParse(code, WITH_STD_LIB);
    LocationTypeExtension te = new LocationTypeExtension(m);
    m.registerTypeSystemExtension(te);
    SemanticConditionList e = m.typeCheck();
    assertFalse("No type error occurred", !e.containsErrors());
    assertInferFails(code);
}
Also used : SemanticConditionList(abs.frontend.analyser.SemanticConditionList) LocationTypeExtension(abs.frontend.typechecker.locationtypes.LocationTypeExtension) Model(abs.frontend.ast.Model)

Example 30 with SemanticConditionList

use of abs.frontend.analyser.SemanticConditionList in project abstools by abstools.

the class LocationTypeTests method assertTypeOkOnly.

private void assertTypeOkOnly(String code) {
    Model m = assertParse(code, WITH_STD_LIB);
    LocationTypeExtension te = new LocationTypeExtension(m);
    m.registerTypeSystemExtension(te);
    m.getErrors();
    SemanticConditionList e = m.typeCheck();
    assertTrue(!e.containsErrors() ? "" : "Found error " + e.getFirstError().getMessage(), !e.containsErrors());
    assertInferOk(code);
}
Also used : SemanticConditionList(abs.frontend.analyser.SemanticConditionList) LocationTypeExtension(abs.frontend.typechecker.locationtypes.LocationTypeExtension) Model(abs.frontend.ast.Model)

Aggregations

SemanticConditionList (abs.frontend.analyser.SemanticConditionList)51 Test (org.junit.Test)30 Model (abs.frontend.ast.Model)24 FrontendTest (abs.frontend.FrontendTest)7 SemanticCondition (abs.frontend.analyser.SemanticCondition)7 LocationTypeInferrerExtension (abs.frontend.typechecker.locationtypes.infer.LocationTypeInferrerExtension)7 LocationType (abs.frontend.typechecker.locationtypes.LocationType)5 LocationTypeExtension (abs.frontend.typechecker.locationtypes.LocationTypeExtension)4 WrongProgramArgumentException (abs.common.WrongProgramArgumentException)3 ProductLine (abs.frontend.ast.ProductLine)3 TypeError (abs.frontend.analyser.TypeError)2 CompilationUnit (abs.frontend.ast.CompilationUnit)2 DeltaModellingException (abs.frontend.delta.DeltaModellingException)2 Main (abs.frontend.parser.Main)2 ParserError (abs.frontend.parser.ParserError)2 File (java.io.File)2 ABSTest (abs.ABSTest)1 InternalBackendException (abs.backend.common.InternalBackendException)1 DefaultABSFormatter (abs.backend.prettyprint.DefaultABSFormatter)1 SemanticError (abs.frontend.analyser.SemanticError)1