diff --git a/lib/src/runner.dart b/lib/src/runner.dart index 47644dcf..3845f3e2 100644 --- a/lib/src/runner.dart +++ b/lib/src/runner.dart @@ -106,12 +106,16 @@ class MigratorRunner extends CommandRunner> { 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 { diff --git a/test/cli_dart_test.dart b/test/cli_dart_test.dart index 95df6a57..4caf8692 100644 --- a/test/cli_dart_test.dart +++ b/test/cli_dart_test.dart @@ -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"]);