Search in sources :

Example 1 with IssueExpectations

use of org.eclipse.n4js.tests.issues.IssueExpectations in project n4js by eclipse.

the class AccessControlTest method executeSpecification.

private static void executeSpecification(TestSpecification specification) throws IOException {
    deleteFixtureDirectory();
    boolean failOnExit = specification.getExpectation().isFixMe();
    Map<MemberType, List<String>> fixMeMessages = new HashMap<>();
    for (MemberType memberType : MemberType.values()) {
        createFixtureDirectory(memberType);
        ScenarioGenerator generator = new ScenarioGenerator(specification, memberType);
        generator.generateScenario(Paths.get(FIXTURE_ROOT, memberType.name()));
        List<Issue> issues = new ArrayList<>(compile(memberType));
        issues.removeIf(issue -> N4JSLanguageConstants.DEFAULT_SUPPRESSED_ISSUE_CODES_FOR_TESTS.contains(issue.getCode()));
        IssueExpectations expectations = generator.createIssues();
        if (specification.getExpectation().isFixMe()) {
            // We want the entire test case to fail only if none of the tested scenarios match their
            // expectations.
            List<String> messages = new ArrayList<>();
            final boolean fixMeFailed = !expectations.matchesExactly(issues, messages);
            if (fixMeFailed)
                fixMeMessages.put(memberType, messages);
            failOnExit &= fixMeFailed;
        } else {
            List<String> messages = new ArrayList<>();
            boolean result = expectations.matchesExactly(issues, messages);
            assertTrue(Joiner.on(", ").join(messages), result);
            messages.clear();
        }
    }
    if (failOnExit) {
        StringBuilder message = new StringBuilder();
        for (Map.Entry<MemberType, List<String>> entry : fixMeMessages.entrySet()) {
            final MemberType memberType = entry.getKey();
            final List<String> messages = entry.getValue();
            message.append("FixMe test failed for member type ").append(memberType).append(": \n");
            for (String line : messages) message.append("    ").append(line).append("\n");
        }
        fail(message.toString());
    }
}
Also used : Issue(org.eclipse.xtext.validation.Issue) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) IssueExpectations(org.eclipse.n4js.tests.issues.IssueExpectations)

Aggregations

ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Map (java.util.Map)1 IssueExpectations (org.eclipse.n4js.tests.issues.IssueExpectations)1 Issue (org.eclipse.xtext.validation.Issue)1