Index: sdk/lib/_internal/pub/test/transformer/cache_test.dart |
diff --git a/sdk/lib/_internal/pub/test/transformer/cache_test.dart b/sdk/lib/_internal/pub/test/transformer/cache_test.dart |
new file mode 100644 |
index 0000000000000000000000000000000000000000..2c16c8901a66a2e676e7b7c2f58e6f4588d0925b |
--- /dev/null |
+++ b/sdk/lib/_internal/pub/test/transformer/cache_test.dart |
@@ -0,0 +1,207 @@ |
+// Copyright (c) 2014, the Dart project authors. Please see the AUTHORS d.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. |
+ |
+library pub_tests; |
+ |
+import 'package:scheduled_test/scheduled_test.dart'; |
+ |
+import '../descriptor.dart' as d; |
+import '../test_pub.dart'; |
+import '../serve/utils.dart'; |
+ |
+// TODO(nweiz): Currently scheduled_test.setUp doesn't play well with test_pub, |
+// since it only assigns the sandbox directory once the main test body has |
+// run. Fix this and move this to a real setUp call. |
+void setUp() { |
+ servePackages((builder) { |
+ builder.serveRepoPackage('barback'); |
+ |
+ builder.serve("foo", "1.2.3", |
+ deps: {'barback': 'any'}, |
+ contents: [ |
+ d.dir("lib", [ |
+ d.file("transformer.dart", replaceTransformer("Hello", "Goodbye")) |
+ ]) |
+ ]); |
+ |
+ builder.serve("bar", "1.2.3", |
+ deps: {'barback': 'any'}, |
+ contents: [ |
+ d.dir("lib", [ |
+ d.file("transformer.dart", replaceTransformer("Goodbye", "See ya")) |
+ ]) |
+ ]); |
+ }); |
+ |
+ d.dir(appPath, [ |
+ d.pubspec({ |
+ "name": "myapp", |
+ "dependencies": { |
+ "foo": "1.2.3", |
+ "bar": "1.2.3" |
+ }, |
+ "transformers": ["foo"] |
+ }), |
+ d.dir("bin", [ |
+ d.file("myapp.dart", "main() => print('Hello!');") |
+ ]) |
+ ]).create(); |
+ |
+ pubGet(); |
+} |
+ |
+main() { |
+ initConfig(); |
+ |
+ integration("caches a transformer snapshot", () { |
+ setUp(); |
+ |
+ var process = pubRun(args: ['myapp']); |
+ process.stdout.expect("Goodbye!"); |
+ process.shouldExit(); |
+ |
+ d.dir(appPath, [ |
+ d.dir(".pub/transformers/release", [ |
+ d.file("manifest.txt", "0.1.2+3\nfoo"), |
+ d.matcherFile("phase1.snapshot", isNot(isEmpty)) |
+ ]) |
+ ]).validate(); |
+ |
Bob Nystrom
2014/09/10 17:58:10
Document running again to make sure running the sn
nweiz
2014/09/10 23:30:13
Done.
|
+ process = pubRun(args: ['myapp']); |
+ process.stdout.expect("Goodbye!"); |
+ process.shouldExit(); |
+ }); |
+ |
+ integration("recaches if the SDK version is out-of-date", () { |
+ setUp(); |
+ |
+ d.dir(appPath, [ |
+ d.dir(".pub/transformers/release", [ |
+ // The version 0.0.1 is different than the test version 0.1.2+3. |
+ d.file("manifest.txt", "0.0.1\nfoo"), |
+ d.file("phase1.snapshot", "junk") |
+ ]) |
+ ]).create(); |
+ |
+ var process = pubRun(args: ['myapp']); |
+ process.stdout.expect("Goodbye!"); |
+ process.shouldExit(); |
+ |
+ d.dir(appPath, [ |
+ d.dir(".pub/transformers/release", [ |
+ d.file("manifest.txt", "0.1.2+3\nfoo"), |
+ d.matcherFile("phase1.snapshot", isNot(isEmpty)) |
+ ]) |
+ ]).validate(); |
+ |
+ process = pubRun(args: ['myapp']); |
+ process.stdout.expect("Goodbye!"); |
+ process.shouldExit(); |
Bob Nystrom
2014/09/10 17:58:10
I don't think it's worth re-running here.
nweiz
2014/09/10 23:30:13
Done.
|
+ }); |
+ |
+ integration("recaches if the phase changes", () { |
+ setUp(); |
+ |
+ var process = pubRun(args: ['myapp']); |
+ process.stdout.expect("Goodbye!"); |
+ process.shouldExit(); |
+ |
+ d.dir(appPath, [ |
+ d.dir(".pub/transformers/release", [ |
+ d.file("manifest.txt", "0.1.2+3\nfoo"), |
+ d.matcherFile("phase1.snapshot", isNot(isEmpty)) |
+ ]) |
+ ]).validate(); |
+ |
+ d.dir(appPath, [ |
+ d.pubspec({ |
+ "name": "myapp", |
+ "dependencies": { |
+ "foo": "1.2.3", |
+ "bar": "1.2.3" |
+ }, |
+ "transformers": ["foo", "bar"] |
+ }), |
+ d.dir("bin", [ |
+ d.file("myapp.dart", "main() => print('Hello!');") |
+ ]) |
+ ]).create(); |
+ |
+ process = pubRun(args: ['myapp']); |
+ process.stdout.expect("See ya!"); |
+ process.shouldExit(); |
+ |
+ d.dir(appPath, [ |
+ d.dir(".pub/transformers/release", [ |
+ d.file("manifest.txt", "0.1.2+3\nbar,foo"), |
+ d.matcherFile("phase1.snapshot", isNot(isEmpty)) |
+ ]) |
+ ]).validate(); |
+ }); |
+ |
+ integration("URL-escapes a custom mode", () { |
+ setUp(); |
+ |
+ pubServe(args: ["--mode", "weird/custom mode", "bin"]); |
+ requestShouldSucceed("myapp.dart", "main() => print('Goodbye!');", |
+ root: 'bin'); |
+ endPubServe(); |
+ |
+ d.dir(appPath, [ |
+ d.dir(".pub/transformers/weird%2Fcustom%20mode", [ |
+ d.file("manifest.txt", "0.1.2+3\nfoo"), |
+ d.matcherFile("phase1.snapshot", isNot(isEmpty)) |
+ ]) |
+ ]).validate(); |
+ }); |
+ |
+ solo_integration("removes an unused phase snapshot", () { |
Bob Nystrom
2014/09/10 17:58:10
Oopsie!
nweiz
2014/09/10 23:30:13
Done.
|
+ setUp(); |
+ |
+ var process = pubRun(args: ['myapp']); |
+ process.stdout.expect("Goodbye!"); |
+ process.shouldExit(); |
+ |
+ d.dir(appPath, [ |
+ d.dir(".pub/transformers/release", [ |
+ // Add a phase2 snapshot that's unused. This should get deleted when we |
+ // run again. |
+ d.file("manifest.txt", "0.1.2+3\nfoo\nbar"), |
+ d.file("phase2.snapshot", "junk") |
+ ]) |
+ ]).create(); |
+ |
+ process = pubRun(args: ['myapp']); |
+ process.stdout.expect("Goodbye!"); |
+ process.shouldExit(); |
+ |
+ d.dir(appPath, [ |
+ d.dir(".pub/transformers/release", [ |
+ d.nothing("phase2.snapshot") |
+ ]) |
+ ]).validate(); |
+ }); |
+} |
+ |
+String replaceTransformer(String input, String output) { |
+ return """ |
+import 'dart:async'; |
+ |
+import 'package:barback/barback.dart'; |
+ |
+class ReplaceTransformer extends Transformer { |
+ ReplaceTransformer.asPlugin(); |
+ |
+ String get allowedExtensions => '.dart'; |
+ |
+ Future apply(Transform transform) { |
+ return transform.primaryInput.readAsString().then((contents) { |
+ transform.addOutput(new Asset.fromString( |
+ transform.primaryInput.id, |
+ contents.replaceAll("$input", "$output"))); |
+ }); |
+ } |
+} |
+"""; |
+} |