Skip to content

Commit

Permalink
[flutter_tools] Remove more shuffles (#107759)
Browse files Browse the repository at this point in the history
  • Loading branch information
christopherfujino authored Jul 26, 2022
1 parent 4056d3f commit b035ef1
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 53 deletions.
Original file line number Diff line number Diff line change
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=20210722"
@Tags(<String>['no-shuffle'])

import 'package:args/command_runner.dart';
import 'package:file/memory.dart';
import 'package:flutter_tools/src/base/file_system.dart';
Expand All @@ -35,6 +29,8 @@ void main() {
Cache.disableLocking();
Directory tempDir;
FakeBundleBuilder fakeBundleBuilder;
final FileSystemStyle fileSystemStyle = globals.fs.path.separator == '/' ?
FileSystemStyle.posix : FileSystemStyle.windows;

setUp(() {
tempDir = globals.fs.systemTempDirectory.createTempSync('flutter_tools_packages_test.');
Expand All @@ -46,6 +42,10 @@ void main() {
tryToDelete(tempDir);
});

MemoryFileSystem fsFactory() {
return MemoryFileSystem.test(style: fileSystemStyle);
}

Future<BuildBundleCommand> runCommandIn(String projectPath, { List<String> arguments }) async {
final BuildBundleCommand command = BuildBundleCommand(bundleBuilder: fakeBundleBuilder);
final CommandRunner<void> runner = createTestCommandRunner(command);
Expand Down Expand Up @@ -86,7 +86,7 @@ void main() {
});

testUsingContext('bundle fails to build for Windows if feature is disabled', () async {
globals.fs.file('lib/main.dart').createSync(recursive: true);
globals.fs.file(globals.fs.path.join('lib', 'main.dart')).createSync(recursive: true);
globals.fs.file('pubspec.yaml').createSync(recursive: true);
globals.fs.file('.packages').createSync(recursive: true);
final CommandRunner<void> runner = createTestCommandRunner(BuildBundleCommand(bundleBuilder: FakeBundleBuilder()));
Expand All @@ -97,13 +97,13 @@ void main() {
'--target-platform=windows-x64',
]), throwsToolExit());
}, overrides: <Type, Generator>{
FileSystem: () => MemoryFileSystem.test(),
FileSystem: fsFactory,
ProcessManager: () => FakeProcessManager.any(),
FeatureFlags: () => TestFeatureFlags(),
});

testUsingContext('bundle fails to build for Linux if feature is disabled', () async {
globals.fs.file('lib/main.dart').createSync(recursive: true);
globals.fs.file(globals.fs.path.join('lib', 'main.dart')).createSync(recursive: true);
globals.fs.file('pubspec.yaml').createSync();
globals.fs.file('.packages').createSync();
final CommandRunner<void> runner = createTestCommandRunner(BuildBundleCommand(bundleBuilder: FakeBundleBuilder()));
Expand All @@ -114,13 +114,13 @@ void main() {
'--target-platform=linux-x64',
]), throwsToolExit());
}, overrides: <Type, Generator>{
FileSystem: () => MemoryFileSystem.test(),
FileSystem: fsFactory,
ProcessManager: () => FakeProcessManager.any(),
FeatureFlags: () => TestFeatureFlags(),
});

testUsingContext('bundle fails to build for macOS if feature is disabled', () async {
globals.fs.file('lib/main.dart').createSync(recursive: true);
globals.fs.file(globals.fs.path.join('lib', 'main.dart')).createSync(recursive: true);
globals.fs.file('pubspec.yaml').createSync();
globals.fs.file('.packages').createSync();
final CommandRunner<void> runner = createTestCommandRunner(BuildBundleCommand(bundleBuilder: FakeBundleBuilder()));
Expand All @@ -131,13 +131,13 @@ void main() {
'--target-platform=darwin',
]), throwsToolExit());
}, overrides: <Type, Generator>{
FileSystem: () => MemoryFileSystem.test(),
FileSystem: fsFactory,
ProcessManager: () => FakeProcessManager.any(),
FeatureFlags: () => TestFeatureFlags(),
});

