|
| 1 | +import 'dart:convert'; |
| 2 | +import 'dart:io'; |
| 3 | + |
| 4 | +import 'package:crypto/crypto.dart'; |
| 5 | +import 'package:path/path.dart' as p; |
| 6 | +import 'package:pub/src/system_cache.dart'; |
| 7 | +import 'package:pub/src/utils.dart'; |
| 8 | +import 'package:test/test.dart'; |
| 9 | + |
| 10 | +import '../descriptor.dart' as d; |
| 11 | +import '../test_pub.dart'; |
| 12 | + |
| 13 | +void main() async { |
| 14 | + test('marks a package active on pub get and global activate', () async { |
| 15 | + final server = await servePackages(); |
| 16 | + |
| 17 | + server.serve('foo', '1.0.0'); |
| 18 | + server.serve('bar', '1.0.0'); |
| 19 | + |
| 20 | + await runPub(args: ['global', 'activate', 'foo']); |
| 21 | + |
| 22 | + // Without cached dependencies we don't register the package |
| 23 | + await d.dir('app_none', [d.appPubspec()]).create(); |
| 24 | + |
| 25 | + await d.appDir(dependencies: {'bar': '1.0.0'}).create(); |
| 26 | + |
| 27 | + await d.dir('app_hosted', [ |
| 28 | + d.appPubspec(dependencies: {'bar': '^1.0.0'}), |
| 29 | + ]).create(); |
| 30 | + |
| 31 | + await d.git('lib', [d.libPubspec('lib', '1.0.0')]).create(); |
| 32 | + |
| 33 | + await d.dir('app_git', [ |
| 34 | + d.appPubspec( |
| 35 | + dependencies: { |
| 36 | + 'lib': {'git': '../lib'}, |
| 37 | + }, |
| 38 | + ), |
| 39 | + ]).create(); |
| 40 | + |
| 41 | + await d.dir('app_path', [ |
| 42 | + d.appPubspec( |
| 43 | + dependencies: { |
| 44 | + 'lib': {'path': '../lib'}, |
| 45 | + }, |
| 46 | + ), |
| 47 | + ]).create(); |
| 48 | + |
| 49 | + await pubGet(workingDirectory: p.join(d.sandbox, 'app_none')); |
| 50 | + await pubGet(workingDirectory: p.join(d.sandbox, 'app_hosted')); |
| 51 | + await pubGet(workingDirectory: p.join(d.sandbox, 'app_git')); |
| 52 | + await pubGet(workingDirectory: p.join(d.sandbox, 'app_path')); |
| 53 | + |
| 54 | + final markingFiles = |
| 55 | + Directory( |
| 56 | + p.join(d.sandbox, cachePath, 'active_roots'), |
| 57 | + ).listSync(recursive: true).whereType<File>().toList(); |
| 58 | + |
| 59 | + expect(markingFiles, hasLength(3)); |
| 60 | + |
| 61 | + for (final file in markingFiles) { |
| 62 | + final uri = |
| 63 | + (jsonDecode(file.readAsStringSync()) as Map)['package_config'] |
| 64 | + as String; |
| 65 | + final hash = hexEncode(sha256.convert(utf8.encode(uri)).bytes); |
| 66 | + final hashFileName = |
| 67 | + '${p.basename(p.dirname(file.path))}${p.basename(file.path)}'; |
| 68 | + expect(hashFileName, hash); |
| 69 | + } |
| 70 | + |
| 71 | + expect(markingFiles, hasLength(3)); |
| 72 | + |
| 73 | + expect(SystemCache(rootDir: p.join(d.sandbox, cachePath)).activeRoots(), { |
| 74 | + p.canonicalize( |
| 75 | + p.join(d.sandbox, 'app_hosted', '.dart_tool', 'package_config.json'), |
| 76 | + ), |
| 77 | + p.canonicalize( |
| 78 | + p.join(d.sandbox, 'app_git', '.dart_tool', 'package_config.json'), |
| 79 | + ), |
| 80 | + |
| 81 | + p.canonicalize( |
| 82 | + p.join( |
| 83 | + d.sandbox, |
| 84 | + cachePath, |
| 85 | + 'global_packages', |
| 86 | + 'foo', |
| 87 | + '.dart_tool', |
| 88 | + 'package_config.json', |
| 89 | + ), |
| 90 | + ), |
| 91 | + }); |
| 92 | + }); |
| 93 | +} |
0 commit comments