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

Print verbose output in HRX format #95

Merged
merged 2 commits into from
Sep 30, 2019
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
10 changes: 7 additions & 3 deletions lib/src/runner.dart
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,16 @@ class MigratorRunner extends CommandRunner<Map<Uri, String>> {

if (argResults['dry-run']) {
print('Dry run. Logging migrated files instead of overwriting...\n');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it make sense to remove this line or make it log to stderr so that the HRX output could be piped somewhere?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we actually don't want people piping the output, since we plan to change the format to a diff at some point in the future anyway so it won't be reliably forwards-compatible.


for (var url in migrated.keys) {
print(p.prettyUri(url));
if (argResults['verbose']) {
print('=' * 80);
// This isn't *strictly* HRX format, since it can produce absolute
// URLs rather than those that are relative to the HRX root, but we
// just need it to be readable, not to interoperate with other tools.
print('<===> ${p.prettyUri(url)}');
print(migrated[url]);
print('-' * 80);
} else {
print(p.prettyUri(url));
}
}
} else {
Expand Down
93 changes: 93 additions & 0 deletions test/cli_dart_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,99 @@ void main() {
await migrator.shouldExit(0);
});

group("with --dry-run", () {
test("prints the name of a file that would be migrated", () async {
await d.file("test.scss", "a {b: abs(-1)}").create();

var migrator = await runMigrator(["--dry-run", "module", "test.scss"]);
expect(
migrator.stdout,
emitsInOrder([
"Dry run. Logging migrated files instead of overwriting...",
"",
"test.scss",
emitsDone
]));
await migrator.shouldExit(0);
});

test("doesn't print the name of a file that doesn't need to be migrated",
() async {
await d.file("test.scss", "a {b: abs(-1)}").create();
await d.file("other.scss", "a {b: c}").create();

var migrator =
await runMigrator(["--dry-run", "module", "test.scss", "other.scss"]);
expect(
migrator.stdout,
emitsInOrder([
"Dry run. Logging migrated files instead of overwriting...",
"",
"test.scss",
emitsDone
]));
await migrator.shouldExit(0);
});

test("doesn't print the name of imported files without --migrate-deps",
() async {
await d.file("test.scss", "@import 'other'").create();
await d.file("_other.scss", "a {b: abs(-1)}").create();

var migrator = await runMigrator(["--dry-run", "module", "test.scss"]);
expect(
migrator.stdout,
emitsInOrder([
"Dry run. Logging migrated files instead of overwriting...",
"",
"test.scss",
emitsDone
]));
await migrator.shouldExit(0);
});

test("prints the name of imported files with --migrate-deps", () async {
await d.file("test.scss", "@import 'other'").create();
await d.file("_other.scss", "a {b: abs(-1)}").create();

var migrator = await runMigrator(
["--dry-run", "--migrate-deps", "module", "test.scss"]);
expect(
migrator.stdout,
emitsInOrder([
"Dry run. Logging migrated files instead of overwriting...",
"",
emitsInAnyOrder(["test.scss", "_other.scss"]),
emitsDone
]));
await migrator.shouldExit(0);
});

test("prints the contents of migrated files with --verbose", () async {
await d.file("test.scss", "@import 'other'").create();
await d.file("_other.scss", "a {b: abs(-1)}").create();

var migrator = await runMigrator(
["--dry-run", "--migrate-deps", "--verbose", "module", "test.scss"]);
expect(
migrator.stdout,
emitsInOrder([
"Dry run. Logging migrated files instead of overwriting...",
"",
emitsInAnyOrder([
emitsInOrder(["<===> test.scss", "@use 'other'"]),
emitsInOrder([
"<===> _other.scss",
'@use "sass:math";',
"a {b: math.abs(-1)}"
]),
]),
emitsDone
]));
await migrator.shouldExit(0);
});
});

group("gracefully handles", () {
test("an unknown command", () async {
var migrator = await runMigrator(["asdf"]);
Expand Down