testUsingContext('bundle --tree-shake-icons fails', () async {
globals.fs.file('lib/main.dart').createSync(recursive: true);
globals.fs.file(globals.fs.path.join('lib', 'main.dart')).createSync(recursive: true);
globals.fs.file('pubspec.yaml').createSync();
globals.fs.file('.packages').createSync();
final CommandRunner<void> runner = createTestCommandRunner(BuildBundleCommand(bundleBuilder: FakeBundleBuilder()));
Expand All @@ -149,12 +149,12 @@ void main() {
'--tree-shake-icons',
]), throwsToolExit(message: 'tree-shake-icons'));
}, overrides: <Type, Generator>{
FileSystem: () => MemoryFileSystem.test(),
FileSystem: fsFactory,
ProcessManager: () => FakeProcessManager.any(),
});

testUsingContext('bundle can build for Windows if feature is enabled', () async {
globals.fs.file('lib/main.dart').createSync(recursive: true);
globals.fs.file(globals.fs.path.join('lib', 'main.dart')).createSync(recursive: true);
globals.fs.file('pubspec.yaml').createSync();
globals.fs.file('.packages').createSync();
final CommandRunner<void> runner = createTestCommandRunner(BuildBundleCommand(bundleBuilder: FakeBundleBuilder()));
Expand All @@ -165,13 +165,13 @@ void main() {
'--target-platform=windows-x64',
]);
}, overrides: <Type, Generator>{
FileSystem: () => MemoryFileSystem.test(),
FileSystem: fsFactory,
ProcessManager: () => FakeProcessManager.any(),
FeatureFlags: () => TestFeatureFlags(isWindowsEnabled: true),
});

testUsingContext('bundle can build for Linux if feature is enabled', () async {
globals.fs.file('lib/main.dart').createSync(recursive: true);
globals.fs.file(globals.fs.path.join('lib', 'main.dart')).createSync(recursive: true);
globals.fs.file('pubspec.yaml').createSync();
globals.fs.file('.packages').createSync();
final CommandRunner<void> runner = createTestCommandRunner(BuildBundleCommand(bundleBuilder: FakeBundleBuilder()));
Expand All @@ -182,13 +182,13 @@ void main() {
'--target-platform=linux-x64',
]);
}, overrides: <Type, Generator>{
FileSystem: () => MemoryFileSystem.test(),
FileSystem: fsFactory,
ProcessManager: () => FakeProcessManager.any(),
FeatureFlags: () => TestFeatureFlags(isLinuxEnabled: true),
});

testUsingContext('bundle can build for macOS if feature is enabled', () async {
globals.fs.file('lib/main.dart').createSync(recursive: true);
globals.fs.file(globals.fs.path.join('lib', 'main.dart')).createSync(recursive: true);
globals.fs.file('pubspec.yaml').createSync();
globals.fs.file('.packages').createSync();
final CommandRunner<void> runner = createTestCommandRunner(BuildBundleCommand(bundleBuilder: FakeBundleBuilder()));
Expand All @@ -199,13 +199,13 @@ void main() {
'--target-platform=darwin',
]);
}, overrides: <Type, Generator>{
FileSystem: () => MemoryFileSystem.test(),
FileSystem: fsFactory,
ProcessManager: () => FakeProcessManager.any(),
FeatureFlags: () => TestFeatureFlags(isMacOSEnabled: true),
});

testUsingContext('passes track widget creation through', () async {
globals.fs.file('lib/main.dart').createSync(recursive: true);
globals.fs.file(globals.fs.path.join('lib', 'main.dart')).createSync(recursive: true);
globals.fs.file('pubspec.yaml').createSync();
globals.fs.file('.packages').createSync();
final CommandRunner<void> runner = createTestCommandRunner(BuildBundleCommand());
Expand All @@ -230,12 +230,12 @@ void main() {
kDartObfuscation: 'false',
});
}),
FileSystem: () => MemoryFileSystem.test(),
FileSystem: fsFactory,
ProcessManager: () => FakeProcessManager.any(),
});

