-
Notifications
You must be signed in to change notification settings - Fork 214
add transformer tests #12
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
Merged
Changes from all commits
Commits
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 hidden or 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 hidden or 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 hidden or 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 |
---|---|---|
|
@@ -16,3 +16,4 @@ dependencies: | |
|
||
dev_dependencies: | ||
test: ^0.12.0 | ||
transformer_test: ^0.1.0 |
This file contains hidden or 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,5 @@ | ||
// 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. | ||
export 'copy_builder.dart'; | ||
export 'generic_builder_transformer.dart'; |
This file contains hidden or 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,30 @@ | ||
// 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 'dart:async'; | ||
|
||
import 'package:build/build.dart'; | ||
|
||
class CopyBuilder implements Builder { | ||
int numCopies; | ||
|
||
CopyBuilder({this.numCopies: 1}); | ||
|
||
Future build(BuildStep buildStep) async { | ||
var ids = declareOutputs(buildStep.input.id); | ||
for (var id in ids) { | ||
buildStep.writeAsString(new Asset(id, buildStep.input.stringContents)); | ||
} | ||
} | ||
|
||
List<AssetId> declareOutputs(AssetId input) { | ||
var outputs = []; | ||
for (int i = 0; i < numCopies; i++) { | ||
outputs.add(_copiedAssetId(input, numCopies == 1 ? null : i)); | ||
} | ||
return outputs; | ||
} | ||
} | ||
|
||
AssetId _copiedAssetId(AssetId inputId, int copyNum) => | ||
inputId.addExtension('.copy${copyNum == null ? '' : '.$copyNum'}'); |
12 changes: 4 additions & 8 deletions
12
test/all_test.dart → test/common/generic_builder_transformer.dart
This file contains hidden or 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 |
---|---|---|
@@ -1,14 +1,10 @@ | ||
// 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:build/build.dart'; | ||
import 'package:test/test.dart'; | ||
|
||
main() { | ||
group('A group of tests', () { | ||
test('First Test', () { | ||
expect(true, isTrue); | ||
}); | ||
}); | ||
class GenericBuilderTransformer extends BuilderTransformer { | ||
final List<Builder> builders; | ||
|
||
GenericBuilderTransformer(this.builders); | ||
} |
This file contains hidden or 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,117 @@ | ||
// 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. | ||
@TestOn('vm') | ||
import 'package:test/test.dart'; | ||
import 'package:transformer_test/utils.dart'; | ||
|
||
import '../common/common.dart'; | ||
|
||
main() { | ||
var singleCopyTransformer = | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider moving the creation of these to a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since they are stateless, I prefer them to be set up just once. |
||
new GenericBuilderTransformer([new CopyBuilder()]); | ||
var multiCopyTransformer = | ||
new GenericBuilderTransformer([new CopyBuilder(numCopies: 2)]); | ||
var singleAndMultiCopyTransformer = new GenericBuilderTransformer( | ||
[new CopyBuilder(), new CopyBuilder(numCopies: 2)]); | ||
|
||
testPhases('single builder, single output', [ | ||
[singleCopyTransformer], | ||
], { | ||
'a|web/a.txt': 'hello', | ||
}, { | ||
'a|web/a.txt.copy': 'hello', | ||
}); | ||
|
||
testPhases('single builder, multiple outputs', [ | ||
[multiCopyTransformer], | ||
], { | ||
'a|web/a.txt': 'hello', | ||
}, { | ||
'a|web/a.txt.copy.0': 'hello', | ||
'a|web/a.txt.copy.1': 'hello', | ||
}); | ||
|
||
testPhases('multiple builders, different outputs', [ | ||
[singleAndMultiCopyTransformer], | ||
], { | ||
'a|web/a.txt': 'hello', | ||
}, { | ||
'a|web/a.txt.copy': 'hello', | ||
'a|web/a.txt.copy.0': 'hello', | ||
'a|web/a.txt.copy.1': 'hello', | ||
}); | ||
|
||
testPhases('multiple builders, same outputs', [ | ||
[ | ||
new GenericBuilderTransformer([new CopyBuilder(), new CopyBuilder()]) | ||
], | ||
], { | ||
'a|web/a.txt': 'hello', | ||
}, {}, [ | ||
_fileExistsError('CopyBuilder', ['a|web/a.txt.copy']), | ||
]); | ||
|
||
testPhases('multiple phases', [ | ||
[singleCopyTransformer], | ||
[multiCopyTransformer], | ||
], { | ||
'a|web/a.txt': 'hello', | ||
}, { | ||
'a|web/a.txt.copy': 'hello', | ||
'a|web/a.txt.copy.0': 'hello', | ||
'a|web/a.txt.copy.1': 'hello', | ||
'a|web/a.txt.copy.copy.0': 'hello', | ||
'a|web/a.txt.copy.copy.1': 'hello', | ||
}); | ||
|
||
testPhases('multiple transformers in the same phase', [ | ||
[singleCopyTransformer, multiCopyTransformer], | ||
], { | ||
'a|web/a.txt': 'hello', | ||
}, { | ||
'a|web/a.txt.copy': 'hello', | ||
'a|web/a.txt.copy.0': 'hello', | ||
'a|web/a.txt.copy.1': 'hello', | ||
}); | ||
|
||
testPhases('cant overwrite files', [ | ||
[singleCopyTransformer] | ||
], { | ||
'a|web/a.txt': 'hello', | ||
'a|web/a.txt.copy': 'hello', | ||
}, {}, [ | ||
_fileExistsError("CopyBuilder", ["a|web/a.txt.copy"]), | ||
]); | ||
|
||
// TODO(jakemac): Skipped because we can't detect this situation today. | ||
// Instead you get a barback error, see | ||
// https://github.com/dart-lang/transformer_test/issues/2 | ||
// | ||
// testPhases('builders in the same phase can\'t output the same file', [ | ||
// [singleCopyTransformer, new GenericBuilderTransformer([new CopyBuilder()])] | ||
// ], { | ||
// 'a|web/a.txt': 'hello', | ||
// }, { | ||
// 'a|web/a.txt.copy': 'hello', | ||
// }, [ | ||
// _fileExistsError("CopyBuilder", ["a|web/a.txt.copy"]), | ||
// ]); | ||
|
||
testPhases('builders in separate phases can\'t output the same file', [ | ||
[singleCopyTransformer], | ||
[singleCopyTransformer], | ||
], { | ||
'a|web/a.txt': 'hello', | ||
}, { | ||
'a|web/a.txt.copy': 'hello', | ||
}, [ | ||
_fileExistsError("CopyBuilder", ["a|web/a.txt.copy"]), | ||
]); | ||
} | ||
|
||
String _fileExistsError(String builder, List<String> files) { | ||
return "error: Builder `Instance of '$builder'` declared outputs " | ||
"`$files` but those files already exist. That build step has been " | ||
"skipped."; | ||
} |
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.
I still think we should be explicit about our (lack of) ordering guarantees here, maybe just as simple as "there are no guarantees about the order in which [Builder]s will be run."
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