Skip to content

Commit

Permalink
Add tests for reporting errors in imports
Browse files Browse the repository at this point in the history
This is a follow-up from #143, which was fixing an issue that we
did not detect due to not having tests to check how we report
errors in imports.
  • Loading branch information
agarciadom committed Dec 19, 2024
1 parent 3092361 commit d8328f8
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@
EnumResolutionTests.class,
CircularImportTests.class,
ImportCachingTests.class,
ItemSelectorTests.class
ItemSelectorTests.class,
ParseProblemTests.class
})
public class EolAcceptanceTestSuite {

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*********************************************************************
* Copyright (c) 2024 The University of York.
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
**********************************************************************/
package org.eclipse.epsilon.eol.engine.test.acceptance;

import static org.hamcrest.CoreMatchers.allOf;
import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertEquals;

import java.io.File;
import java.nio.file.Files;

import org.eclipse.epsilon.eol.EolModule;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;

public class ParseProblemTests {

@Rule
public TemporaryFolder tempFolder = new TemporaryFolder();

private static final String BAD_EOL = "'incomplete string";

@Test
public void missingImport() throws Exception {
EolModule module = new EolModule();
module.parse("import \"missing.eol\";");
assertEquals(1, module.getParseProblems().size());
assertThat("Expected parse problem is raised",
module.getParseProblems().get(0).getReason(),
allOf(
containsString("not found"),
containsString("missing.eol")
));
}

@Test
public void parseProblemsLocal() throws Exception {
EolModule module = new EolModule();
module.parse(BAD_EOL);
assertEquals(1, module.getParseProblems().size());
}

@Test
public void parseProblemsImported() throws Exception {
File fParseProblems = tempFolder.newFile("parseProblems.eol");
Files.write(fParseProblems.toPath(), BAD_EOL.getBytes());

EolModule module = new EolModule();
module.parse(String.format("import \"%s\";", fParseProblems.getPath()));
assertEquals(1, module.getParseProblems().size());
assertThat("Expected parse problem is raised",
module.getParseProblems().get(0).getReason(),
allOf(
containsString("contains errors"),
containsString("parseProblems.eol")
));
}

}

0 comments on commit d8328f8

Please sign in to comment.