Skip to content

Commit

Permalink
234: added compiler test
Browse files Browse the repository at this point in the history
  • Loading branch information
LorenzoBettini committed Aug 5, 2020
1 parent 250e200 commit 59f3238
Show file tree
Hide file tree
Showing 8 changed files with 309 additions and 51 deletions.
Expand Up @@ -57,6 +57,8 @@ abstract class EdeltaAbstractTest {
protected static String PERSON_LIST_ECORE = "PersonList.ecore"
protected static String TEST1_REFS_ECORE = "TestEcoreForReferences1.ecore"
protected static String TEST2_REFS_ECORE = "TestEcoreForReferences2.ecore"
protected static String SIMPLE_ECORE = "Simple.ecore"
protected static String ANOTHER_SIMPLE_ECORE = "AnotherSimple.ecore"

/**
* Parse several input sources using the "foo" EPackage
Expand Down
131 changes: 115 additions & 16 deletions edelta.parent/edelta.tests/src/edelta/tests/EdeltaCompilerTest.xtend
Expand Up @@ -1195,7 +1195,7 @@ class EdeltaCompilerTest extends EdeltaAbstractTest {

@Test
def void testCompilationOfRenameReferencesAcrossEPackagesSingleModifyEcore() {
// it is crucial to use real ecore files so that we mimick what happens in
// it is crucial to use real ecore files so that we mimic what happens in
// the workbench and make sure that original ecores are not modified.
val rs = createResourceSetWithEcores(
#[TEST1_REFS_ECORE, TEST2_REFS_ECORE],
Expand Down Expand Up @@ -1306,6 +1306,66 @@ class EdeltaCompilerTest extends EdeltaAbstractTest {
)
}

@Test
def void testExecutionOfModificationsOfMetamodelsAcrossSeveralFilesIntroducingDepOnAnotherMetamodel() {
checkCompiledCodeExecutionWithSeveralFiles(
#[SIMPLE_ECORE, ANOTHER_SIMPLE_ECORE],
#[
'''
import org.eclipse.emf.ecore.EClass
package test1
metamodel "simple"
def setBaseClass(EClass c) : void {
c.getESuperTypes += ecoreref(SimpleClass)
}
''',
'''
import org.eclipse.emf.ecore.EClass
import test1.MyFile0
package test2
metamodel "anothersimple"
use test1.MyFile0 as extension my
modifyEcore aModificationTest epackage anothersimple {
// the other file's operation will set the
// base class of this package class to another package class
ecoreref(AnotherSimpleClass).setBaseClass
// now anothersimple refers to simple
// now modify the abstract property of the
// superclass in the other package
ecoreref(AnotherSimpleClass).ESuperTypes.head.abstract = true
}
'''
],
"test2.MyFile1",
#[
SIMPLE_ECORE ->
'''
<?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="simple" nsURI="http://www.simple" nsPrefix="simple">
<eClassifiers xsi:type="ecore:EClass" name="SimpleClass" abstract="true"/>
</ecore:EPackage>
''',
ANOTHER_SIMPLE_ECORE ->
'''
<?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="anothersimple" nsURI="http://www.anothersimple" nsPrefix="anothersimple">
<eClassifiers xsi:type="ecore:EClass" name="AnotherSimpleClass" eSuperTypes="Simple.ecore#//SimpleClass"/>
</ecore:EPackage>
'''
],
true
)
}
@Test
def void testExecutionOfComplexOperationsWithSubPackages() {
'''
Expand Down Expand Up @@ -1721,16 +1781,20 @@ class EdeltaCompilerTest extends EdeltaAbstractTest {
}
def private createResourceSet(CharSequence... inputs) {
val pairs = newArrayList() => [
val pairs = createInputPairs(inputs)
val rs = resourceSet(pairs)
addEPackageForTests(rs)
return rs
}
def private createInputPairs(CharSequence[] inputs) {
newArrayList() => [
list |
inputs.forEach[e, i|
list += "MyFile" + i + "." +
extensionProvider.getPrimaryFileExtension() -> e
]
]
val rs = resourceSet(pairs)
addEPackageForTests(rs)
return rs
}
def private createResourceSetWithEcores(List<String> ecoreNames, CharSequence input) {
Expand All @@ -1746,6 +1810,18 @@ class EdeltaCompilerTest extends EdeltaAbstractTest {
return rs
}
def private createResourceSetWithEcoresAndSeveralInputs(List<String> ecoreNames, List<CharSequence> inputs) {
val ecorePairs = newArrayList(
ECORE_ECORE -> EdeltaTestUtils.loadFile(METAMODEL_PATH + ECORE_ECORE)
)
ecorePairs +=
ecoreNames.map[ecoreName |
ecoreName -> EdeltaTestUtils.loadFile(METAMODEL_PATH + ecoreName)]
val inputPairs = createInputPairs(inputs)
val rs = resourceSet(ecorePairs + inputPairs)
return rs
}
def private checkCompiledCodeExecution(CharSequence input, CharSequence expectedGeneratedEcore,
boolean checkValidationErrors) {
wipeModifiedDirectoryContents
Expand Down Expand Up @@ -1781,22 +1857,45 @@ class EdeltaCompilerTest extends EdeltaAbstractTest {
assertGeneratedJavaCodeCompiles
}
val genClass = compiledClass
val edeltaObj = genClass.getDeclaredConstructor().newInstance()
// load ecore files
for (ecoreName : ecoreNames) {
edeltaObj.invoke("loadEcoreFile", #[METAMODEL_PATH + ecoreName])
checkExecutionAndAssertExpectedModifiedEcores(genClass, ecoreNames, expectedModifiedEcores)
]
}
def private checkCompiledCodeExecutionWithSeveralFiles(List<String> ecoreNames,
List<CharSequence> inputs,
String classToExecute,
List<Pair<CharSequence, CharSequence>> expectedModifiedEcores,
boolean checkValidationErrors) {
wipeModifiedDirectoryContents
val rs = createResourceSetWithEcoresAndSeveralInputs(ecoreNames, inputs)
rs.compile [
if (checkValidationErrors) {
assertNoValidationErrors
}
edeltaObj.invoke("execute")
edeltaObj.invoke("saveModifiedEcores", #[MODIFIED])
for (expected : expectedModifiedEcores) {
compareSingleFileContents(
MODIFIED+"/"+expected.key,
expected.value.toString
)
if (checkValidationErrors) {
assertGeneratedJavaCodeCompiles
}
val genClass = getCompiledClass(classToExecute)
checkExecutionAndAssertExpectedModifiedEcores(genClass, ecoreNames, expectedModifiedEcores)
]
}
private def void checkExecutionAndAssertExpectedModifiedEcores(Class<?> genClass, List<String> ecoreNames, List<Pair<CharSequence, CharSequence>> expectedModifiedEcores) {
val edeltaObj = genClass.getDeclaredConstructor().newInstance()
// load ecore files
for (ecoreName : ecoreNames) {
edeltaObj.invoke("loadEcoreFile", #[METAMODEL_PATH + ecoreName])
}
edeltaObj.invoke("execute")
edeltaObj.invoke("saveModifiedEcores", #[MODIFIED])
for (expected : expectedModifiedEcores) {
compareSingleFileContents(
MODIFIED+"/"+expected.key,
expected.value.toString
)
}
}
def private void wipeModifiedDirectoryContents() {
cleanDirectory(MODIFIED);
}
Expand Down
Expand Up @@ -921,7 +921,7 @@ class EdeltaInterpreterTest extends EdeltaAbstractTest {
}
@Test
def void testModificationsOfMetamodelsAcrossSeveralFiles() {
def void testModificationsOfMetamodelsAcrossSeveralFilesIntroducingDepOnAnotherMetamodel() {
val program = parseSeveralWithTestEcores(
#[
'''
Expand Down
@@ -0,0 +1,5 @@
<?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="anothersimple" nsURI="http://www.anothersimple" nsPrefix="anothersimple">
<eClassifiers xsi:type="ecore:EClass" name="AnotherSimpleClass"/>
</ecore:EPackage>
@@ -0,0 +1,5 @@
<?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="simple" nsURI="http://www.simple" nsPrefix="simple">
<eClassifiers xsi:type="ecore:EClass" name="SimpleClass"/>
</ecore:EPackage>
Expand Up @@ -93,6 +93,10 @@ public abstract class EdeltaAbstractTest {

protected static String TEST2_REFS_ECORE = "TestEcoreForReferences2.ecore";

protected static String SIMPLE_ECORE = "Simple.ecore";

protected static String ANOTHER_SIMPLE_ECORE = "AnotherSimple.ecore";

/**
* Parse several input sources using the "foo" EPackage
* and returns the parsed program corresponding
Expand Down

0 comments on commit 59f3238

Please sign in to comment.