OLD | NEW |
| (Empty) |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | |
2 // for details. All rights reserved. Use of this source code is governed by a | |
3 // BSD-style license that can be found in the LICENSE file. | |
4 | |
5 /// Collection of utilities which are useful for creating unit tests for | |
6 /// Barback transformers. | |
7 library code_transformers.tests; | |
8 | |
9 import 'dart:async' show Future; | |
10 import 'dart:io' show Platform; | |
11 | |
12 import 'package:barback/barback.dart' show Transformer; | |
13 import 'package:path/path.dart' as path; | |
14 import 'package:unittest/unittest.dart'; | |
15 | |
16 import 'src/test_harness.dart'; | |
17 import 'src/dart_sdk.dart'; | |
18 | |
19 export 'src/test_harness.dart' show StringFormatter; | |
20 | |
21 /// Defines a test which invokes [applyTransformers]. | |
22 testPhases(String testName, List<List<Transformer>> phases, | |
23 Map<String, String> inputs, Map<String, String> results, | |
24 [List<String> messages, | |
25 StringFormatter formatter = StringFormatter.noTrailingWhitespace]) { | |
26 test(testName, () => applyTransformers(phases, | |
27 inputs: inputs, | |
28 results: results, | |
29 messages: messages, | |
30 formatter: formatter)); | |
31 } | |
32 | |
33 /// Updates the provided transformers with [inputs] as asset inputs then | |
34 /// validates that [results] were generated. | |
35 /// | |
36 /// The keys for inputs and results are 'package_name|lib/file.dart'. | |
37 /// Only files which are specified in results are validated. | |
38 /// | |
39 /// If [messages] is non-null then this will validate that only the specified | |
40 /// messages were generated, ignoring info messages. | |
41 Future applyTransformers(List<List<Transformer>> phases, | |
42 {Map<String, String> inputs: const {}, Map<String, String> results: const { | |
43 }, List<String> messages: const [], | |
44 StringFormatter formatter: StringFormatter.noTrailingWhitespace}) { | |
45 var helper = new TestHelper(phases, inputs, messages, formatter: formatter) | |
46 ..run(); | |
47 return helper.checkAll(results).then((_) => helper.tearDown()); | |
48 } | |
49 | |
50 /// Variant of [dartSdkDirectory] which includes additional cases only | |
51 /// typically encountered in Dart's testing environment. | |
52 String get testingDartSdkDirectory { | |
53 var sdkDir = dartSdkDirectory; | |
54 if (sdkDir == null) { | |
55 // If we cannot find the SDK dir, then assume this is being run from Dart's | |
56 // source directory and this script is the main script. | |
57 var segments = path.split(path.fromUri(Platform.script)); | |
58 var index = segments.indexOf('pkg'); | |
59 expect(index, greaterThan(0), | |
60 reason: 'testingDartSdkDirectory is only supported in pkg/ tests'); | |
61 sdkDir = path.joinAll(segments.sublist(0, index)..add('sdk')); | |
62 } | |
63 return sdkDir; | |
64 } | |
OLD | NEW |