-
Notifications
You must be signed in to change notification settings - Fork 229
Test package APIs rather than resource APIs. #1451
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+249
−286
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
// Copyright (c) 2016, the Dart project authors. Please see the AUTHORS 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 file. | ||
|
||
import 'package:path/path.dart' as p; | ||
import 'package:scheduled_test/scheduled_test.dart'; | ||
|
||
import '../../descriptor.dart' as d; | ||
import '../../test_pub.dart'; | ||
|
||
main() { | ||
integration('an immutable application sees a file: package config', () { | ||
servePackages((builder) { | ||
builder.serve("bar", "1.0.0"); | ||
|
||
builder.serve("foo", "1.0.0", | ||
deps: {"bar": "1.0.0"}, | ||
contents: [ | ||
d.dir("bin", [ | ||
d.file("script.dart", """ | ||
import 'dart:isolate'; | ||
|
||
main() async { | ||
print(await Isolate.packageRoot); | ||
print(await Isolate.packageConfig); | ||
print(await Isolate.resolvePackageUri( | ||
Uri.parse('package:foo/resource.txt'))); | ||
print(await Isolate.resolvePackageUri( | ||
Uri.parse('package:bar/resource.txt'))); | ||
} | ||
""") | ||
]) | ||
]); | ||
}); | ||
|
||
schedulePub(args: ["global", "activate", "foo"]); | ||
|
||
var pub = pubRun(global: true, args: ["foo:script"]); | ||
|
||
pub.stdout.expect("null"); | ||
|
||
var packageConfigPath = | ||
p.join(sandboxDir, cachePath, "global_packages/foo/.packages"); | ||
pub.stdout.expect(p.toUri(packageConfigPath).toString()); | ||
|
||
schedule(() async { | ||
var fooResourcePath = p.join( | ||
await globalPackageServer.pathInCache('foo', '1.0.0'), | ||
"lib/resource.txt"); | ||
pub.stdout.expect(p.toUri(fooResourcePath).toString()); | ||
}); | ||
|
||
schedule(() async { | ||
var barResourcePath = p.join( | ||
await globalPackageServer.pathInCache('bar', '1.0.0'), | ||
"lib/resource.txt"); | ||
pub.stdout.expect(p.toUri(barResourcePath).toString()); | ||
}); | ||
pub.shouldExit(0); | ||
}); | ||
|
||
integration('a mutable application sees an http: package root', () { | ||
d.dir("foo", [ | ||
d.libPubspec("foo", "1.0.0") | ||
]).create(); | ||
|
||
d.dir(appPath, [ | ||
d.appPubspec({"foo": {"path": "../foo"}}), | ||
d.dir("bin", [ | ||
d.file("script.dart", """ | ||
import 'dart:isolate'; | ||
|
||
main() async { | ||
print(await Isolate.packageRoot); | ||
print(await Isolate.packageConfig); | ||
print(await Isolate.resolvePackageUri( | ||
Uri.parse('package:myapp/resource.txt'))); | ||
print(await Isolate.resolvePackageUri( | ||
Uri.parse('package:foo/resource.txt'))); | ||
} | ||
""") | ||
]) | ||
]).create(); | ||
|
||
schedulePub(args: ["global", "activate", "-s", "path", "."]); | ||
|
||
var pub = pubRun(global: true, args: ["myapp:script"]); | ||
|
||
pub.stdout.expect( | ||
allOf(startsWith("http://localhost:"), endsWith("/packages/"))); | ||
pub.stdout.expect("null"); | ||
pub.stdout.expect(allOf( | ||
startsWith("http://localhost:"), | ||
endsWith("/packages/myapp/resource.txt"))); | ||
pub.stdout.expect(allOf( | ||
startsWith("http://localhost:"), | ||
endsWith("/packages/foo/resource.txt"))); | ||
pub.shouldExit(0); | ||
}); | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
// Copyright (c) 2016, the Dart project authors. Please see the AUTHORS 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 file. | ||
|
||
import 'package:path/path.dart' as p; | ||
import 'package:scheduled_test/scheduled_test.dart'; | ||
|
||
import 'package:pub/src/io.dart'; | ||
|
||
import '../descriptor.dart' as d; | ||
import '../test_pub.dart'; | ||
|
||
final _transformer = """ | ||
import 'dart:async'; | ||
|
||
import 'package:barback/barback.dart'; | ||
|
||
class MyTransformer extends Transformer { | ||
MyTransformer.asPlugin(); | ||
|
||
String get allowedExtensions => '.in'; | ||
|
||
Future apply(Transform transform) async { | ||
transform.addOutput(new Asset.fromString( | ||
transform.primaryInput.id.changeExtension('.txt'), | ||
await transform.primaryInput.readAsString())); | ||
} | ||
} | ||
"""; | ||
|
||
final _script = """ | ||
import 'dart:isolate'; | ||
|
||
main() async { | ||
print(await Isolate.packageRoot); | ||
print(await Isolate.packageConfig); | ||
print(await Isolate.resolvePackageUri( | ||
Uri.parse('package:myapp/resource.txt'))); | ||
print(await Isolate.resolvePackageUri( | ||
Uri.parse('package:foo/resource.txt'))); | ||
} | ||
"""; | ||
|
||
main() { | ||
integration('an untransformed application sees a file: package config', () { | ||
d.dir("foo", [ | ||
d.libPubspec("foo", "1.0.0") | ||
]).create(); | ||
|
||
d.dir(appPath, [ | ||
d.appPubspec({"foo": {"path": "../foo"}}), | ||
d.dir("bin", [ | ||
d.file("script.dart", _script) | ||
]) | ||
]).create(); | ||
|
||
pubGet(); | ||
var pub = pubRun(args: ["bin/script"]); | ||
|
||
pub.stdout.expect("null"); | ||
pub.stdout.expect( | ||
p.toUri(p.join(sandboxDir, "myapp/.packages")).toString()); | ||
pub.stdout.expect( | ||
p.toUri(p.join(sandboxDir, "myapp/lib/resource.txt")).toString()); | ||
pub.stdout.expect( | ||
p.toUri(p.join(sandboxDir, "foo/lib/resource.txt")).toString()); | ||
pub.shouldExit(0); | ||
}); | ||
|
||
integration('a transformed application sees an http: package root', () { | ||
serveBarback(); | ||
|
||
d.dir("foo", [ | ||
d.libPubspec("foo", "1.0.0") | ||
]).create(); | ||
|
||
d.dir(appPath, [ | ||
d.pubspec({ | ||
"name": "myapp", | ||
"transformers": ["myapp/src/transformer"], | ||
"dependencies": {"barback": "any"} | ||
}), | ||
d.dir("lib", [ | ||
d.file("resource.in", "hello!"), | ||
d.dir("src", [ | ||
d.file("transformer.dart", _transformer) | ||
]) | ||
]), | ||
d.dir("bin", [ | ||
d.file("script.dart", _script) | ||
]) | ||
]).create(); | ||
|
||
pubGet(); | ||
var pub = pubRun(args: ["bin/script"]); | ||
|
||
pub.stdout.expect( | ||
allOf(startsWith("http://localhost:"), endsWith("/packages/"))); | ||
pub.stdout.expect("null"); | ||
pub.stdout.expect(allOf( | ||
startsWith("http://localhost:"), | ||
endsWith("/packages/myapp/resource.txt"))); | ||
pub.stdout.expect(allOf( | ||
startsWith("http://localhost:"), | ||
endsWith("/packages/foo/resource.txt"))); | ||
pub.shouldExit(0); | ||
}); | ||
|
||
integration('a snapshotted application sees a file: package root', () { | ||
servePackages((builder) { | ||
builder.serve("foo", "1.0.0", | ||
contents: [ | ||
d.dir("bin", [ | ||
d.file("script.dart", _script) | ||
]) | ||
]); | ||
}); | ||
|
||
d.dir(appPath, [ | ||
d.appPubspec({ | ||
"foo": "any" | ||
}) | ||
]).create(); | ||
|
||
pubGet(output: contains("Precompiled foo:script.")); | ||
|
||
var pub = pubRun(args: ["foo:script"]); | ||
|
||
pub.stdout.expect("null"); | ||
pub.stdout.expect( | ||
p.toUri(p.join(sandboxDir, "myapp/.packages")).toString()); | ||
pub.stdout.expect( | ||
p.toUri(p.join(sandboxDir, "myapp/lib/resource.txt")).toString()); | ||
schedule(() async { | ||
var fooResourcePath = p.join( | ||
await globalPackageServer.pathInCache('foo', '1.0.0'), | ||
"lib/resource.txt"); | ||
pub.stdout.expect(p.toUri(fooResourcePath).toString()); | ||
}); | ||
pub.shouldExit(0); | ||
}); | ||
} |
This file was deleted.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the same string as the above script, right? If so, declare a constant for it. Ideally stick it somewhere that the run/package_api_test can get to it too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. I didn't share it across files, though, because I couldn't think of a nice semantic thing to call it.