`pub run` Don't write about precompilation if no terminal is attached (#2531)
diff --git a/lib/src/command/run.dart b/lib/src/command/run.dart
index 931e8ec..8abfe67 100644
--- a/lib/src/command/run.dart
+++ b/lib/src/command/run.dart
@@ -76,10 +76,14 @@
final vmArgs = vmArgFromExperiments(experiments);
var exitCode = await runExecutable(
- entrypoint, Executable.adaptProgramName(package, executable), args,
- enableAsserts: argResults['enable-asserts'] || argResults['checked'],
- recompile: entrypoint.precompileExecutable,
- vmArgs: vmArgs);
+ entrypoint,
+ Executable.adaptProgramName(package, executable),
+ args,
+ enableAsserts: argResults['enable-asserts'] || argResults['checked'],
+ recompile: (executable) => log.warningsOnlyUnlessTerminal(
+ () => entrypoint.precompileExecutable(executable)),
+ vmArgs: vmArgs,
+ );
await flushThenExit(exitCode);
}
diff --git a/test/run/precompile_test.dart b/test/run/precompile_test.dart
index 9c50b5c..9fad74e 100644
--- a/test/run/precompile_test.dart
+++ b/test/run/precompile_test.dart
@@ -16,22 +16,39 @@
''';
void main() {
- test('`pub run` precompiles script', () async {
+ Future<void> setupForPubRunToPrecompile() async {
await d.dir(appPath, [
d.appPubspec({'test': '1.0.0'}),
]).create();
await servePackages((server) => server
..serve('test', '1.0.0', contents: [
- d.dir('bin', [d.file('test.dart', SCRIPT)])
+ d.dir('bin',
+ [d.file('test.dart', 'main(List<String> args) => print("hello");')])
]));
await pubGet(args: ['--no-precompile']);
+ }
+ test('`pub run` precompiles script', () async {
+ await setupForPubRunToPrecompile();
var pub = await pubRun(args: ['test']);
await pub.shouldExit(0);
final lines = await pub.stdout.rest.toList();
expect(lines, contains('Precompiling executable...'));
+ expect(lines, contains('hello'));
+ });
+
+ test(
+ "`pub run` doesn't write about precompilation when a terminal is not attached",
+ () async {
+ await setupForPubRunToPrecompile();
+
+ var pub = await pubRun(args: ['test'], verbose: false);
+ await pub.shouldExit(0);
+ final lines = await pub.stdout.rest.toList();
+ expect(lines, isNot(contains('Precompiling executable...')));
+ expect(lines, contains('hello'));
});
// Regression test of https://github.com/dart-lang/pub/issues/2483
diff --git a/test/test_pub.dart b/test/test_pub.dart
index bbf77fb..3dd5407 100644
--- a/test/test_pub.dart
+++ b/test/test_pub.dart
@@ -207,10 +207,15 @@
Future<PubProcess> pubRun(
{bool global = false,
Iterable<String> args,
- Map<String, String> environment}) async {
+ Map<String, String> environment,
+ bool verbose = true}) async {
var pubArgs = global ? ['global', 'run'] : ['run'];
pubArgs.addAll(args);
- var pub = await startPub(args: pubArgs, environment: environment);
+ var pub = await startPub(
+ args: pubArgs,
+ environment: environment,
+ verbose: verbose,
+ );
// Loading sources and transformers isn't normally printed, but the pub test
// infrastructure runs pub in verbose mode, which enables this.
@@ -363,7 +368,8 @@
{Iterable<String> args,
String tokenEndpoint,
String workingDirectory,
- Map<String, String> environment}) async {
+ Map<String, String> environment,
+ bool verbose = true}) async {
args ??= [];
ensureDir(_pathInSandbox(appPath));
@@ -395,7 +401,7 @@
final dotPackagesPath = (await Isolate.packageConfig).toString();
var dartArgs = ['--packages=$dotPackagesPath'];
- dartArgs..addAll([pubPath, '--verbose'])..addAll(args);
+ dartArgs..addAll([pubPath, if (verbose) '--verbose'])..addAll(args);
return await PubProcess.start(dartBin, dartArgs,
environment: getPubTestEnvironment(tokenEndpoint)