Skip to content

Commit

Permalink
Fix another bug in SDK override logic (#1782)
Browse files Browse the repository at this point in the history
We'd previously been disabling SDK overrides any time the minimum
constraint was a pre-release version, whether or not that version had
anything to do with the SDK. We not only disable the overrides when
the minimum constraint is a pre-release version *of the current SDK*.

Closes #1781
Closes #1780
See dart-lang/sdk#31926
See dart-lang/sdk#31940
  • Loading branch information
nex3 authored and munificent committed Jan 18, 2018
1 parent 9b21c14 commit 64c5f40
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 17 deletions.
6 changes: 5 additions & 1 deletion lib/src/pubspec.dart
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,11 @@ class Pubspec {
if (!allowPreReleaseSdk) return false;
if (!sdk.version.isPreRelease) return false;
if (sdkConstraint.includeMax) return false;
if (sdkConstraint.min != null && sdkConstraint.min.isPreRelease) {
if (sdkConstraint.min != null &&
sdkConstraint.min.isPreRelease &&
sdkConstraint.min.major == sdk.version.major &&
sdkConstraint.min.minor == sdk.version.minor &&
sdkConstraint.min.patch == sdk.version.patch) {
return false;
}
if (sdkConstraint.max == null) return false;
Expand Down
48 changes: 32 additions & 16 deletions test/version_solver_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1216,18 +1216,18 @@ void dartSdkConstraint() {
output: isNot(contains('PUB_ALLOW_PRERELEASE_SDK')));
});

test("no min pre-release constraint", () async {
test("no min pre-release constraint that matches the current SDK",
() async {
await d.dir(appPath, [
await d.pubspec({
'name': 'myapp',
'environment': {'sdk': '>=1.2.3-dev.2.0 <2.0.0'}
'environment': {'sdk': '>=1.2.3-dev.2.0 <1.2.3'}
})
]).create();

await expectResolves(
environment: {'_PUB_TEST_SDK_VERSION': '1.2.3-dev.1.0'},
error: 'Package myapp requires SDK version >=1.2.3-dev.2.0 <2.0.0 '
'but the current SDK is 1.2.3-dev.1.0.');
environment: {'_PUB_TEST_SDK_VERSION': '1.2.3-dev.3.0'},
output: isNot(contains('PUB_ALLOW_PRERELEASE_SDK')));
});

test("no build release constraints", () async {
Expand All @@ -1244,18 +1244,34 @@ void dartSdkConstraint() {
});
});

test("works generally", () async {
await d.dir(appPath, [
await d.pubspec({
'name': 'myapp',
'environment': {'sdk': '<1.2.3'}
})
]).create();
group("allows", () {
test("an exclusive max that matches the current SDK", () async {
await d.dir(appPath, [
await d.pubspec({
'name': 'myapp',
'environment': {'sdk': '<1.2.3'}
})
]).create();

await expectResolves(
environment: {'_PUB_TEST_SDK_VERSION': '1.2.3-dev.1.0'},
output: allOf(contains('PUB_ALLOW_PRERELEASE_SDK'),
contains('<=1.2.3-dev.1.0'), contains('myapp')));
await expectResolves(
environment: {'_PUB_TEST_SDK_VERSION': '1.2.3-dev.1.0'},
output: allOf(contains('PUB_ALLOW_PRERELEASE_SDK'),
contains('<=1.2.3-dev.1.0'), contains('myapp')));
});

test("a pre-release min that doesn't match the current SDK", () async {
await d.dir(appPath, [
await d.pubspec({
'name': 'myapp',
'environment': {'sdk': '>=1.0.0-dev.1.0 <1.2.3'}
})
]).create();

await expectResolves(
environment: {'_PUB_TEST_SDK_VERSION': '1.2.3-dev.1.0'},
output: allOf(contains('PUB_ALLOW_PRERELEASE_SDK'),
contains('<=1.2.3-dev.1.0'), contains('myapp')));
});
});
});
}
Expand Down

0 comments on commit 64c5f40

Please sign in to comment.