-
Notifications
You must be signed in to change notification settings - Fork 218
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use pretty validation output with smithy diff
Smithy diff now uses the pretty validation output. The old and new models are both validated, but only build-failing errors are shown. When the original model fails, a label is added before ERROR/DANGER to show it's on the OLD model. When the new model fails, it shows a NEW label. When running the diff with two valid models, events have a label of DIFF. The events shown here use the --severity option and default to WARNING when not set.
- Loading branch information
Showing
6 changed files
with
245 additions
and
77 deletions.
There are no files selected for viewing
98 changes: 98 additions & 0 deletions
98
smithy-cli/src/it/java/software/amazon/smithy/cli/DiffCommandTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
/* | ||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"). | ||
* You may not use this file except in compliance with the License. | ||
* A copy of the License is located at | ||
* | ||
* http://aws.amazon.com/apache2.0 | ||
* | ||
* or in the "license" file accompanying this file. This file is distributed | ||
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
* express or implied. See the License for the specific language governing | ||
* permissions and limitations under the License. | ||
*/ | ||
|
||
package software.amazon.smithy.cli; | ||
|
||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.containsString; | ||
import static org.hamcrest.Matchers.equalTo; | ||
|
||
import java.io.FileWriter; | ||
import java.io.IOException; | ||
import java.io.PrintWriter; | ||
import java.io.UncheckedIOException; | ||
import java.nio.file.Path; | ||
import org.junit.jupiter.api.Test; | ||
import software.amazon.smithy.utils.ListUtils; | ||
|
||
public class DiffCommandTest { | ||
@Test | ||
public void passingDiffEventsExitZero() { | ||
IntegUtils.withTempDir("diff", dir -> { | ||
Path a = dir.resolve("a.smithy"); | ||
writeFile(a, "$version: \"2.0\"\nnamespace example\nstring A\n"); | ||
|
||
RunResult result = IntegUtils.run(dir, ListUtils.of("diff", "--old", a.toString(), "--new", a.toString())); | ||
assertThat(result.getExitCode(), equalTo(0)); | ||
}); | ||
} | ||
|
||
@Test | ||
public void showsLabelForOldModelEvents() { | ||
IntegUtils.withTempDir("diff", dir -> { | ||
Path a = dir.resolve("a.smithy"); | ||
writeFile(a, "$version: \"2.0\"\nnamespace example\n@aaaaaa\nstring A\n"); | ||
|
||
RunResult result = IntegUtils.run(dir, ListUtils.of("diff", "--old", a.toString(), "--new", a.toString())); | ||
assertThat(result.getExitCode(), equalTo(1)); | ||
assertThat(result.getOutput(), containsString("── OLD ─ ERROR ──")); | ||
}); | ||
} | ||
|
||
@Test | ||
public void showsLabelForNewModelEvents() { | ||
IntegUtils.withTempDir("diff", dir -> { | ||
Path a = dir.resolve("a.smithy"); | ||
writeFile(a, "$version: \"2.0\"\nnamespace example\nstring A\n"); | ||
|
||
Path b = dir.resolve("b.smithy"); | ||
writeFile(b, "$version: \"2.0\"\nnamespace example\n@aaaaaa\nstring A\n"); | ||
|
||
RunResult result = IntegUtils.run(dir, ListUtils.of("diff", "--old", a.toString(), "--new", b.toString())); | ||
assertThat(result.getExitCode(), equalTo(1)); | ||
assertThat(result.getOutput(), containsString("── NEW ─ ERROR ──")); | ||
}); | ||
} | ||
|
||
@Test | ||
public void showsLabelForDiffEvents() { | ||
IntegUtils.withTempDir("diff", dir -> { | ||
Path a = dir.resolve("a.smithy"); | ||
writeFile(a, "$version: \"2.0\"\nnamespace example\nstring A\n"); | ||
|
||
Path b = dir.resolve("b.smithy"); | ||
writeFile(b, "$version: \"2.0\"\nnamespace example\nstring A\nstring B\n"); // Added B. | ||
|
||
RunResult result = IntegUtils.run(dir, ListUtils.of( | ||
"diff", | ||
"--old", a.toString(), | ||
"--new", b.toString(), | ||
"--severity", "NOTE")); // Note that this is required since the default severity is WARNING. | ||
assertThat(result.getExitCode(), equalTo(0)); | ||
assertThat(result.getOutput(), containsString("── DIFF ─ NOTE ──")); | ||
}); | ||
} | ||
|
||
private void writeFile(Path path, String contents) { | ||
try { | ||
FileWriter fileWriter = new FileWriter(path.toString()); | ||
PrintWriter printWriter = new PrintWriter(fileWriter); | ||
printWriter.print(contents); | ||
printWriter.close(); | ||
} catch (IOException e) { | ||
throw new UncheckedIOException(e); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.