mirror of
https://github.com/sigmasternchen/xtext-core
synced 2025-03-15 16:28:56 +00:00
load XtextValidationTest.ecore from code to avoid validation problems in workspace. fixes #47
Signed-off-by: Christian Dietrich <christian.dietrich@itemis.de>
This commit is contained in:
parent
edf68739d8
commit
b37a087fd7
3 changed files with 52 additions and 13 deletions
|
@ -287,10 +287,14 @@ public abstract class AbstractXtextTests extends Assert implements ResourceLoadH
|
|||
protected void disableSerializerTest() {
|
||||
isSerializerTestDisabled = true;
|
||||
}
|
||||
|
||||
protected Object getClasspathURIContext() {
|
||||
return getClass();
|
||||
}
|
||||
|
||||
protected XtextResource doGetResource(InputStream in, URI uri) throws Exception {
|
||||
XtextResourceSet rs = get(XtextResourceSet.class);
|
||||
rs.setClasspathURIContext(getClass());
|
||||
rs.setClasspathURIContext(getClasspathURIContext());
|
||||
XtextResource resource = (XtextResource) getResourceFactory().createResource(uri);
|
||||
rs.getResources().add(resource);
|
||||
resource.load(in, null);
|
||||
|
|
|
@ -1,10 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ecore:EPackage xmi:version="2.0"
|
||||
xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" name="XtextValidationBugs"
|
||||
nsURI="http://XtextValidationBugs" nsPrefix="XtextValidationBugs">
|
||||
<eClassifiers xsi:type="ecore:EClass" name="Bug322875">
|
||||
<eStructuralFeatures xsi:type="ecore:EReference" name="referencesETypeFromClasspathPackage"
|
||||
eType="ecore:EClass classpath:/org/eclipse/xtext/Xtext.ecore#//Grammar"/>
|
||||
</eClassifiers>
|
||||
</ecore:EPackage>
|
|
@ -9,6 +9,10 @@ package org.eclipse.xtext.xtext;
|
|||
|
||||
import static com.google.common.collect.Maps.*;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
|
@ -56,12 +60,14 @@ import org.eclipse.xtext.validation.CheckMode;
|
|||
import org.eclipse.xtext.validation.IResourceValidator;
|
||||
import org.eclipse.xtext.validation.Issue;
|
||||
import org.eclipse.xtext.validation.ValidationMessageAcceptor;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.collect.Collections2;
|
||||
import com.google.common.collect.Sets;
|
||||
import com.google.common.io.Files;
|
||||
|
||||
/**
|
||||
* @author Sebastian Zarnekow - Initial contribution and API
|
||||
|
@ -70,12 +76,28 @@ import com.google.common.collect.Sets;
|
|||
public class XtextValidationTest extends AbstractValidationMessageAcceptingTestCase {
|
||||
|
||||
private String lastMessage;
|
||||
private URL xtextValidationTest_ecore;
|
||||
|
||||
@Override
|
||||
public void setUp() throws Exception {
|
||||
super.setUp();
|
||||
with(XtextStandaloneSetup.class);
|
||||
EValidator.Registry.INSTANCE.put(EcorePackage.eINSTANCE, EcoreValidator.INSTANCE);
|
||||
File tempFile = File.createTempFile("XtextValidationTest", ".ecore");
|
||||
tempFile.deleteOnExit();
|
||||
Files.write("<?xml version='1.0' encoding='UTF-8'?>" +
|
||||
"<ecore:EPackage xmi:version='2.0' xmlns:xmi='http://www.omg.org/XMI'"+
|
||||
" xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'"+
|
||||
" xmlns:ecore='http://www.eclipse.org/emf/2002/Ecore'"+
|
||||
" name='XtextValidationBugs'"+
|
||||
" nsURI='http://XtextValidationBugs'"+
|
||||
" nsPrefix='XtextValidationBugs'>"+
|
||||
" <eClassifiers xsi:type='ecore:EClass' name='Bug322875'>"+
|
||||
" <eStructuralFeatures xsi:type='ecore:EReference' name='referencesETypeFromClasspathPackage' eType='ecore:EClass classpath:/org/eclipse/xtext/Xtext.ecore#//Grammar'/>"+
|
||||
" </eClassifiers>"+
|
||||
"</ecore:EPackage>"
|
||||
, tempFile, StandardCharsets.UTF_8);
|
||||
xtextValidationTest_ecore = tempFile.toURI().toURL();
|
||||
}
|
||||
|
||||
private void configureValidator(XtextValidator validator, ValidationMessageAcceptor messageAcceptor, EObject currentObject) {
|
||||
|
@ -339,7 +361,7 @@ public class XtextValidationTest extends AbstractValidationMessageAcceptingTestC
|
|||
assertEquals(diag.getChildren().toString(), 4, diag.getChildren().size());
|
||||
assertEquals("diag.isError", diag.getSeverity(), Diagnostic.ERROR);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testBug322875_01() throws Exception {
|
||||
String testGrammar = "grammar foo.Bar with org.eclipse.xtext.common.Terminals\n " +
|
||||
|
@ -351,6 +373,30 @@ public class XtextValidationTest extends AbstractValidationMessageAcceptingTestC
|
|||
assertBug322875(resource);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object getClasspathURIContext() {
|
||||
return new ClassLoader(getClass().getClassLoader()) {
|
||||
@Override
|
||||
public URL getResource(String name) {
|
||||
if ("org/eclipse/xtext/xtext/XtextValidationTest.ecore".equals(name)) {
|
||||
return xtextValidationTest_ecore;
|
||||
}
|
||||
if ("org/eclipse/xtext/Xtext.ecore".equals(name)) {
|
||||
URL resource = super.getResource(name);
|
||||
if (resource == null) {
|
||||
try {
|
||||
return new File("../org.eclipse.xtext/org/eclipse/xtext/Xtext.ecore").toURI().toURL();
|
||||
} catch (MalformedURLException e) {
|
||||
throw new IllegalStateException("this should never happen");
|
||||
}
|
||||
}
|
||||
}
|
||||
URL resource = super.getResource(name);
|
||||
return resource;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
protected void assertBug322875(XtextResource resource) {
|
||||
Diagnostic diag = Diagnostician.INSTANCE.validate(resource.getContents().get(0));
|
||||
assertNotNull("diag", diag);
|
||||
|
@ -743,7 +789,6 @@ public class XtextValidationTest extends AbstractValidationMessageAcceptingTestC
|
|||
"grammar org.foo.Bar with org.eclipse.xtext.testlanguages.SimpleExpressionsTestLanguage\n" +
|
||||
"import 'classpath:/org/eclipse/xtext/testlanguages/SimpleExpressionsTestLanguage.ecore' as mm\n" +
|
||||
"Atom returns mm::Atom: name = ID;", 1);
|
||||
// System.out.println(resource.getErrors());
|
||||
assertEquals(resource.getErrors().toString(), 1, resource.getErrors().size());
|
||||
assertTrue(resource.getWarnings().toString(), resource.getWarnings().isEmpty());
|
||||
|
||||
|
|
Loading…
Reference in a new issue