Skip to content

Commit

Permalink
Attempt to write exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
Matyrobbrt committed Nov 18, 2023
1 parent 2cee096 commit 846924a
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions src/test/java/net/neoforged/elc/tests/RunTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,23 @@
import java.nio.charset.StandardCharsets;

public abstract class RunTest {
protected final void assertExpectedConfig(LaunchConfig config, String name) throws XMLStreamException, ParserConfigurationException, IOException, SAXException {
final StringWriter writer = new StringWriter();
config.write(writer);
final var factory = DocumentBuilderFactory.newInstance().newDocumentBuilder();
final var original = factory.parse(new ByteArrayInputStream(writer.toString().getBytes(StandardCharsets.UTF_8)));
final var in = RunTest.class.getResourceAsStream("/" + name);
final var fromFile = factory.parse(in);
in.close();
protected final void assertExpectedConfig(LaunchConfig config, String name) {
try {
final StringWriter writer = new StringWriter();
config.write(writer);
final var factory = DocumentBuilderFactory.newInstance().newDocumentBuilder();
final var original = factory.parse(new ByteArrayInputStream(writer.toString().getBytes(StandardCharsets.UTF_8)));
final var in = RunTest.class.getResourceAsStream("/" + name);
final var fromFile = factory.parse(in);
in.close();

original.normalizeDocument();
fromFile.normalizeDocument();
Assertions.assertTrue(original.isEqualNode(fromFile), "Documents did not match!");
original.normalizeDocument();
fromFile.normalizeDocument();
Assertions.assertTrue(original.isEqualNode(fromFile), "Documents did not match!");
} catch (Exception exception) {
System.err.println("Failed to run tests: " + exception.getMessage());
exception.printStackTrace(System.err);
throw new RuntimeException("Failed to run tests", exception);
}
}
}

0 comments on commit 846924a

Please sign in to comment.