|
| 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/memory.dart'; |
| 7 | +import 'package:flutter_tools/src/dart/package_map.dart'; |
| 8 | + |
| 9 | +import '../../src/common.dart'; |
| 10 | + |
| 11 | +void main() { |
| 12 | + group('findPackageConfigFile', () { |
| 13 | + late FileSystem fileSystem; |
| 14 | + |
| 15 | + setUp(() { |
| 16 | + fileSystem = MemoryFileSystem.test(); |
| 17 | + }); |
| 18 | + |
| 19 | + test('should find an immediate .dart_tool/package_config.json', () { |
| 20 | + fileSystem.file('.dart_tool/package_config.json').createSync(recursive: true); |
| 21 | + expect(findPackageConfigFile(fileSystem.currentDirectory), isNotNull); |
| 22 | + }); |
| 23 | + |
| 24 | + test('should find a parent .dart_tool/package_config.json', () { |
| 25 | + fileSystem.file('.dart_tool/package_config.json').createSync(recursive: true); |
| 26 | + fileSystem.currentDirectory.childDirectory('child').createSync(recursive: true); |
| 27 | + expect(findPackageConfigFile(fileSystem.currentDirectory.childDirectory('child')), isNotNull); |
| 28 | + }); |
| 29 | + |
| 30 | + test('should not find a .dart_tool/package_config.json in an existing directory', () { |
| 31 | + fileSystem.currentDirectory.childDirectory('child').createSync(recursive: true); |
| 32 | + expect(findPackageConfigFile(fileSystem.currentDirectory.childDirectory('child')), isNull); |
| 33 | + }); |
| 34 | + |
| 35 | + // Regression test: https://github.com/flutter/flutter/issues/163901. |
| 36 | + test('should not find a .dart_tool/package_config.json in a missing directory', () { |
| 37 | + expect(findPackageConfigFile(fileSystem.currentDirectory.childDirectory('missing')), isNull); |
| 38 | + }); |
| 39 | + |
| 40 | + // Regression test: https://github.com/flutter/flutter/issues/163901. |
| 41 | + test('should find a .dart_tool/package_config.json in a parent of a missing directory', () { |
| 42 | + fileSystem.file('.dart_tool/package_config.json').createSync(recursive: true); |
| 43 | + expect( |
| 44 | + findPackageConfigFile(fileSystem.currentDirectory.childDirectory('missing')), |
| 45 | + isNotNull, |
| 46 | + ); |
| 47 | + }); |
| 48 | + }); |
| 49 | +} |
0 commit comments