Tests of workspace error handling (#4195)
diff --git a/test/descriptor.dart b/test/descriptor.dart index 8a8f783..915082b 100644 --- a/test/descriptor.dart +++ b/test/descriptor.dart
@@ -111,7 +111,6 @@ String version, { Map<String, Object?>? deps, Map<String, Object?>? devDeps, - String? resolution, String? sdk, Map<String, Object?>? extras, bool resolutionWorkspace = false,
diff --git a/test/workspace_test.dart b/test/workspace_test.dart index d603f5d..79ec525 100644 --- a/test/workspace_test.dart +++ b/test/workspace_test.dart
@@ -5,6 +5,7 @@ import 'dart:io'; import 'package:path/path.dart' as p; +import 'package:pub/src/exit_codes.dart'; import 'package:test/test.dart'; import 'package:yaml/yaml.dart'; @@ -180,7 +181,9 @@ ); }); - test('reports errors in workspace pubspec.yamls correctly', () async { + test( + 'ignores the source of dependencies on root packages. (Uses the local version instead)', + () async { await dir(appPath, [ libPubspec( 'myapp', @@ -206,6 +209,98 @@ await pubGet(environment: {'_PUB_TEST_SDK_VERSION': '3.7.0'}); }); + test('reports errors in workspace pubspec.yamls correctly', () async { + await dir(appPath, [ + libPubspec( + 'myapp', + '1.2.3', + extras: { + 'workspace': ['pkgs/a'], + }, + sdk: '^3.7.0', + ), + dir('pkgs', [ + dir('a', [ + libPubspec( + 'a', + '1.1.1', + deps: { + 'foo': [1, 2, 3], + }, + resolutionWorkspace: true, + ), + ]), + ]), + ]).create(); + final s = p.separator; + await pubGet( + environment: {'_PUB_TEST_SDK_VERSION': '3.7.0'}, + error: contains( + 'Error on line 1, column 118 of pkgs${s}a${s}pubspec.yaml: A dependency specification must be a string or a mapping.', + ), + exitCode: DATA, + ); + }); + + test('reports solve failures in workspace pubspec.yamls correctly', () async { + await dir(appPath, [ + libPubspec( + 'myapp', + '1.2.3', + extras: { + 'workspace': ['pkgs/a'], + }, + sdk: '^3.7.0', + ), + dir('pkgs', [ + dir('a', [ + libPubspec( + 'a', + '1.1.1', + deps: { + 'foo': {'posted': 'https://abc'}, + }, + resolutionWorkspace: true, + ), + ]), + ]), + ]).create(); + await pubGet( + environment: {'_PUB_TEST_SDK_VERSION': '3.7.0'}, + error: contains( + 'Because every version of a depends on foo from unknown source "posted", version solving failed.', + ), + ); + }); + + test('Rejects workspace pubspecs without "resolution: workspace"', () async { + await dir(appPath, [ + libPubspec( + 'myapp', + '1.2.3', + extras: { + 'workspace': ['pkgs/a'], + }, + sdk: '^3.7.0', + ), + dir('pkgs', [ + dir('a', [ + libPubspec( + 'a', + '1.1.1', + ), + ]), + ]), + ]).create(); + final s = p.separator; + await pubGet( + environment: {'_PUB_TEST_SDK_VERSION': '3.7.0'}, + error: contains( + 'pkgs${s}a${s}pubspec.yaml is inluded in the workspace from .${s}pubspec.yaml, but does not have `resolution: workspace`.', + ), + ); + }); + test('Can resolve from any directory inside the workspace', () async { await dir(appPath, [ libPubspec(