org.eclipse.xtext.testing.validation.ValidationTestHelper Java Examples

The following examples show how to use org.eclipse.xtext.testing.validation.ValidationTestHelper. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: XsemanticsValidatorTests.java    From xsemantics with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void setUp() throws Exception {
	super.setUp();
	validator = get(XsemanticsValidator.class);
	validator.setEnableWarnings(false);
	tester = new ValidatorTester<XsemanticsValidator>(validator,
			getInjector());
	validationTestHelper = get(ValidationTestHelper.class);
}
 
Example #2
Source File: TestAssertions.java    From sarl with Apache License 2.0 5 votes vote down vote up
/** Assert that the given object was compiled without any error except the ones with the specified codes.
 *
 * @param validationHelper the helper for running the validation process.
 * @param source the compiled object from which errors should be retrieved.
 * @param codes the list of the error codes to be ignored.
 * @since 0.7
 */
public void assertNoErrorsExcept(ValidationTestHelper validationHelper, EObject source, String... codes) {
	assert validationHelper != null;
	final List<String> codeSet = Arrays.asList(codes);
	final List<Issue> validate = validationHelper.validate(source);
	final Predicate<Issue> pred = input -> Severity.ERROR == input.getSeverity() && !codeSet.contains(input.getCode());
	if (Iterables.any(validate, pred)) {
		fail("Expected no error, found: " + Iterables.filter(validate, pred));
	}
}
 
Example #3
Source File: TestEObjects.java    From sarl with Apache License 2.0 5 votes vote down vote up
/** Create an instance of class.
 *
 * @param parser the SARL parser.
 * @param validationHelper the validation test helper. If it is {@code null}, no validation.
 * @param string the content of the file.
 * @param resourceSet the set of resources in which the file is created.
 * @return the SARL script extracted from the file content.
 * @since 0.9
 */
public static SarlScript file(ParseHelper<SarlScript> parser, ValidationTestHelper validationHelper,
		String string, ResourceSet resourceSet) throws Exception {
	assert parser != null;
	SarlScript script;
	if (resourceSet == null) {
		script = parser.parse(string);
	} else {
		script = parser.parse(string, resourceSet);
	}
	if (validationHelper != null) {
		Resource resource = script.eResource();
		ResourceSet resourceSet0 = resource.getResourceSet();
		if (resourceSet0 instanceof XtextResourceSet) {
			((XtextResourceSet) resourceSet0).setClasspathURIContext(TestEObjects.class);
		}
		assertEquals(0, resource.getErrors().size(), () -> resource.getErrors().toString());
		Collection<Issue> issues = Collections2.filter(issues(validationHelper, resource), new Predicate<Issue>() {
			@Override
			public boolean apply(Issue input) {
				return input.getSeverity() == Severity.ERROR;
			}
		});
		assertTrue(issues.isEmpty(), () -> "Resource contained errors : " + issues.toString());
	}
	return script;
}
 
Example #4
Source File: TestAssertions.java    From sarl with Apache License 2.0 5 votes vote down vote up
/** Assert that the given object was compiled with at least one error.
 *
 * @param validationHelper the helper for running the validation process.
 * @param source the compiled object from which errors should be retrieved.
 * @param codes the list of the error codes to be ignored.
 * @since 0.7
 */
public void assertAnyError(ValidationTestHelper validationHelper, EObject source, String... codes) {
	assert validationHelper != null;
	final List<String> codeSet = Arrays.asList(codes);
	final List<Issue> validate = validationHelper.validate(source);
	if (!Iterables.any(validate, input -> Severity.ERROR == input.getSeverity() && !codeSet.contains(input.getCode()))) {
		fail("Expected an error, but got nothing");
	}
}
 
Example #5
Source File: OperatorExtensions.java    From sarl with Apache License 2.0 4 votes vote down vote up
private static ValidationTestHelper getValidation() {
	if (validation == null) {
		validation = getInjector().getInstance(ValidationTestHelper.class);
	}
	return validation;
}
 
Example #6
Source File: TestEObjects.java    From sarl with Apache License 2.0 3 votes vote down vote up
/** Create an instance of behavior unit.
 *
 * @param parser the SARL parser.
 * @param validationHelper the validation test helper. If it is {@code null}, no validation.
 * @param string the file content to parse.
 * @param prefix the set of lines to put before the class declaration of the function.
 * @return the SARL behavior unit.
 */
