|
| 1 | +// Copyright (c) 2016, 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 | +@TestOn('vm') |
| 5 | +import 'package:test/test.dart'; |
| 6 | +import 'package:transformer_test/utils.dart'; |
| 7 | + |
| 8 | +import '../common/common.dart'; |
| 9 | + |
| 10 | +main() { |
| 11 | + var singleCopyTransformer = |
| 12 | + new GenericBuilderTransformer([new CopyBuilder()]); |
| 13 | + var multiCopyTransformer = |
| 14 | + new GenericBuilderTransformer([new CopyBuilder(numCopies: 2)]); |
| 15 | + var singleAndMultiCopyTransformer = new GenericBuilderTransformer( |
| 16 | + [new CopyBuilder(), new CopyBuilder(numCopies: 2)]); |
| 17 | + |
| 18 | + testPhases('single builder, single output', [ |
| 19 | + [singleCopyTransformer], |
| 20 | + ], { |
| 21 | + 'a|web/a.txt': 'hello', |
| 22 | + }, { |
| 23 | + 'a|web/a.txt.copy': 'hello', |
| 24 | + }); |
| 25 | + |
| 26 | + testPhases('single builder, multiple outputs', [ |
| 27 | + [multiCopyTransformer], |
| 28 | + ], { |
| 29 | + 'a|web/a.txt': 'hello', |
| 30 | + }, { |
| 31 | + 'a|web/a.txt.copy.0': 'hello', |
| 32 | + 'a|web/a.txt.copy.1': 'hello', |
| 33 | + }); |
| 34 | + |
| 35 | + testPhases('multiple builders, different outputs', [ |
| 36 | + [singleAndMultiCopyTransformer], |
| 37 | + ], { |
| 38 | + 'a|web/a.txt': 'hello', |
| 39 | + }, { |
| 40 | + 'a|web/a.txt.copy': 'hello', |
| 41 | + 'a|web/a.txt.copy.0': 'hello', |
| 42 | + 'a|web/a.txt.copy.1': 'hello', |
| 43 | + }); |
| 44 | + |
| 45 | + testPhases('multiple builders, same outputs', [ |
| 46 | + [ |
| 47 | + new GenericBuilderTransformer([new CopyBuilder(), new CopyBuilder()]) |
| 48 | + ], |
| 49 | + ], { |
| 50 | + 'a|web/a.txt': 'hello', |
| 51 | + }, {}, [ |
| 52 | + _fileExistsError('CopyBuilder', ['a|web/a.txt.copy']), |
| 53 | + ]); |
| 54 | + |
| 55 | + testPhases('multiple phases', [ |
| 56 | + [singleCopyTransformer], |
| 57 | + [multiCopyTransformer], |
| 58 | + ], { |
| 59 | + 'a|web/a.txt': 'hello', |
| 60 | + }, { |
| 61 | + 'a|web/a.txt.copy': 'hello', |
| 62 | + 'a|web/a.txt.copy.0': 'hello', |
| 63 | + 'a|web/a.txt.copy.1': 'hello', |
| 64 | + 'a|web/a.txt.copy.copy.0': 'hello', |
| 65 | + 'a|web/a.txt.copy.copy.1': 'hello', |
| 66 | + }); |
| 67 | + |
| 68 | + testPhases('multiple transformers in the same phase', [ |
| 69 | + [singleCopyTransformer, multiCopyTransformer], |
| 70 | + ], { |
| 71 | + 'a|web/a.txt': 'hello', |
| 72 | + }, { |
| 73 | + 'a|web/a.txt.copy': 'hello', |
| 74 | + 'a|web/a.txt.copy.0': 'hello', |
| 75 | + 'a|web/a.txt.copy.1': 'hello', |
| 76 | + }); |
| 77 | + |
| 78 | + testPhases('cant overwrite files', [ |
| 79 | + [singleCopyTransformer] |
| 80 | + ], { |
| 81 | + 'a|web/a.txt': 'hello', |
| 82 | + 'a|web/a.txt.copy': 'hello', |
| 83 | + }, {}, [ |
| 84 | + _fileExistsError("CopyBuilder", ["a|web/a.txt.copy"]), |
| 85 | + ]); |
| 86 | + |
| 87 | + // TODO(jakemac): Skipped because we can't detect this situation today. |
| 88 | + // Instead you get a barback error, see |
| 89 | + // https://github.com/dart-lang/transformer_test/issues/2 |
| 90 | + // |
| 91 | + // testPhases('builders in the same phase can\'t output the same file', [ |
| 92 | + // [singleCopyTransformer, new GenericBuilderTransformer([new CopyBuilder()])] |
| 93 | + // ], { |
| 94 | + // 'a|web/a.txt': 'hello', |
| 95 | + // }, { |
| 96 | + // 'a|web/a.txt.copy': 'hello', |
| 97 | + // }, [ |
| 98 | + // _fileExistsError("CopyBuilder", ["a|web/a.txt.copy"]), |
| 99 | + // ]); |
| 100 | + |
| 101 | + testPhases('builders in separate phases can\'t output the same file', [ |
| 102 | + [singleCopyTransformer], |
| 103 | + [singleCopyTransformer], |
| 104 | + ], { |
| 105 | + 'a|web/a.txt': 'hello', |
| 106 | + }, { |
| 107 | + 'a|web/a.txt.copy': 'hello', |
| 108 | + }, [ |
| 109 | + _fileExistsError("CopyBuilder", ["a|web/a.txt.copy"]), |
| 110 | + ]); |
| 111 | +} |
| 112 | + |
| 113 | +String _fileExistsError(String builder, List<String> files) { |
| 114 | + return "error: Builder `Instance of '$builder'` declared outputs " |
| 115 | + "`$files` but those files already exist. That build step has been " |
| 116 | + "skipped."; |
| 117 | +} |
0 commit comments