testUsingContext('passes dart-define through', () async {
globals.fs.file('lib/main.dart').createSync(recursive: true);
globals.fs.file(globals.fs.path.join('lib', 'main.dart')).createSync(recursive: true);
globals.fs.file('pubspec.yaml').createSync();
globals.fs.file('.packages').createSync();
final CommandRunner<void> runner = createTestCommandRunner(BuildBundleCommand());
Expand All @@ -261,12 +261,12 @@ void main() {
kDartObfuscation: 'false',
});
}),
FileSystem: () => MemoryFileSystem.test(),
FileSystem: fsFactory,
ProcessManager: () => FakeProcessManager.any(),
});

testUsingContext('passes filesystem-scheme through', () async {
globals.fs.file('lib/main.dart').createSync(recursive: true);
globals.fs.file(globals.fs.path.join('lib', 'main.dart')).createSync(recursive: true);
globals.fs.file('pubspec.yaml').createSync();
globals.fs.file('.packages').createSync();
final CommandRunner<void> runner = createTestCommandRunner(BuildBundleCommand());
Expand All @@ -291,12 +291,12 @@ void main() {
kDartObfuscation: 'false',
});
}),
FileSystem: () => MemoryFileSystem.test(),
FileSystem: fsFactory,
ProcessManager: () => FakeProcessManager.any(),
});

testUsingContext('passes filesystem-roots through', () async {
globals.fs.file('lib/main.dart').createSync(recursive: true);
globals.fs.file(globals.fs.path.join('lib', 'main.dart')).createSync(recursive: true);
globals.fs.file('pubspec.yaml').createSync();
globals.fs.file('.packages').createSync();
final CommandRunner<void> runner = createTestCommandRunner(BuildBundleCommand());
Expand All @@ -322,12 +322,12 @@ void main() {
kDartObfuscation: 'false',
});
}),
FileSystem: () => MemoryFileSystem.test(),
FileSystem: fsFactory,
ProcessManager: () => FakeProcessManager.any(),
});

testUsingContext('passes extra frontend-options through', () async {
globals.fs.file('lib/main.dart').createSync(recursive: true);
globals.fs.file(globals.fs.path.join('lib', 'main.dart')).createSync(recursive: true);
globals.fs.file('pubspec.yaml').createSync();
globals.fs.file('.packages').createSync();
final CommandRunner<void> runner = createTestCommandRunner(BuildBundleCommand());
Expand All @@ -353,12 +353,12 @@ void main() {
kDartObfuscation: 'false',
});
}),
FileSystem: () => MemoryFileSystem.test(),
FileSystem: fsFactory,
ProcessManager: () => FakeProcessManager.any(),
});

testUsingContext('passes extra gen_snapshot-options through', () async {
globals.fs.file('lib/main.dart').createSync(recursive: true);
globals.fs.file(globals.fs.path.join('lib', 'main.dart')).createSync(recursive: true);
globals.fs.file('pubspec.yaml').createSync();
globals.fs.file('.packages').createSync();
final CommandRunner<void> runner = createTestCommandRunner(BuildBundleCommand());
Expand All @@ -384,12 +384,12 @@ void main() {
kDartObfuscation: 'false',
});
}),
FileSystem: () => MemoryFileSystem.test(),
FileSystem: fsFactory,
ProcessManager: () => FakeProcessManager.any(),
});

testUsingContext('passes profile options through', () async {
globals.fs.file('lib/main.dart').createSync(recursive: true);
globals.fs.file(globals.fs.path.join('lib', 'main.dart')).createSync(recursive: true);
globals.fs.file('pubspec.yaml').createSync();
globals.fs.file('.packages').createSync();
final CommandRunner<void> runner = createTestCommandRunner(BuildBundleCommand());
Expand Down Expand Up @@ -423,12 +423,12 @@ void main() {
kDartObfuscation: 'false',
});
}),
FileSystem: () => MemoryFileSystem.test(),
FileSystem: fsFactory,
ProcessManager: () => FakeProcessManager.any(),
});

testUsingContext('passes release options through', () async {
globals.fs.file('lib/main.dart').createSync(recursive: true);
globals.fs.file(globals.fs.path.join('lib', 'main.dart')).createSync(recursive: true);
globals.fs.file('pubspec.yaml').createSync();
globals.fs.file('.packages').createSync();
final CommandRunner<void> runner = createTestCommandRunner(BuildBundleCommand());
Expand Down Expand Up @@ -462,7 +462,7 @@ void main() {
kDartObfuscation: 'false',
});
}),
FileSystem: () => MemoryFileSystem.test(),
FileSystem: fsFactory,
ProcessManager: () => FakeProcessManager.any(),
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// 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=20210722"
@Tags(<String>['no-shuffle'])

