-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
including removal of deprecated JUnit exception rule
- Loading branch information
1 parent
7907959
commit 203d467
Showing
8 changed files
with
455 additions
and
496 deletions.
There are no files selected for viewing
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
31 changes: 18 additions & 13 deletions
31
...clipse.xsemantics.example.lambda.tests/org.eclipse.xsemantics.example.lambda.tests.launch
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,16 +1,21 @@ | ||
<?xml version="1.0" encoding="UTF-8" standalone="no"?> | ||
<launchConfiguration type="org.eclipse.jdt.junit.launchconfig"> | ||
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS"> | ||
<listEntry value="/org.eclipse.xsemantics.example.lambda.tests"/> | ||
</listAttribute> | ||
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES"> | ||
<listEntry value="4"/> | ||
</listAttribute> | ||
<stringAttribute key="org.eclipse.jdt.junit.CONTAINER" value="=org.eclipse.xsemantics.example.lambda.tests"/> | ||
<booleanAttribute key="org.eclipse.jdt.junit.KEEPRUNNING_ATTR" value="false"/> | ||
<stringAttribute key="org.eclipse.jdt.junit.TESTNAME" value=""/> | ||
<stringAttribute key="org.eclipse.jdt.junit.TEST_KIND" value="org.eclipse.jdt.junit.loader.junit4"/> | ||
<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value=""/> | ||
<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="org.eclipse.xsemantics.example.lambda.tests"/> | ||
<stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="-ea"/> | ||
<booleanAttribute key="org.eclipse.debug.core.ATTR_FORCE_SYSTEM_CONSOLE_ENCODING" value="false"/> | ||
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS"> | ||
<listEntry value="/org.eclipse.xsemantics.example.lambda.tests"/> | ||
</listAttribute> | ||
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES"> | ||
<listEntry value="4"/> | ||
</listAttribute> | ||
<stringAttribute key="org.eclipse.jdt.junit.CONTAINER" value="=org.eclipse.xsemantics.example.lambda.tests"/> | ||
<booleanAttribute key="org.eclipse.jdt.junit.KEEPRUNNING_ATTR" value="false"/> | ||
<stringAttribute key="org.eclipse.jdt.junit.TESTNAME" value=""/> | ||
<stringAttribute key="org.eclipse.jdt.junit.TEST_KIND" value="org.eclipse.jdt.junit.loader.junit4"/> | ||
<booleanAttribute key="org.eclipse.jdt.launching.ATTR_ATTR_USE_ARGFILE" value="false"/> | ||
<booleanAttribute key="org.eclipse.jdt.launching.ATTR_SHOW_CODEDETAILS_IN_EXCEPTION_MESSAGES" value="true"/> | ||
<booleanAttribute key="org.eclipse.jdt.launching.ATTR_USE_CLASSPATH_ONLY_JAR" value="false"/> | ||
<stringAttribute key="org.eclipse.jdt.launching.JRE_CONTAINER" value="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-17/"/> | ||
<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value=""/> | ||
<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="org.eclipse.xsemantics.example.lambda.tests"/> | ||
<stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="-ea"/> | ||
</launchConfiguration> |
234 changes: 234 additions & 0 deletions
234
....lambda.tests/src/org/eclipse/xsemantics/example/lambda/tests/LambdaAbstractBaseTest.java
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,234 @@ | ||
/** | ||
* Copyright (c) 2013-2017 Lorenzo Bettini. | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v1.0 | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
* | ||
* Contributors: | ||
* Lorenzo Bettini - Initial contribution and API | ||
*/ | ||
package org.eclipse.xsemantics.example.lambda.tests; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertFalse; | ||
import static org.junit.Assert.assertNotNull; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
import org.eclipse.xsemantics.example.lambda.lambda.Abstraction; | ||
import org.eclipse.xsemantics.example.lambda.lambda.ArrowType; | ||
import org.eclipse.xsemantics.example.lambda.lambda.Constant; | ||
import org.eclipse.xsemantics.example.lambda.lambda.Program; | ||
import org.eclipse.xsemantics.example.lambda.lambda.Term; | ||
import org.eclipse.xsemantics.example.lambda.lambda.Type; | ||
import org.eclipse.xsemantics.example.lambda.lambda.TypeVariable; | ||
import org.eclipse.xsemantics.example.lambda.lambda.Variable; | ||
import org.eclipse.xsemantics.example.lambda.tests.util.LambdaTestsUtil; | ||
import org.eclipse.xsemantics.example.lambda.validation.LambdaValidator; | ||
import org.eclipse.xsemantics.example.lambda.xsemantics.LambdaStringRepresentation; | ||
import org.eclipse.xsemantics.example.lambda.xsemantics.LambdaStringRepresentationWithTypeBeautifier; | ||
import org.eclipse.xsemantics.example.lambda.xsemantics.LambdaUtils; | ||
import org.eclipse.xsemantics.example.lambda.xsemantics.LambdaXsemanticsSystem; | ||
import org.eclipse.xsemantics.example.lambda.xsemantics.TypeSubstitutions; | ||
import org.eclipse.xsemantics.runtime.Result; | ||
import org.eclipse.xsemantics.runtime.RuleApplicationTrace; | ||
import org.eclipse.xsemantics.runtime.StringRepresentation; | ||
import org.eclipse.xsemantics.runtime.TraceUtils; | ||
import org.eclipse.xtext.testing.InjectWith; | ||
import org.eclipse.xtext.testing.XtextRunner; | ||
import org.eclipse.xtext.testing.util.ParseHelper; | ||
import org.eclipse.xtext.testing.validation.ValidationTestHelper; | ||
import org.eclipse.xtext.xbase.lib.Exceptions; | ||
import org.eclipse.xtext.xbase.lib.Extension; | ||
import org.junit.Assert; | ||
import org.junit.Before; | ||
import org.junit.BeforeClass; | ||
import org.junit.runner.RunWith; | ||
|
||
import com.google.inject.Inject; | ||
import com.google.inject.Injector; | ||
|
||
@RunWith(XtextRunner.class) | ||
@InjectWith(LambdaInjectorProvider.class) | ||
public abstract class LambdaAbstractBaseTest { | ||
@Inject | ||
protected LambdaValidator validator; | ||
|
||
@Inject | ||
protected Injector injector; | ||
|
||
@Inject | ||
@Extension | ||
protected ParseHelper<Program> parseHelper; | ||
|
||
@Inject | ||
@Extension | ||
protected ValidationTestHelper validationTestHelper; | ||
|
||
@Inject | ||
protected LambdaXsemanticsSystem system; | ||
|
||
@Inject | ||
@Extension | ||
private StringRepresentation stringRepresentation; | ||
|
||
@Inject | ||
protected LambdaExpectedTraces traces; | ||
|
||
@Inject | ||
@Extension | ||
private TraceUtils traceUtils; | ||
|
||
protected TypeSubstitutions substitutions; | ||
|
||
@Inject | ||
protected LambdaStringRepresentation reprForSubstitutions; | ||
|
||
@Inject | ||
protected LambdaStringRepresentationWithTypeBeautifier reprBeautifier; | ||
|
||
@Inject | ||
protected LambdaUtils lambdaUtils; | ||
|
||
protected RuleApplicationTrace trace; | ||
|
||
@BeforeClass | ||
public static void setNewLine() { | ||
System.setProperty("line.separator", "\n"); | ||
} | ||
|
||
@Before | ||
public void setUp() { | ||
lambdaUtils.resetCounter(); | ||
substitutions = new TypeSubstitutions(); | ||
trace = new RuleApplicationTrace(); | ||
} | ||
|
||
public Program parseAndGetProgram(final CharSequence prog) { | ||
try { | ||
return parseHelper.parse(prog); | ||
} catch (Throwable _e) { | ||
throw Exceptions.sneakyThrow(_e); | ||
} | ||
} | ||
|
||
public Program parseAndAssertNoError(final CharSequence prog) { | ||
try { | ||
final Program model = parseHelper.parse(prog); | ||
validationTestHelper.assertNoErrors(model); | ||
return model; | ||
} catch (Throwable _e) { | ||
throw Exceptions.sneakyThrow(_e); | ||
} | ||
} | ||
|
||
protected Program getLambdaProgram(final String program) { | ||
try { | ||
return parseHelper.parse(program); | ||
} catch (Throwable _e) { | ||
throw Exceptions.sneakyThrow(_e); | ||
} | ||
} | ||
|
||
public <T extends Object> void assertFailure(final Result<T> result) { | ||
if (!result.failed()) { | ||
assertTrue( | ||
"should have failed, instead got: " + stringRepresentation.string(result.getValue()) | ||
+ "\n" + traceUtils.traceAsString(trace), | ||
result.failed()); | ||
} | ||
} | ||
|
||
public void assertFailure(final Boolean result) { | ||
if (result.booleanValue()) { | ||
assertTrue("should have failed", result.booleanValue()); | ||
} | ||
} | ||
|
||
public <T extends Object> void assertFailureTrace(final Result<T> result, final CharSequence expectedTrace) { | ||
assertFailure(result); | ||
assertEqualsStrings(expectedTrace, traceUtils.failureTraceAsString(result.getRuleFailedException())); | ||
} | ||
|
||
public void assertEqualsStrings(final Object expected, final Object actual) { | ||
Assert.assertEquals(("" + expected).replace("\r", ""), ("" + actual).replace("\r", "")); | ||
} | ||
|
||
public <T extends Object> void assertResultAsString(final Result<T> result, final String expected) { | ||
if (result.failed()) { | ||
assertFalse("should not have failed: " + | ||
traceUtils.failureTraceAsString(result.getRuleFailedException()), | ||
result.failed()); | ||
} | ||
assertEqualsStrings(expected, | ||
stringRepresentation.string(result.getValue())); | ||
} | ||
|
||
public <T extends Object> void assertResultAsString(final T result, final String expected) { | ||
assertNotNull(result); | ||
assertEqualsStrings(expected, stringRepresentation.string(result)); | ||
} | ||
|
||
public <T extends Object> void assertResultAsStringBeautifier(final Result<T> result, final String expected) { | ||
if (result.failed()) { | ||
Assert.assertFalse("should not have failed: " + | ||
traceUtils.failureTraceAsString(result.getRuleFailedException()), | ||
result.failed()); | ||
} | ||
assertEqualsStrings(expected, reprBeautifier.string(result.getValue())); | ||
} | ||
|
||
public void assertResult2AsString(final Type result, final String expected) { | ||
assertNotNull(result); | ||
assertNotNull(result); | ||
assertEqualsStrings(expected, stringRepresentation.string(result)); | ||
} | ||
|
||
public void assertResultTrue(final Boolean result) { | ||
assertTrue((result).booleanValue()); | ||
} | ||
|
||
public TypeVariable getTypeVariable(final Type type) { | ||
return (TypeVariable) type; | ||
} | ||
|
||
public ArrowType getArrowType(final Type type) { | ||
return (ArrowType) type; | ||
} | ||
|
||
public Term getTerm(final CharSequence prog) { | ||
return parseAndGetProgram(prog).getTerm(); | ||
} | ||
|
||
public Abstraction getAbstraction(final CharSequence prog) { | ||
return getAbstraction(getTerm(prog)); | ||
} | ||
|
||
public Abstraction getAbstraction(final Term term) { | ||
return (Abstraction) term; | ||
} | ||
|
||
public Variable getVariable(final Term term) { | ||
return (Variable) term; | ||
} | ||
|
||
public Constant getConstant(final Term term) { | ||
return (Constant) term; | ||
} | ||
|
||
public void assertTypeVariable(final Type type, final String expectedName) { | ||
assertEquals(expectedName, getTypeVariable(type).getTypevarName()); | ||
} | ||
|
||
public void assertArrowType(final Type type, final String expectedName) { | ||
assertEquals(expectedName, stringRepresentation.string(getArrowType(type))); | ||
} | ||
|
||
public void assertTypeSubstitutions(final TypeSubstitutions substitutions, final String expected) { | ||
assertEqualsStrings("subst{" + expected + "}", reprForSubstitutions.string(substitutions)); | ||
} | ||
|
||
public String rep(final Type type) { | ||
return LambdaTestsUtil.rep(type); | ||
} | ||
} |
Oops, something went wrong.