From 0ce337ababfc5e441f8a2092a631d8852e70da85 Mon Sep 17 00:00:00 2001 From: Nate Bosch Date: Tue, 7 Aug 2018 14:22:39 -0700 Subject: [PATCH 1/3] Rename --checked to --check-asserts Keep the old flag as an alias, run with checked mode if either is set. Behavior will be weird for cases like `--checked --no-check-asserts` but it's not worth the extra complexity to track that down. Update tests using the flag. Use consistent single quotes in the files that were being edited anyway. --- lib/src/command/global_run.dart | 24 +++++++-------- lib/src/command/run.dart | 30 +++++++++---------- lib/src/executable.dart | 10 +++---- lib/src/global_packages.dart | 2 +- .../run/errors_if_outside_bin_test.dart | 4 +-- .../run/missing_executable_arg_test.dart | 8 ++--- .../run/runs_script_in_checked_mode_test.dart | 11 +++---- ...errors_if_no_executable_is_given_test.dart | 8 ++--- .../errors_if_path_in_dependency_test.dart | 12 ++++---- .../runs_the_script_in_checked_mode_test.dart | 8 ++--- ...uns_the_script_in_unchecked_mode_test.dart | 10 +++---- 11 files changed, 64 insertions(+), 63 deletions(-) diff --git a/lib/src/command/global_run.dart b/lib/src/command/global_run.dart index 75f37f62f..1ba031021 100644 --- a/lib/src/command/global_run.dart +++ b/lib/src/command/global_run.dart @@ -13,28 +13,28 @@ import '../utils.dart'; /// Handles the `global run` pub command. class GlobalRunCommand extends PubCommand { - String get name => "run"; + String get name => 'run'; String get description => - "Run an executable from a globally activated package.\n" + 'Run an executable from a globally activated package.\n' "NOTE: We are currently optimizing this command's startup time."; - String get invocation => "pub global run : [args...]"; + String get invocation => 'pub global run : [args...]'; bool get allowTrailingOptions => false; GlobalRunCommand() { - argParser.addFlag("checked", - abbr: "c", help: "Enable runtime type checks and assertions."); - argParser.addOption("mode", help: "Deprecated option", hide: true); + argParser.addFlag('check-asserts', abbr: 'c', help: 'Enable assertions.'); + argParser.addFlag('checked', hide: true); + argParser.addOption('mode', help: 'Deprecated option', hide: true); } Future run() async { if (argResults.rest.isEmpty) { - usageException("Must specify an executable to run."); + usageException('Must specify an executable to run.'); } var package; var executable = argResults.rest[0]; - if (executable.contains(":")) { - var parts = split1(executable, ":"); + if (executable.contains(':')) { + var parts = split1(executable, ':'); package = parts[0]; executable = parts[1]; } else { @@ -48,12 +48,12 @@ class GlobalRunCommand extends PubCommand { 'package.'); } - if (argResults.wasParsed("mode")) { - log.warning("The --mode flag is deprecated and has no effect."); + if (argResults.wasParsed('mode')) { + log.warning('The --mode flag is deprecated and has no effect.'); } var exitCode = await globals.runExecutable(package, executable, args, - checked: argResults["checked"]); + checked: argResults['check-asserts'] || argResults['checked']); await flushThenExit(exitCode); } } diff --git a/lib/src/command/run.dart b/lib/src/command/run.dart index 9afe3923d..d394e9199 100644 --- a/lib/src/command/run.dart +++ b/lib/src/command/run.dart @@ -14,20 +14,20 @@ import '../utils.dart'; /// Handles the `run` pub command. class RunCommand extends PubCommand { - String get name => "run"; - String get description => "Run an executable from a package."; - String get invocation => "pub run [args...]"; + String get name => 'run'; + String get description => 'Run an executable from a package.'; + String get invocation => 'pub run [args...]'; bool get allowTrailingOptions => false; RunCommand() { - argParser.addFlag("checked", - abbr: "c", help: "Enable runtime type checks and assertions."); - argParser.addOption("mode", help: "Deprecated option", hide: true); + argParser.addFlag('check-asserts', abbr: 'c', help: 'Enable assertions.'); + argParser.addFlag('checked', hide: true); + argParser.addOption('mode', help: 'Deprecated option', hide: true); } Future run() async { if (argResults.rest.isEmpty) { - usageException("Must specify an executable to run."); + usageException('Must specify an executable to run.'); } var package = entrypoint.root.name; @@ -36,14 +36,14 @@ class RunCommand extends PubCommand { // A command like "foo:bar" runs the "bar" script from the "foo" package. // If there is no colon prefix, default to the root package. - if (executable.contains(":")) { - var components = split1(executable, ":"); + if (executable.contains(':')) { + var components = split1(executable, ':'); package = components[0]; executable = components[1]; if (p.split(executable).length > 1) { usageException( - "Cannot run an executable in a subdirectory of a dependency."); + 'Cannot run an executable in a subdirectory of a dependency.'); } } else if (onlyIdentifierRegExp.hasMatch(executable)) { // "pub run foo" means the same thing as "pub run foo:foo" as long as @@ -51,16 +51,16 @@ class RunCommand extends PubCommand { package = executable; } - if (argResults.wasParsed("mode")) { - log.warning("The --mode flag is deprecated and has no effect."); + if (argResults.wasParsed('mode')) { + log.warning('The --mode flag is deprecated and has no effect.'); } // The user may pass in an executable without an extension, but the file // to actually execute will always have one. - if (p.extension(executable) != ".dart") executable += ".dart"; + if (p.extension(executable) != '.dart') executable += '.dart'; var snapshotPath = p.join( - entrypoint.cachePath, "bin", package, "$executable.snapshot.dart2"); + entrypoint.cachePath, 'bin', package, '$executable.snapshot.dart2'); // Don't ever compile snapshots for mutable packages, since their code may // change later on. @@ -69,7 +69,7 @@ class RunCommand extends PubCommand { !entrypoint.packageGraph.isPackageMutable(package)); var exitCode = await runExecutable(entrypoint, package, executable, args, - checked: argResults['checked'], + checked: argResults['check-asserts'] || argResults['checked'], snapshotPath: useSnapshot ? snapshotPath : null, recompile: entrypoint.precompileExecutables); await flushThenExit(exitCode); diff --git a/lib/src/executable.dart b/lib/src/executable.dart index ced7de35e..e38188807 100644 --- a/lib/src/executable.dart +++ b/lib/src/executable.dart @@ -22,7 +22,7 @@ import 'utils.dart'; /// /// Arguments from [args] will be passed to the spawned Dart application. /// -/// If [checked] is true, the program is run in checked mode. +/// If [checked] is true, the program is run with assertions enabled. /// /// If [packagesFile] is passed, it's used as the package config file path for /// the executable. Otherwise, `entrypoint.packagesFile` is used. @@ -117,7 +117,7 @@ Future _executablePath( return p.absolute(fullPath); } -/// Like [runSnapshot], but runs [recompile] if [path] doesn't exist yet. +/// Like [_runSnapshot], but runs [recompile] if [path] doesn't exist yet. /// /// Returns `null` if [path] doesn't exist and isn't generated by [recompile]. Future _runOrCompileSnapshot(String path, Iterable args, @@ -130,7 +130,7 @@ Future _runOrCompileSnapshot(String path, Iterable args, if (!fileExists(path)) return null; } - return await runSnapshot(path, args, + return await _runSnapshot(path, args, recompile: recompile, packagesFile: packagesFile, checked: checked); } @@ -141,12 +141,12 @@ Future _runOrCompileSnapshot(String path, Iterable args, /// expected to regenerate a snapshot at [path], after which the snapshot will /// be re-run. /// -/// If [checked] is set, runs the snapshot in checked mode. +/// If [checked] is set, runs the snapshot with assertions enabled. /// /// Returns the snapshot's exit code. /// /// This doesn't do any validation of the snapshot's SDK version. -Future runSnapshot(String path, Iterable args, +Future _runSnapshot(String path, Iterable args, {Future recompile(), String packagesFile, bool checked = false}) async { diff --git a/lib/src/global_packages.dart b/lib/src/global_packages.dart index e6fa3e08a..58df59a1c 100644 --- a/lib/src/global_packages.dart +++ b/lib/src/global_packages.dart @@ -373,7 +373,7 @@ class GlobalPackages { /// recompiled if the SDK has been upgraded since it was first compiled and /// then run. Otherwise, it will be run from source. /// - /// If [checked] is true, the program is run in checked mode. + /// If [checked] is true, the program is run with assertions enabled. /// /// Returns the exit code from the executable. Future runExecutable( diff --git a/test/global/run/errors_if_outside_bin_test.dart b/test/global/run/errors_if_outside_bin_test.dart index 9104ba708..db1c15880 100644 --- a/test/global/run/errors_if_outside_bin_test.dart +++ b/test/global/run/errors_if_outside_bin_test.dart @@ -22,8 +22,8 @@ main() { Cannot run an executable in a subdirectory of a global package. Usage: pub global run : [args...] --h, --help Print this usage information. --c, --[no-]checked Enable runtime type checks and assertions. +-h, --help Print this usage information. +-c, --[no-]check-asserts Enable assertions. Run "pub help" to see global options. """, exitCode: exit_codes.USAGE); diff --git a/test/global/run/missing_executable_arg_test.dart b/test/global/run/missing_executable_arg_test.dart index e1f2b9c18..32e33d4ff 100644 --- a/test/global/run/missing_executable_arg_test.dart +++ b/test/global/run/missing_executable_arg_test.dart @@ -10,14 +10,14 @@ import '../../test_pub.dart'; main() { test('fails if no executable was given', () { - return runPub(args: ["global", "run"], error: """ + return runPub(args: ['global', 'run'], error: ''' Must specify an executable to run. Usage: pub global run : [args...] - -h, --help Print this usage information. - -c, --[no-]checked Enable runtime type checks and assertions. + -h, --help Print this usage information. + -c, --[no-]check-asserts Enable assertions. Run "pub help" to see global options. - """, exitCode: exit_codes.USAGE); + ''', exitCode: exit_codes.USAGE); }); } diff --git a/test/global/run/runs_script_in_checked_mode_test.dart b/test/global/run/runs_script_in_checked_mode_test.dart index 86af68956..480de433c 100644 --- a/test/global/run/runs_script_in_checked_mode_test.dart +++ b/test/global/run/runs_script_in_checked_mode_test.dart @@ -10,15 +10,16 @@ import '../../test_pub.dart'; main() { test('runs a script in checked mode', () async { await servePackages((builder) { - builder.serve("foo", "1.0.0", contents: [ - d.dir("bin", [d.file("script.dart", "main() { assert(false); }")]) + builder.serve('foo', '1.0.0', contents: [ + d.dir('bin', [d.file('script.dart', 'main() { assert(false); }')]) ]); }); - await runPub(args: ["global", "activate", "foo"]); + await runPub(args: ['global', 'activate', 'foo']); - var pub = await pubRun(global: true, args: ["--checked", "foo:script"]); - expect(pub.stderr, emitsThrough(contains("Failed assertion"))); + var pub = + await pubRun(global: true, args: ['--check-asserts', 'foo:script']); + expect(pub.stderr, emitsThrough(contains('Failed assertion'))); await pub.shouldExit(255); }); } diff --git a/test/run/errors_if_no_executable_is_given_test.dart b/test/run/errors_if_no_executable_is_given_test.dart index c7991eb3a..fb4e25be2 100644 --- a/test/run/errors_if_no_executable_is_given_test.dart +++ b/test/run/errors_if_no_executable_is_given_test.dart @@ -13,14 +13,14 @@ main() { test('Errors if the executable does not exist.', () async { await d.dir(appPath, [d.appPubspec()]).create(); - await runPub(args: ["run"], error: """ + await runPub(args: ['run'], error: ''' Must specify an executable to run. Usage: pub run [args...] --h, --help Print this usage information. --c, --[no-]checked Enable runtime type checks and assertions. +-h, --help Print this usage information. +-c, --[no-]check-asserts Enable assertions. Run "pub help" to see global options. -""", exitCode: exit_codes.USAGE); +''', exitCode: exit_codes.USAGE); }); } diff --git a/test/run/errors_if_path_in_dependency_test.dart b/test/run/errors_if_path_in_dependency_test.dart index 2037b2cb7..a9cb42c98 100644 --- a/test/run/errors_if_path_in_dependency_test.dart +++ b/test/run/errors_if_path_in_dependency_test.dart @@ -13,22 +13,22 @@ main() { test( 'Errors if the executable is in a subdirectory in a ' 'dependency.', () async { - await d.dir("foo", [d.libPubspec("foo", "1.0.0")]).create(); + await d.dir('foo', [d.libPubspec('foo', '1.0.0')]).create(); await d.dir(appPath, [ d.appPubspec({ - "foo": {"path": "../foo"} + 'foo': {'path': '../foo'} }) ]).create(); - await runPub(args: ["run", "foo:sub/dir"], error: """ + await runPub(args: ['run', 'foo:sub/dir'], error: ''' Cannot run an executable in a subdirectory of a dependency. Usage: pub run [args...] --h, --help Print this usage information. --c, --[no-]checked Enable runtime type checks and assertions. +-h, --help Print this usage information. +-c, --[no-]check-asserts Enable assertions. Run "pub help" to see global options. -""", exitCode: exit_codes.USAGE); +''', exitCode: exit_codes.USAGE); }); } diff --git a/test/run/runs_the_script_in_checked_mode_test.dart b/test/run/runs_the_script_in_checked_mode_test.dart index 228ce33f7..6811e46a3 100644 --- a/test/run/runs_the_script_in_checked_mode_test.dart +++ b/test/run/runs_the_script_in_checked_mode_test.dart @@ -8,16 +8,16 @@ import '../descriptor.dart' as d; import '../test_pub.dart'; main() { - test('runs the script in checked mode with "--checked"', () async { + test('runs the script with assertions with "--check-asserts"', () async { await d.dir(appPath, [ d.appPubspec(), - d.dir("bin", [d.file("script.dart", "main() { assert(false); }")]) + d.dir('bin', [d.file('script.dart', 'main() { assert(false); }')]) ]).create(); await pubGet(); await runPub( - args: ["run", "--checked", "bin/script"], - error: contains("Failed assertion"), + args: ['run', '--check-asserts', 'bin/script'], + error: contains('Failed assertion'), exitCode: 255); }); } diff --git a/test/run/runs_the_script_in_unchecked_mode_test.dart b/test/run/runs_the_script_in_unchecked_mode_test.dart index 9f69be27a..588a8db6a 100644 --- a/test/run/runs_the_script_in_unchecked_mode_test.dart +++ b/test/run/runs_the_script_in_unchecked_mode_test.dart @@ -7,21 +7,21 @@ import 'package:test/test.dart'; import '../descriptor.dart' as d; import '../test_pub.dart'; -const SCRIPT = """ +const SCRIPT = ''' main() { assert(false); print("no checks"); } -"""; +'''; main() { - test('runs the script in unchecked mode by default', () async { + test('runs the script without assertions by default', () async { await d.dir(appPath, [ d.appPubspec(), - d.dir("bin", [d.file("script.dart", SCRIPT)]) + d.dir('bin', [d.file('script.dart', SCRIPT)]) ]).create(); await pubGet(); - await runPub(args: ["run", "bin/script"], output: contains("no checks")); + await runPub(args: ['run', 'bin/script'], output: contains('no checks')); }); } From 40aa32cfb31015699e35b5f5ef885353441afd17 Mon Sep 17 00:00:00 2001 From: Nate Bosch Date: Tue, 7 Aug 2018 14:38:57 -0700 Subject: [PATCH 2/3] check-asserts -> enable-asserts for consistency with the VM and Dart2Js --- lib/src/command/global_run.dart | 6 +++--- lib/src/command/run.dart | 6 +++--- test/global/run/errors_if_outside_bin_test.dart | 4 ++-- test/global/run/missing_executable_arg_test.dart | 4 ++-- test/run/errors_if_no_executable_is_given_test.dart | 4 ++-- test/run/errors_if_path_in_dependency_test.dart | 4 ++-- 6 files changed, 14 insertions(+), 14 deletions(-) diff --git a/lib/src/command/global_run.dart b/lib/src/command/global_run.dart index 1ba031021..0b9dd146c 100644 --- a/lib/src/command/global_run.dart +++ b/lib/src/command/global_run.dart @@ -21,8 +21,8 @@ class GlobalRunCommand extends PubCommand { bool get allowTrailingOptions => false; GlobalRunCommand() { - argParser.addFlag('check-asserts', abbr: 'c', help: 'Enable assertions.'); - argParser.addFlag('checked', hide: true); + argParser.addFlag('enable-asserts', help: 'Enable assert statements.'); + argParser.addFlag('checked', abbr: 'c', hide: true); argParser.addOption('mode', help: 'Deprecated option', hide: true); } @@ -53,7 +53,7 @@ class GlobalRunCommand extends PubCommand { } var exitCode = await globals.runExecutable(package, executable, args, - checked: argResults['check-asserts'] || argResults['checked']); + checked: argResults['enable-asserts'] || argResults['checked']); await flushThenExit(exitCode); } } diff --git a/lib/src/command/run.dart b/lib/src/command/run.dart index d394e9199..c017a96c3 100644 --- a/lib/src/command/run.dart +++ b/lib/src/command/run.dart @@ -20,8 +20,8 @@ class RunCommand extends PubCommand { bool get allowTrailingOptions => false; RunCommand() { - argParser.addFlag('check-asserts', abbr: 'c', help: 'Enable assertions.'); - argParser.addFlag('checked', hide: true); + argParser.addFlag('enable-asserts', help: 'Enable assert statements.'); + argParser.addFlag('checked', abbr: 'c', hide: true); argParser.addOption('mode', help: 'Deprecated option', hide: true); } @@ -69,7 +69,7 @@ class RunCommand extends PubCommand { !entrypoint.packageGraph.isPackageMutable(package)); var exitCode = await runExecutable(entrypoint, package, executable, args, - checked: argResults['check-asserts'] || argResults['checked'], + checked: argResults['enable-asserts'] || argResults['checked'], snapshotPath: useSnapshot ? snapshotPath : null, recompile: entrypoint.precompileExecutables); await flushThenExit(exitCode); diff --git a/test/global/run/errors_if_outside_bin_test.dart b/test/global/run/errors_if_outside_bin_test.dart index db1c15880..43d3732e2 100644 --- a/test/global/run/errors_if_outside_bin_test.dart +++ b/test/global/run/errors_if_outside_bin_test.dart @@ -22,8 +22,8 @@ main() { Cannot run an executable in a subdirectory of a global package. Usage: pub global run : [args...] --h, --help Print this usage information. --c, --[no-]check-asserts Enable assertions. +-h, --help Print this usage information. + --[no-]enable-asserts Enable assert statements. Run "pub help" to see global options. """, exitCode: exit_codes.USAGE); diff --git a/test/global/run/missing_executable_arg_test.dart b/test/global/run/missing_executable_arg_test.dart index 32e33d4ff..614cf3fcf 100644 --- a/test/global/run/missing_executable_arg_test.dart +++ b/test/global/run/missing_executable_arg_test.dart @@ -14,8 +14,8 @@ main() { Must specify an executable to run. Usage: pub global run : [args...] - -h, --help Print this usage information. - -c, --[no-]check-asserts Enable assertions. + -h, --help Print this usage information. + --[no-]enable-asserts Enable assert statements. Run "pub help" to see global options. ''', exitCode: exit_codes.USAGE); diff --git a/test/run/errors_if_no_executable_is_given_test.dart b/test/run/errors_if_no_executable_is_given_test.dart index fb4e25be2..a33610ba0 100644 --- a/test/run/errors_if_no_executable_is_given_test.dart +++ b/test/run/errors_if_no_executable_is_given_test.dart @@ -17,8 +17,8 @@ main() { Must specify an executable to run. Usage: pub run [args...] --h, --help Print this usage information. --c, --[no-]check-asserts Enable assertions. +-h, --help Print this usage information. + --[no-]enable-asserts Enable assert statements. Run "pub help" to see global options. ''', exitCode: exit_codes.USAGE); diff --git a/test/run/errors_if_path_in_dependency_test.dart b/test/run/errors_if_path_in_dependency_test.dart index a9cb42c98..1c2b1297c 100644 --- a/test/run/errors_if_path_in_dependency_test.dart +++ b/test/run/errors_if_path_in_dependency_test.dart @@ -25,8 +25,8 @@ main() { Cannot run an executable in a subdirectory of a dependency. Usage: pub run [args...] --h, --help Print this usage information. --c, --[no-]check-asserts Enable assertions. +-h, --help Print this usage information. + --[no-]enable-asserts Enable assert statements. Run "pub help" to see global options. ''', exitCode: exit_codes.USAGE); From aa6601133cf630b0a5fce399ebf82d3b37b2df91 Mon Sep 17 00:00:00 2001 From: Nate Bosch Date: Wed, 8 Aug 2018 13:56:55 -0700 Subject: [PATCH 3/3] Fix args in tests --- test/global/run/runs_script_in_checked_mode_test.dart | 4 ++-- test/run/runs_the_script_in_checked_mode_test.dart | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/test/global/run/runs_script_in_checked_mode_test.dart b/test/global/run/runs_script_in_checked_mode_test.dart index 480de433c..b01b22806 100644 --- a/test/global/run/runs_script_in_checked_mode_test.dart +++ b/test/global/run/runs_script_in_checked_mode_test.dart @@ -8,7 +8,7 @@ import '../../descriptor.dart' as d; import '../../test_pub.dart'; main() { - test('runs a script in checked mode', () async { + test('runs a script with assertions enabled', () async { await servePackages((builder) { builder.serve('foo', '1.0.0', contents: [ d.dir('bin', [d.file('script.dart', 'main() { assert(false); }')]) @@ -18,7 +18,7 @@ main() { await runPub(args: ['global', 'activate', 'foo']); var pub = - await pubRun(global: true, args: ['--check-asserts', 'foo:script']); + await pubRun(global: true, args: ['--enable-asserts', 'foo:script']); expect(pub.stderr, emitsThrough(contains('Failed assertion'))); await pub.shouldExit(255); }); diff --git a/test/run/runs_the_script_in_checked_mode_test.dart b/test/run/runs_the_script_in_checked_mode_test.dart index 6811e46a3..68ec58fe4 100644 --- a/test/run/runs_the_script_in_checked_mode_test.dart +++ b/test/run/runs_the_script_in_checked_mode_test.dart @@ -8,7 +8,7 @@ import '../descriptor.dart' as d; import '../test_pub.dart'; main() { - test('runs the script with assertions with "--check-asserts"', () async { + test('runs the script with assertions enabled', () async { await d.dir(appPath, [ d.appPubspec(), d.dir('bin', [d.file('script.dart', 'main() { assert(false); }')]) @@ -16,7 +16,7 @@ main() { await pubGet(); await runPub( - args: ['run', '--check-asserts', 'bin/script'], + args: ['run', '--enable-asserts', 'bin/script'], error: contains('Failed assertion'), exitCode: 255); });