Search in sources :

Example 1 with LogCapture

use of org.eclipse.xtext.testing.logging.LoggingTester.LogCapture in project xtext-xtend by eclipse.

the class JavaClasspathTest method testNoJavaInClasspath.

@Test
public void testNoJavaInClasspath() throws Exception {
    LogCapture capturedLogging = LoggingTester.captureLogging(Level.ERROR, AbstractClassMirror.class, new Runnable() {

        @Override
        public void run() {
            LogCapture capturedLogging = LoggingTester.captureLogging(Level.ERROR, JdtTypeMirror.class, new Runnable() {

                @Override
                public void run() {
                    try {
                        IProject project = testHelper.getProject();
                        IJavaProject javaProject = JavaCore.create(project);
                        IFile file = project.getFile("src/Foo.xtend");
                        if (!file.exists())
                            file.create(new StringInputStream(TEST_CLAZZ), true, null);
                        IClasspathEntry jrePath = JavaProjectSetupUtil.getJreContainerClasspathEntry(javaProject);
                        assertNotNull("JRE Lib classpath entry not found.", jrePath);
                        // remove JRE Lib
                        JavaProjectSetupUtil.deleteClasspathEntry(javaProject, jrePath.getPath());
                        IResourcesSetupUtil.waitForBuild();
                        markerAssert.assertErrorMarker(file, IssueCodes.JDK_NOT_ON_CLASSPATH);
                        // add JRE back
                        JavaProjectSetupUtil.addToClasspath(javaProject, jrePath);
                        IResourcesSetupUtil.waitForBuild();
                        markerAssert.assertNoErrorMarker(file);
                    } catch (Exception e) {
                        throw new RuntimeException(e);
                    }
                }
            });
            assertFalse(capturedLogging.getLogEntries().isEmpty());
        }
    });
    assertFalse(capturedLogging.getLogEntries().isEmpty());
}
Also used : JdtTypeMirror(org.eclipse.xtext.common.types.access.jdt.JdtTypeMirror) StringInputStream(org.eclipse.xtext.util.StringInputStream) IJavaProject(org.eclipse.jdt.core.IJavaProject) IFile(org.eclipse.core.resources.IFile) IClasspathEntry(org.eclipse.jdt.core.IClasspathEntry) LogCapture(org.eclipse.xtext.testing.logging.LoggingTester.LogCapture) IProject(org.eclipse.core.resources.IProject) Test(org.junit.Test)

Example 2 with LogCapture

use of org.eclipse.xtext.testing.logging.LoggingTester.LogCapture in project xtext-core by eclipse.

the class CrossRefTest method testGetMultiValuedLinkText.

