diff --git a/utils/tests/pub/pub_test.dart b/utils/tests/pub/pub_test.dart index 952455d0597..26f71922b15 100644 --- a/utils/tests/pub/pub_test.dart +++ b/utils/tests/pub/pub_test.dart @@ -93,11 +93,15 @@ installCommand() { test('checks out a package from the SDK', () { dir(sdkPath, [ file('revision', '1234'), - dir('pkg', [packageDir("foo", "0.0.1234")]) + dir('pkg', [ + dir('foo', [ + file('foo.dart', 'main() => "foo";') + ]) + ]) ]).scheduleCreate(); dir(appPath, [ - pubspec({"dependencies": {"foo": null}}) + file('pubspec.yaml', 'dependencies:\n foo:') ]).scheduleCreate(); schedulePub(args: ['install'], @@ -105,7 +109,11 @@ installCommand() { Dependencies installed! '''); - packagesDir({"foo": "0.0.1234"}).scheduleValidate(); + dir(packagesPath, [ + dir('foo', [ + file('foo.dart', 'main() => "foo";') + ]) + ]).scheduleValidate(); run(); }); @@ -117,15 +125,27 @@ installCommand() { file('foo.dart', 'main() => "foo";') ]).scheduleCreate(); - appDir([{"git": "../foo.git"}]).scheduleCreate(); + dir(appPath, [ + file('pubspec.yaml', ''' +dependencies: + foo: + git: ../foo.git +''') + ]).scheduleCreate(); schedulePub(args: ['install'], output: const RegExp(@"Dependencies installed!$")); dir(cachePath, [ dir('git', [ - dir('cache', [gitPackageCacheDir('foo')]), - gitPackageCacheDir('foo') + dir('cache', [ + dir(new RegExp(@'foo-[a-f0-9]+'), [ + file('foo.dart', 'main() => "foo";') + ]) + ]), + dir(new RegExp(@'foo-[a-f0-9]+'), [ + file('foo.dart', 'main() => "foo";') + ]) ]) ]).scheduleValidate(); @@ -143,14 +163,24 @@ installCommand() { git('foo.git', [ file('foo.dart', 'main() => "foo";'), - appPubspec([{"git": "../bar.git"}]) + file('pubspec.yaml', ''' +dependencies: + bar: + git: ../bar.git +''') ]).scheduleCreate(); git('bar.git', [ file('bar.dart', 'main() => "bar";') ]).scheduleCreate(); - appDir([{"git": "../foo.git"}]).scheduleCreate(); + dir(appPath, [ + file('pubspec.yaml', ''' +dependencies: + foo: + git: ../foo.git +''') + ]).scheduleCreate(); schedulePub(args: ['install'], output: const RegExp("Dependencies installed!\$")); @@ -158,11 +188,19 @@ installCommand() { dir(cachePath, [ dir('git', [ dir('cache', [ - gitPackageCacheDir('foo'), - gitPackageCacheDir('bar') + dir(new RegExp(@'foo-[a-f0-9]+'), [ + file('foo.dart', 'main() => "foo";') + ]), + dir(new RegExp(@'bar-[a-f0-9]+'), [ + file('bar.dart', 'main() => "bar";') + ]) ]), - gitPackageCacheDir('foo'), - gitPackageCacheDir('bar') + dir(new RegExp(@'foo-[a-f0-9]+'), [ + file('foo.dart', 'main() => "foo";') + ]), + dir(new RegExp(@'bar-[a-f0-9]+'), [ + file('bar.dart', 'main() => "bar";') + ]) ]) ]).scheduleValidate(); @@ -185,15 +223,27 @@ installCommand() { file('foo.dart', 'main() => "foo";') ]).scheduleCreate(); - appDir([{"git": "../foo.git"}]).scheduleCreate(); + dir(appPath, [ + file('pubspec.yaml', ''' +dependencies: + foo: + git: ../foo.git +''') + ]).scheduleCreate(); schedulePub(args: ['install'], output: const RegExp(@"Dependencies installed!$")); dir(cachePath, [ dir('git', [ - dir('cache', [gitPackageCacheDir('foo')]), - gitPackageCacheDir('foo') + dir('cache', [ + dir(new RegExp(@'foo-[a-f0-9]+'), [ + file('foo.dart', 'main() => "foo";') + ]) + ]), + dir(new RegExp(@'foo-[a-f0-9]+'), [ + file('foo.dart', 'main() => "foo";') + ]) ]) ]).scheduleValidate(); @@ -218,9 +268,17 @@ installCommand() { // git/cache directory but create a new git/ directory. dir(cachePath, [ dir('git', [ - dir('cache', [gitPackageCacheDir('foo', 2)]), - gitPackageCacheDir('foo'), - gitPackageCacheDir('foo', 2) + dir('cache', [ + dir(new RegExp(@'foo-[a-f0-9]+'), [ + file('foo.dart', 'main() => "foo 2";') + ]) + ]), + dir(new RegExp(@'foo-[a-f0-9]+'), [ + file('foo.dart', 'main() => "foo";') + ]), + dir(new RegExp(@'foo-[a-f0-9]+'), [ + file('foo.dart', 'main() => "foo 2";') + ]) ]) ]).scheduleValidate(); @@ -240,15 +298,27 @@ installCommand() { file('foo.dart', 'main() => "foo";') ]).scheduleCreate(); - appDir([{"git": "../foo.git"}]).scheduleCreate(); + dir(appPath, [ + file('pubspec.yaml', ''' +dependencies: + foo: + git: ../foo.git +''') + ]).scheduleCreate(); schedulePub(args: ['install'], output: const RegExp(@"Dependencies installed!$")); dir(cachePath, [ dir('git', [ - dir('cache', [gitPackageCacheDir('foo')]), - gitPackageCacheDir('foo') + dir('cache', [ + dir(new RegExp(@'foo-[a-f0-9]+'), [ + file('foo.dart', 'main() => "foo";') + ]) + ]), + dir(new RegExp(@'foo-[a-f0-9]+'), [ + file('foo.dart', 'main() => "foo";') + ]) ]) ]).scheduleValidate(); @@ -276,13 +346,23 @@ installCommand() { file('foo.dart', 'main() => "foo 1";') ]); repo.scheduleCreate(); - var commit = repo.revParse('HEAD'); + var commitFuture = repo.revParse('HEAD'); git('foo.git', [ file('foo.dart', 'main() => "foo 2";') ]).scheduleCommit(); - appDir([{"git": {"url": "../foo.git", "ref": commit}}]).scheduleCreate(); + dir(appPath, [ + async(commitFuture.transform((commit) { + return file('pubspec.yaml', ''' +dependencies: + foo: + git: + url: ../foo.git + ref: $commit +'''); + })) + ]).scheduleCreate(); schedulePub(args: ['install'], output: const RegExp(@"Dependencies installed!$")); @@ -297,63 +377,210 @@ installCommand() { }); test('checks out a package from a pub server', () { - servePackages("localhost", 3123, [package("foo", "1.2.3")]); + servePackages("localhost", 3123, ['{name: foo, version: 1.2.3}']); - appDir([dependency("foo", "1.2.3")]).scheduleCreate(); + dir(appPath, [ + file('pubspec.yaml', ''' +dependencies: + foo: + repo: + name: foo + url: http://localhost:3123 + version: 1.2.3 +''') + ]).scheduleCreate(); schedulePub(args: ['install'], output: const RegExp("Dependencies installed!\$")); - cacheDir({"foo": "1.2.3"}).scheduleValidate(); - packagesDir({"foo": "1.2.3"}).scheduleValidate(); + dir(cachePath, [ + dir('repo', [ + dir('localhost%583123', [ + dir('foo-1.2.3', [ + file('pubspec.yaml', '{name: foo, version: 1.2.3}'), + file('foo.dart', 'main() => print("foo 1.2.3");') + ]) + ]) + ]) + ]).scheduleValidate(); + + dir(packagesPath, [ + dir('foo', [ + file('pubspec.yaml', '{name: foo, version: 1.2.3}'), + file('foo.dart', 'main() => print("foo 1.2.3");') + ]) + ]).scheduleValidate(); run(); }); test('checks out packages transitively from a pub server', () { servePackages("localhost", 3123, [ - package("foo", "1.2.3", [dependency("bar", "2.0.4")]), - package("bar", "2.0.3"), - package("bar", "2.0.4"), - package("bar", "2.0.5") + ''' +name: foo +version: 1.2.3 +dependencies: + bar: + repo: {name: bar, url: http://localhost:3123} + version: 2.0.4 +''', + '{name: bar, version: 2.0.3}', + '{name: bar, version: 2.0.4}', + '{name: bar, version: 2.0.5}', ]); - appDir([dependency("foo", "1.2.3")]).scheduleCreate(); + dir(appPath, [ + file('pubspec.yaml', ''' +dependencies: + foo: + repo: + name: foo + url: http://localhost:3123 + version: 1.2.3 +''') + ]).scheduleCreate(); schedulePub(args: ['install'], output: const RegExp("Dependencies installed!\$")); - cacheDir({"foo": "1.2.3", "bar": "2.0.4"}).scheduleValidate(); - packagesDir({"foo": "1.2.3", "bar": "2.0.4"}).scheduleValidate(); + dir(cachePath, [ + dir('repo', [ + dir('localhost%583123', [ + dir('foo-1.2.3', [ + file('pubspec.yaml', ''' +name: foo +version: 1.2.3 +dependencies: + bar: + repo: {name: bar, url: http://localhost:3123} + version: 2.0.4 +'''), + file('foo.dart', 'main() => print("foo 1.2.3");') + ]), + dir('bar-2.0.4', [ + file('pubspec.yaml', '{name: bar, version: 2.0.4}'), + file('bar.dart', 'main() => print("bar 2.0.4");') + ]) + ]) + ]) + ]).scheduleValidate(); + + dir(packagesPath, [ + dir('foo', [ + file('pubspec.yaml', ''' +name: foo +version: 1.2.3 +dependencies: + bar: + repo: {name: bar, url: http://localhost:3123} + version: 2.0.4 +'''), + file('foo.dart', 'main() => print("foo 1.2.3");') + ]), + dir('bar', [ + file('pubspec.yaml', '{name: bar, version: 2.0.4}'), + file('bar.dart', 'main() => print("bar 2.0.4");') + ]) + ]).scheduleValidate(); run(); }); test('resolves version constraints from a pub server', () { servePackages("localhost", 3123, [ - package("foo", "1.2.3", [dependency("baz", ">=2.0.0")]), - package("bar", "2.3.4", [dependency("baz", "<3.0.0")]), - package("baz", "2.0.3"), - package("baz", "2.0.4"), - package("baz", "3.0.1") + ''' +name: foo +version: 1.2.3 +dependencies: + baz: + repo: {name: baz, url: http://localhost:3123} + version: ">=2.0.0" +''', + ''' +name: bar +version: 2.3.4 +dependencies: + baz: + repo: {name: baz, url: http://localhost:3123} + version: "<3.0.0" +''', + '{name: baz, version: 2.0.3}', + '{name: baz, version: 2.0.4}', + '{name: baz, version: 3.0.1}', ]); - appDir([dependency("foo"), dependency("bar")]).scheduleCreate(); + dir(appPath, [ + file('pubspec.yaml', ''' +dependencies: + foo: {repo: {name: foo, url: http://localhost:3123}} + bar: {repo: {name: bar, url: http://localhost:3123}} +''') + ]).scheduleCreate(); schedulePub(args: ['install'], output: const RegExp("Dependencies installed!\$")); - cacheDir({ - "foo": "1.2.3", - "bar": "2.3.4", - "baz": "2.0.4" - }).scheduleValidate(); + dir(cachePath, [ + dir('repo', [ + dir('localhost%583123', [ + dir('foo-1.2.3', [ + file('pubspec.yaml', ''' +name: foo +version: 1.2.3 +dependencies: + baz: + repo: {name: baz, url: http://localhost:3123} + version: ">=2.0.0" +'''), + file('foo.dart', 'main() => print("foo 1.2.3");') + ]), + dir('bar-2.3.4', [ + file('pubspec.yaml', ''' +name: bar +version: 2.3.4 +dependencies: + baz: + repo: {name: baz, url: http://localhost:3123} + version: "<3.0.0" +'''), + file('bar.dart', 'main() => print("bar 2.3.4");') + ]), + dir('baz-2.0.4', [ + file('pubspec.yaml', '{name: baz, version: 2.0.4}'), + file('baz.dart', 'main() => print("baz 2.0.4");') + ]) + ]) + ]) + ]).scheduleValidate(); - packagesDir({ - "foo": "1.2.3", - "bar": "2.3.4", - "baz": "2.0.4" - }).scheduleValidate(); + dir(packagesPath, [ + dir('foo', [ + file('pubspec.yaml', ''' +name: foo +version: 1.2.3 +dependencies: + baz: + repo: {name: baz, url: http://localhost:3123} + version: ">=2.0.0" +'''), + file('foo.dart', 'main() => print("foo 1.2.3");') + ]), + dir('bar', [ + file('pubspec.yaml', ''' +name: bar +version: 2.3.4 +dependencies: + baz: + repo: {name: baz, url: http://localhost:3123} + version: "<3.0.0" +'''), + file('bar.dart', 'main() => print("bar 2.3.4");') + ]), + dir('baz', [ + file('pubspec.yaml', '{name: baz, version: 2.0.4}'), + file('baz.dart', 'main() => print("baz 2.0.4");') + ]) + ]).scheduleValidate(); run(); }); @@ -365,7 +592,13 @@ installCommand() { file('foo.dart', 'main() => "foo";') ]).scheduleCreate(); - appDir([{"git": "../foo.git"}]).scheduleCreate(); + dir(appPath, [ + file('pubspec.yaml', ''' +dependencies: + foo: + git: ../foo.git +''') + ]).scheduleCreate(); // This install should lock the foo.git dependency to the current revision. schedulePub(args: ['install'], @@ -404,7 +637,13 @@ installCommand() { file('foo.dart', 'main() => "foo";') ]).scheduleCreate(); - appDir([{"git": "../foo.git"}]).scheduleCreate(); + dir(appPath, [ + file('pubspec.yaml', ''' +dependencies: + foo: + git: ../foo.git +''') + ]).scheduleCreate(); schedulePub(args: ['install'], output: const RegExp(@"Dependencies installed!$")); @@ -417,10 +656,17 @@ installCommand() { git('foo.git', [ file('foo.dart', 'main() => "foo 1.0.0";'), - libPubspec("foo", "1.0.0") + file('pubspec.yaml', 'version: 1.0.0') ]).scheduleCommit(); - appDir([{"git": "../foo.git", "version": ">=1.0.0"}]).scheduleCreate(); + dir(appPath, [ + file('pubspec.yaml', ''' +dependencies: + foo: + git: ../foo.git + version: ">=1.0.0" +''') + ]).scheduleCreate(); schedulePub(args: ['install'], output: const RegExp(@"Dependencies installed!$")); @@ -440,10 +686,16 @@ installCommand() { git('foo.git', [ file('foo.dart', 'main() => "foo 1.0.0";'), - libPubspec("foo", "1.0.0") + file('pubspec.yaml', 'version: 1.0.0') ]).scheduleCreate(); - appDir([{"git": "../foo.git"}]).scheduleCreate(); + dir(appPath, [ + file('pubspec.yaml', ''' +dependencies: + foo: + git: ../foo.git +''') + ]).scheduleCreate(); schedulePub(args: ['install'], output: const RegExp(@"Dependencies installed!$")); @@ -456,10 +708,17 @@ installCommand() { git('foo.git', [ file('foo.dart', 'main() => "foo 1.0.1";'), - libPubspec("foo", "1.0.1") + file('pubspec.yaml', 'version: 1.0.1') ]).scheduleCommit(); - appDir([{"git": "../foo.git", "version": ">=1.0.0"}]).scheduleCreate(); + dir(appPath, [ + file('pubspec.yaml', ''' +dependencies: + foo: + git: ../foo.git + version: ">=1.0.0" +''') + ]).scheduleCreate(); schedulePub(args: ['install'], output: const RegExp(@"Dependencies installed!$")); @@ -474,82 +733,138 @@ installCommand() { }); test('keeps a pub server package locked to the version in the lockfile', () { - servePackages("localhost", 3123, [package("foo", "1.0.0")]); + servePackages("localhost", 3123, ['{name: foo, version: 1.0.0}']); - appDir([dependency("foo")]).scheduleCreate(); + dir(appPath, [ + file('pubspec.yaml', ''' +dependencies: + foo: + repo: {name: foo, url: http://localhost:3123} +''') + ]).scheduleCreate(); // This install should lock the foo dependency to version 1.0.0. schedulePub(args: ['install'], output: const RegExp(@"Dependencies installed!$")); - packagesDir({"foo": "1.0.0"}).scheduleValidate(); + dir(packagesPath, [ + dir('foo', [ + file('foo.dart', 'main() => print("foo 1.0.0");') + ]) + ]).scheduleValidate(); // Delete the packages path to simulate a new checkout of the application. dir(packagesPath).scheduleDelete(); // Start serving a newer package as well. servePackages("localhost", 3123, [ - package("foo", "1.0.0"), - package("foo", "1.0.1") + '{name: foo, version: 1.0.0}', + '{name: foo, version: 1.0.1}' ]); // This install shouldn't update the foo dependency due to the lockfile. schedulePub(args: ['install'], output: const RegExp(@"Dependencies installed!$")); - packagesDir({"foo": "1.0.0"}).scheduleValidate(); + dir(packagesPath, [ + dir('foo', [ + file('foo.dart', 'main() => print("foo 1.0.0");') + ]) + ]).scheduleValidate(); run(); }); test('updates a locked pub server package with a new incompatible ' 'constraint', () { - servePackages("localhost", 3123, [package("foo", "1.0.0")]); + servePackages("localhost", 3123, ['{name: foo, version: 1.0.0}']); - appDir([dependency("foo")]).scheduleCreate(); + dir(appPath, [ + file('pubspec.yaml', ''' +dependencies: + foo: + repo: {name: foo, url: http://localhost:3123} +''') + ]).scheduleCreate(); schedulePub(args: ['install'], output: const RegExp(@"Dependencies installed!$")); - packagesDir({"foo": "1.0.0"}).scheduleValidate(); + dir(packagesPath, [ + dir('foo', [ + file('foo.dart', 'main() => print("foo 1.0.0");') + ]) + ]).scheduleValidate(); servePackages("localhost", 3123, [ - package("foo", "1.0.0"), - package("foo", "1.0.1") + '{name: foo, version: 1.0.0}', + '{name: foo, version: 1.0.1}' ]); - appDir([dependency("foo", ">1.0.0")]).scheduleCreate(); + dir(appPath, [ + file('pubspec.yaml', ''' +dependencies: + foo: + repo: {name: foo, url: http://localhost:3123} + version: ">1.0.0" +''') + ]).scheduleCreate(); schedulePub(args: ['install'], output: const RegExp(@"Dependencies installed!$")); - packagesDir({"foo": "1.0.1"}).scheduleValidate(); + dir(packagesPath, [ + dir('foo', [ + file('foo.dart', 'main() => print("foo 1.0.1");') + ]) + ]).scheduleValidate(); run(); }); test("doesn't update a locked pub server package with a new compatible " "constraint", () { - servePackages("localhost", 3123, [package("foo", "1.0.0")]); + servePackages("localhost", 3123, ['{name: foo, version: 1.0.0}']); - appDir([dependency("foo")]).scheduleCreate(); + dir(appPath, [ + file('pubspec.yaml', ''' +dependencies: + foo: + repo: {name: foo, url: http://localhost:3123} +''') + ]).scheduleCreate(); schedulePub(args: ['install'], output: const RegExp(@"Dependencies installed!$")); - packagesDir({"foo": "1.0.0"}).scheduleValidate(); + dir(packagesPath, [ + dir('foo', [ + file('foo.dart', 'main() => print("foo 1.0.0");') + ]) + ]).scheduleValidate(); servePackages("localhost", 3123, [ - package("foo", "1.0.0"), - package("foo", "1.0.1") + '{name: foo, version: 1.0.0}', + '{name: foo, version: 1.0.1}' ]); - appDir([dependency("foo", ">=1.0.0")]).scheduleCreate(); + dir(appPath, [ + file('pubspec.yaml', ''' +dependencies: + foo: + repo: {name: foo, url: http://localhost:3123} + version: ">=1.0.0" +''') + ]).scheduleCreate(); schedulePub(args: ['install'], output: const RegExp(@"Dependencies installed!$")); - packagesDir({"foo": "1.0.0"}).scheduleValidate(); + dir(packagesPath, [ + dir('foo', [ + file('foo.dart', 'main() => print("foo 1.0.0");') + ]) + ]).scheduleValidate(); run(); }); @@ -557,52 +872,157 @@ installCommand() { test("unlocks dependencies if necessary to ensure that a new dependency " "is satisfied", () { servePackages("localhost", 3123, [ - package("foo", "1.0.0", [dependency("bar", "<2.0.0")]), - package("bar", "1.0.0", [dependency("baz", "<2.0.0")]), - package("baz", "1.0.0", [dependency("qux", "<2.0.0")]), - package("qux", "1.0.0") - ]); + ''' +name: foo +version: 1.0.0 +dependencies: + bar: + version: "<2.0.0" + repo: {name: bar, url: http://localhost:3123} +''', + ''' +name: bar +version: 1.0.0 +dependencies: + baz: + version: "<2.0.0" + repo: {name: baz, url: http://localhost:3123} +''', + ''' +name: baz +version: 1.0.0 +dependencies: + qux: + version: "<2.0.0" + repo: {name: qux, url: http://localhost:3123} +''', + ''' +name: qux +version: 1.0.0 +''']); - appDir([dependency("foo")]).scheduleCreate(); + dir(appPath, [ + file('pubspec.yaml', ''' +dependencies: + foo: + repo: {name: foo, url: http://localhost:3123} +''') + ]).scheduleCreate(); schedulePub(args: ['install'], output: const RegExp(@"Dependencies installed!$")); - packagesDir({ - "foo": "1.0.0", - "bar": "1.0.0", - "baz": "1.0.0", - "qux": "1.0.0" - }).scheduleValidate(); + dir(packagesPath, [ + dir('foo', [ + file('foo.dart', 'main() => print("foo 1.0.0");') + ]), + dir('bar', [ + file('bar.dart', 'main() => print("bar 1.0.0");') + ]), + dir('baz', [ + file('baz.dart', 'main() => print("baz 1.0.0");') + ]), + dir('qux', [ + file('qux.dart', 'main() => print("qux 1.0.0");') + ]) + ]).scheduleValidate(); servePackages("localhost", 3123, [ - package("foo", "1.0.0", [dependency("bar", "<2.0.0")]), - package("foo", "2.0.0", [dependency("bar", "<3.0.0")]), + ''' +name: foo +version: 1.0.0 +dependencies: + bar: + version: "<2.0.0" + repo: {name: bar, url: http://localhost:3123} +''', + ''' +name: foo +version: 2.0.0 +dependencies: + bar: + version: "<3.0.0" + repo: {name: bar, url: http://localhost:3123} +''', + ''' +name: bar +version: 1.0.0 +dependencies: + baz: + version: "<2.0.0" + repo: {name: baz, url: http://localhost:3123} +''', + ''' +name: bar +version: 2.0.0 +dependencies: + baz: + version: "<3.0.0" + repo: {name: baz, url: http://localhost:3123} +''', + ''' +name: baz +version: 1.0.0 +dependencies: + qux: + version: "<2.0.0" + repo: {name: qux, url: http://localhost:3123} +''', + ''' +name: baz +version: 2.0.0 +dependencies: + qux: + version: "<3.0.0" + repo: {name: qux, url: http://localhost:3123} +''', + ''' +name: qux +version: 1.0.0 +''', + ''' +name: qux +version: 2.0.0 +''', + ''' +name: newdep +version: 2.0.0 +dependencies: + baz: + version: ">=1.5.0" + repo: {name: baz, url: http://localhost:3123} +''']); - package("bar", "1.0.0", [dependency("baz", "<2.0.0")]), - package("bar", "2.0.0", [dependency("baz", "<3.0.0")]), - - package("baz", "1.0.0", [dependency("qux", "<2.0.0")]), - package("baz", "2.0.0", [dependency("qux", "<3.0.0")]), - - package("qux", "1.0.0"), - package("qux", "2.0.0"), - - package("newdep", "2.0.0", [dependency("baz", ">=1.5.0")]) - ]); - - appDir([dependency("foo"), dependency("newdep")]).scheduleCreate(); + dir(appPath, [ + file('pubspec.yaml', ''' +dependencies: + foo: + repo: {name: foo, url: http://localhost:3123} + newdep: + repo: {name: newdep, url: http://localhost:3123} +''') + ]).scheduleCreate(); schedulePub(args: ['install'], output: const RegExp(@"Dependencies installed!$")); - packagesDir({ - "foo": "2.0.0", - "bar": "2.0.0", - "baz": "2.0.0", - "qux": "1.0.0", - "newdep": "2.0.0" - }).scheduleValidate(); + dir(packagesPath, [ + dir('foo', [ + file('foo.dart', 'main() => print("foo 2.0.0");') + ]), + dir('bar', [ + file('bar.dart', 'main() => print("bar 2.0.0");') + ]), + dir('baz', [ + file('baz.dart', 'main() => print("baz 2.0.0");') + ]), + dir('qux', [ + file('qux.dart', 'main() => print("qux 1.0.0");') + ]), + dir('newdep', [ + file('newdep.dart', 'main() => print("newdep 2.0.0");') + ]) + ]).scheduleValidate(); run(); }); @@ -610,46 +1030,127 @@ installCommand() { test("doesn't unlock dependencies if a new dependency is already " "satisfied", () { servePackages("localhost", 3123, [ - package("foo", "1.0.0", [dependency("bar", "<2.0.0")]), - package("bar", "1.0.0", [dependency("baz", "<2.0.0")]), - package("baz", "1.0.0") - ]); + ''' +name: foo +version: 1.0.0 +dependencies: + bar: + version: "<2.0.0" + repo: {name: bar, url: http://localhost:3123} +''', + ''' +name: bar +version: 1.0.0 +dependencies: + baz: + version: "<2.0.0" + repo: {name: baz, url: http://localhost:3123} +''', + ''' +name: baz +version: 1.0.0 +''']); - appDir([dependency("foo")]).scheduleCreate(); + dir(appPath, [ + file('pubspec.yaml', ''' +dependencies: + foo: + repo: {name: foo, url: http://localhost:3123} +''') + ]).scheduleCreate(); schedulePub(args: ['install'], output: const RegExp(@"Dependencies installed!$")); - packagesDir({ - "foo": "1.0.0", - "bar": "1.0.0", - "baz": "1.0.0" - }).scheduleValidate(); + dir(packagesPath, [ + dir('foo', [ + file('foo.dart', 'main() => print("foo 1.0.0");') + ]), + dir('bar', [ + file('bar.dart', 'main() => print("bar 1.0.0");') + ]), + dir('baz', [ + file('baz.dart', 'main() => print("baz 1.0.0");') + ]) + ]).scheduleValidate(); servePackages("localhost", 3123, [ - package("foo", "1.0.0", [dependency("bar", "<2.0.0")]), - package("foo", "2.0.0", [dependency("bar", "<3.0.0")]), + ''' +name: foo +version: 1.0.0 +dependencies: + bar: + version: "<2.0.0" + repo: {name: bar, url: http://localhost:3123} +''', + ''' +name: foo +version: 2.0.0 +dependencies: + bar: + version: "<3.0.0" + repo: {name: bar, url: http://localhost:3123} +''', + ''' +name: bar +version: 1.0.0 +dependencies: + baz: + version: "<2.0.0" + repo: {name: baz, url: http://localhost:3123} +''', + ''' +name: bar +version: 2.0.0 +dependencies: + baz: + version: "<3.0.0" + repo: {name: baz, url: http://localhost:3123} +''', + ''' +name: baz +version: 1.0.0 +''', + ''' +name: baz +version: 2.0.0 +''', + ''' +name: newdep +version: 2.0.0 +dependencies: + baz: + version: ">=1.0.0" + repo: {name: baz, url: http://localhost:3123} +''']); - package("bar", "1.0.0", [dependency("baz", "<2.0.0")]), - package("bar", "2.0.0", [dependency("baz", "<3.0.0")]), - - package("baz", "1.0.0"), - package("baz", "2.0.0"), - - package("newdep", "2.0.0", [dependency("baz", ">=1.0.0")]) - ]); - - appDir([dependency("foo"), dependency("newdep")]).scheduleCreate(); + dir(appPath, [ + file('pubspec.yaml', ''' +dependencies: + foo: + repo: {name: foo, url: http://localhost:3123} + newdep: + repo: {name: newdep, url: http://localhost:3123} +''') + ]).scheduleCreate(); schedulePub(args: ['install'], output: const RegExp(@"Dependencies installed!$")); - packagesDir({ - "foo": "1.0.0", - "bar": "1.0.0", - "baz": "1.0.0", - "newdep": "2.0.0" - }).scheduleValidate(); + dir(packagesPath, [ + dir('foo', [ + file('foo.dart', 'main() => print("foo 1.0.0");') + ]), + dir('bar', [ + file('bar.dart', 'main() => print("bar 1.0.0");') + ]), + dir('baz', [ + file('baz.dart', 'main() => print("baz 1.0.0");') + ]), + dir('newdep', [ + file('newdep.dart', 'main() => print("newdep 2.0.0");') + ]) + ]).scheduleValidate(); run(); }); @@ -667,7 +1168,15 @@ updateCommand() { file('bar.dart', 'main() => "bar";') ]).scheduleCreate(); - appDir([{"git": "../foo.git"}, {"git": "../bar.git"}]).scheduleCreate(); + dir(appPath, [ + file('pubspec.yaml', ''' +dependencies: + foo: + git: ../foo.git + bar: + git: ../bar.git +''') + ]).scheduleCreate(); schedulePub(args: ['install'], output: const RegExp(@"Dependencies installed!$")); @@ -716,7 +1225,15 @@ updateCommand() { file('bar.dart', 'main() => "bar";') ]).scheduleCreate(); - appDir([{"git": "../foo.git"}, {"git": "../bar.git"}]).scheduleCreate(); + dir(appPath, [ + file('pubspec.yaml', ''' +dependencies: + foo: + git: ../foo.git + bar: + git: ../bar.git +''') + ]).scheduleCreate(); schedulePub(args: ['install'], output: const RegExp(@"Dependencies installed!$")); @@ -759,14 +1276,24 @@ updateCommand() { git('foo.git', [ file('foo.dart', 'main() => "foo";'), - libPubspec("foo", "1.0.0", [{"git": "../foo-dep.git"}]) + file('pubspec.yaml', ''' +dependencies: + foo-dep: + git: ../foo-dep.git +''') ]).scheduleCreate(); git('foo-dep.git', [ - file('foo-dep.dart', 'main() => "foo-dep";'), + file('foo-dep.dart', 'main() => "foo-dep";') ]).scheduleCreate(); - appDir([{"git": "../foo.git"}]).scheduleCreate(); + dir(appPath, [ + file('pubspec.yaml', ''' +dependencies: + foo: + git: ../foo.git +''') + ]).scheduleCreate(); schedulePub(args: ['install'], output: const RegExp(@"Dependencies installed!$")); @@ -774,7 +1301,11 @@ updateCommand() { dir(packagesPath, [ dir('foo', [ file('foo.dart', 'main() => "foo";'), - libPubspec("foo", "1.0.0", [{"git": "../foo-dep.git"}]) + file('pubspec.yaml', ''' +dependencies: + foo-dep: + git: ../foo-dep.git +''') ]), dir('foo-dep', [ file('foo-dep.dart', 'main() => "foo-dep";') @@ -783,7 +1314,11 @@ updateCommand() { git('foo.git', [ file('foo.dart', 'main() => "foo 2";'), - libPubspec("foo", "1.0.0", [{"git": "../foo-dep.git"}]) + file('pubspec.yaml', ''' +dependencies: + foo-dep: + git: ../foo-dep.git +''') ]).scheduleCreate(); git('foo-dep.git', [ @@ -796,7 +1331,11 @@ updateCommand() { dir(packagesPath, [ dir('foo', [ file('foo.dart', 'main() => "foo 2";'), - libPubspec("foo", "1.0.0", [{"git": "../foo-dep.git"}]) + file('pubspec.yaml', ''' +dependencies: + foo-dep: + git: ../foo-dep.git +''') ]), dir('foo-dep', [ file('foo-dep.dart', 'main() => "foo-dep";') @@ -809,32 +1348,80 @@ updateCommand() { test("updates one locked pub server package's dependencies if it's " "necessary", () { servePackages("localhost", 3123, [ - package("foo", "1.0.0", [dependency("foo-dep")]), - package("foo-dep", "1.0.0") + ''' +name: foo +version: 1.0.0 +dependencies: + foo-dep: + repo: + name: foo-dep + url: http://localhost:3123 +''', + '{name: foo-dep, version: 1.0.0}' ]); - appDir([dependency("foo")]).scheduleCreate(); + dir(appPath, [ + file('pubspec.yaml', ''' +dependencies: + foo: + repo: + name: foo + url: http://localhost:3123 +''') + ]).scheduleCreate(); schedulePub(args: ['install'], output: const RegExp(@"Dependencies installed!$")); - packagesDir({ - "foo": "1.0.0", - "foo-dep": "1.0.0" - }).scheduleValidate(); + dir(packagesPath, [ + dir('foo', [ + file('foo.dart', 'main() => print("foo 1.0.0");'), + file('pubspec.yaml', ''' +name: foo +version: 1.0.0 +dependencies: + foo-dep: + repo: + name: foo-dep + url: http://localhost:3123 +''') + ]), + dir('foo-dep', [ + file('foo-dep.dart', 'main() => print("foo-dep 1.0.0");') + ]) + ]).scheduleValidate(); servePackages("localhost", 3123, [ - package("foo", "2.0.0", [dependency("foo-dep", ">1.0.0")]), - package("foo-dep", "2.0.0") + ''' +name: foo +version: 2.0.0 +dependencies: + foo-dep: + repo: {name: foo-dep, url: http://localhost:3123} + version: ">1.0.0" +''', + '{name: foo-dep, version: 2.0.0}' ]); schedulePub(args: ['update', 'foo'], output: const RegExp(@"Dependencies updated!$")); - packagesDir({ - "foo": "2.0.0", - "foo-dep": "2.0.0" - }).scheduleValidate(); + dir(packagesPath, [ + dir('foo', [ + file('foo.dart', 'main() => print("foo 2.0.0");'), + file('pubspec.yaml', ''' +name: foo +version: 2.0.0 +dependencies: + foo-dep: + repo: {name: foo-dep, url: http://localhost:3123} + version: ">1.0.0" +''') + ]), + dir('foo-dep', [ + file('foo-dep.dart', 'main() => print("foo-dep 2.0.0");') + ]) + ]).scheduleValidate(); run(); }); @@ -842,35 +1429,71 @@ updateCommand() { test("updates a locked package's dependers in order to get it to max " "version", () { servePackages("localhost", 3123, [ - package("foo", "1.0.0", [dependency("bar", "<2.0.0")]), - package("bar", "1.0.0") + ''' +name: foo +version: 1.0.0 +dependencies: + bar: + version: "<2.0.0" + repo: {name: bar, url: http://localhost:3123} +''', + '{name: bar, version: 1.0.0}' ]); - appDir([dependency("foo"), dependency("bar")]).scheduleCreate(); + dir(appPath, [ + file('pubspec.yaml', ''' +dependencies: + foo: + repo: {name: foo, url: http://localhost:3123} + bar: + repo: {name: bar, url: http://localhost:3123} +''') + ]).scheduleCreate(); schedulePub(args: ['install'], output: const RegExp(@"Dependencies installed!$")); - packagesDir({ - "foo": "1.0.0", - "bar": "1.0.0" - }).scheduleValidate(); + dir(packagesPath, [ + dir('foo', [ + file('foo.dart', 'main() => print("foo 1.0.0");'), + ]), + dir('bar', [ + file('bar.dart', 'main() => print("bar 1.0.0");') + ]) + ]).scheduleValidate(); servePackages("localhost", 3123, [ - package("foo", "1.0.0", [dependency("bar", "<2.0.0")]), - package("foo", "2.0.0", [dependency("bar", "<3.0.0")]), - - package("bar", "1.0.0"), - package("bar", "2.0.0") + ''' +name: foo +version: 1.0.0 +dependencies: + bar: + version: "<2.0.0" + repo: {name: bar, url: http://localhost:3123} +''', + ''' +name: foo +version: 2.0.0 +dependencies: + bar: + version: "<3.0.0" + repo: {name: bar, url: http://localhost:3123} +''', + '{name: bar, version: 1.0.0}', + '{name: bar, version: 2.0.0}' ]); schedulePub(args: ['update', 'bar'], output: const RegExp(@"Dependencies updated!$")); - packagesDir({ - "foo": "2.0.0", - "bar": "2.0.0" - }).scheduleValidate(); + dir(packagesPath, [ + dir('foo', [ + file('foo.dart', 'main() => print("foo 2.0.0");'), + ]), + dir('bar', [ + file('bar.dart', 'main() => print("bar 2.0.0");') + ]) + ]).scheduleValidate(); run(); }); diff --git a/utils/tests/pub/test_pub.dart b/utils/tests/pub/test_pub.dart index 067343330b8..d272cb7f026 100644 --- a/utils/tests/pub/test_pub.dart +++ b/utils/tests/pub/test_pub.dart @@ -18,10 +18,7 @@ #import('../../../pkg/unittest/unittest.dart'); #import('../../lib/file_system.dart', prefix: 'fs'); -#import('../../pub/git_source.dart'); #import('../../pub/io.dart'); -#import('../../pub/repo_source.dart'); -#import('../../pub/sdk_source.dart'); #import('../../pub/utils.dart'); #import('../../pub/yaml/yaml.dart'); @@ -126,16 +123,17 @@ Future _closeServer() { /** * Creates an HTTP server that replicates the structure of pub.dartlang.org. - * [pubspecs] is a list of unserialized pubspecs representing the packages to + * [pubspecs] is a list of YAML-format pubspecs representing the packages to * serve. */ -void servePackages(String host, int port, List pubspecs) { +void servePackages(String host, int port, List pubspecs) { var packages = >{}; - for (var spec in pubspecs) { - var name = spec['name']; - var version = spec['version']; - packages.putIfAbsent(name, () => {})[version] = yaml(spec); - } + pubspecs.forEach((spec) { + var parsed = loadYaml(spec); + var name = parsed['name']; + var version = parsed['version']; + packages.putIfAbsent(name, () => {})[version] = spec; + }); serve(host, port, [ dir('packages', flatten(packages.getKeys().map((name) { @@ -158,158 +156,6 @@ void servePackages(String host, int port, List pubspecs) { ]); } -/** Converts [value] into a YAML string. */ -String yaml(value) => JSON.stringify(value); - -/** - * Describes a file named `pubspec.yaml` with the given YAML-serialized - * [contents], which should be a serializable object. - * - * [contents] may contain [Future]s that resolve to serializable objects, which - * may in turn contain [Future]s recursively. - */ -Descriptor pubspec(Map contents) { - return async(_awaitObject(contents).transform((resolvedContents) => - file("pubspec.yaml", yaml(resolvedContents)))); -} - -/** - * Describes a file named `pubspec.yaml` for an application package with the - * given [dependencies]. - */ -Descriptor appPubspec(List dependencies) => - pubspec({"dependencies": _dependencyListToMap(dependencies)}); - -/** - * Describes a file named `pubspec.yaml` for a library package with the given - * [name], [version], and [dependencies]. - */ -Descriptor libPubspec(String name, String version, [List dependencies]) => - pubspec(package(name, version, dependencies)); - -/** - * Describes a map representing a library package with the given [name], - * [version], and [dependencies]. - */ -Map package(String name, String version, [List dependencies]) { - var package = {"name": name, "version": version}; - if (dependencies != null) { - package["dependencies"] = _dependencyListToMap(dependencies); - } - return package; -} - -/** - * Describes a map representing a dependency on a package in the package - * repository. - */ -Map dependency(String name, [String versionConstraint]) { - var dependency = {"repo": {"name": name, "url": "http://localhost:3123"}}; - if (versionConstraint != null) dependency["version"] = versionConstraint; - return dependency; -} - -/** - * Describes a directory for a package installed from the mock package repo. - * This directory is of the form found in the `packages/` directory. - */ -DirectoryDescriptor packageDir(String name, String version) { - return dir(name, [ - file("$name.dart", 'main() => print("$name $version");') - ]); -} - -/** - * Describes a directory for a package installed from the mock package server. - * This directory is of the form found in the global package cache. - */ -DirectoryDescriptor packageCacheDir(String name, String version) { - return dir("$name-$version", [ - file("$name.dart", 'main() => print("$name $version");') - ]); -} - -/** - * Describes a directory for a Git package. This directory is of the form found - * in the global package cache. - */ -DirectoryDescriptor gitPackageCacheDir(String name, [int modifier]) { - var value = name; - if (modifier != null) value = "$name $modifier"; - return dir(new RegExp("$name${@'-[a-f0-9]+'}"), [ - file('$name.dart', 'main() => "$value";') - ]); -} - -/** - * Describes the `packages/` directory containing all the given [packages], - * which should be name/version pairs. The packages will be validated against - * the format produced by the mock package server. - */ -DirectoryDescriptor packagesDir(Map packages) { - var contents = []; - packages.forEach((name, version) { - contents.add(packageDir(name, version)); - }); - return dir(packagesPath, contents); -} - -/** - * Describes the global package cache directory containing all the given - * [packages], which should be name/version pairs. The packages will be - * validated against the format produced by the mock package server. - * - * A package's value may also be a list of versions, in which case all versions - * are expected to be installed. - */ -DirectoryDescriptor cacheDir(Map packages) { - var contents = []; - packages.forEach((name, versions) { - if (versions is! List) versions = [versions]; - for (var version in versions) { - contents.add(packageCacheDir(name, version)); - } - }); - return dir(cachePath, [ - dir('repo', [dir('localhost%583123', contents)]) - ]); -} - -/** - * Describes the application directory, containing only a pubspec specifying the - * given [dependencies]. - */ -DirectoryDescriptor appDir(List dependencies) => - dir(appPath, [appPubspec(dependencies)]); - -/** - * Converts a list of dependencies as passed to [package] into a hash as used in - * a pubspec. - */ -Map _dependencyListToMap(List dependencies) { - var result = {}; - dependencies.map((dependency) { - var sourceName = only(dependency.getKeys()); - var source; - switch (sourceName) { - case "git": - source = new GitSource(); - break; - case "repo": - source = new RepoSource(); - break; - case "sdk": - source = new SdkSource(''); - break; - default: - throw 'Unknown source "$sourceName"'; - } - - result[source.packageName(dependency[sourceName])] = dependency; - }); - return result; -} - /** * The path of the package cache directory used for tests. Relative to the * sandbox directory. @@ -739,15 +585,23 @@ class DirectoryDescriptor extends Descriptor { * the creation is done. */ Future create(parentDir) { - // Create the directory. - return ensureDir(join(parentDir, _stringName)).chain((dir) { - if (contents == null) return new Future.immediate(dir); + final completer = new Completer(); - // Recursively create all of its children. - final childFutures = contents.map((child) => child.create(dir)); - // Only complete once all of the children have been created too. - return Futures.wait(childFutures).transform((_) => dir); + // Create the directory. + ensureDir(join(parentDir, _stringName)).then((dir) { + if (contents == null) { + completer.complete(dir); + } else { + // Recursively create all of its children. + final childFutures = contents.map((child) => child.create(dir)); + Futures.wait(childFutures).then((_) { + // Only complete once all of the children have been created too. + completer.complete(dir); + }); + } }); + + return completer.future; } /** @@ -949,31 +803,6 @@ class TarFileDescriptor extends Descriptor { } } -/** - * Takes a simple data structure (composed of [Map]s, [List]s, scalar objects, - * and [Future]s) and recursively resolves all the [Future]s contained within. - * Completes with the fully resolved structure. - */ -Future _awaitObject(object) { - // Unroll nested futures. - if (object is Future) return object.chain(_awaitObject); - if (object is Collection) return Futures.wait(object.map(_awaitObject)); - if (object is! Map) return new Future.immediate(object); - - var pairs = >[]; - object.forEach((key, value) { - pairs.add(_awaitObject(value) - .transform((resolved) => new Pair(key, resolved))); - }); - return Futures.wait(pairs).transform((resolvedPairs) { - var map = {}; - for (var pair in resolvedPairs) { - map[pair.first] = pair.last; - } - return map; - }); -} - /** * Schedules a callback to be called as part of the test case. */