|
| 1 | +// Copyright 2014 The Flutter Authors. All rights reserved. |
| 2 | +// Use of this source code is governed by a BSD-style license that can be |
| 3 | +// found in the LICENSE file. |
| 4 | + |
| 5 | +import 'package:file/file.dart'; |
| 6 | +import 'package:file/local.dart'; |
| 7 | +import 'package:path/path.dart' as p; |
| 8 | +import 'package:test/test.dart'; |
| 9 | + |
| 10 | +import '../bin/generate_gradle_lockfiles.dart' as bin; |
| 11 | + |
| 12 | +void main() { |
| 13 | + const FileSystem localFs = LocalFileSystem(); |
| 14 | + late Directory tmpFlutterRoot; |
| 15 | + |
| 16 | + setUp(() { |
| 17 | + tmpFlutterRoot = localFs.systemTempDirectory.createTempSync('generate_gradle_lockfiles_test.'); |
| 18 | + |
| 19 | + // Simulate a version of the top-level directory structure. |
| 20 | + // It's not critical that it is a "real" structure, as long as it includes: |
| 21 | + // - At least one top-level directory that is "engine" |
| 22 | + // - At least one top-level directory that is not "engine" |
| 23 | + // - At least one nested directory (in not "engine") that is "engine" |
| 24 | + final List<String> directoriesToCreate = <String>[ |
| 25 | + p.join('dev', 'integration_tests', 'android_test', 'android'), |
| 26 | + p.join('engine', 'src', 'flutter', 'third_party', 'some_package', 'android'), |
| 27 | + p.join('packages', 'flutter_tools', 'test', 'fixtures', 'engine', 'android'), |
| 28 | + ]; |
| 29 | + |
| 30 | + for (final String path in directoriesToCreate) { |
| 31 | + localFs.directory(p.join(tmpFlutterRoot.path, path)).createSync(recursive: true); |
| 32 | + } |
| 33 | + }); |
| 34 | + |
| 35 | + tearDown(() { |
| 36 | + tmpFlutterRoot.deleteSync(recursive: true); |
| 37 | + }); |
| 38 | + |
| 39 | + test('discoverAndroidDirectories resolves a total of 2 directories of the possible 3', () { |
| 40 | + expect(bin.discoverAndroidDirectories(tmpFlutterRoot), hasLength(2)); |
| 41 | + }); |
| 42 | + |
| 43 | + test('discoverAndroidDirectories does not traverse into the top-level "engine" directory', () { |
| 44 | + for (final Directory directory in bin.discoverAndroidDirectories(tmpFlutterRoot)) { |
| 45 | + if (directory.path.contains(p.join('engine', 'src', 'flutter'))) { |
| 46 | + fail('Unexpected: ${directory.path} should be excluded (top-level engine directory)'); |
| 47 | + } |
| 48 | + } |
| 49 | + }); |
| 50 | + |
| 51 | + test('discoverAndroidDirectories does traverse into a non top-level "engine" directory', () { |
| 52 | + final Iterable<String> paths = bin |
| 53 | + .discoverAndroidDirectories(tmpFlutterRoot) |
| 54 | + .map((Directory r) => r.path); |
| 55 | + expect( |
| 56 | + paths, |
| 57 | + containsAll(<Matcher>[contains(p.join('test', 'fixtures', 'engine', 'android'))]), |
| 58 | + reason: 'A directory named "engine" that is not a root directory should be traversed', |
| 59 | + ); |
| 60 | + }); |
| 61 | +} |
0 commit comments