diff --git a/smithy-cli/src/main/java/software/amazon/smithy/cli/commands/MigrateCommand.java b/smithy-cli/src/main/java/software/amazon/smithy/cli/commands/MigrateCommand.java index a922398d227..e081e6c0d26 100644 --- a/smithy-cli/src/main/java/software/amazon/smithy/cli/commands/MigrateCommand.java +++ b/smithy-cli/src/main/java/software/amazon/smithy/cli/commands/MigrateCommand.java @@ -70,8 +70,8 @@ final class MigrateCommand implements Command { private static final Logger LOGGER = Logger.getLogger(MigrateCommand.class.getName()); - private static final Pattern VERSION_1 = Pattern.compile("(?m)^\\s*\\$\\s*version:\\s*\"1\\.0\"\\s*$"); - private static final Pattern VERSION_2 = Pattern.compile("(?m)^\\s*\\$\\s*version:\\s*\"2\\.0\"\\s*$"); + private static final Pattern VERSION_1 = Pattern.compile("(?m)^\\s*\\$\\s*version:\\s*\"1(\\.0)?\"\\s*$"); + private static final Pattern VERSION_2 = Pattern.compile("(?m)^\\s*\\$\\s*version:\\s*\"2(\\.0)?\"\\s*$"); private final String parentCommandName; MigrateCommand(String parentCommandName) { diff --git a/smithy-cli/src/test/java/software/amazon/smithy/cli/commands/MigrateCommandTest.java b/smithy-cli/src/test/java/software/amazon/smithy/cli/commands/MigrateCommandTest.java index 9d2c42aa14a..7c20b8cf330 100644 --- a/smithy-cli/src/test/java/software/amazon/smithy/cli/commands/MigrateCommandTest.java +++ b/smithy-cli/src/test/java/software/amazon/smithy/cli/commands/MigrateCommandTest.java @@ -114,6 +114,25 @@ public void testUpgradeDirectoryWithJar() throws Exception { assertDirEqual(baseDir.getParent().resolve("v2"), tempDir); } + @ParameterizedTest(name = "{1}") + @MethodSource("noopSource") + public void testUpgradeV2Noop(Path noopTestFilePath, String name) { + Model model = Model.assembler().addImport(noopTestFilePath).assemble().unwrap(); + String actual = new MigrateCommand("smithy").upgradeFile(model, noopTestFilePath); + String expected = IoUtils.readUtf8File(noopTestFilePath); + + if (!actual.equals(expected)) { + Assertions.fail("Expected models to be equal:\n\nActual:\n\n" + actual + "\n\nExpected:\n\n" + expected); + } + } + + public static Stream noopSource() throws Exception { + Path start = Paths.get(MigrateCommandTest.class.getResource("upgrade/no-op").toURI()); + return Files.walk(start) + .filter(path -> Files.isRegularFile(path)) + .map(path -> Arguments.of(path, path.getFileName().toString().replace(".v2.smithy", ""))); + } + private void assertDirEqual(Path actualDir, Path expectedDir) throws Exception { Set files = Files.walk(actualDir) .filter(Files::isRegularFile) diff --git a/smithy-cli/src/test/resources/software/amazon/smithy/cli/commands/upgrade/cases/version.v1.smithy b/smithy-cli/src/test/resources/software/amazon/smithy/cli/commands/upgrade/cases/version-absent.v1.smithy similarity index 100% rename from smithy-cli/src/test/resources/software/amazon/smithy/cli/commands/upgrade/cases/version.v1.smithy rename to smithy-cli/src/test/resources/software/amazon/smithy/cli/commands/upgrade/cases/version-absent.v1.smithy diff --git a/smithy-cli/src/test/resources/software/amazon/smithy/cli/commands/upgrade/cases/version.v2.smithy b/smithy-cli/src/test/resources/software/amazon/smithy/cli/commands/upgrade/cases/version-absent.v2.smithy similarity index 100% rename from smithy-cli/src/test/resources/software/amazon/smithy/cli/commands/upgrade/cases/version.v2.smithy rename to smithy-cli/src/test/resources/software/amazon/smithy/cli/commands/upgrade/cases/version-absent.v2.smithy diff --git a/smithy-cli/src/test/resources/software/amazon/smithy/cli/commands/upgrade/cases/version-decimal-suffix.v1.smithy b/smithy-cli/src/test/resources/software/amazon/smithy/cli/commands/upgrade/cases/version-decimal-suffix.v1.smithy new file mode 100644 index 00000000000..75513885011 --- /dev/null +++ b/smithy-cli/src/test/resources/software/amazon/smithy/cli/commands/upgrade/cases/version-decimal-suffix.v1.smithy @@ -0,0 +1,5 @@ +$version: "1.0" + +namespace com.example + +string Foo diff --git a/smithy-cli/src/test/resources/software/amazon/smithy/cli/commands/upgrade/cases/version-decimal-suffix.v2.smithy b/smithy-cli/src/test/resources/software/amazon/smithy/cli/commands/upgrade/cases/version-decimal-suffix.v2.smithy new file mode 100644 index 00000000000..1c4e1bafe8a --- /dev/null +++ b/smithy-cli/src/test/resources/software/amazon/smithy/cli/commands/upgrade/cases/version-decimal-suffix.v2.smithy @@ -0,0 +1,5 @@ +$version: "2.0" + +namespace com.example + +string Foo diff --git a/smithy-cli/src/test/resources/software/amazon/smithy/cli/commands/upgrade/cases/version-no-decimal-suffix.v1.smithy b/smithy-cli/src/test/resources/software/amazon/smithy/cli/commands/upgrade/cases/version-no-decimal-suffix.v1.smithy new file mode 100644 index 00000000000..15fa4f3d80f --- /dev/null +++ b/smithy-cli/src/test/resources/software/amazon/smithy/cli/commands/upgrade/cases/version-no-decimal-suffix.v1.smithy @@ -0,0 +1,5 @@ +$version: "1" + +namespace com.example + +string Foo diff --git a/smithy-cli/src/test/resources/software/amazon/smithy/cli/commands/upgrade/cases/version-no-decimal-suffix.v2.smithy b/smithy-cli/src/test/resources/software/amazon/smithy/cli/commands/upgrade/cases/version-no-decimal-suffix.v2.smithy new file mode 100644 index 00000000000..1c4e1bafe8a --- /dev/null +++ b/smithy-cli/src/test/resources/software/amazon/smithy/cli/commands/upgrade/cases/version-no-decimal-suffix.v2.smithy @@ -0,0 +1,5 @@ +$version: "2.0" + +namespace com.example + +string Foo diff --git a/smithy-cli/src/test/resources/software/amazon/smithy/cli/commands/upgrade/no-op/decimal-suffix.v2.smithy b/smithy-cli/src/test/resources/software/amazon/smithy/cli/commands/upgrade/no-op/decimal-suffix.v2.smithy new file mode 100644 index 00000000000..7343178e2b7 --- /dev/null +++ b/smithy-cli/src/test/resources/software/amazon/smithy/cli/commands/upgrade/no-op/decimal-suffix.v2.smithy @@ -0,0 +1 @@ +$version: "2.0" diff --git a/smithy-cli/src/test/resources/software/amazon/smithy/cli/commands/upgrade/no-op/no-decimal-suffix.v2.smithy b/smithy-cli/src/test/resources/software/amazon/smithy/cli/commands/upgrade/no-op/no-decimal-suffix.v2.smithy new file mode 100644 index 00000000000..ec40852bad1 --- /dev/null +++ b/smithy-cli/src/test/resources/software/amazon/smithy/cli/commands/upgrade/no-op/no-decimal-suffix.v2.smithy @@ -0,0 +1 @@ +$version: "2"