| // Copyright (c) 2014, 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. | |
| @TestOn('vm') | |
| library; | |
| import 'package:pub/src/validator.dart'; | |
| import 'package:pub/src/validator/sdk_constraint.dart'; | |
| import 'package:test/test.dart'; | |
| import '../descriptor.dart' as d; | |
| import '../test_pub.dart'; | |
| import 'utils.dart'; | |
| Validator sdkConstraint() => SdkConstraintValidator(); | |
| void main() { | |
| group('should consider a package valid if it', () { | |
| test('has no SDK constraint', () async { | |
| await d.validPackage().create(); | |
| await expectValidationDeprecated(sdkConstraint); | |
| }); | |
| test('has an SDK constraint without ^', () async { | |
| await d.dir(appPath, [ | |
| d.libPubspec('test_pkg', '1.0.0', sdk: '>=1.8.0 <2.0.0'), | |
| ]).create(); | |
| await expectValidationDeprecated(sdkConstraint); | |
| }); | |
| test('has an SDK constraint with ^', () async { | |
| await d.dir(appPath, [ | |
| d.libPubspec('test_pkg', '1.0.0', sdk: '^1.8.0'), | |
| ]).create(); | |
| await expectValidationDeprecated(sdkConstraint); | |
| }); | |
| test('depends on a pre-release Dart SDK from a pre-release', () async { | |
| await d.dir(appPath, [ | |
| d.libPubspec('test_pkg', '1.0.0-dev.1', sdk: '>=1.8.0-dev.1 <2.0.0'), | |
| ]).create(); | |
| await expectValidationDeprecated(sdkConstraint); | |
| }); | |
| test('has a Flutter SDK constraint with an appropriate Dart SDK ' | |
| 'constraint', () async { | |
| await d.dir(appPath, [ | |
| d.pubspec({ | |
| 'name': 'test_pkg', | |
| 'version': '1.0.0', | |
| 'environment': {'sdk': '>=1.19.0 <2.0.0', 'flutter': '^1.2.3'}, | |
| }), | |
| ]).create(); | |
| await expectValidationDeprecated(sdkConstraint); | |
| }); | |
| test('has a Fuchsia SDK constraint with an appropriate Dart SDK ' | |
| 'constraint', () async { | |
| await d.dir(appPath, [ | |
| d.pubspec({ | |
| 'name': 'test_pkg', | |
| 'version': '1.0.0-dev.1', | |
| 'environment': { | |
| 'sdk': '>=2.0.0-dev.51.0 <2.0.0', | |
| 'fuchsia': '^1.2.3', | |
| }, | |
| }), | |
| ]).create(); | |
| await expectValidationDeprecated(sdkConstraint); | |
| }); | |
| }); | |
| group('should consider a package invalid if it', () { | |
| test('has no upper bound SDK constraint', () async { | |
| await d.dir(appPath, [ | |
| d.libPubspec('test_pkg', '1.0.0', sdk: '>=1.8.0'), | |
| ]).create(); | |
| await expectValidationDeprecated( | |
| sdkConstraint, | |
| errors: anyElement(contains('should have an upper bound constraint')), | |
| ); | |
| }); | |
| test('has no SDK constraint', () async { | |
| await d.dir(appPath, [ | |
| d.rawPubspec({'name': 'test_pkg', 'version': '1.0.0'}), | |
| ]).create(); | |
| await expectValidationDeprecated( | |
| sdkConstraint, | |
| errors: anyElement(contains('should have an upper bound constraint')), | |
| ); | |
| }); | |
| test('depends on a pre-release sdk from a non-pre-release', () async { | |
| await d.dir(appPath, [ | |
| d.libPubspec('test_pkg', '1.0.0', sdk: '>=1.8.0-dev.1 <2.0.0'), | |
| ]).create(); | |
| await expectValidationDeprecated( | |
| sdkConstraint, | |
| warnings: anyElement( | |
| contains('consider publishing the package as a pre-release instead'), | |
| ), | |
| ); | |
| }); | |
| test('Gives a hint if package has a <3.0.0 constraint ' | |
| 'that is interpreted as <4.0.0', () async { | |
| await d.dir(appPath, [ | |
| d.rawPubspec({ | |
| 'name': 'test_pkg', | |
| 'version': '1.0.0', | |
| 'environment': {'sdk': '^2.19.0'}, | |
| }), | |
| ]).create(); | |
| await expectValidationDeprecated( | |
| sdkConstraint, | |
| hints: anyElement(''' | |
| The declared SDK constraint is '^2.19.0', this is interpreted as '>=2.19.0 <4.0.0'. | |
| Consider updating the SDK constraint to: | |
| environment: | |
| sdk: '>=2.19.0 <4.0.0' | |
| '''), | |
| ); | |
| }); | |
| }); | |
| } |