import 'package:file/memory.dart';
import 'package:flutter_tools/src/artifacts.dart';
import 'package:flutter_tools/src/base/file_system.dart';
Expand Down Expand Up @@ -99,7 +93,11 @@ environment:
void main() {

group('Dart plugin registrant' , () {
final FileSystem fileSystem = MemoryFileSystem.test();
late FileSystem fileSystem;

setUp(() {
fileSystem = MemoryFileSystem.test();
});

testWithoutContext('skipped based on environment.generateDartPluginRegistry',
() async {
Expand All @@ -123,6 +121,7 @@ void main() {

expect(const DartPluginRegistrantTarget().canSkip(environment2), isFalse);
});

testWithoutContext('skipped based on platform', () async {
const Map<String, bool> canSkip = <String, bool>{
'darwin-x64': false,
Expand Down Expand Up @@ -334,7 +333,8 @@ void main() {
projectDir
.childDirectory('.dart_tool')
.childFile('package_config.json')
.writeAsStringSync(_kSamplePackageJson);
..createSync(recursive: true)
..writeAsStringSync(_kSamplePackageJson);

projectDir.childFile('pubspec.yaml').writeAsStringSync(_kSamplePubspecFile);

Expand All @@ -345,7 +345,8 @@ void main() {
environment.fileSystem.currentDirectory
.childDirectory('path_provider_linux')
.childFile('pubspec.yaml')
.writeAsStringSync(_kSamplePluginPubspec);
..createSync(recursive: true)
..writeAsStringSync(_kSamplePluginPubspec);

final FlutterProject testProject = FlutterProject.fromDirectoryTest(projectDir);
await DartPluginRegistrantTarget.test(testProject).build(environment);
Expand Down
15 changes: 9 additions & 6 deletions packages/flutter_tools/test/general.shard/channel_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// 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=20210723"
@Tags(<String>['no-shuffle'])

import 'package:args/command_runner.dart';
import 'package:file/memory.dart';
import 'package:flutter_tools/src/base/file_system.dart';
Expand All @@ -33,6 +27,9 @@ void main() {
});

Future<void> simpleChannelTest(List<String> args) async {
fakeProcessManager.addCommands(const <FakeCommand>[
FakeCommand(command: <String>['git', 'branch', '-r'], stdout: ' branch-1\n branch-2'),
]);
final ChannelCommand command = ChannelCommand();
final CommandRunner<void> runner = createTestCommandRunner(command);
await runner.run(args);
Expand All @@ -48,10 +45,16 @@ void main() {

testUsingContext('list', () async {
await simpleChannelTest(<String>['channel']);
}, overrides: <Type, Generator>{
ProcessManager: () => fakeProcessManager,
FileSystem: () => MemoryFileSystem.test(),
});

testUsingContext('verbose list', () async {
await simpleChannelTest(<String>['channel', '-v']);
}, overrides: <Type, Generator>{
ProcessManager: () => fakeProcessManager,
FileSystem: () => MemoryFileSystem.test(),
});

testUsingContext('sorted by stability', () async {
Expand Down
3 changes: 1 addition & 2 deletions packages/flutter_tools/test/src/context.dart
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@ void testUsingContext(
TemplateRenderer: () => const MustacheTemplateRenderer(),
},
body: () {
final String flutterRoot = getFlutterRoot();
return runZonedGuarded<Future<dynamic>>(() {
try {
return context.run<dynamic>(
Expand All @@ -134,7 +133,7 @@ void testUsingContext(
if (initializeFlutterRoot) {
// Provide a sane default for the flutterRoot directory. Individual
// tests can override this either in the test or during setup.
Cache.flutterRoot ??= flutterRoot;
Cache.flutterRoot ??= getFlutterRoot();
}
return await testMethod();
},
Expand Down

0 comments on commit b035ef1

Please sign in to comment.