Skip to content

Commit

Permalink
Print verbose output in HRX format
Browse files Browse the repository at this point in the history
Eventually we want to print this in diff format (see #27), but there's
not an up-to-date diff library in Dart at the moment so this is a
stop-gap measure for better output.
  • Loading branch information
nex3 committed Sep 30, 2019
1 parent 44efa5c commit d8ce759
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 3 deletions.
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');

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
84 changes: 84 additions & 0 deletions test/cli_dart_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,90 @@ 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

0 comments on commit d8ce759

Please sign in to comment.