-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #182 from LorenzoBettini/diagnostic-helper
Diagnostic helper
- Loading branch information
Showing
7 changed files
with
395 additions
and
345 deletions.
There are no files selected for viewing
129 changes: 129 additions & 0 deletions
129
edelta.parent/edelta.tests/src/edelta/tests/EdeltaInterpreterDiagnosticHelperTest.xtend
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
package edelta.tests | ||
|
||
import com.google.inject.Inject | ||
import edelta.interpreter.EdeltaInterpreterDiagnosticHelper | ||
import edelta.resource.derivedstate.EdeltaDerivedStateHelper | ||
import org.eclipse.xtext.testing.InjectWith | ||
import org.eclipse.xtext.testing.XtextRunner | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
|
||
import static org.eclipse.xtext.xbase.XbasePackage.Literals.* | ||
|
||
@RunWith(XtextRunner) | ||
@InjectWith(EdeltaInjectorProviderCustom) | ||
class EdeltaInterpreterDiagnosticHelperTest extends EdeltaAbstractTest { | ||
|
||
@Inject EdeltaInterpreterDiagnosticHelper diagnosticHelper | ||
|
||
@Inject EdeltaDerivedStateHelper derivedStateHelper | ||
|
||
@Test def void testAddErrorWithCurrentExpression() { | ||
val input = ''' | ||
metamodel "foo" | ||
modifyEcore aTest epackage foo { | ||
val s = null | ||
} | ||
''' | ||
input.parseWithTestEcore => [ | ||
val exp = lastModifyEcoreOperation.body.blockLastExpression | ||
diagnosticHelper.setCurrentExpression(exp) | ||
diagnosticHelper.addError(null, "issueCode", "an error") | ||
assertError( | ||
XVARIABLE_DECLARATION, | ||
"issueCode", | ||
input.lastIndexOf("val s = null"), | ||
"val s = null".length, | ||
"an error" | ||
) | ||
] | ||
} | ||
|
||
@Test def void testAddErrorWithDifferentCorrespondingExpression() { | ||
val input = ''' | ||
metamodel "foo" | ||
modifyEcore aTest epackage foo { | ||
var s = null | ||
s = null | ||
} | ||
''' | ||
input.parseWithTestEcore => [ | ||
// just an ENamedElement to pass to show method as | ||
// the problematic object | ||
val problematic = copiedEPackages.last | ||
// associate it to the first expression in the derived state | ||
val correspondingExpression = lastModifyEcoreOperation.body.blockFirstExpression | ||
derivedStateHelper.getEnamedElementXExpressionMap(eResource) | ||
.put(problematic, correspondingExpression) | ||
val currentExpression = lastModifyEcoreOperation.body.blockLastExpression | ||
diagnosticHelper.setCurrentExpression(currentExpression) | ||
diagnosticHelper.addError(problematic, "issueCode", "an error") | ||
// the error is associated to the associated expression to problematic object | ||
// not with the current expression | ||
assertError( | ||
XVARIABLE_DECLARATION, | ||
"issueCode", | ||
input.lastIndexOf("val s = null"), | ||
"val s = null".length, | ||
"an error" | ||
) | ||
] | ||
} | ||
|
||
@Test def void testAddWarningWithCurrentExpression() { | ||
val input = ''' | ||
metamodel "foo" | ||
modifyEcore aTest epackage foo { | ||
val s = null | ||
} | ||
''' | ||
input.parseWithTestEcore => [ | ||
val exp = lastModifyEcoreOperation.body.blockLastExpression | ||
diagnosticHelper.setCurrentExpression(exp) | ||
diagnosticHelper.addWarning(null, "issueCode", "a warning") | ||
assertWarning( | ||
XVARIABLE_DECLARATION, | ||
"issueCode", | ||
input.lastIndexOf("val s = null"), | ||
"val s = null".length, | ||
"a warning" | ||
) | ||
] | ||
} | ||
|
||
@Test def void testAddWarningWithDifferentCorrespondingExpression() { | ||
val input = ''' | ||
metamodel "foo" | ||
modifyEcore aTest epackage foo { | ||
var s = null | ||
s = null | ||
} | ||
''' | ||
input.parseWithTestEcore => [ | ||
// just an ENamedElement to pass to show method as | ||
// the problematic object | ||
val problematic = copiedEPackages.last | ||
// associate it to the first expression in the derived state | ||
val correspondingExpression = lastModifyEcoreOperation.body.blockFirstExpression | ||
derivedStateHelper.getEnamedElementXExpressionMap(eResource) | ||
.put(problematic, correspondingExpression) | ||
val currentExpression = lastModifyEcoreOperation.body.blockLastExpression | ||
diagnosticHelper.setCurrentExpression(currentExpression) | ||
diagnosticHelper.addWarning(problematic, "issueCode", "a warning") | ||
// the warning is associated to the associated expression to problematic object | ||
// not with the current expression | ||
assertWarning( | ||
XVARIABLE_DECLARATION, | ||
"issueCode", | ||
input.lastIndexOf("val s = null"), | ||
"val s = null".length, | ||
"a warning" | ||
) | ||
] | ||
} | ||
|
||
} |
142 changes: 15 additions & 127 deletions
142
edelta.parent/edelta.tests/src/edelta/tests/EdeltaInterpreterEdeltaImplTest.xtend
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,157 +1,45 @@ | ||
package edelta.tests | ||
|
||
import com.google.inject.Inject | ||
import edelta.interpreter.EdeltaInterpreterDiagnosticHelper | ||
import edelta.interpreter.EdeltaInterpreterEdeltaImpl | ||
import edelta.resource.derivedstate.EdeltaDerivedStateHelper | ||
import edelta.validation.EdeltaValidator | ||
import org.apache.log4j.Level | ||
import org.eclipse.emf.ecore.EcoreFactory | ||
import org.eclipse.xtext.testing.InjectWith | ||
import org.eclipse.xtext.testing.XtextRunner | ||
import org.junit.Before | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
|
||
import static org.eclipse.xtext.xbase.XbasePackage.Literals.* | ||
import static org.junit.Assert.* | ||
import static org.mockito.Mockito.* | ||
|
||
@RunWith(XtextRunner) | ||
@InjectWith(EdeltaInjectorProviderCustom) | ||
class EdeltaInterpreterEdeltaImplTest extends EdeltaAbstractTest { | ||
var EdeltaInterpreterEdeltaImpl edelta | ||
|
||
@Inject EdeltaDerivedStateHelper derivedStateHelper | ||
var EdeltaInterpreterDiagnosticHelper diagnosticHelper | ||
|
||
@Before | ||
def void setup() { | ||
edelta = new EdeltaInterpreterEdeltaImpl(#[], derivedStateHelper) | ||
edelta.logger = spy(edelta.logger) | ||
diagnosticHelper = mock(EdeltaInterpreterDiagnosticHelper) | ||
edelta = new EdeltaInterpreterEdeltaImpl(#[], diagnosticHelper) | ||
} | ||
|
||
@Test def void testFirstEPackageHasPrecedence() { | ||
val p1 = EcoreFactory.eINSTANCE.createEPackage => [name = "Test"] | ||
val p2 = EcoreFactory.eINSTANCE.createEPackage => [name = "Test"] | ||
edelta = new EdeltaInterpreterEdeltaImpl(#[p1, p2], derivedStateHelper) | ||
edelta = new EdeltaInterpreterEdeltaImpl(#[p1, p2], diagnosticHelper) | ||
assertSame(p1, edelta.getEPackage("Test")) | ||
} | ||
|
||
@Test def void testShowErrorWithNullCurrentExpression() { | ||
edelta.showError(null, "an error") | ||
verify(edelta.logger).log(Level.ERROR, ": an error") | ||
@Test def void testShowError() { | ||
val element = EcoreFactory.eINSTANCE.createEClass | ||
edelta.showError(element, "a message") | ||
verify(diagnosticHelper) | ||
.addError(element, EdeltaValidator.LIVE_VALIDATION_ERROR, "a message") | ||
} | ||
|
||
@Test def void testShowErrorWithCurrentExpression() { | ||
val input = ''' | ||
metamodel "foo" | ||
modifyEcore aTest epackage foo { | ||
val s = null | ||
} | ||
''' | ||
input.parseWithTestEcore => [ | ||
val exp = lastModifyEcoreOperation.body.blockLastExpression | ||
edelta.setCurrentExpression(exp) | ||
edelta.showError(null, "an error") | ||
assertError( | ||
XVARIABLE_DECLARATION, | ||
EdeltaValidator.LIVE_VALIDATION_ERROR, | ||
input.lastIndexOf("val s = null"), | ||
"val s = null".length, | ||
"an error" | ||
) | ||
] | ||
} | ||
|
||
@Test def void testShowErrorWithDifferentCorrespondingExpression() { | ||
val input = ''' | ||
metamodel "foo" | ||
modifyEcore aTest epackage foo { | ||
var s = null | ||
s = null | ||
} | ||
''' | ||
input.parseWithTestEcore => [ | ||
// just an ENamedElement to pass to show method as | ||
// the problematic object | ||
val problematic = copiedEPackages.last | ||
// associate it to the first expression in the derived state | ||
val correspondingExpression = lastModifyEcoreOperation.body.blockFirstExpression | ||
derivedStateHelper.getEnamedElementXExpressionMap(eResource) | ||
.put(problematic, correspondingExpression) | ||
val currentExpression = lastModifyEcoreOperation.body.blockLastExpression | ||
edelta.setCurrentExpression(currentExpression) | ||
edelta.showError(problematic, "an error") | ||
// the error is associated to the associated expression to problematic object | ||
// not with the current expression | ||
assertError( | ||
XVARIABLE_DECLARATION, | ||
EdeltaValidator.LIVE_VALIDATION_ERROR, | ||
input.lastIndexOf("val s = null"), | ||
"val s = null".length, | ||
"an error" | ||
) | ||
] | ||
} | ||
|
||
@Test def void testShowWarningWithNullCurrentExpression() { | ||
edelta.showWarning(null, "an error") | ||
verify(edelta.logger).log(Level.WARN, ": an error") | ||
} | ||
|
||
@Test def void testShowWarningWithCurrentExpression() { | ||
val input = ''' | ||
metamodel "foo" | ||
modifyEcore aTest epackage foo { | ||
val s = null | ||
} | ||
''' | ||
input.parseWithTestEcore => [ | ||
val exp = lastModifyEcoreOperation.body.blockLastExpression | ||
edelta.setCurrentExpression(exp) | ||
edelta.showWarning(null, "a warning") | ||
assertWarning( | ||
XVARIABLE_DECLARATION, | ||
EdeltaValidator.LIVE_VALIDATION_WARNING, | ||
input.lastIndexOf("val s = null"), | ||
"val s = null".length, | ||
"a warning" | ||
) | ||
] | ||
} | ||
|
||
@Test def void testShowWarningWithDifferentCorrespondingExpression() { | ||
val input = ''' | ||
metamodel "foo" | ||
modifyEcore aTest epackage foo { | ||
var s = null | ||
s = null | ||
} | ||
''' | ||
input.parseWithTestEcore => [ | ||
// just an ENamedElement to pass to show method as | ||
// the problematic object | ||
val problematic = copiedEPackages.last | ||
// associate it to the first expression in the derived state | ||
val correspondingExpression = lastModifyEcoreOperation.body.blockFirstExpression | ||
derivedStateHelper.getEnamedElementXExpressionMap(eResource) | ||
.put(problematic, correspondingExpression) | ||
val currentExpression = lastModifyEcoreOperation.body.blockLastExpression | ||
edelta.setCurrentExpression(currentExpression) | ||
edelta.showWarning(problematic, "a warning") | ||
// the warning is associated to the associated expression to problematic object | ||
// not with the current expression | ||
assertWarning( | ||
XVARIABLE_DECLARATION, | ||
EdeltaValidator.LIVE_VALIDATION_WARNING, | ||
input.lastIndexOf("val s = null"), | ||
"val s = null".length, | ||
"a warning" | ||
) | ||
] | ||
@Test def void testShowWarning() { | ||
val element = EcoreFactory.eINSTANCE.createEClass | ||
edelta.showWarning(element, "a message") | ||
verify(diagnosticHelper) | ||
.addWarning(element, EdeltaValidator.LIVE_VALIDATION_WARNING, "a message") | ||
} | ||
|
||
} |
Oops, something went wrong.