Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@ on:

jobs:
build:
runs-on: ubuntu-latest
name: Java ${{ matrix.java }}
runs-on: ${{ matrix.os }}
name: Java ${{ matrix.java }} ${{ matrix.os }}
strategy:
matrix:
java: [8, 11]
os: [ubuntu-latest, windows-latest]

steps:
- uses: actions/checkout@v2
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ plugins {

ext {
// Load the Smithy version from VERSION.
libraryVersion = project.file("VERSION").getText('UTF-8').replace("\n", "")
libraryVersion = project.file("VERSION").getText('UTF-8').replace(System.lineSeparator(), "")
}

println "Smithy version: '${libraryVersion}'"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import static org.junit.jupiter.api.Assertions.assertEquals;

import java.io.IOException;
import java.net.URISyntaxException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.List;
Expand Down Expand Up @@ -62,12 +63,12 @@ public void generatesResources(String modelFile) {

public static List<String> integFiles() {
try {
return Files.walk(Paths.get(TestRunnerTest.class.getResource("integ").getPath()))
return Files.walk(Paths.get(TestRunnerTest.class.getResource("integ").toURI()))
.filter(Files::isRegularFile)
.filter(file -> file.toString().endsWith(".smithy"))
.map(Object::toString)
.collect(Collectors.toList());
} catch (IOException e) {
} catch (IOException | URISyntaxException e) {
throw new RuntimeException(e);
}
}
Expand Down
2 changes: 1 addition & 1 deletion smithy-aws-protocol-tests/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
*/

plugins {
id "software.amazon.smithy" version "0.5.1"
id "software.amazon.smithy" version "0.5.2"
}

description = "Defines protocol tests for AWS HTTP protocols."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ public void createsEmptyManifest() throws Exception {

assertThat(files, hasItem(outputDirectory.resolve("source/sources/manifest")));
assertThat("\n", equalTo(IoUtils.readUtf8File(results.allArtifacts()
.filter(path -> path.toString().endsWith("/manifest"))
.filter(path -> path.toString().endsWith(System.getProperty("file.separator") + "manifest"))
.findFirst()
.get())));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import static org.hamcrest.Matchers.hasKey;
import static org.hamcrest.Matchers.is;

import java.nio.file.Paths;
import java.util.Optional;
import org.junit.jupiter.api.Test;
import software.amazon.smithy.build.MockManifest;
Expand Down Expand Up @@ -57,7 +58,7 @@ public void createsSymbolsAndFilesForShapeWriters() {
delegator.useShapeWriter(shape, writer -> { });

assertThat(observer.onShapeWriterUseCalled, is(true));
assertThat(delegator.getWriters(), hasKey("com/foo/Baz.bam"));
assertThat(delegator.getWriters(), hasKey(Paths.get("com/foo/Baz.bam").toString()));
}

@Test
Expand All @@ -77,7 +78,7 @@ public void canObserveAndWriteBeforeEachFile() {
writer.write("Hello");
});

assertThat(delegator.getWriters().get("com/foo/Baz.bam").toString(),
assertThat(delegator.getWriters().get(Paths.get("com/foo/Baz.bam").toString()).toString(),
equalTo("/// Writing com.foo#Baz\nHello\n"));
}

Expand Down Expand Up @@ -114,7 +115,8 @@ public void writesNewlineBetweenFiles() {
writer.write(".");
});

assertThat(delegator.getWriters().get("foo/baz").toString(), equalTo(".\n\n.\n"));
assertThat(delegator.getWriters().get(Paths.get("foo/baz").toString()).toString(),
equalTo(".\n\n.\n"));
}

@Test
Expand All @@ -133,7 +135,8 @@ public void canDisableNewlineBetweenFiles() {
writer.writeInline(".");
});

