Unverified Commit 628ae57e authored by Jenn Magder's avatar Jenn Magder Committed by GitHub

Remove mocks from compile_expression_test (#78092)

parent 67aaaba4
...@@ -71,7 +71,7 @@ void main() { ...@@ -71,7 +71,7 @@ void main() {
@required CompleterIOSink stdinSink, @required CompleterIOSink stdinSink,
}) { }) {
assert(stdinSink != null); assert(stdinSink != null);
stdinSink.writes.clear(); stdinSink.clear();
when(fontSubsetProcess.exitCode).thenAnswer((_) async => exitCode); when(fontSubsetProcess.exitCode).thenAnswer((_) async => exitCode);
when(fontSubsetProcess.stdout).thenAnswer((_) => Stream<List<int>>.fromIterable(<List<int>>[utf8.encode(stdout)])); 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)])); when(fontSubsetProcess.stderr).thenAnswer((_) => Stream<List<int>>.fromIterable(<List<int>>[utf8.encode(stderr)]));
...@@ -257,7 +257,7 @@ void main() { ...@@ -257,7 +257,7 @@ void main() {
outputPath: outputPath, outputPath: outputPath,
relativePath: relativePath, relativePath: relativePath,
); );
expect(stdinSink.writes, <List<int>>[utf8.encode('59470\n')]); expect(stdinSink.getAndClear(), '59470\n');
_resetFontSubsetInvocation(stdinSink: stdinSink); _resetFontSubsetInvocation(stdinSink: stdinSink);
expect(subsetted, true); expect(subsetted, true);
...@@ -267,7 +267,7 @@ void main() { ...@@ -267,7 +267,7 @@ void main() {
relativePath: relativePath, relativePath: relativePath,
); );
expect(subsetted, true); 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.run(_getConstFinderArgs(appDill.path))).called(1);
verify(mockProcessManager.start(fontSubsetArgs)).called(2); verify(mockProcessManager.start(fontSubsetArgs)).called(2);
......
...@@ -21,14 +21,13 @@ import 'package:process/process.dart'; ...@@ -21,14 +21,13 @@ import 'package:process/process.dart';
import '../src/common.dart'; import '../src/common.dart';
import '../src/context.dart'; import '../src/context.dart';
import '../src/mocks.dart'; import '../src/fakes.dart';
void main() { void main() {
ProcessManager mockProcessManager; ProcessManager mockProcessManager;
ResidentCompiler generator; ResidentCompiler generator;
MockProcess mockFrontendServer; MockProcess mockFrontendServer;
MockStdIn mockFrontendServerStdIn; MemoryIOSink frontendServerStdIn;
MockStream mockFrontendServerStdErr;
StreamController<String> stdErrStreamController; StreamController<String> stdErrStreamController;
BufferLogger testLogger; BufferLogger testLogger;
MemoryFileSystem fileSystem; MemoryFileSystem fileSystem;
...@@ -37,8 +36,7 @@ void main() { ...@@ -37,8 +36,7 @@ void main() {
testLogger = BufferLogger.test(); testLogger = BufferLogger.test();
mockProcessManager = MockProcessManager(); mockProcessManager = MockProcessManager();
mockFrontendServer = MockProcess(); mockFrontendServer = MockProcess();
mockFrontendServerStdIn = MockStdIn(); frontendServerStdIn = MemoryIOSink();
mockFrontendServerStdErr = MockStream();
fileSystem = MemoryFileSystem.test(); fileSystem = MemoryFileSystem.test();
generator = ResidentCompiler( generator = ResidentCompiler(
'sdkroot', 'sdkroot',
...@@ -50,15 +48,13 @@ void main() { ...@@ -50,15 +48,13 @@ void main() {
fileSystem: fileSystem, fileSystem: fileSystem,
); );
when(mockFrontendServer.stdin).thenReturn(mockFrontendServerStdIn); stdErrStreamController = StreamController<String>();
when(mockFrontendServer.stdin).thenReturn(frontendServerStdIn);
when(mockFrontendServer.stderr) when(mockFrontendServer.stderr)
.thenAnswer((Invocation invocation) => mockFrontendServerStdErr); .thenAnswer((Invocation invocation) => stdErrStreamController.stream.transform(utf8.encoder));
when(mockFrontendServer.exitCode).thenAnswer((Invocation invocation) { when(mockFrontendServer.exitCode).thenAnswer((Invocation invocation) {
return Completer<int>().future; 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.canRun(any)).thenReturn(true);
when(mockProcessManager.start(any)).thenAnswer( when(mockProcessManager.start(any)).thenAnswer(
...@@ -100,9 +96,8 @@ void main() { ...@@ -100,9 +96,8 @@ void main() {
outputPath: '/build/', outputPath: '/build/',
packageConfig: PackageConfig.empty, packageConfig: PackageConfig.empty,
).then((CompilerOutput output) { ).then((CompilerOutput output) {
expect(mockFrontendServerStdIn.getAndClear(), expect(frontendServerStdIn.getAndClear(),
'compile file:///path/to/main.dart\n'); 'compile file:///path/to/main.dart\n');
verifyNoMoreInteractions(mockFrontendServerStdIn);
expect(testLogger.errorText, expect(testLogger.errorText,
equals('line1\nline2\n')); equals('line1\nline2\n'));
expect(output.outputFilename, equals('/path/to/main.dart.dill')); expect(output.outputFilename, equals('/path/to/main.dart.dill'));
......
...@@ -48,7 +48,7 @@ void main() { ...@@ -48,7 +48,7 @@ void main() {
process.sendCommand(imageFile, goldenKey, false); process.sendCommand(imageFile, goldenKey, false);
final Map<String, dynamic> response = await process.getResponse(); final Map<String, dynamic> response = await process.getResponse();
final String stringToStdin = stringFromMemoryIOSink(ioSink); final String stringToStdin = ioSink.getAndClear();
expect(response, expectedResponse); expect(response, expectedResponse);
expect(stringToStdin, '{"imageFile":"test_image_file","key":"file://golden_key/","update":false}\n'); expect(stringToStdin, '{"imageFile":"test_image_file","key":"file://golden_key/","update":false}\n');
...@@ -75,7 +75,7 @@ void main() { ...@@ -75,7 +75,7 @@ void main() {
process.sendCommand(imageFile2, goldenKey2, true); process.sendCommand(imageFile2, goldenKey2, true);
final Map<String, dynamic> response2 = await process.getResponse(); final Map<String, dynamic> response2 = await process.getResponse();
final String stringToStdin = stringFromMemoryIOSink(ioSink); final String stringToStdin = ioSink.getAndClear();
expect(response1, expectedResponse1); expect(response1, expectedResponse1);
expect(response2, expectedResponse2); expect(response2, expectedResponse2);
...@@ -101,7 +101,7 @@ Other JSON data after the initial data ...@@ -101,7 +101,7 @@ Other JSON data after the initial data
process.sendCommand(imageFile, goldenKey, false); process.sendCommand(imageFile, goldenKey, false);
final Map<String, dynamic> response = await process.getResponse(); final Map<String, dynamic> response = await process.getResponse();
final String stringToStdin = stringFromMemoryIOSink(ioSink); final String stringToStdin = ioSink.getAndClear();
expect(response, expectedResponse); expect(response, expectedResponse);
expect(stringToStdin, '{"imageFile":"test_image_file","key":"file://golden_key/","update":false}\n'); expect(stringToStdin, '{"imageFile":"test_image_file","key":"file://golden_key/","update":false}\n');
...@@ -112,5 +112,3 @@ Other JSON data after the initial data ...@@ -112,5 +112,3 @@ Other JSON data after the initial data
Stream<List<int>> stdoutFromString(String string) => Stream<List<int>>.fromIterable(<List<int>>[ Stream<List<int>> stdoutFromString(String string) => Stream<List<int>>.fromIterable(<List<int>>[
utf8.encode(string), 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 { ...@@ -252,6 +252,16 @@ class MemoryIOSink implements IOSink {
@override @override
Future<void> flush() async { } 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 { class MemoryStdout extends MemoryIOSink implements io.Stdout {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment