Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(291)

Unified Diff: test/descriptor/packages.dart

Issue 2377063002: Make "--no-packages-dir" the default. (Closed)
Patch Set: Revise. Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « test/descriptor.dart ('k') | test/dev_dependency_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/descriptor/packages.dart
diff --git a/test/descriptor/packages.dart b/test/descriptor/packages.dart
index a7470c66eda89f087b5a993861b4bcff7570c4a9..c447754ee25730b41c96b5e4662bb6ac71891cec 100644
--- a/test/descriptor/packages.dart
+++ b/test/descriptor/packages.dart
@@ -9,6 +9,7 @@ import "dart:convert" show UTF8;
import 'package:package_config/packages_file.dart' as packages_file;
import 'package:path/path.dart' as p;
+import 'package:pub_semver/pub_semver.dart';
import 'package:scheduled_test/descriptor.dart';
import 'package:scheduled_test/scheduled_test.dart';
@@ -16,11 +17,6 @@ import '../test_pub.dart';
/// Describes a `.packages` file and its contents.
class PackagesFileDescriptor extends Descriptor {
- // RegExp recognizing semantic version numbers.
- static final _semverRE =
- new RegExp(r"^(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)"
- r"(?:-[a-zA-Z\d-]+)?(?:\+[a-zA-Z\d-]+)?$");
-
/// A map from package names to strings describing where the packages are
/// located on disk.
final Map<String, String> _dependencies;
@@ -38,8 +34,11 @@ class PackagesFileDescriptor extends Descriptor {
var mapping = <String, Uri>{};
_dependencies.forEach((package, version) {
var packagePath;
- if (_semverRE.hasMatch(version)) {
- // If it's a semver, it's a cache reference.
+ if (_isSemver(version)) {
+ // See if it's a semver.
+ new Version.parse(version);
nweiz 2016/09/29 00:32:41 I don't think you want to parse here anymore.
Bob Nystrom 2016/09/29 00:56:41 Oops, done.
+
+ // If we get here, it's a cache reference.
packagePath = p.join(cachePath, "$package-$version");
} else {
// Otherwise it's a path relative to the pubspec file,
@@ -84,7 +83,7 @@ class PackagesFileDescriptor extends Descriptor {
}
var description = _dependencies[package];
- if (_semverRE.hasMatch(description)) {
+ if (_isSemver(description)) {
if (!map[package].path.contains(description)) {
fail(".packages of $package has incorrect version. "
"Expected $description, found location: ${map[package]}.");
@@ -109,5 +108,17 @@ class PackagesFileDescriptor extends Descriptor {
}
}
+ /// Returns `true` if [text] is a valid semantic version number string.
+ bool _isSemver(String text) {
+ try {
+ // See if it's a semver.
+ new Version.parse(text);
+ return true;
+ } on FormatException catch (_) {
+ // Do nothing.
+ }
+ return false;
+ }
+
String describe() => name;
}
« no previous file with comments | « test/descriptor.dart ('k') | test/dev_dependency_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698