Convert analyze_test to testWithoutContext (#53141)
This commit is contained in:
@@ -5,30 +5,11 @@
|
||||
import 'package:file/file.dart';
|
||||
import 'package:file/memory.dart';
|
||||
import 'package:flutter_tools/src/cache.dart';
|
||||
import 'package:flutter_tools/src/globals.dart' as globals;
|
||||
|
||||
import '../../src/common.dart';
|
||||
import '../../src/context.dart';
|
||||
|
||||
const String _kFlutterRoot = '/data/flutter';
|
||||
|
||||
/// Return true if [fileList] contains a path that resides inside the Flutter repository.
|
||||
/// If [fileList] is empty, then return true if the current directory resides inside the Flutter repository.
|
||||
bool inRepo(List<String> fileList) {
|
||||
if (fileList == null || fileList.isEmpty) {
|
||||
fileList = <String>[globals.fs.path.current];
|
||||
}
|
||||
final String root = globals.fs.path.normalize(globals.fs.path.absolute(Cache.flutterRoot));
|
||||
final String prefix = root + globals.fs.path.separator;
|
||||
for (String file in fileList) {
|
||||
file = globals.fs.path.normalize(globals.fs.path.absolute(file));
|
||||
if (file == root || file.startsWith(prefix)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void main() {
|
||||
FileSystem fs;
|
||||
Directory tempDir;
|
||||
@@ -45,27 +26,39 @@ void main() {
|
||||
});
|
||||
|
||||
group('analyze', () {
|
||||
testUsingContext('inRepo', () {
|
||||
testWithoutContext('inRepo', () {
|
||||
bool inRepo(List<String> fileList) {
|
||||
if (fileList == null || fileList.isEmpty) {
|
||||
fileList = <String>[fs.path.current];
|
||||
}
|
||||
final String root = fs.path.normalize(fs.path.absolute(Cache.flutterRoot));
|
||||
final String prefix = root + fs.path.separator;
|
||||
for (String file in fileList) {
|
||||
file = fs.path.normalize(fs.path.absolute(file));
|
||||
if (file == root || file.startsWith(prefix)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// Absolute paths
|
||||
expect(inRepo(<String>[tempDir.path]), isFalse);
|
||||
expect(inRepo(<String>[globals.fs.path.join(tempDir.path, 'foo')]), isFalse);
|
||||
expect(inRepo(<String>[fs.path.join(tempDir.path, 'foo')]), isFalse);
|
||||
expect(inRepo(<String>[Cache.flutterRoot]), isTrue);
|
||||
expect(inRepo(<String>[globals.fs.path.join(Cache.flutterRoot, 'foo')]), isTrue);
|
||||
expect(inRepo(<String>[fs.path.join(Cache.flutterRoot, 'foo')]), isTrue);
|
||||
|
||||
// Relative paths
|
||||
globals.fs.currentDirectory = Cache.flutterRoot;
|
||||
fs.currentDirectory = Cache.flutterRoot;
|
||||
expect(inRepo(<String>['.']), isTrue);
|
||||
expect(inRepo(<String>['foo']), isTrue);
|
||||
globals.fs.currentDirectory = tempDir.path;
|
||||
fs.currentDirectory = tempDir.path;
|
||||
expect(inRepo(<String>['.']), isFalse);
|
||||
expect(inRepo(<String>['foo']), isFalse);
|
||||
|
||||
// Ensure no exceptions
|
||||
inRepo(null);
|
||||
inRepo(<String>[]);
|
||||
}, overrides: <Type, Generator>{
|
||||
FileSystem: () => fs,
|
||||
ProcessManager: () => FakeProcessManager.any(),
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user