Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix migrate command version matchers #1769

Merged
merged 1 commit into from
May 12, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Arguments> 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<Path> files = Files.walk(actualDir)
.filter(Files::isRegularFile)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
$version: "1.0"

namespace com.example

string Foo
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
$version: "2.0"

namespace com.example

string Foo
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
$version: "1"

namespace com.example

string Foo
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
$version: "2.0"

namespace com.example

string Foo
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
$version: "2.0"
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
$version: "2"