assertThat(delegator.getWriters().get("foo/baz").toString(), equalTo("..\n"));
assertThat(delegator.getWriters().get(Paths.get("foo/baz").toString()).toString(),
equalTo("..\n"));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ private static String inferErrorFileLocation(String modelLocation) {

private static List<ValidationEvent> loadExpectedEvents(String errorsFileLocation) {
String contents = IoUtils.readUtf8File(errorsFileLocation);
return Arrays.stream(contents.split("\n"))
return Arrays.stream(contents.split(System.lineSeparator()))
.filter(line -> !line.trim().isEmpty())
.map(SmithyTestCase::parseValidationEvent)
.collect(Collectors.toList());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ public void testParserRunner(String file) {
.unwrap();
throw new IllegalStateException("Expected a parse error for " + file);
} catch (RuntimeException e) {
String actualMessage = e.getMessage().replace("\n", "\\n");
String expectedMessage = expectedError.replace("\n", "\\n");
String actualMessage = cleanErrorMessage(e.getMessage());
String expectedMessage = cleanErrorMessage(expectedError);
if (!actualMessage.contains(expectedMessage)) {
throw new IllegalStateException(
String.format("Expected a different parse error for %s.\nExpected (%s)\nFound (%s)",
Expand All @@ -60,6 +60,18 @@ public void testParserRunner(String file) {
}
}

private String cleanErrorMessage(String errorMessage) {
return errorMessage
// We'll never see EOF on Windows since we only get 2 context characters and those
// will be taken up by the line separator characters.
.replace("[EOF]", "")
// Make sure the line separators and representations of them are consistent across
// operating systems.
.replace("\r\n", "\\n")
.replace("\r", "\\n")
.replace("\n", "\\n");
}

public static Collection<String> data() throws Exception {
try {
Stream<Path> paths = Files.walk(Paths.get(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@

import java.io.File;
import java.io.IOException;
import java.nio.file.FileSystemException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
Expand All @@ -44,6 +45,7 @@
import java.util.Optional;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Assumptions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import software.amazon.smithy.model.Model;
Expand Down Expand Up @@ -268,7 +270,14 @@ public Path createSymbolicLink(Path target, String linkName) throws IOException
if (Files.exists(link)) {
Files.delete(link);
}
return Files.createSymbolicLink(link, target);
try {
return Files.createSymbolicLink(link, target);
} catch (FileSystemException e) {
// Skip tests if symlinks are unable to be created. This can happen on Windows, for instance, where the
// permissions to create them are not enabled by default.
Assumptions.assumeFalse(System.getProperty("os.name").toLowerCase().contains("windows"), e.getMessage());
throw e;
}
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public void testConversion(Path path) {
}

String serializedString = serialized.entrySet().iterator().next().getValue();
Assertions.assertEquals(serializedString, IoUtils.readUtf8File(path));
Assertions.assertEquals(serializedString, IoUtils.readUtf8File(path).replaceAll("\\R", "\n"));
}

@Test
Expand All @@ -57,7 +57,8 @@ public void multipleNamespacesGenerateMultipleFiles() throws Exception {
.basePath(outputDir)
.build();
Map<Path, String> serialized = serializer.serialize(model);
serialized.forEach((path, generated) -> assertThat(generated, equalTo(IoUtils.readUtf8File(path))));
serialized.forEach((path, generated) -> assertThat(
generated, equalTo(IoUtils.readUtf8File(path).replaceAll("\\R", "\n"))));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,23 +70,25 @@ public void readsFromStringPath() throws Exception {
// Windows doesn't like the result of URL#getPath, so to test this
// we create a Path from the URI, convert that to a string, then pass
// it to the helper method which uses Paths.get again.
assertEquals("This is a test.\n",
assertEquals("This is a test." + System.lineSeparator(),
IoUtils.readUtf8File(Paths.get(getClass().getResource("test.txt").toURI()).toString()));
}

@Test
public void readsFromPath() throws URISyntaxException {
assertEquals("This is a test.\n", IoUtils.readUtf8File(Paths.get(getClass().getResource("test.txt").toURI())));
assertEquals("This is a test." + System.lineSeparator(),
IoUtils.readUtf8File(Paths.get(getClass().getResource("test.txt").toURI())));
}

@Test
public void readsFromClass() {
assertEquals("This is a test.\n", IoUtils.readUtf8Resource(getClass(), "test.txt"));
assertEquals("This is a test." + System.lineSeparator(),
IoUtils.readUtf8Resource(getClass(), "test.txt"));
}

@Test
public void readsFromClassLoader() {
assertEquals("This is a test.\n", IoUtils.readUtf8Resource(
assertEquals("This is a test." + System.lineSeparator(), IoUtils.readUtf8Resource(
getClass().getClassLoader(), "software/amazon/smithy/utils/test.txt"));
}

Expand Down