|
| 1 | +// Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file |
| 2 | +// for details. All rights reserved. Use of this source code is governed by a |
| 3 | +// BSD-style license that can be found in the LICENSE file. |
| 4 | + |
| 5 | +import 'package:test/test.dart'; |
| 6 | + |
| 7 | +import '../descriptor.dart' as d; |
| 8 | +import '../test_pub.dart'; |
| 9 | + |
| 10 | +const _validMain = 'main() {}'; |
| 11 | + |
| 12 | +main() { |
| 13 | + _testExecutablesOutput(output, {bool dev: true}) => () async { |
| 14 | + await pubGet(); |
| 15 | + await runPub( |
| 16 | + args: ['deps', '--executables'] |
| 17 | + ..addAll(dev ? ['--dev'] : ['--no-dev']), |
| 18 | + output: output); |
| 19 | + }; |
| 20 | + |
| 21 | + _testAllDepsOutput(output) => _testExecutablesOutput(output); |
| 22 | + _testNonDevDepsOutput(output) => _testExecutablesOutput(output, dev: false); |
| 23 | + |
| 24 | + group("lists nothing when no executables found", () { |
| 25 | + setUp(() async { |
| 26 | + await d.dir(appPath, [d.appPubspec()]).create(); |
| 27 | + }); |
| 28 | + |
| 29 | + test("all dependencies", _testAllDepsOutput('\n')); |
| 30 | + test("non-dev dependencies", _testNonDevDepsOutput('\n')); |
| 31 | + }); |
| 32 | + |
| 33 | + group("skips non-Dart executables", () { |
| 34 | + setUp(() async { |
| 35 | + await d.dir(appPath, [ |
| 36 | + d.appPubspec(), |
| 37 | + d.dir('bin', [d.file('foo.py'), d.file('bar.sh')]) |
| 38 | + ]).create(); |
| 39 | + }); |
| 40 | + |
| 41 | + test("all dependencies", _testAllDepsOutput('\n')); |
| 42 | + test("non-dev dependencies", _testNonDevDepsOutput('\n')); |
| 43 | + }); |
| 44 | + |
| 45 | + group("skips Dart executables which are not parsable", () { |
| 46 | + setUp(() async { |
| 47 | + await d.dir(appPath, [ |
| 48 | + d.appPubspec(), |
| 49 | + d.dir('bin', [d.file('foo.dart', 'main() {')]) |
| 50 | + ]).create(); |
| 51 | + }); |
| 52 | + |
| 53 | + test("all dependencies", _testAllDepsOutput('\n')); |
| 54 | + test("non-dev dependencies", _testNonDevDepsOutput('\n')); |
| 55 | + }); |
| 56 | + |
| 57 | + group("skips Dart executables without entrypoints", () { |
| 58 | + setUp(() async { |
| 59 | + await d.dir(appPath, [ |
| 60 | + d.appPubspec(), |
| 61 | + d.dir( |
| 62 | + 'bin', [d.file('foo.dart'), d.file('bar.dart', 'main(x, y, z) {}')]) |
| 63 | + ]).create(); |
| 64 | + }); |
| 65 | + |
| 66 | + test("all dependencies", _testAllDepsOutput('\n')); |
| 67 | + test("non-dev dependencies", _testNonDevDepsOutput('\n')); |
| 68 | + }); |
| 69 | + |
| 70 | + group("lists valid Dart executables with entrypoints", () { |
| 71 | + setUp(() async { |
| 72 | + await d.dir(appPath, [ |
| 73 | + d.appPubspec(), |
| 74 | + d.dir('bin', |
| 75 | + [d.file('foo.dart', _validMain), d.file('bar.dart', _validMain)]) |
| 76 | + ]).create(); |
| 77 | + }); |
| 78 | + |
| 79 | + test("all dependencies", _testAllDepsOutput('myapp: bar, foo')); |
| 80 | + test("non-dev dependencies", _testNonDevDepsOutput('myapp: bar, foo')); |
| 81 | + }); |
| 82 | + |
| 83 | + group("skips executables in sub directories", () { |
| 84 | + setUp(() async { |
| 85 | + await d.dir(appPath, [ |
| 86 | + d.appPubspec(), |
| 87 | + d.dir('bin', [ |
| 88 | + d.file('foo.dart', _validMain), |
| 89 | + d.dir('sub', [d.file('bar.dart', _validMain)]) |
| 90 | + ]) |
| 91 | + ]).create(); |
| 92 | + }); |
| 93 | + |
| 94 | + test("all dependencies", _testAllDepsOutput('myapp:foo')); |
| 95 | + test("non-dev dependencies", _testNonDevDepsOutput('myapp:foo')); |
| 96 | + }); |
| 97 | + |
| 98 | + group("lists executables from a dependency", () { |
| 99 | + setUp(() async { |
| 100 | + await d.dir('foo', [ |
| 101 | + d.libPubspec('foo', '1.0.0'), |
| 102 | + d.dir('bin', [d.file('bar.dart', _validMain)]) |
| 103 | + ]).create(); |
| 104 | + |
| 105 | + await d.dir(appPath, [ |
| 106 | + d.appPubspec({ |
| 107 | + 'foo': {'path': '../foo'} |
| 108 | + }) |
| 109 | + ]).create(); |
| 110 | + }); |
| 111 | + |
| 112 | + test("all dependencies", _testAllDepsOutput('foo:bar')); |
| 113 | + test("non-dev dependencies", _testNonDevDepsOutput('foo:bar')); |
| 114 | + }); |
| 115 | + |
| 116 | + group("lists executables only from immediate dependencies", () { |
| 117 | + setUp(() async { |
| 118 | + await d.dir(appPath, [ |
| 119 | + d.appPubspec({ |
| 120 | + 'foo': {'path': '../foo'} |
| 121 | + }) |
| 122 | + ]).create(); |
| 123 | + |
| 124 | + await d.dir('foo', [ |
| 125 | + d.libPubspec('foo', '1.0.0', deps: { |
| 126 | + 'baz': {'path': '../baz'} |
| 127 | + }), |
| 128 | + d.dir('bin', [d.file('bar.dart', _validMain)]) |
| 129 | + ]).create(); |
| 130 | + |
| 131 | + await d.dir('baz', [ |
| 132 | + d.libPubspec('baz', '1.0.0'), |
| 133 | + d.dir('bin', [d.file('qux.dart', _validMain)]) |
| 134 | + ]).create(); |
| 135 | + }); |
| 136 | + |
| 137 | + test("all dependencies", _testAllDepsOutput('foo:bar')); |
| 138 | + test("non-dev dependencies", _testNonDevDepsOutput('foo:bar')); |
| 139 | + }); |
| 140 | + |
| 141 | + group("applies formatting before printing executables", () { |
| 142 | + setUp(() async { |
| 143 | + await d.dir(appPath, [ |
| 144 | + d.appPubspec({ |
| 145 | + 'foo': {'path': '../foo'}, |
| 146 | + 'bar': {'path': '../bar'} |
| 147 | + }), |
| 148 | + d.dir('bin', [d.file('myapp.dart', _validMain)]) |
| 149 | + ]).create(); |
| 150 | + |
| 151 | + await d.dir('foo', [ |
| 152 | + d.libPubspec('foo', '1.0.0'), |
| 153 | + d.dir('bin', |
| 154 | + [d.file('baz.dart', _validMain), d.file('foo.dart', _validMain)]) |
| 155 | + ]).create(); |
| 156 | + |
| 157 | + await d.dir('bar', [ |
| 158 | + d.libPubspec('bar', '1.0.0'), |
| 159 | + d.dir('bin', [d.file('qux.dart', _validMain)]) |
| 160 | + ]).create(); |
| 161 | + }); |
| 162 | + |
| 163 | + test("all dependencies", _testAllDepsOutput(''' |
| 164 | + myapp |
| 165 | + bar:qux |
| 166 | + foo: foo, baz''')); |
| 167 | + test("non-dev dependencies", _testNonDevDepsOutput(''' |
| 168 | + myapp |
| 169 | + bar:qux |
| 170 | + foo: foo, baz''')); |
| 171 | + }); |
| 172 | + |
| 173 | + group("dev dependencies", () { |
| 174 | + setUp(() async { |
| 175 | + await d.dir('foo', [ |
| 176 | + d.libPubspec('foo', '1.0.0'), |
| 177 | + d.dir('bin', [d.file('bar.dart', _validMain)]) |
| 178 | + ]).create(); |
| 179 | + |
| 180 | + await d.dir(appPath, [ |
| 181 | + d.pubspec({ |
| 182 | + 'name': 'myapp', |
| 183 | + 'dev_dependencies': { |
| 184 | + 'foo': {'path': '../foo'} |
| 185 | + } |
| 186 | + }) |
| 187 | + ]).create(); |
| 188 | + }); |
| 189 | + |
| 190 | + test("are listed if --dev flag is set", _testAllDepsOutput('foo:bar')); |
| 191 | + test("are skipped if --no-dev flag is set", _testNonDevDepsOutput('\n')); |
| 192 | + }); |
| 193 | + |
| 194 | + group("overriden dependencies executables", () { |
| 195 | + setUp(() async { |
| 196 | + await d.dir('foo-1.0', [ |
| 197 | + d.libPubspec('foo', '1.0.0'), |
| 198 | + d.dir('bin', [d.file('bar.dart', _validMain)]) |
| 199 | + ]).create(); |
| 200 | + |
| 201 | + await d.dir('foo-2.0', [ |
| 202 | + d.libPubspec('foo', '2.0.0'), |
| 203 | + d.dir('bin', |
| 204 | + [d.file('bar.dart', _validMain), d.file('baz.dart', _validMain)]) |
| 205 | + ]).create(); |
| 206 | + |
| 207 | + await d.dir(appPath, [ |
| 208 | + d.pubspec({ |
| 209 | + 'name': 'myapp', |
| 210 | + 'dependencies': { |
| 211 | + 'foo': {'path': '../foo-1.0'} |
| 212 | + }, |
| 213 | + 'dependency_overrides': { |
| 214 | + 'foo': {'path': '../foo-2.0'} |
| 215 | + } |
| 216 | + }) |
| 217 | + ]).create(); |
| 218 | + }); |
| 219 | + |
| 220 | + test( |
| 221 | + 'are listed if --dev flag is set', _testAllDepsOutput('foo: bar, baz')); |
| 222 | + test('are listed if --no-dev flag is set', |
| 223 | + _testNonDevDepsOutput('foo: bar, baz')); |
| 224 | + }); |
| 225 | +} |
0 commit comments