Skip to content
This repository has been archived by the owner on May 29, 2023. It is now read-only.

Commit

Permalink
Merge pull request #12 from dart-lang/devoncarew_docs_and_test
Browse files Browse the repository at this point in the history
Devoncarew docs and test
  • Loading branch information
devoncarew committed Apr 5, 2015
2 parents c7fc3ea + 5f7d431 commit 65b179f
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 6 deletions.
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,26 @@ A library to reflect on the local pub cache.
[![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].
Expand Down
1 change: 0 additions & 1 deletion lib/pub_cache.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import 'src/impl.dart';

/// 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;
Expand Down
30 changes: 25 additions & 5 deletions test/pub_cache_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -135,18 +135,38 @@ void defineTests() {
});

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);
}
});
});
}

0 comments on commit 65b179f

Please sign in to comment.