2019-11-27 23:04:02 +00:00
|
|
|
// Copyright 2014 The Flutter Authors. All rights reserved.
|
2019-08-15 02:00:31 +00:00
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2021-01-27 23:17:53 +00:00
|
|
|
// @dart = 2.8
|
|
|
|
|
2019-08-15 02:00:31 +00:00
|
|
|
import 'dart:async';
|
|
|
|
|
2020-06-18 17:33:17 +00:00
|
|
|
import 'package:flutter_tools/src/artifacts.dart';
|
2019-08-15 02:00:31 +00:00
|
|
|
import 'package:flutter_tools/src/base/async_guard.dart';
|
|
|
|
import 'package:flutter_tools/src/base/io.dart';
|
2020-06-18 17:33:17 +00:00
|
|
|
import 'package:flutter_tools/src/base/logger.dart';
|
2020-09-23 14:03:59 +00:00
|
|
|
import 'package:flutter_tools/src/base/platform.dart';
|
2019-10-14 22:26:14 +00:00
|
|
|
import 'package:flutter_tools/src/build_info.dart';
|
2019-08-15 02:00:31 +00:00
|
|
|
import 'package:flutter_tools/src/compile.dart';
|
|
|
|
import 'package:flutter_tools/src/convert.dart';
|
|
|
|
import 'package:mockito/mockito.dart';
|
2020-04-20 21:02:49 +00:00
|
|
|
import 'package:package_config/package_config.dart';
|
2021-02-08 17:21:46 +00:00
|
|
|
import 'package:process/process.dart';
|
2019-08-15 02:00:31 +00:00
|
|
|
|
|
|
|
import '../src/common.dart';
|
|
|
|
import '../src/context.dart';
|
|
|
|
import '../src/mocks.dart';
|
|
|
|
|
|
|
|
void main() {
|
|
|
|
ProcessManager mockProcessManager;
|
|
|
|
ResidentCompiler generator;
|
2020-10-16 17:54:19 +00:00
|
|
|
ResidentCompiler generatorWithScheme;
|
2019-08-15 02:00:31 +00:00
|
|
|
MockProcess mockFrontendServer;
|
|
|
|
MockStdIn mockFrontendServerStdIn;
|
|
|
|
MockStream mockFrontendServerStdErr;
|
|
|
|
StreamController<String> stdErrStreamController;
|
2020-06-18 17:33:17 +00:00
|
|
|
BufferLogger testLogger;
|
2019-08-15 02:00:31 +00:00
|
|
|
|
|
|
|
setUp(() {
|
2020-06-18 17:33:17 +00:00
|
|
|
testLogger = BufferLogger.test();
|
2019-08-15 02:00:31 +00:00
|
|
|
mockProcessManager = MockProcessManager();
|
|
|
|
mockFrontendServer = MockProcess();
|
|
|
|
mockFrontendServerStdIn = MockStdIn();
|
|
|
|
mockFrontendServerStdErr = MockStream();
|
2020-06-18 17:33:17 +00:00
|
|
|
generator = ResidentCompiler(
|
|
|
|
'sdkroot',
|
|
|
|
buildMode: BuildMode.debug,
|
|
|
|
logger: testLogger,
|
|
|
|
processManager: mockProcessManager,
|
|
|
|
artifacts: Artifacts.test(),
|
2020-09-23 14:03:59 +00:00
|
|
|
platform: FakePlatform(operatingSystem: 'linux'),
|
2020-06-18 17:33:17 +00:00
|
|
|
);
|
2020-10-16 17:54:19 +00:00
|
|
|
generatorWithScheme = ResidentCompiler(
|
|
|
|
'sdkroot',
|
|
|
|
buildMode: BuildMode.debug,
|
|
|
|
logger: testLogger,
|
|
|
|
processManager: mockProcessManager,
|
|
|
|
artifacts: Artifacts.test(),
|
|
|
|
platform: FakePlatform(operatingSystem: 'linux'),
|
|
|
|
fileSystemRoots: <String>[
|
|
|
|
'/foo/bar/fizz',
|
|
|
|
],
|
|
|
|
fileSystemScheme: 'scheme',
|
|
|
|
);
|
2019-08-15 02:00:31 +00:00
|
|
|
|
|
|
|
when(mockFrontendServer.stdin).thenReturn(mockFrontendServerStdIn);
|
|
|
|
when(mockFrontendServer.stderr)
|
|
|
|
.thenAnswer((Invocation invocation) => mockFrontendServerStdErr);
|
|
|
|
when(mockFrontendServer.exitCode).thenAnswer((Invocation invocation) {
|
|
|
|
return Completer<int>().future;
|
|
|
|
});
|
|
|
|
stdErrStreamController = StreamController<String>();
|
|
|
|
when(mockFrontendServerStdErr.transform<String>(any))
|
|
|
|
.thenAnswer((Invocation invocation) => stdErrStreamController.stream);
|
|
|
|
|
|
|
|
when(mockProcessManager.canRun(any)).thenReturn(true);
|
|
|
|
when(mockProcessManager.start(any)).thenAnswer(
|
|
|
|
(Invocation invocation) => Future<Process>.value(mockFrontendServer)
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2020-06-18 17:33:17 +00:00
|
|
|
testWithoutContext('incremental compile single dart compile', () async {
|
2019-08-15 02:00:31 +00:00
|
|
|
when(mockFrontendServer.stdout)
|
|
|
|
.thenAnswer((Invocation invocation) => Stream<List<int>>.fromFuture(
|
|
|
|
Future<List<int>>.value(utf8.encode(
|
|
|
|
'result abc\nline1\nline2\nabc\nabc /path/to/main.dart.dill 0'
|
|
|
|
))
|
|
|
|
));
|
|
|
|
|
|
|
|
final CompilerOutput output = await generator.recompile(
|
2020-04-20 21:02:49 +00:00
|
|
|
Uri.parse('/path/to/main.dart'),
|
2019-08-15 02:00:31 +00:00
|
|
|
null /* invalidatedFiles */,
|
|
|
|
outputPath: '/build/',
|
2020-04-20 21:02:49 +00:00
|
|
|
packageConfig: PackageConfig.empty,
|
2019-08-15 02:00:31 +00:00
|
|
|
);
|
|
|
|
expect(mockFrontendServerStdIn.getAndClear(), 'compile /path/to/main.dart\n');
|
|
|
|
verifyNoMoreInteractions(mockFrontendServerStdIn);
|
2020-06-03 19:00:03 +00:00
|
|
|
expect(testLogger.errorText, equals('line1\nline2\n'));
|
2019-08-15 02:00:31 +00:00
|
|
|
expect(output.outputFilename, equals('/path/to/main.dart.dill'));
|
|
|
|
});
|
|
|
|
|
2020-10-16 17:54:19 +00:00
|
|
|
testWithoutContext('incremental compile single dart compile with filesystem scheme', () async {
|
|
|
|
when(mockFrontendServer.stdout)
|
|
|
|
.thenAnswer((Invocation invocation) => Stream<List<int>>.fromFuture(
|
|
|
|
Future<List<int>>.value(utf8.encode(
|
|
|
|
'result abc\nline1\nline2\nabc\nabc /path/to/main.dart.dill 0'
|
|
|
|
))
|
|
|
|
));
|
|
|
|
|
|
|
|
final CompilerOutput output = await generatorWithScheme.recompile(
|
|
|
|
Uri.parse('file:///foo/bar/fizz/main.dart'),
|
|
|
|
null /* invalidatedFiles */,
|
|
|
|
outputPath: '/build/',
|
|
|
|
packageConfig: PackageConfig.empty,
|
|
|
|
);
|
|
|
|
expect(mockFrontendServerStdIn.getAndClear(), 'compile scheme:///main.dart\n');
|
|
|
|
verifyNoMoreInteractions(mockFrontendServerStdIn);
|
|
|
|
expect(testLogger.errorText, equals('line1\nline2\n'));
|
|
|
|
expect(output.outputFilename, equals('/path/to/main.dart.dill'));
|
|
|
|
});
|
|
|
|
|
2020-06-18 17:33:17 +00:00
|
|
|
testWithoutContext('incremental compile single dart compile abnormally terminates', () async {
|
2019-08-15 02:00:31 +00:00
|
|
|
when(mockFrontendServer.stdout)
|
|
|
|
.thenAnswer((Invocation invocation) => const Stream<List<int>>.empty()
|
|
|
|
);
|
|
|
|
|
|
|
|
expect(asyncGuard(() => generator.recompile(
|
2020-04-20 21:02:49 +00:00
|
|
|
Uri.parse('/path/to/main.dart'),
|
2019-08-15 02:00:31 +00:00
|
|
|
null, /* invalidatedFiles */
|
|
|
|
outputPath: '/build/',
|
2020-04-20 21:02:49 +00:00
|
|
|
packageConfig: PackageConfig.empty,
|
2020-01-27 22:36:02 +00:00
|
|
|
)), throwsToolExit());
|
2019-08-15 02:00:31 +00:00
|
|
|
});
|
|
|
|
|
2020-06-18 17:33:17 +00:00
|
|
|
testWithoutContext('incremental compile single dart compile abnormally terminates via exitCode', () async {
|
2019-08-15 02:00:31 +00:00
|
|
|
when(mockFrontendServer.exitCode)
|
|
|
|
.thenAnswer((Invocation invocation) async => 1);
|
|
|
|
when(mockFrontendServer.stdout)
|
|
|
|
.thenAnswer((Invocation invocation) => const Stream<List<int>>.empty()
|
|
|
|
);
|
|
|
|
|
|
|
|
expect(asyncGuard(() => generator.recompile(
|
2020-04-20 21:02:49 +00:00
|
|
|
Uri.parse('/path/to/main.dart'),
|
2019-08-15 02:00:31 +00:00
|
|
|
null, /* invalidatedFiles */
|
|
|
|
outputPath: '/build/',
|
2020-04-20 21:02:49 +00:00
|
|
|
packageConfig: PackageConfig.empty,
|
2020-01-27 22:36:02 +00:00
|
|
|
)), throwsToolExit());
|
2019-08-15 02:00:31 +00:00
|
|
|
});
|
|
|
|
|
2020-06-18 17:33:17 +00:00
|
|
|
testWithoutContext('incremental compile and recompile', () async {
|
2019-08-15 02:00:31 +00:00
|
|
|
final StreamController<List<int>> streamController = StreamController<List<int>>();
|
|
|
|
when(mockFrontendServer.stdout)
|
|
|
|
.thenAnswer((Invocation invocation) => streamController.stream);
|
|
|
|
streamController.add(utf8.encode('result abc\nline0\nline1\nabc\nabc /path/to/main.dart.dill 0\n'));
|
|
|
|
await generator.recompile(
|
2020-04-20 21:02:49 +00:00
|
|
|
Uri.parse('/path/to/main.dart'),
|
2019-08-15 02:00:31 +00:00
|
|
|
null, /* invalidatedFiles */
|
|
|
|
outputPath: '/build/',
|
2020-04-20 21:02:49 +00:00
|
|
|
packageConfig: PackageConfig.empty,
|
2019-08-15 02:00:31 +00:00
|
|
|
);
|
|
|
|
expect(mockFrontendServerStdIn.getAndClear(), 'compile /path/to/main.dart\n');
|
|
|
|
|
|
|
|
// No accept or reject commands should be issued until we
|
|
|
|
// send recompile request.
|
|
|
|
await _accept(streamController, generator, mockFrontendServerStdIn, '');
|
|
|
|
await _reject(streamController, generator, mockFrontendServerStdIn, '', '');
|
|
|
|
|
|
|
|
await _recompile(streamController, generator, mockFrontendServerStdIn,
|
|
|
|
'result abc\nline1\nline2\nabc\nabc /path/to/main.dart.dill 0\n');
|
|
|
|
|
2020-02-07 15:35:55 +00:00
|
|
|
await _accept(streamController, generator, mockFrontendServerStdIn, r'^accept\n$');
|
2019-08-15 02:00:31 +00:00
|
|
|
|
|
|
|
await _recompile(streamController, generator, mockFrontendServerStdIn,
|
|
|
|
'result abc\nline1\nline2\nabc\nabc /path/to/main.dart.dill 0\n');
|
|
|
|
// No sources returned from reject command.
|
|
|
|
await _reject(streamController, generator, mockFrontendServerStdIn, 'result abc\nabc\n',
|
2020-02-07 15:35:55 +00:00
|
|
|
r'^reject\n$');
|
2019-08-15 02:00:31 +00:00
|
|
|
verifyNoMoreInteractions(mockFrontendServerStdIn);
|
|
|
|
expect(mockFrontendServerStdIn.getAndClear(), isEmpty);
|
2019-11-24 05:54:43 +00:00
|
|
|
expect(testLogger.errorText, equals(
|
2020-06-03 19:00:03 +00:00
|
|
|
'line0\nline1\n'
|
|
|
|
'line1\nline2\n'
|
|
|
|
'line1\nline2\n'
|
2019-08-15 02:00:31 +00:00
|
|
|
));
|
|
|
|
});
|
|
|
|
|
2020-10-16 17:54:19 +00:00
|
|
|
testWithoutContext('incremental compile and recompile with filesystem scheme', () async {
|
|
|
|
final StreamController<List<int>> streamController = StreamController<List<int>>();
|
|
|
|
when(mockFrontendServer.stdout)
|
|
|
|
.thenAnswer((Invocation invocation) => streamController.stream);
|
|
|
|
streamController.add(utf8.encode('result abc\nline0\nline1\nabc\nabc /path/to/main.dart.dill 0\n'));
|
|
|
|
await generatorWithScheme.recompile(
|
|
|
|
Uri.parse('file:///foo/bar/fizz/main.dart'),
|
|
|
|
null, /* invalidatedFiles */
|
|
|
|
outputPath: '/build/',
|
|
|
|
packageConfig: PackageConfig.empty,
|
|
|
|
);
|
|
|
|
expect(mockFrontendServerStdIn.getAndClear(), 'compile scheme:///main.dart\n');
|
|
|
|
|
|
|
|
// No accept or reject commands should be issued until we
|
|
|
|
// send recompile request.
|
|
|
|
await _accept(streamController, generatorWithScheme, mockFrontendServerStdIn, '');
|
|
|
|
await _reject(streamController, generatorWithScheme, mockFrontendServerStdIn, '', '');
|
|
|
|
|
|
|
|
await _recompile(streamController, generatorWithScheme, mockFrontendServerStdIn,
|
|
|
|
'result abc\nline1\nline2\nabc\nabc /path/to/main.dart.dill 0\n',
|
|
|
|
mainUri: Uri.parse('file:///foo/bar/fizz/main.dart'),
|
2020-10-16 22:23:54 +00:00
|
|
|
expectedMainUri: 'scheme:///main.dart');
|
2020-10-16 17:54:19 +00:00
|
|
|
|
|
|
|
await _accept(streamController, generatorWithScheme, mockFrontendServerStdIn, r'^accept\n$');
|
|
|
|
|
|
|
|
await _recompile(streamController, generatorWithScheme, mockFrontendServerStdIn,
|
|
|
|
'result abc\nline1\nline2\nabc\nabc /path/to/main.dart.dill 0\n',
|
|
|
|
mainUri: Uri.parse('file:///foo/bar/fizz/main.dart'),
|
2020-10-16 22:23:54 +00:00
|
|
|
expectedMainUri: 'scheme:///main.dart');
|
|
|
|
// No sources returned from reject command.
|
|
|
|
await _reject(streamController, generatorWithScheme, mockFrontendServerStdIn, 'result abc\nabc\n',
|
|
|
|
r'^reject\n$');
|
|
|
|
verifyNoMoreInteractions(mockFrontendServerStdIn);
|
|
|
|
expect(mockFrontendServerStdIn.getAndClear(), isEmpty);
|
|
|
|
expect(testLogger.errorText, equals(
|
|
|
|
'line0\nline1\n'
|
|
|
|
'line1\nline2\n'
|
|
|
|
'line1\nline2\n'
|
|
|
|
));
|
|
|
|
});
|
|
|
|
|
|
|
|
testWithoutContext('incremental compile and recompile non-entrypoint file with filesystem scheme', () async {
|
|
|
|
final Uri mainUri = Uri.parse('file:///foo/bar/fizz/main.dart');
|
|
|
|
const String expectedMainUri = 'scheme:///main.dart';
|
|
|
|
final List<Uri> updatedUris = <Uri>[
|
|
|
|
mainUri,
|
|
|
|
Uri.parse('file:///foo/bar/fizz/other.dart'),
|
|
|
|
];
|
|
|
|
const List<String> expectedUpdatedUris = <String>[
|
|
|
|
expectedMainUri,
|
|
|
|
'scheme:///other.dart',
|
|
|
|
];
|
|
|
|
|
|
|
|
final StreamController<List<int>> streamController = StreamController<List<int>>();
|
|
|
|
when(mockFrontendServer.stdout)
|
|
|
|
.thenAnswer((Invocation invocation) => streamController.stream);
|
|
|
|
streamController.add(utf8.encode('result abc\nline0\nline1\nabc\nabc /path/to/main.dart.dill 0\n'));
|
|
|
|
await generatorWithScheme.recompile(
|
|
|
|
Uri.parse('file:///foo/bar/fizz/main.dart'),
|
|
|
|
null, /* invalidatedFiles */
|
|
|
|
outputPath: '/build/',
|
|
|
|
packageConfig: PackageConfig.empty,
|
|
|
|
);
|
|
|
|
expect(mockFrontendServerStdIn.getAndClear(), 'compile scheme:///main.dart\n');
|
|
|
|
|
|
|
|
// No accept or reject commands should be issued until we
|
|
|
|
// send recompile request.
|
|
|
|
await _accept(streamController, generatorWithScheme, mockFrontendServerStdIn, '');
|
|
|
|
await _reject(streamController, generatorWithScheme, mockFrontendServerStdIn, '', '');
|
|
|
|
|
|
|
|
await _recompile(streamController, generatorWithScheme, mockFrontendServerStdIn,
|
|
|
|
'result abc\nline1\nline2\nabc\nabc /path/to/main.dart.dill 0\n',
|
|
|
|
mainUri: mainUri,
|
|
|
|
expectedMainUri: expectedMainUri,
|
|
|
|
updatedUris: updatedUris,
|
|
|
|
expectedUpdatedUris: expectedUpdatedUris);
|
|
|
|
|
|
|
|
await _accept(streamController, generatorWithScheme, mockFrontendServerStdIn, r'^accept\n$');
|
|
|
|
|
|
|
|
await _recompile(streamController, generatorWithScheme, mockFrontendServerStdIn,
|
|
|
|
'result abc\nline1\nline2\nabc\nabc /path/to/main.dart.dill 0\n',
|
|
|
|
mainUri: mainUri,
|
|
|
|
expectedMainUri: expectedMainUri,
|
|
|
|
updatedUris: updatedUris,
|
|
|
|
expectedUpdatedUris: expectedUpdatedUris);
|
2020-10-16 17:54:19 +00:00
|
|
|
// No sources returned from reject command.
|
|
|
|
await _reject(streamController, generatorWithScheme, mockFrontendServerStdIn, 'result abc\nabc\n',
|
|
|
|
r'^reject\n$');
|
|
|
|
verifyNoMoreInteractions(mockFrontendServerStdIn);
|
|
|
|
expect(mockFrontendServerStdIn.getAndClear(), isEmpty);
|
|
|
|
expect(testLogger.errorText, equals(
|
|
|
|
'line0\nline1\n'
|
|
|
|
'line1\nline2\n'
|
|
|
|
'line1\nline2\n'
|
|
|
|
));
|
|
|
|
});
|
|
|
|
|
2020-06-18 17:33:17 +00:00
|
|
|
testWithoutContext('incremental compile can suppress errors', () async {
|
2020-06-03 19:00:03 +00:00
|
|
|
final StreamController<List<int>> stdoutController = StreamController<List<int>>();
|
|
|
|
when(mockFrontendServer.stdout)
|
|
|
|
.thenAnswer((Invocation invocation) => stdoutController.stream);
|
|
|
|
|
|
|
|
stdoutController.add(utf8.encode('result abc\nline0\nline1\nabc\nabc /path/to/main.dart.dill 0\n'));
|
|
|
|
|
|
|
|
await generator.recompile(
|
|
|
|
Uri.parse('/path/to/main.dart'),
|
|
|
|
<Uri>[],
|
|
|
|
outputPath: '/build/',
|
|
|
|
packageConfig: PackageConfig.empty,
|
|
|
|
);
|
|
|
|
expect(mockFrontendServerStdIn.getAndClear(), 'compile /path/to/main.dart\n');
|
|
|
|
|
|
|
|
await _recompile(stdoutController, generator, mockFrontendServerStdIn,
|
|
|
|
'result abc\nline1\nline2\nabc\nabc /path/to/main.dart.dill 0\n');
|
|
|
|
|
|
|
|
await _accept(stdoutController, generator, mockFrontendServerStdIn, r'^accept\n$');
|
|
|
|
|
|
|
|
await _recompile(stdoutController, generator, mockFrontendServerStdIn,
|
|
|
|
'result abc\nline1\nline2\nabc\nabc /path/to/main.dart.dill 0\n', suppressErrors: true);
|
|
|
|
|
|
|
|
verifyNoMoreInteractions(mockFrontendServerStdIn);
|
|
|
|
expect(mockFrontendServerStdIn.getAndClear(), isEmpty);
|
|
|
|
|
|
|
|
// Compiler message is not printed with suppressErrors: true above.
|
|
|
|
expect(testLogger.errorText, isNot(equals(
|
|
|
|
'line1\nline2\n'
|
|
|
|
)));
|
2020-06-18 17:33:17 +00:00
|
|
|
expect(testLogger.traceText, contains(
|
|
|
|
'line1\nline2\n'
|
|
|
|
));
|
2020-06-03 19:00:03 +00:00
|
|
|
});
|
|
|
|
|
2020-06-18 17:33:17 +00:00
|
|
|
testWithoutContext('incremental compile and recompile twice', () async {
|
2019-08-15 02:00:31 +00:00
|
|
|
final StreamController<List<int>> streamController = StreamController<List<int>>();
|
|
|
|
when(mockFrontendServer.stdout)
|
|
|
|
.thenAnswer((Invocation invocation) => streamController.stream);
|
|
|
|
streamController.add(utf8.encode(
|
|
|
|
'result abc\nline0\nline1\nabc\nabc /path/to/main.dart.dill 0\n'
|
|
|
|
));
|
2020-04-20 21:02:49 +00:00
|
|
|
await generator.recompile(
|
|
|
|
Uri.parse('/path/to/main.dart'),
|
|
|
|
null /* invalidatedFiles */,
|
|
|
|
outputPath: '/build/',
|
|
|
|
packageConfig: PackageConfig.empty,
|
|
|
|
);
|
2019-08-15 02:00:31 +00:00
|
|
|
expect(mockFrontendServerStdIn.getAndClear(), 'compile /path/to/main.dart\n');
|
|
|
|
|
|
|
|
await _recompile(streamController, generator, mockFrontendServerStdIn,
|
|
|
|
'result abc\nline1\nline2\nabc\nabc /path/to/main.dart.dill 0\n');
|
|
|
|
await _recompile(streamController, generator, mockFrontendServerStdIn,
|
|
|
|
'result abc\nline2\nline3\nabc\nabc /path/to/main.dart.dill 0\n');
|
|
|
|
|
|
|
|
verifyNoMoreInteractions(mockFrontendServerStdIn);
|
|
|
|
expect(mockFrontendServerStdIn.getAndClear(), isEmpty);
|
2019-11-24 05:54:43 +00:00
|
|
|
expect(testLogger.errorText, equals(
|
2020-06-03 19:00:03 +00:00
|
|
|
'line0\nline1\n'
|
|
|
|
'line1\nline2\n'
|
|
|
|
'line2\nline3\n'
|
2019-08-15 02:00:31 +00:00
|
|
|
));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<void> _recompile(
|
|
|
|
StreamController<List<int>> streamController,
|
|
|
|
ResidentCompiler generator,
|
|
|
|
MockStdIn mockFrontendServerStdIn,
|
2020-10-16 17:54:19 +00:00
|
|
|
String mockCompilerOutput, {
|
|
|
|
bool suppressErrors = false,
|
|
|
|
Uri mainUri,
|
2020-10-16 22:23:54 +00:00
|
|
|
String expectedMainUri = '/path/to/main.dart',
|
|
|
|
List<Uri> updatedUris,
|
|
|
|
List<String> expectedUpdatedUris,
|
2020-10-16 17:54:19 +00:00
|
|
|
}) async {
|
|
|
|
mainUri ??= Uri.parse('/path/to/main.dart');
|
2020-10-16 22:23:54 +00:00
|
|
|
updatedUris ??= <Uri>[mainUri];
|
|
|
|
expectedUpdatedUris ??= <String>[expectedMainUri];
|
2020-10-16 17:54:19 +00:00
|
|
|
|
2019-08-15 02:00:31 +00:00
|
|
|
// Put content into the output stream after generator.recompile gets
|
|
|
|
// going few lines below, resets completer.
|
|
|
|
scheduleMicrotask(() {
|
|
|
|
streamController.add(utf8.encode(mockCompilerOutput));
|
|
|
|
});
|
|
|
|
final CompilerOutput output = await generator.recompile(
|
2020-10-16 17:54:19 +00:00
|
|
|
mainUri,
|
2020-10-16 22:23:54 +00:00
|
|
|
updatedUris,
|
2019-08-15 02:00:31 +00:00
|
|
|
outputPath: '/build/',
|
2020-04-20 21:02:49 +00:00
|
|
|
packageConfig: PackageConfig.empty,
|
2020-06-03 19:00:03 +00:00
|
|
|
suppressErrors: suppressErrors,
|
2019-08-15 02:00:31 +00:00
|
|
|
);
|
|
|
|
expect(output.outputFilename, equals('/path/to/main.dart.dill'));
|
|
|
|
final String commands = mockFrontendServerStdIn.getAndClear();
|
2020-04-20 21:02:49 +00:00
|
|
|
final RegExp whitespace = RegExp(r'\s+');
|
|
|
|
final List<String> parts = commands.split(whitespace);
|
|
|
|
|
|
|
|
// Test that uuid matches at beginning and end.
|
2020-10-16 22:23:54 +00:00
|
|
|
expect(parts[2], equals(parts[3 + updatedUris.length]));
|
|
|
|
expect(parts[1], equals(expectedMainUri));
|
|
|
|
for (int i = 0; i < expectedUpdatedUris.length; i++) {
|
|
|
|
expect(parts[3 + i], equals(expectedUpdatedUris[i]));
|
|
|
|
}
|
2019-08-15 02:00:31 +00:00
|
|
|
mockFrontendServerStdIn.stdInWrites.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<void> _accept(
|
|
|
|
StreamController<List<int>> streamController,
|
|
|
|
ResidentCompiler generator,
|
|
|
|
MockStdIn mockFrontendServerStdIn,
|
|
|
|
String expected,
|
|
|
|
) async {
|
|
|
|
// Put content into the output stream after generator.recompile gets
|
|
|
|
// going few lines below, resets completer.
|
|
|
|
generator.accept();
|
|
|
|
final String commands = mockFrontendServerStdIn.getAndClear();
|
|
|
|
final RegExp re = RegExp(expected);
|
|
|
|
expect(commands, matches(re));
|
|
|
|
mockFrontendServerStdIn.stdInWrites.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<void> _reject(
|
|
|
|
StreamController<List<int>> streamController,
|
|
|
|
ResidentCompiler generator,
|
|
|
|
MockStdIn mockFrontendServerStdIn,
|
|
|
|
String mockCompilerOutput,
|
|
|
|
String expected,
|
|
|
|
) async {
|
|
|
|
// Put content into the output stream after generator.recompile gets
|
|
|
|
// going few lines below, resets completer.
|
|
|
|
scheduleMicrotask(() {
|
|
|
|
streamController.add(utf8.encode(mockCompilerOutput));
|
|
|
|
});
|
|
|
|
final CompilerOutput output = await generator.reject();
|
|
|
|
expect(output, isNull);
|
|
|
|
final String commands = mockFrontendServerStdIn.getAndClear();
|
|
|
|
final RegExp re = RegExp(expected);
|
|
|
|
expect(commands, matches(re));
|
|
|
|
mockFrontendServerStdIn.stdInWrites.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
class MockProcess extends Mock implements Process {}
|
|
|
|
class MockProcessManager extends Mock implements ProcessManager {}
|