-
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 updated output with smithy build and diff
Smithy diff and build now uses the pretty validation output and color theming options. Because Styles were copied and repated multiple times, I introduced a ColorTheme class to store reusable styles. This isn't a swappable color scheme system, but could be evolved into one in the future if needed. For Smithy Diff: 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. For Smithy Build: Each projection output is contained in a titled section using a colored title to match whether the projection passed or failed. Any events encountered during the projection are emitted using the updated styling and have a prefix label using the projection name.
- Loading branch information
Showing
22 changed files
with
471 additions
and
163 deletions.
There are no files selected for viewing
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
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
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
51 changes: 51 additions & 0 deletions
51
smithy-cli/src/main/java/software/amazon/smithy/cli/ColorTheme.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,51 @@ | ||
/* | ||
* 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; | ||
|
||
/** | ||
* Standardizes on colors across commands. | ||
*/ | ||
public final class ColorTheme { | ||
|
||
public static final Style EM_UNDERLINE = Style.of(Style.BRIGHT_WHITE, Style.UNDERLINE); | ||
public static final Style DEPRECATED = Style.of(Style.BG_YELLOW, Style.BLACK); | ||
|
||
public static final Style MUTED = Style.of(Style.BRIGHT_BLACK); | ||
public static final Style EVENT_SHAPE_ID = Style.of(Style.BRIGHT_MAGENTA); | ||
public static final Style LITERAL = Style.of(Style.CYAN); | ||
|
||
public static final Style ERROR_TITLE = Style.of(Style.BG_RED, Style.BLACK); | ||
public static final Style ERROR = Style.of(Style.RED); | ||
|
||
public static final Style DANGER_TITLE = Style.of(Style.BG_MAGENTA, Style.BLACK); | ||
public static final Style DANGER = Style.of(Style.MAGENTA); | ||
|
||
public static final Style WARNING_TITLE = Style.of(Style.BG_YELLOW, Style.BLACK); | ||
public static final Style WARNING = Style.of(Style.YELLOW); | ||
|
||
public static final Style NOTE_TITLE = Style.of(Style.BG_CYAN, Style.BLACK); | ||
public static final Style NOTE = Style.of(Style.CYAN); | ||
|
||
public static final Style SUPPRESSED_TITLE = Style.of(Style.BG_GREEN, Style.BLACK); | ||
public static final Style SUPPRESSED = Style.of(Style.GREEN); | ||
|
||
public static final Style SUCCESS = Style.of(Style.GREEN); | ||
|
||
public static final Style DIFF_TITLE = Style.of(Style.BG_BRIGHT_BLACK, Style.WHITE); | ||
public static final Style DIFF_EVENT_TITLE = Style.of(Style.BG_BRIGHT_BLUE, Style.BLACK); | ||
|
||
private ColorTheme() {} | ||
} |
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
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.