Remove mocks from compile_expression_test (#78092)
This commit is contained in:
@@ -71,7 +71,7 @@ void main() {
|
||||
@required CompleterIOSink stdinSink,
|
||||
}) {
|
||||
assert(stdinSink != null);
|
||||
stdinSink.writes.clear();
|
||||
stdinSink.clear();
|
||||
when(fontSubsetProcess.exitCode).thenAnswer((_) async => exitCode);
|
||||
when(fontSubsetProcess.stdout).thenAnswer((_) => Stream<List<int>>.fromIterable(<List<int>>[utf8.encode(stdout)]));
|
||||
when(fontSubsetProcess.stderr).thenAnswer((_) => Stream<List<int>>.fromIterable(<List<int>>[utf8.encode(stderr)]));
|
||||
@@ -257,7 +257,7 @@ void main() {
|
||||
outputPath: outputPath,
|
||||
relativePath: relativePath,
|
||||
);
|
||||
expect(stdinSink.writes, <List<int>>[utf8.encode('59470\n')]);
|
||||
expect(stdinSink.getAndClear(), '59470\n');
|
||||
_resetFontSubsetInvocation(stdinSink: stdinSink);
|
||||
|
||||
expect(subsetted, true);
|
||||
@@ -267,7 +267,7 @@ void main() {
|
||||
relativePath: relativePath,
|
||||
);
|
||||
expect(subsetted, true);
|
||||
expect(stdinSink.writes, <List<int>>[utf8.encode('59470\n')]);
|
||||
expect(stdinSink.getAndClear(), '59470\n');
|
||||
|
||||
verify(mockProcessManager.run(_getConstFinderArgs(appDill.path))).called(1);
|
||||
verify(mockProcessManager.start(fontSubsetArgs)).called(2);
|
||||
|
||||
@@ -21,14 +21,13 @@ import 'package:process/process.dart';
|
||||
|
||||
import '../src/common.dart';
|
||||
import '../src/context.dart';
|
||||
import '../src/mocks.dart';
|
||||
import '../src/fakes.dart';
|
||||
|
||||
void main() {
|
||||
ProcessManager mockProcessManager;
|
||||
ResidentCompiler generator;
|
||||
MockProcess mockFrontendServer;
|
||||
MockStdIn mockFrontendServerStdIn;
|
||||
MockStream mockFrontendServerStdErr;
|
||||
MemoryIOSink frontendServerStdIn;
|
||||
StreamController<String> stdErrStreamController;
|
||||
BufferLogger testLogger;
|
||||
MemoryFileSystem fileSystem;
|
||||
@@ -37,8 +36,7 @@ void main() {
|
||||
testLogger = BufferLogger.test();
|
||||
mockProcessManager = MockProcessManager();
|
||||
mockFrontendServer = MockProcess();
|
||||
mockFrontendServerStdIn = MockStdIn();
|
||||
mockFrontendServerStdErr = MockStream();
|
||||
frontendServerStdIn = MemoryIOSink();
|
||||
fileSystem = MemoryFileSystem.test();
|
||||
generator = ResidentCompiler(
|
||||
'sdkroot',
|
||||
@@ -50,15 +48,13 @@ void main() {
|
||||
fileSystem: fileSystem,
|
||||
);
|
||||
|
||||
when(mockFrontendServer.stdin).thenReturn(mockFrontendServerStdIn);
|
||||
stdErrStreamController = StreamController<String>();
|
||||
when(mockFrontendServer.stdin).thenReturn(frontendServerStdIn);
|
||||
when(mockFrontendServer.stderr)
|
||||
.thenAnswer((Invocation invocation) => mockFrontendServerStdErr);
|
||||
.thenAnswer((Invocation invocation) => stdErrStreamController.stream.transform(utf8.encoder));
|
||||
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(
|
||||
@@ -100,9 +96,8 @@ void main() {
|
||||
outputPath: '/build/',
|
||||
packageConfig: PackageConfig.empty,
|
||||
).then((CompilerOutput output) {
|
||||
expect(mockFrontendServerStdIn.getAndClear(),
|
||||
expect(frontendServerStdIn.getAndClear(),
|
||||
'compile file:///path/to/main.dart\n');
|
||||
verifyNoMoreInteractions(mockFrontendServerStdIn);
|
||||
expect(testLogger.errorText,
|
||||
equals('line1\nline2\n'));
|
||||
expect(output.outputFilename, equals('/path/to/main.dart.dill'));
|
||||
|
||||
@@ -48,7 +48,7 @@ void main() {
|
||||
process.sendCommand(imageFile, goldenKey, false);
|
||||
|
||||
final Map<String, dynamic> response = await process.getResponse();
|
||||
final String stringToStdin = stringFromMemoryIOSink(ioSink);
|
||||
final String stringToStdin = ioSink.getAndClear();
|
||||
|
||||
expect(response, expectedResponse);
|
||||
expect(stringToStdin, '{"imageFile":"test_image_file","key":"file://golden_key/","update":false}\n');
|
||||
@@ -75,7 +75,7 @@ void main() {
|
||||
process.sendCommand(imageFile2, goldenKey2, true);
|
||||
|
||||
final Map<String, dynamic> response2 = await process.getResponse();
|
||||
final String stringToStdin = stringFromMemoryIOSink(ioSink);
|
||||
final String stringToStdin = ioSink.getAndClear();
|
||||
|
||||
expect(response1, expectedResponse1);
|
||||
expect(response2, expectedResponse2);
|
||||
@@ -101,7 +101,7 @@ Other JSON data after the initial data
|
||||
process.sendCommand(imageFile, goldenKey, false);
|
||||
|
||||
final Map<String, dynamic> response = await process.getResponse();
|
||||
final String stringToStdin = stringFromMemoryIOSink(ioSink);
|
||||
final String stringToStdin = ioSink.getAndClear();
|
||||
|
||||
expect(response, expectedResponse);
|
||||
expect(stringToStdin, '{"imageFile":"test_image_file","key":"file://golden_key/","update":false}\n');
|
||||
@@ -112,5 +112,3 @@ Other JSON data after the initial data
|
||||
Stream<List<int>> stdoutFromString(String string) => Stream<List<int>>.fromIterable(<List<int>>[
|
||||
utf8.encode(string),
|
||||
]);
|
||||
|
||||
String stringFromMemoryIOSink(MemoryIOSink ioSink) => utf8.decode(ioSink.writes.expand((List<int> l) => l).toList());
|
||||
|
||||
@@ -252,6 +252,16 @@ class MemoryIOSink implements IOSink {
|
||||
|
||||
@override
|
||||
Future<void> flush() async { }
|
||||
|
||||
void clear() {
|
||||
writes.clear();
|
||||
}
|
||||
|
||||
String getAndClear() {
|
||||
final String result = utf8.decode(writes.expand((List<int> l) => l).toList());
|
||||
clear();
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
class MemoryStdout extends MemoryIOSink implements io.Stdout {
|
||||
|
||||
Reference in New Issue
Block a user