@Test
public void testGetMultiValuedLinkText() throws Exception {
    with(LazyLinkingTestLanguageStandaloneSetup.class);
    crossRefSerializer = get(ICrossReferenceSerializer.class);
    final LazyLinkingTestLanguageGrammarAccess g = (LazyLinkingTestLanguageGrammarAccess) get(IGrammarAccess.class);
    final XtextResource r = CrossRefTest.this.getResourceFromStringAndExpect("type TypeA {} type TypeB { TypeA TypeC TypeB p1; }", 1);
    LogCapture log = LoggingTester.captureLogging(Level.ERROR, LazyLinkingResource.class, new Runnable() {

        @Override
        public void run() {
            Model model = (Model) r.getContents().get(0);
            assertEquals(2, model.getTypes().size());
            org.eclipse.xtext.linking.lazy.lazyLinking.Type type = model.getTypes().get(1);
            assertEquals("TypeB", type.getName());
            assertEquals(1, type.getProperties().size());
            Property prop = type.getProperties().get(0);
            assertEquals("p1", prop.getName());
            assertEquals(3, prop.getType().size());
            org.eclipse.xtext.linking.lazy.lazyLinking.Type propType = prop.getType().get(0);
            assertFalse(propType.eIsProxy());
            String linkText = crossRefSerializer.serializeCrossRef(prop, g.getPropertyAccess().getTypeTypeCrossReference_0_0(), propType, null);
            assertEquals("TypeA", linkText);
            propType = prop.getType().get(1);
            assertTrue(propType.eIsProxy());
            INode node = getCrossReferenceNode(prop, GrammarUtil.getReference(g.getPropertyAccess().getTypeTypeCrossReference_0_0()), propType);
            linkText = crossRefSerializer.serializeCrossRef(prop, g.getPropertyAccess().getTypeTypeCrossReference_0_0(), propType, node);
            assertEquals("TypeC", linkText);
            propType = prop.getType().get(2);
            assertFalse(propType.eIsProxy());
            node = getCrossReferenceNode(prop, GrammarUtil.getReference(g.getPropertyAccess().getTypeTypeCrossReference_0_0()), propType);
            linkText = crossRefSerializer.serializeCrossRef(prop, g.getPropertyAccess().getTypeTypeCrossReference_0_0(), propType, null);
            assertEquals("TypeB", linkText);
            Adapter adapter = (Adapter) NodeModelUtils.getNode(prop);
            prop.eAdapters().remove(adapter);
            propType = prop.getType().get(1);
            assertTrue(propType.eIsProxy());
            linkText = crossRefSerializer.serializeCrossRef(prop, g.getPropertyAccess().getTypeTypeCrossReference_0_0(), propType, null);
            assertNull(linkText);
        }
    });
    log.assertNumberOfLogEntries(2);
}
Also used : ICrossReferenceSerializer(org.eclipse.xtext.parsetree.reconstr.ITokenSerializer.ICrossReferenceSerializer) INode(org.eclipse.xtext.nodemodel.INode) IGrammarAccess(org.eclipse.xtext.IGrammarAccess) XtextResource(org.eclipse.xtext.resource.XtextResource) Adapter(org.eclipse.emf.common.notify.Adapter) Type(org.eclipse.xtext.linking.langATestLanguage.Type) Model(org.eclipse.xtext.linking.lazy.lazyLinking.Model) LogCapture(org.eclipse.xtext.testing.logging.LoggingTester.LogCapture) LazyLinkingTestLanguageGrammarAccess(org.eclipse.xtext.linking.lazy.services.LazyLinkingTestLanguageGrammarAccess) Property(org.eclipse.xtext.linking.lazy.lazyLinking.Property) Test(org.junit.Test)

Example 3 with LogCapture

use of org.eclipse.xtext.testing.logging.LoggingTester.LogCapture in project xtext-core by eclipse.

the class Bug281990Test method testRecursionErrorMessage.

@Test
public void testRecursionErrorMessage() throws Exception {
    LogCapture loggings = LoggingTester.captureLogging(Level.ERROR, LazyLinkingResource.class, new Runnable() {

        @Override
        public void run() {
            try {
                EObject model = getModelAndExpect("type Foo extends Foo.bar { Foo foo; }", 2);
                assertTrue(((Model) model).getTypes().get(0).getParentId().eIsProxy());
                assertTrue(model.eResource().getErrors().get(0).getMessage().contains("Couldn't"));
            } catch (Exception e) {
                throw Exceptions.sneakyThrow(e);
            }
        }
    });
    loggings.assertNumberOfLogEntries(1);
}
Also used : EObject(org.eclipse.emf.ecore.EObject) LogCapture(org.eclipse.xtext.testing.logging.LoggingTester.LogCapture) Test(org.junit.Test)

Aggregations

LogCapture (org.eclipse.xtext.testing.logging.LoggingTester.LogCapture)3 Test (org.junit.Test)3 IFile (org.eclipse.core.resources.IFile)1 IProject (org.eclipse.core.resources.IProject)1 Adapter (org.eclipse.emf.common.notify.Adapter)1 EObject (org.eclipse.emf.ecore.EObject)1 IClasspathEntry (org.eclipse.jdt.core.IClasspathEntry)1 IJavaProject (org.eclipse.jdt.core.IJavaProject)1 IGrammarAccess (org.eclipse.xtext.IGrammarAccess)1 JdtTypeMirror (org.eclipse.xtext.common.types.access.jdt.JdtTypeMirror)1 Type (org.eclipse.xtext.linking.langATestLanguage.Type)1 Model (org.eclipse.xtext.linking.lazy.lazyLinking.Model)1 Property (org.eclipse.xtext.linking.lazy.lazyLinking.Property)1 LazyLinkingTestLanguageGrammarAccess (org.eclipse.xtext.linking.lazy.services.LazyLinkingTestLanguageGrammarAccess)1 INode (org.eclipse.xtext.nodemodel.INode)1 ICrossReferenceSerializer (org.eclipse.xtext.parsetree.reconstr.ITokenSerializer.ICrossReferenceSerializer)1 XtextResource (org.eclipse.xtext.resource.XtextResource)1 StringInputStream (org.eclipse.xtext.util.StringInputStream)1