public static SarlBehaviorUnit behaviorUnit(ParseHelper<SarlScript> parser, ValidationTestHelper validationHelper,
		String string, String... prefix) throws Exception {
	SarlAgent agent = agent(parser, validationHelper,
			IterableExtensions.join(Arrays.asList(prefix), TestUtils.getLineSeparator())
			+ TestUtils.getLineSeparator() + "agent Foo { " + string + "}");
	return (SarlBehaviorUnit) agent.getMembers().get(0);
}
 
Example #7
Source File: TestEObjects.java    From sarl with Apache License 2.0 3 votes vote down vote up
/** Create an instance of field.
 *
 * @param parser the SARL parser.
 * @param validationHelper the validation test helper. If it is {@code null}, no validation.
 * @param string the file content to parse.
 * @param prefix the set of lines to put before the class declaration of the function.
 * @return the SARL field.
 */
public static SarlField field(ParseHelper<SarlScript> parser, ValidationTestHelper validationHelper,
		String string, String... prefix) throws Exception {
	SarlClass clazz = clazz(parser, validationHelper,
			IterableExtensions.join(Arrays.asList(prefix), TestUtils.getLineSeparator())
			+ TestUtils.getLineSeparator() + "class Foo { " + string + "}");
	return (SarlField) clazz.getMembers().get(0);
}
 
Example #8
Source File: TestEObjects.java    From sarl with Apache License 2.0 3 votes vote down vote up
/** Create an instance of JVM constructor.
 *
 * @param parser the SARL parser.
 * @param associations the provider of associations between the JVM and the SARL Ecores.
 * @param validationHelper the validation test helper. If it is {@code null}, no validation.
 * @param string the file content to parse.
 * @param prefix the set of lines to put before the class declaration of the function.
 * @return the JVM constructor.
 */
public static JvmConstructor jvmConstructor(ParseHelper<SarlScript> parser, Provider<SarlJvmModelAssociations> associations,
		ValidationTestHelper validationHelper, String string, String... prefix) throws Exception {
	assert associations != null;
	SarlConstructor constructor = constructor(parser, validationHelper, string, prefix);
	return (JvmConstructor) associations.get().getPrimaryJvmElement(constructor);
}
 
Example #9
Source File: TestEObjects.java    From sarl with Apache License 2.0 3 votes vote down vote up
/** Create an instance of constructor.
 *
 * @param parser the SARL parser.
 * @param validationHelper the validation test helper. If it is {@code null}, no validation.
 * @param string the file content to parse.
 * @param prefix the set of lines to put before the class declaration of the function.
 * @return the SARL constructor.
 */
public static SarlConstructor constructor(ParseHelper<SarlScript> parser, ValidationTestHelper validationHelper,
		String string, String... prefix) throws Exception {
	SarlClass clazz = clazz(parser, validationHelper,
			IterableExtensions.join(Arrays.asList(prefix), TestUtils.getLineSeparator())
			+ TestUtils.getLineSeparator() + "class Foo { " + string + "}");
	return (SarlConstructor) clazz.getMembers().get(0);
}
 
Example #10
Source File: TestEObjects.java    From sarl with Apache License 2.0 3 votes vote down vote up
/** Create an instance of JVM function.
 *
 * @param parser the SARL parser.
 * @param associations the provider of associations between the JVM and the SARL Ecores.
 * @param validationHelper the validation test helper. If it is {@code null}, no validation.
 * @param string the file content to parse.
 * @param prefix the set of lines to put before the class declaration of the function.
 * @return the JVM operation signature.
 */
public static JvmOperation jvmOperationSignature(ParseHelper<SarlScript> parser, Provider<SarlJvmModelAssociations> associations,
		ValidationTestHelper validationHelper, String string, String... prefix) throws Exception {
	assert associations != null;
	SarlAction action = functionSignature(parser, validationHelper, string, prefix);
	return (JvmOperation) associations.get().getPrimaryJvmElement(action);
}
 
Example #11
Source File: TestEObjects.java    From sarl with Apache License 2.0 3 votes vote down vote up
/** Create an instance of function signature.
 *
 * @param parser the SARL parser.
 * @param validationHelper the validation test helper. If it is {@code null}, no validation.
 * @param string the file content to parse.
 * @param prefix the set of lines to put before the class declaration of the function.
 * @return the SARL action.
 */
public static SarlAction functionSignature(ParseHelper<SarlScript> parser, ValidationTestHelper validationHelper,
		String string, String... prefix) throws Exception {
	SarlInterface interfaze = interfaze(parser, validationHelper,
			IterableExtensions.join(Arrays.asList(prefix), TestUtils.getLineSeparator())
			+ TestUtils.getLineSeparator() + "interface Foo { " + string + "}");
	return (SarlAction) interfaze.getMembers().get(0);
}
 
