Skip to content

Commit 9f00679

Browse files
authored
Rename --checked to --enable-asserts (#1964)
Keep the old flag as an alias, run with checked mode if either is set. Behavior will be weird for cases like `--checked --no-enable-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.
1 parent 3195e85 commit 9f00679

11 files changed

+65
-64
lines changed

lib/src/command/global_run.dart

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,28 +13,28 @@ import '../utils.dart';
1313

1414
/// Handles the `global run` pub command.
1515
class GlobalRunCommand extends PubCommand {
16-
String get name => "run";
16+
String get name => 'run';
1717
String get description =>
18-
"Run an executable from a globally activated package.\n"
18+
'Run an executable from a globally activated package.\n'
1919
"NOTE: We are currently optimizing this command's startup time.";
20-
String get invocation => "pub global run <package>:<executable> [args...]";
20+
String get invocation => 'pub global run <package>:<executable> [args...]';
2121
bool get allowTrailingOptions => false;
2222

2323
GlobalRunCommand() {
24-
argParser.addFlag("checked",
25-
abbr: "c", help: "Enable runtime type checks and assertions.");
26-
argParser.addOption("mode", help: "Deprecated option", hide: true);
24+
argParser.addFlag('enable-asserts', help: 'Enable assert statements.');
25+
argParser.addFlag('checked', abbr: 'c', hide: true);
26+
argParser.addOption('mode', help: 'Deprecated option', hide: true);
2727
}
2828

2929
Future run() async {
3030
if (argResults.rest.isEmpty) {
31-
usageException("Must specify an executable to run.");
31+
usageException('Must specify an executable to run.');
3232
}
3333

3434
var package;
3535
var executable = argResults.rest[0];
36-
if (executable.contains(":")) {
37-
var parts = split1(executable, ":");
36+
if (executable.contains(':')) {
37+
var parts = split1(executable, ':');
3838
package = parts[0];
3939
executable = parts[1];
4040
} else {
@@ -48,12 +48,12 @@ class GlobalRunCommand extends PubCommand {
4848
'package.');
4949
}
5050

51-
if (argResults.wasParsed("mode")) {
52-
log.warning("The --mode flag is deprecated and has no effect.");
51+
if (argResults.wasParsed('mode')) {
52+
log.warning('The --mode flag is deprecated and has no effect.');
5353
}
5454

5555
var exitCode = await globals.runExecutable(package, executable, args,
56-
checked: argResults["checked"]);
56+
checked: argResults['enable-asserts'] || argResults['checked']);
5757
await flushThenExit(exitCode);
5858
}
5959
}

lib/src/command/run.dart

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,20 @@ import '../utils.dart';
1414

1515
/// Handles the `run` pub command.
1616
class RunCommand extends PubCommand {
17-
String get name => "run";
18-
String get description => "Run an executable from a package.";
19-
String get invocation => "pub run <executable> [args...]";
17+
String get name => 'run';
18+
String get description => 'Run an executable from a package.';
19+
String get invocation => 'pub run <executable> [args...]';
2020
bool get allowTrailingOptions => false;
2121

2222
RunCommand() {
23-
argParser.addFlag("checked",
24-
abbr: "c", help: "Enable runtime type checks and assertions.");
25-
argParser.addOption("mode", help: "Deprecated option", hide: true);
23+
argParser.addFlag('enable-asserts', help: 'Enable assert statements.');
24+
argParser.addFlag('checked', abbr: 'c', hide: true);
25+
argParser.addOption('mode', help: 'Deprecated option', hide: true);
2626
}
2727

2828
Future run() async {
2929
if (argResults.rest.isEmpty) {
30-
usageException("Must specify an executable to run.");
30+
usageException('Must specify an executable to run.');
3131
}
3232

3333
var package = entrypoint.root.name;
@@ -36,31 +36,31 @@ class RunCommand extends PubCommand {
3636

3737
// A command like "foo:bar" runs the "bar" script from the "foo" package.
3838
// If there is no colon prefix, default to the root package.
39-
if (executable.contains(":")) {
40-
var components = split1(executable, ":");
39+
if (executable.contains(':')) {
40+
var components = split1(executable, ':');
4141
package = components[0];
4242
executable = components[1];
4343

4444
if (p.split(executable).length > 1) {
4545
usageException(
46-
"Cannot run an executable in a subdirectory of a dependency.");
46+
'Cannot run an executable in a subdirectory of a dependency.');
4747
}
4848
} else if (onlyIdentifierRegExp.hasMatch(executable)) {
4949
// "pub run foo" means the same thing as "pub run foo:foo" as long as
5050
// "foo" is a valid Dart identifier (and thus package name).
5151
package = executable;
5252
}
5353

54-
if (argResults.wasParsed("mode")) {
55-
log.warning("The --mode flag is deprecated and has no effect.");
54+
if (argResults.wasParsed('mode')) {
55+
log.warning('The --mode flag is deprecated and has no effect.');
5656
}
5757

5858
// The user may pass in an executable without an extension, but the file
5959
// to actually execute will always have one.
60-
if (p.extension(executable) != ".dart") executable += ".dart";
60+
if (p.extension(executable) != '.dart') executable += '.dart';
6161

6262
var snapshotPath = p.join(
63-
entrypoint.cachePath, "bin", package, "$executable.snapshot.dart2");
63+
entrypoint.cachePath, 'bin', package, '$executable.snapshot.dart2');
6464

6565
// Don't ever compile snapshots for mutable packages, since their code may
6666
// change later on.
@@ -69,7 +69,7 @@ class RunCommand extends PubCommand {
6969
!entrypoint.packageGraph.isPackageMutable(package));
7070

7171
var exitCode = await runExecutable(entrypoint, package, executable, args,
72-
checked: argResults['checked'],
72+
checked: argResults['enable-asserts'] || argResults['checked'],
7373
snapshotPath: useSnapshot ? snapshotPath : null,
7474
recompile: entrypoint.precompileExecutables);
7575
await flushThenExit(exitCode);

lib/src/executable.dart

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import 'utils.dart';
2222
///
2323
/// Arguments from [args] will be passed to the spawned Dart application.
2424
///
25-
/// If [checked] is true, the program is run in checked mode.
25+
/// If [checked] is true, the program is run with assertions enabled.
2626
///
2727
/// If [packagesFile] is passed, it's used as the package config file path for
2828
/// the executable. Otherwise, `entrypoint.packagesFile` is used.
@@ -117,7 +117,7 @@ Future<String> _executablePath(
117117
return p.absolute(fullPath);
118118
}
119119

120-
/// Like [runSnapshot], but runs [recompile] if [path] doesn't exist yet.
120+
/// Like [_runSnapshot], but runs [recompile] if [path] doesn't exist yet.
121121
///
122122
/// Returns `null` if [path] doesn't exist and isn't generated by [recompile].
123123
Future<int> _runOrCompileSnapshot(String path, Iterable<String> args,
@@ -130,7 +130,7 @@ Future<int> _runOrCompileSnapshot(String path, Iterable<String> args,
130130
if (!fileExists(path)) return null;
131131
}
132132

133-
return await runSnapshot(path, args,
133+
return await _runSnapshot(path, args,
134134
recompile: recompile, packagesFile: packagesFile, checked: checked);
135135
}
136136

@@ -141,12 +141,12 @@ Future<int> _runOrCompileSnapshot(String path, Iterable<String> args,
141141
/// expected to regenerate a snapshot at [path], after which the snapshot will
142142
/// be re-run.
143143
///
144-
/// If [checked] is set, runs the snapshot in checked mode.
144+
/// If [checked] is set, runs the snapshot with assertions enabled.
145145
///
146146
/// Returns the snapshot's exit code.
147147
///
148148
/// This doesn't do any validation of the snapshot's SDK version.
149-
Future<int> runSnapshot(String path, Iterable<String> args,
149+
Future<int> _runSnapshot(String path, Iterable<String> args,
150150
{Future<void> recompile(),
151151
String packagesFile,
152152
bool checked = false}) async {

lib/src/global_packages.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ class GlobalPackages {
373373
/// recompiled if the SDK has been upgraded since it was first compiled and
374374
/// then run. Otherwise, it will be run from source.
375375
///
376-
/// If [checked] is true, the program is run in checked mode.
376+
/// If [checked] is true, the program is run with assertions enabled.
377377
///
378378
/// Returns the exit code from the executable.
379379
Future<int> runExecutable(

test/global/run/errors_if_outside_bin_test.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ main() {
2222
Cannot run an executable in a subdirectory of a global package.
2323
2424
Usage: pub global run <package>:<executable> [args...]
25-
-h, --help Print this usage information.
26-
-c, --[no-]checked Enable runtime type checks and assertions.
25+
-h, --help Print this usage information.
26+
--[no-]enable-asserts Enable assert statements.
2727
2828
Run "pub help" to see global options.
2929
""", exitCode: exit_codes.USAGE);

test/global/run/missing_executable_arg_test.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@ import '../../test_pub.dart';
1010

1111
main() {
1212
test('fails if no executable was given', () {
13-
return runPub(args: ["global", "run"], error: """
13+
return runPub(args: ['global', 'run'], error: '''
1414
Must specify an executable to run.
1515
1616
Usage: pub global run <package>:<executable> [args...]
17-
-h, --help Print this usage information.
18-
-c, --[no-]checked Enable runtime type checks and assertions.
17+
-h, --help Print this usage information.
18+
--[no-]enable-asserts Enable assert statements.
1919
2020
Run "pub help" to see global options.
21-
""", exitCode: exit_codes.USAGE);
21+
''', exitCode: exit_codes.USAGE);
2222
});
2323
}

test/global/run/runs_script_in_checked_mode_test.dart

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,18 @@ import '../../descriptor.dart' as d;
88
import '../../test_pub.dart';
99

1010
main() {
11-
test('runs a script in checked mode', () async {
11+
test('runs a script with assertions enabled', () async {
1212
await servePackages((builder) {
13-
builder.serve("foo", "1.0.0", contents: [
14-
d.dir("bin", [d.file("script.dart", "main() { assert(false); }")])
13+
builder.serve('foo', '1.0.0', contents: [
14+
d.dir('bin', [d.file('script.dart', 'main() { assert(false); }')])
1515
]);
1616
});
1717

18-
await runPub(args: ["global", "activate", "foo"]);
18+
await runPub(args: ['global', 'activate', 'foo']);
1919

20-
var pub = await pubRun(global: true, args: ["--checked", "foo:script"]);
21-
expect(pub.stderr, emitsThrough(contains("Failed assertion")));
20+
var pub =
21+
await pubRun(global: true, args: ['--enable-asserts', 'foo:script']);
22+
expect(pub.stderr, emitsThrough(contains('Failed assertion')));
2223
await pub.shouldExit(255);
2324
});
2425
}

test/run/errors_if_no_executable_is_given_test.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@ main() {
1313
test('Errors if the executable does not exist.', () async {
1414
await d.dir(appPath, [d.appPubspec()]).create();
1515

16-
await runPub(args: ["run"], error: """
16+
await runPub(args: ['run'], error: '''
1717
Must specify an executable to run.
1818
1919
Usage: pub run <executable> [args...]
20-
-h, --help Print this usage information.
21-
-c, --[no-]checked Enable runtime type checks and assertions.
20+
-h, --help Print this usage information.
21+
--[no-]enable-asserts Enable assert statements.
2222
2323
Run "pub help" to see global options.
24-
""", exitCode: exit_codes.USAGE);
24+
''', exitCode: exit_codes.USAGE);
2525
});
2626
}

test/run/errors_if_path_in_dependency_test.dart

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,22 @@ main() {
1313
test(
1414
'Errors if the executable is in a subdirectory in a '
1515
'dependency.', () async {
16-
await d.dir("foo", [d.libPubspec("foo", "1.0.0")]).create();
16+
await d.dir('foo', [d.libPubspec('foo', '1.0.0')]).create();
1717

1818
await d.dir(appPath, [
1919
d.appPubspec({
20-
"foo": {"path": "../foo"}
20+
'foo': {'path': '../foo'}
2121
})
2222
]).create();
2323

24-
await runPub(args: ["run", "foo:sub/dir"], error: """
24+
await runPub(args: ['run', 'foo:sub/dir'], error: '''
2525
Cannot run an executable in a subdirectory of a dependency.
2626
2727
Usage: pub run <executable> [args...]
28-
-h, --help Print this usage information.
29-
-c, --[no-]checked Enable runtime type checks and assertions.
28+
-h, --help Print this usage information.
29+
--[no-]enable-asserts Enable assert statements.
3030
3131
Run "pub help" to see global options.
32-
""", exitCode: exit_codes.USAGE);
32+
''', exitCode: exit_codes.USAGE);
3333
});
3434
}

test/run/runs_the_script_in_checked_mode_test.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,16 @@ import '../descriptor.dart' as d;
88
import '../test_pub.dart';
99

1010
main() {
11-
test('runs the script in checked mode with "--checked"', () async {
11+
test('runs the script with assertions enabled', () async {
1212
await d.dir(appPath, [
1313
d.appPubspec(),
14-
d.dir("bin", [d.file("script.dart", "main() { assert(false); }")])
14+
d.dir('bin', [d.file('script.dart', 'main() { assert(false); }')])
1515
]).create();
1616

1717
await pubGet();
1818
await runPub(
19-
args: ["run", "--checked", "bin/script"],
20-
error: contains("Failed assertion"),
19+
args: ['run', '--enable-asserts', 'bin/script'],
20+
error: contains('Failed assertion'),
2121
exitCode: 255);
2222
});
2323
}

test/run/runs_the_script_in_unchecked_mode_test.dart

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,21 @@ import 'package:test/test.dart';
77
import '../descriptor.dart' as d;
88
import '../test_pub.dart';
99

10-
const SCRIPT = """
10+
const SCRIPT = '''
1111
main() {
1212
assert(false);
1313
print("no checks");
1414
}
15-
""";
15+
''';
1616

1717
main() {
18-
test('runs the script in unchecked mode by default', () async {
18+
test('runs the script without assertions by default', () async {
1919
await d.dir(appPath, [
2020
d.appPubspec(),
21-
d.dir("bin", [d.file("script.dart", SCRIPT)])
21+
d.dir('bin', [d.file('script.dart', SCRIPT)])
2222
]).create();
2323

2424
await pubGet();
25-
await runPub(args: ["run", "bin/script"], output: contains("no checks"));
25+
await runPub(args: ['run', 'bin/script'], output: contains('no checks'));
2626
});
2727
}

0 commit comments

Comments
 (0)