Skip to content

Commit

Permalink
[flutter_tools] add shuffle to hermetic run_tests (#105462)
Browse files Browse the repository at this point in the history
  • Loading branch information
christopherfujino committed Jun 9, 2022
1 parent 0cdb3bf commit 8bea632
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 12 deletions.
Expand Up @@ -4,12 +4,6 @@

// @dart = 2.8

// TODO(gspencergoog): Remove this tag once this test's state leaks/test
// dependencies have been fixed.
// https://github.com/flutter/flutter/issues/85160
// Fails with "flutter test --test-randomize-ordering-seed=1000"
@Tags(<String>['no-shuffle'])

import 'dart:async';

import 'package:file/file.dart';
Expand Down Expand Up @@ -405,7 +399,6 @@ void main() {
Usage: () => usage,
});


testUsingContext('passes device target platform to usage', () async {
final RunCommand command = RunCommand();
final FakeDevice mockDevice = FakeDevice(sdkNameAndVersion: 'iOS 13')
Expand All @@ -431,7 +424,7 @@ void main() {
expect(usage.commands, contains(
TestUsageCommand('run', parameters: CustomDimensions.fromMap(<String, String>{
'cd3': 'false', 'cd4': 'ios', 'cd22': 'iOS 13',
'cd23': 'debug', 'cd18': 'false', 'cd15': 'swift', 'cd31': 'false',
'cd23': 'debug', 'cd18': 'false', 'cd15': 'swift', 'cd31': 'true',
'cd56': 'false',
})
)));
Expand All @@ -441,6 +434,7 @@ void main() {
DeviceManager: () => mockDeviceManager,
FileSystem: () => fs,
ProcessManager: () => FakeProcessManager.any(),
Stdio: () => FakeStdio(),
Usage: () => usage,
});

Expand Down
44 changes: 40 additions & 4 deletions packages/flutter_tools/test/src/fakes.dart
Expand Up @@ -222,9 +222,9 @@ class MemoryStdout extends MemoryIOSink implements io.Stdout {

/// A Stdio that collects stdout and supports simulated stdin.
class FakeStdio extends Stdio {
final MemoryStdout _stdout = MemoryStdout();
final MemoryStdout _stdout = MemoryStdout()..terminalColumns = 80;
final MemoryIOSink _stderr = MemoryIOSink();
final StreamController<List<int>> _stdin = StreamController<List<int>>();
final FakeStdin _stdin = FakeStdin();

@override
MemoryStdout get stdout => _stdout;
Expand All @@ -233,16 +233,52 @@ class FakeStdio extends Stdio {
MemoryIOSink get stderr => _stderr;

@override
Stream<List<int>> get stdin => _stdin.stream;
Stream<List<int>> get stdin => _stdin;

void simulateStdin(String line) {
_stdin.add(utf8.encode('$line\n'));
_stdin.controller.add(utf8.encode('$line\n'));
}

@override
bool hasTerminal = true;

List<String> get writtenToStdout => _stdout.writes.map<String>(_stdout.encoding.decode).toList();
List<String> get writtenToStderr => _stderr.writes.map<String>(_stderr.encoding.decode).toList();
}

class FakeStdin extends Fake implements Stdin {
final StreamController<List<int>> controller = StreamController<List<int>>();

@override
bool echoMode = true;

@override
bool echoNewlineMode = true;

@override
bool lineMode = true;

@override
Stream<S> transform<S>(StreamTransformer<List<int>, S> transformer) {
return controller.stream.transform(transformer);
}

@override
StreamSubscription<List<int>> listen(
void Function(List<int> event)? onData, {
Function? onError,
void Function()? onDone,
bool? cancelOnError,
}) {
return controller.stream.listen(
onData,
onError: onError,
onDone: onDone,
cancelOnError: cancelOnError,
);
}
}

class FakePlistParser implements PlistParser {
FakePlistParser([Map<String, Object>? underlyingValues]):
_underlyingValues = underlyingValues ?? <String, Object>{};
Expand Down

0 comments on commit 8bea632

Please sign in to comment.