Example #12
Source File: TestEObjects.java    From sarl with Apache License 2.0 3 votes vote down vote up
/** Create an instance of JVM function.
 *
 * @param parser the SARL parser.
 * @param associations the provider of associations between the JVM and the SARL Ecores.
 * @param validationHelper the validation test helper. If it is {@code null}, no validation.
 * @param string the file content to parse.
 * @param prefix the set of lines to put before the class declaration of the function.
 * @return the JVM operation.
 */
public static JvmOperation jvmOperation(ParseHelper<SarlScript> parser, Provider<SarlJvmModelAssociations> associations,
		ValidationTestHelper validationHelper, String string, String... prefix) throws Exception {
	assert associations != null;
	SarlAction action = function(parser, validationHelper, string, prefix);
	return (JvmOperation) associations.get().getPrimaryJvmElement(action);
}
 
Example #13
Source File: TestEObjects.java    From sarl with Apache License 2.0 3 votes vote down vote up
/** Create an instance of function.
 *
 * @param parser the SARL parser.
 * @param validationHelper the validation test helper. If it is {@code null}, no validation.
 * @param string the file content to parse.
 * @param prefix the set of lines to put before the class declaration of the function.
 * @return the SARL function.
 */
public static SarlAction function(ParseHelper<SarlScript> parser, ValidationTestHelper validationHelper, String string, String... prefix) throws Exception {
	SarlClass clazz = clazz(parser, validationHelper,
			IterableExtensions.join(Arrays.asList(prefix), TestUtils.getLineSeparator())
			+ TestUtils.getLineSeparator() + "class Foo { " + string + "}");
	return (SarlAction) clazz.getMembers().get(0);
}
 
Example #14
Source File: TestEObjects.java    From sarl with Apache License 2.0 2 votes vote down vote up
/** Create an instance of interface.
 *
 * @param parser the SARL parser.
 * @param validationHelper the validation test helper. If it is {@code null}, no validation.
 * @param string the file content to parse.
 * @return the SARL interface.
 */
public static SarlInterface interfaze(ParseHelper<SarlScript> parser, ValidationTestHelper validationHelper, String string) throws Exception {
	List<XtendTypeDeclaration> decls = file(parser, validationHelper, string).getXtendTypes();
	return (SarlInterface) decls.get(decls.size() - 1);
}
 
Example #15
Source File: TestEObjects.java    From sarl with Apache License 2.0 2 votes vote down vote up
/** Create an instance of enumeration.
 *
 * @param parser the SARL parser.
 * @param validationHelper the validation test helper. If it is {@code null}, no validation.
 * @param string the file content to parse.
 * @return the SARL enumeration.
 */
public static SarlEnumeration enumeration(ParseHelper<SarlScript> parser, ValidationTestHelper validationHelper, String string) throws Exception {
	List<XtendTypeDeclaration> decls = file(parser, validationHelper, string).getXtendTypes();
	return (SarlEnumeration) decls.get(decls.size() - 1);
}
 
Example #16
Source File: TestEObjects.java    From sarl with Apache License 2.0 2 votes vote down vote up
/** Create an instance of annotation type.
 *
 * @param parser the SARL parser.
 * @param validationHelper the validation test helper. If it is {@code null}, no validation.
 * @param string the file content to parse.
 * @return the SARL annotation.
 */
public static SarlAnnotationType annotationType(ParseHelper<SarlScript> parser, ValidationTestHelper validationHelper, String string) throws Exception {
	List<XtendTypeDeclaration> decls = file(parser, validationHelper, string).getXtendTypes();
	return (SarlAnnotationType) decls.get(decls.size() - 1);
}
 
Example #17
Source File: TestEObjects.java    From sarl with Apache License 2.0 2 votes vote down vote up
/** Create an instance of class.
 *
 * @param parser the SARL parser.
 * @param validationHelper the validation test helper. If it is {@code null}, no validation.
 * @param string the file content to parse.
 * @return the SARL class.
 */
public static SarlClass clazz(ParseHelper<SarlScript> parser, ValidationTestHelper validationHelper, String string) throws Exception {
	List<XtendTypeDeclaration> decls = file(parser, validationHelper, string).getXtendTypes();
	return (SarlClass) decls.get(decls.size() - 1);
}
 
Example #18
Source File: TestEObjects.java    From sarl with Apache License 2.0 2 votes vote down vote up
/** Create an instance of behavior.
 *
 * @param parser the SARL parser.
 * @param validationHelper the validation test helper. If it is {@code null}, no validation.
 * @param string the file content to parse.
 * @return the SARL behavior.
 */
public static SarlBehavior behavior(ParseHelper<SarlScript> parser, ValidationTestHelper validationHelper, String string) throws Exception {
	List<XtendTypeDeclaration> decls = file(parser, validationHelper, string).getXtendTypes();
	return (SarlBehavior) decls.get(decls.size() - 1);
}
 
Example #19
Source File: TestEObjects.java    From sarl with Apache License 2.0 2 votes vote down vote up
/** Create an instance of skill.
 *
 * @param parser the SARL parser.
 * @param validationHelper the validation test helper. If it is {@code null}, no validation.
 * @param string the file content to parse.
 * @return the SARL skill.
 */
public static SarlSkill skill(ParseHelper<SarlScript> parser, ValidationTestHelper validationHelper, String string) throws Exception {
	List<XtendTypeDeclaration> decls = file(parser, validationHelper, string).getXtendTypes();
	return (SarlSkill) decls.get(decls.size() - 1);
}
 
Example #20
Source File: TestEObjects.java    From sarl with Apache License 2.0 2 votes vote down vote up
/** Create an instance of event.
 *
 * @param parser the SARL parser.
 * @param validationHelper the validation test helper. If it is {@code null}, no validation.
 * @param string the file content to parse.
 * @return the SARL event.
 */
public static SarlEvent event(ParseHelper<SarlScript> parser, ValidationTestHelper validationHelper, String string) throws Exception {
	List<XtendTypeDeclaration> decls = file(parser, validationHelper, string).getXtendTypes();
	return (SarlEvent) decls.get(decls.size() - 1);
}
 
Example #21
Source File: TestEObjects.java    From sarl with Apache License 2.0 2 votes vote down vote up
/** Create an instance of capacity.
 *
 * @param parser the SARL parser.
 * @param validationHelper the validation test helper. If it is {@code null}, no validation.
 * @param string the file content to parse.
 * @return the SARL capacity.
 */
public static SarlCapacity capacity(ParseHelper<SarlScript> parser, ValidationTestHelper validationHelper, String string) throws Exception {
	List<XtendTypeDeclaration> decls = file(parser, validationHelper, string).getXtendTypes();
	return (SarlCapacity) decls.get(decls.size() - 1);
}
 
Example #22
Source File: TestEObjects.java    From sarl with Apache License 2.0 2 votes vote down vote up
/** Create an instance of agent.
 *
 * @param parser the SARL parser.
 * @param validationHelper the validation test helper. If it is {@code null}, no validation.
 * @param string the file content to parse.
 * @return the SARL agent.
 */
public static SarlAgent agent(ParseHelper<SarlScript> parser, ValidationTestHelper validationHelper, String string) throws Exception {
	List<XtendTypeDeclaration> decls = file(parser, validationHelper, string).getXtendTypes();
	return (SarlAgent) decls.get(decls.size() - 1);
}
 
Example #23
Source File: TestEObjects.java    From sarl with Apache License 2.0 2 votes vote down vote up
/** Create an instance of class.
 *
 * @param parser the SARL parser.
 * @param validationHelper the validation test helper. If it is {@code null}, no validation.
 * @param string the content of the file.
 * @return the SARL script extracted from the file content.
 */
public static SarlScript file(ParseHelper<SarlScript> parser, ValidationTestHelper validationHelper, String string) throws Exception {
	return file(parser, validationHelper, string, null);
}
 
Example #24
Source File: TestEObjects.java    From sarl with Apache License 2.0 2 votes vote down vote up
/** Validate the given resource and reply the issues.
 *
 * @param validationHelper the validation test helper.
 * @param resource the resource to validate.
 * @return the list of issues.
 */
public static List<Issue> issues(ValidationTestHelper validationHelper, Resource resource) {
	assert validationHelper != null;
	return validationHelper.validate(resource);
}
 
Example #25
Source File: TestEObjects.java    From sarl with Apache License 2.0 2 votes vote down vote up
/** Validate the given file and reply the issues.
 *
 * @param validationHelper the validation test helper.
 * @param file the resource to validate.
 * @return the list of issues.
 */
public static List<Issue> issues(ValidationTestHelper validationHelper, SarlScript file) {
	return issues(validationHelper, file.eResource());
}