Merge pull request #12 from dart-lang/devoncarew_docs_and_test
Devoncarew docs and test
diff --git a/README.md b/README.md
index 15e0368..5efb808 100644
--- a/README.md
+++ b/README.md
@@ -6,6 +6,26 @@
[![Build status](https://ci.appveyor.com/api/projects/status/w75vsabfhgmo93hq/branch/master?svg=true)](https://ci.appveyor.com/project/devoncarew/pub-cache/branch/master)
[![Coverage Status](https://img.shields.io/coveralls/dart-lang/pub_cache.svg)](https://coveralls.io/r/dart-lang/pub_cache?branch=master)
+## How do I use it?
+
+`pub_cache` lets you reflect on the information in your Pub cache. For example,
+to find all the applications that have been activated:
+
+```dart
+PubCache cache = new PubCache();
+for (Application app in cache.getGlobalApplications()) {
+ print('activated app: ${app.name}, version: ${app.version}');
+}
+```
+
+Some other interesting use cases:
+
+- finding all the activated applications whose defining package has a specific
+ meta-data file
+- given a package name, locate the directory on disk for that package, and
+ using that location to read resources contained in the package
+- finding the latest non-dev version of all the packages in the cache
+
## Features and bugs
Please file feature requests and bugs at the [issue tracker][tracker].
diff --git a/lib/pub_cache.dart b/lib/pub_cache.dart
index 83755af..6407f04 100644
--- a/lib/pub_cache.dart
+++ b/lib/pub_cache.dart
@@ -14,7 +14,6 @@
/// A programmatic API for reflecting on Pub's cache directory.
class PubCache {
-
/// Return the location of Pub's package cache.
static Directory getSystemCacheLocation() {
Map env = Platform.environment;
diff --git a/test/pub_cache_test.dart b/test/pub_cache_test.dart
index b93c0ca..4301d6f 100644
--- a/test/pub_cache_test.dart
+++ b/test/pub_cache_test.dart
@@ -135,18 +135,38 @@
});
group('integration', () {
- test('list', () {
+ test('list apps', () {
+ StringBuffer buf = new StringBuffer();
PubCache cache = new PubCache();
var apps = cache.getGlobalApplications();
- print('${apps.length} activated applications:');
- apps.forEach((app) => print(' ${app}'));
+ apps.forEach((app) => buf.writeln(' ${app}'));
+ expect(buf.toString(), isNotEmpty);
+ });
+ test('list packages', () {
+ StringBuffer buf = new StringBuffer();
+ PubCache cache = new PubCache();
var packages = cache.getCachedPackages();
- print('\n${packages.length} packages in cache:');
packages.forEach((pkg) {
List versions = cache.getAllPackageVersions(pkg);
- print(' ${pkg} [${versions.map((p) => p.version.toString()).join(', ')}]');
+ buf.writeln(
+ ' ${pkg} [${versions.map((p) => p.version.toString()).join(', ')}]');
});
+ expect(buf.toString(), isNotEmpty);
+ });
+
+ test('everything resolves', () {
+ PubCache cache = new PubCache();
+
+ for (Application app in cache.getGlobalApplications()) {
+ for (PackageRef ref in app.getPackageRefs()) {
+ expect(ref.resolve(), isNotNull);
+ }
+ }
+
+ for (PackageRef ref in cache.getPackageRefs()) {
+ expect(ref.resolve(), isNotNull);
+ }
});
});
}