blob: 053a616e0e4e8130ad3027090665a87f0971ea38 [file] [log] [blame]
// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:file/file.dart';
import 'package:file/memory.dart';
import 'package:flutter_tools/src/cache.dart';
import '../../src/common.dart';
const String _kFlutterRoot = '/data/flutter';
void main() {
FileSystem fs;
Directory tempDir;
setUp(() {
fs = MemoryFileSystem();
fs.directory(_kFlutterRoot).createSync(recursive: true);
Cache.flutterRoot = _kFlutterRoot;
tempDir = fs.systemTempDirectory.createTempSync('flutter_analysis_test.');
});
tearDown(() {
tryToDelete(tempDir);
});
group('analyze', () {
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>[fs.path.join(tempDir.path, 'foo')]), isFalse);
expect(inRepo(<String>[Cache.flutterRoot]), isTrue);
expect(inRepo(<String>[fs.path.join(Cache.flutterRoot, 'foo')]), isTrue);
// Relative paths
fs.currentDirectory = Cache.flutterRoot;
expect(inRepo(<String>['.']), isTrue);
expect(inRepo(<String>['foo']), isTrue);
fs.currentDirectory = tempDir.path;
expect(inRepo(<String>['.']), isFalse);
expect(inRepo(<String>['foo']), isFalse);
// Ensure no exceptions
inRepo(null);
inRepo(<String>[]);
});
});
}