Skip to content

Commit

Permalink
Attempt #2 to test correctly under Windows.
Browse files Browse the repository at this point in the history
  • Loading branch information
bdferris-v2 committed Apr 7, 2023
1 parent 994b2fa commit 538b99f
Showing 1 changed file with 5 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,15 @@ private static String retrieveReportString(Path path) throws IOException {
String content = Files.readString(path);
Gson gson = new GsonBuilder().setPrettyPrinting().create();
JsonObject obj = gson.fromJson(content, JsonObject.class);
String jsonAsString = gson.toJson(obj);
// On Windows systems, the pretty-printed JSON output will have window line separators, which
// will cause a test failure when comparing against our expected strings with Unix line
// separators if we don't normalize them.
return jsonAsString.replace(System.lineSeparator(), "\n");
return gson.toJson(obj);
}

private static String retrieveResource(String name) throws IOException {
try (InputStream in = MainTest.class.getResourceAsStream(name)) {
return new String(in.readAllBytes(), StandardCharsets.UTF_8);
String content = new String(in.readAllBytes(), StandardCharsets.UTF_8);
// On Windows systems, resource files will be checked out by Git with Windows line separators.
// However, all our tests assume Unix line separators. So we fix up the content here.
return content.replace(System.lineSeparator(), "\n");
}
}

Expand Down

0 comments on commit 538b99f

Please sign in to comment.