forked from dart-lang/build
/
patch_build_dependencies_test.dart
106 lines (90 loc) · 2.83 KB
/
patch_build_dependencies_test.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
// Copyright (c) 2022, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'dart:io';
import 'package:build_development_tools/patch_build_dependencies.dart';
import 'package:path/path.dart' as p;
import 'package:test/test.dart';
import 'package:test_descriptor/test_descriptor.dart' as d;
void main() {
test('without previous overrides', () {
return _testTransformation(
'''
name: test
environment:
sdk: ^2.12.0
dependencies:
foo: ^1.0.0
dev_dependencies:
bar: ^1.2.3
''',
'''
name: test
environment:
sdk: ^2.12.0
dependencies:
foo: ^1.0.0
dev_dependencies:
bar: ^1.2.3
dependency_overrides: {build: {path: ${_packagePath('build')}}, build_config: {path: ${_packagePath('build_config')}}, build_daemon: {path: ${_packagePath('build_daemon')}}, build_modules: {path: ${_packagePath('build_modules')}}, build_resolvers: {path: ${_packagePath('build_resolvers')}}, build_runner: {path: ${_packagePath('build_runner')}}, build_runner_core: {path: ${_packagePath('build_runner_core')}}, build_test: {path: ${_packagePath('build_test')}}, build_vm_compilers: {path: ${_packagePath('build_vm_compilers')}}, build_web_compilers: {path: ${_packagePath('build_web_compilers')}}, scratch_space: {path: ${_packagePath('scratch_space')}}}
''',
);
});
test('with existing overrides', () {
return _testTransformation(
'''
name: test
environment:
sdk: ^2.12.0
dependencies:
foo: ^1.0.0
dev_dependencies:
bar: ^1.2.3
dependency_overrides:
unrelated: ^1.0.0
build_runner: ^1.2.3
''',
'''
name: test
environment:
sdk: ^2.12.0
dependencies:
foo: ^1.0.0
dev_dependencies:
bar: ^1.2.3
dependency_overrides:
unrelated: ^1.0.0
build_runner:
path: ${_packagePath('build_runner')}
build:
path: ${_packagePath('build')}
build_config:
path: ${_packagePath('build_config')}
build_daemon:
path: ${_packagePath('build_daemon')}
build_modules:
path: ${_packagePath('build_modules')}
build_resolvers:
path: ${_packagePath('build_resolvers')}
build_runner_core:
path: ${_packagePath('build_runner_core')}
build_test:
path: ${_packagePath('build_test')}
build_vm_compilers:
path: ${_packagePath('build_vm_compilers')}
build_web_compilers:
path: ${_packagePath('build_web_compilers')}
scratch_space:
path: ${_packagePath('scratch_space')}
''',
);
});
}
String _packagePath(String package) {
return p.join(Directory.current.path, package);
}
Future<void> _testTransformation(String old, String updated) async {
await d.dir('package', [d.file('pubspec.yaml', old)]).create();
await patchBuildDependencies(p.join(d.sandbox, 'package'));
await d.dir('package', [d.file('pubspec.yaml', updated)]).validate();
}