From e92ad5535542536f58e3fc2d488af9769627a1c2 Mon Sep 17 00:00:00 2001 From: "nweiz@google.com" <nweiz@google.com> Date: Fri, 25 Jul 2014 00:33:13 +0000 Subject: [PATCH] Produce useful error messages for empty pubspecs. BUG=20103 R=blois@google.com Review URL: https://codereview.chromium.org//417023002 git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge@38565 260f80e4-7a28-3924-810f-c04153c831b5 --- lib/src/pubspec.dart | 4 +--- test/get/path/empty_pubspec_test.dart | 30 +++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 3 deletions(-) create mode 100644 test/get/path/empty_pubspec_test.dart diff --git a/lib/src/pubspec.dart b/lib/src/pubspec.dart index 8496063a..883a77c9 100644 --- a/lib/src/pubspec.dart +++ b/lib/src/pubspec.dart @@ -273,11 +273,9 @@ class Pubspec { /// [Version.none]. factory Pubspec.parse(String contents, SourceRegistry sources, {String expectedName, Uri location}) { - if (contents.trim() == '') return new Pubspec.empty(); - var pubspecNode = loadYamlNode(contents, sourceUrl: location); if (pubspecNode is YamlScalar && pubspecNode.value == null) { - pubspecNode = new YamlMap(); + pubspecNode = new YamlMap(sourceUrl: location); } else if (pubspecNode is! YamlMap) { throw new PubspecException( 'The pubspec must be a YAML mapping.', pubspecNode.span); diff --git a/test/get/path/empty_pubspec_test.dart b/test/get/path/empty_pubspec_test.dart new file mode 100644 index 00000000..4950bec5 --- /dev/null +++ b/test/get/path/empty_pubspec_test.dart @@ -0,0 +1,30 @@ +// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS d.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 d.file. + +import 'package:path/path.dart' as p; + +import '../../../lib/src/exit_codes.dart' as exit_codes; +import '../../descriptor.dart' as d; +import '../../test_pub.dart'; + +main() { + initConfig(); + // Regression test for issue 20103. + integration('path dependency to an empty pubspec', () { + d.dir('foo', [ + d.libDir('foo'), + d.file('pubspec.yaml', '') + ]).create(); + + d.dir(appPath, [ + d.appPubspec({ + "foo": {"path": "../foo"} + }) + ]).create(); + + pubGet(exitCode: exit_codes.DATA, error: + 'Error on line 1, column 1 of ${p.join('..', 'foo', 'pubspec.yaml')}: ' + 'Missing the required "name" field.'); + }); +} \ No newline at end of file -- GitLab