-
Notifications
You must be signed in to change notification settings - Fork 224
Configurable package folding #650
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
Show all changes
22 commits
Select commit
Hold shift + click to select a range
f458021
customizable package folding
grouma fd92345
fix null errors
grouma 3490613
fix compact reporter tests
grouma 512d160
remove unecessary async
grouma 5e8e0ec
add test chain tests
grouma 1a45042
fix grammar
grouma 082bb8b
add changelog and configuration details
grouma f2b3e00
merge
grouma ea6db49
doc changes and other minor fixes
grouma 1ddcf6f
check for only one of only or except
grouma 7ebb648
change configuration logic
grouma c1d6b48
sync package resolver
grouma 87ff301
refactor test_chain file
grouma 8de90ce
account for null invoker
grouma 2582c99
more review changes
grouma cd33dc9
more review changes
grouma cab199a
package validation
grouma 70b7342
better validate
grouma 9f7c729
different conditionals
grouma 2d90d0b
more review changes
grouma d1513de
fix style
grouma 0c3dc52
merge and prep for release
grouma 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
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,52 @@ | ||
| // Copyright (c) 2017, 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:stack_trace/stack_trace.dart'; | ||
|
|
||
| import '../backend/invoker.dart'; | ||
| import '../util/stack_trace_mapper.dart'; | ||
|
|
||
| /// Converts [trace] into a Dart stack trace | ||
| StackTraceMapper _mapper; | ||
|
|
||
| /// The list of packages to fold when producing [Chain]s. | ||
| Set<String> _exceptPackages = new Set.from(['test', 'stream_channel']); | ||
|
|
||
| /// If non-empty, all packages not in this list will be folded when producing | ||
| /// [Chain]s. | ||
| Set<String> _onlyPackages = new Set(); | ||
|
|
||
| /// Configure the resources used for test chaining. | ||
| /// | ||
| /// [mapper] is used to convert traces into Dart stack traces. | ||
| /// [exceptPackages] is the list of packages to fold when producing a [Chain]. | ||
| /// [onlyPackages] is the list of packages to keep in a [Chain]. If non-empty, | ||
| /// all packages not in this will be folded. | ||
| void configureTestChaining( | ||
| {StackTraceMapper mapper, | ||
| Set<String> exceptPackages, | ||
| Set<String> onlyPackages}) { | ||
| if (mapper != null) _mapper = mapper; | ||
| if (exceptPackages != null) _exceptPackages = exceptPackages; | ||
| if (onlyPackages != null) _onlyPackages = onlyPackages; | ||
| } | ||
|
|
||
| /// Returns [stackTrace] converted to a [Chain] with all irrelevant frames | ||
| /// folded together. | ||
| /// | ||
| /// If [verbose] is `true`, returns the chain for [stackTrace] unmodified. | ||
| Chain terseChain(StackTrace stackTrace, {bool verbose: false}) { | ||
| var testTrace = _mapper?.mapStackTrace(stackTrace) ?? stackTrace; | ||
| if (verbose) return new Chain.forTrace(testTrace); | ||
| return new Chain.forTrace(testTrace).foldFrames((frame) { | ||
| if (_onlyPackages.isNotEmpty) { | ||
| return !_onlyPackages.contains(frame.package); | ||
| } | ||
| return _exceptPackages.contains(frame.package); | ||
| }, terse: true); | ||
| } | ||
|
|
||
| /// Converts [stackTrace] to a [Chain] following the test's configuration. | ||
| Chain testChain(StackTrace stackTrace) => terseChain(stackTrace, | ||
| verbose: Invoker.current?.liveTest?.test?.metadata?.verboseTrace ?? true); | ||
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
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 |
|---|---|---|
|
|
@@ -21,6 +21,19 @@ import '../configuration.dart'; | |
| import '../configuration/suite.dart'; | ||
| import 'reporters.dart'; | ||
|
|
||
| /// A regular expression matching a Dart identifier. | ||
| /// | ||
| /// This also matches a package name, since they must be Dart identifiers. | ||
| final identifierRegExp = new RegExp(r"[a-zA-Z_]\w*"); | ||
|
|
||
| /// A regular expression matching allowed package names. | ||
| /// | ||
| /// This allows dot-separated valid Dart identifiers. The dots are there for | ||
| /// compatibility with Google's internal Dart packages, but they may not be used | ||
| /// when publishing a package to pub.dartlang.org. | ||
| final _packageName = new RegExp( | ||
| "^${identifierRegExp.pattern}(\\.${identifierRegExp.pattern})*\$"); | ||
|
|
||
| /// Loads configuration information from a YAML file at [path]. | ||
| /// | ||
| /// If [global] is `true`, this restricts the configuration file to only rules | ||
|
|
@@ -74,6 +87,7 @@ class _ConfigurationLoader { | |
| Configuration _loadGlobalTestConfig() { | ||
| var verboseTrace = _getBool("verbose_trace"); | ||
| var chainStackTraces = _getBool("chain_stack_traces"); | ||
| var foldStackFrames = _loadFoldedStackFrames(); | ||
| var jsTrace = _getBool("js_trace"); | ||
|
|
||
| var timeout = _parseValue("timeout", (value) => new Timeout.parse(value)); | ||
|
|
@@ -108,7 +122,9 @@ class _ConfigurationLoader { | |
| jsTrace: jsTrace, | ||
| timeout: timeout, | ||
| presets: presets, | ||
| chainStackTraces: chainStackTraces) | ||
| chainStackTraces: chainStackTraces, | ||
| foldTraceExcept: foldStackFrames["except"], | ||
| foldTraceOnly: foldStackFrames["only"]) | ||
| .merge(_extractPresets/*<PlatformSelector>*/( | ||
| onPlatform, (map) => new Configuration(onPlatform: map))); | ||
|
|
||
|
|
@@ -263,6 +279,44 @@ class _ConfigurationLoader { | |
| excludeTags: excludeTags); | ||
| } | ||
|
|
||
| /// Returns a map representation of the `fold_stack_frames` configuration. | ||
| /// | ||
| /// The key `except` will correspond to the list of packages to fold. | ||
| /// The key `only` will correspond to the list of packages to keep in a | ||
| /// test [Chain]. | ||
|
Member
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. If the map only has string keys, the type annotation should indicate that.
Member
Author
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. Done. |
||
| Map<String, List<String>> _loadFoldedStackFrames() { | ||
| var foldOptionSet = false; | ||
| return _getMap("fold_stack_frames", key: (keyNode) { | ||
| _validate(keyNode, "Must be a string", (value) => value is String); | ||
| _validate(keyNode, 'Must be "only" or "except".', | ||
| (value) => value == "only" || value == "except"); | ||
|
|
||
| if (foldOptionSet) { | ||
| throw new SourceSpanFormatException( | ||
| 'Can only contain one of "only" or "except".', | ||
| keyNode.span, | ||
| _source); | ||
| } | ||
| foldOptionSet = true; | ||
| return keyNode.value; | ||
| }, value: (valueNode) { | ||
| _validate( | ||
| valueNode, | ||
| "Folded packages must be strings.", | ||
| (valueList) => | ||
| valueList is YamlList && | ||
| valueList.every((value) => value is String)); | ||
|
|
||
| _validate( | ||
| valueNode, | ||
| "Invalid package name.", | ||
| (valueList) => | ||
| valueList.every((value) => _packageName.hasMatch(value))); | ||
|
|
||
| return valueNode.value; | ||
| }); | ||
| } | ||
|
|
||
| /// Throws an exception with [message] if [test] returns `false` when passed | ||
| /// [node]'s value. | ||
| void _validate(YamlNode node, String message, bool test(value)) { | ||
|
|
||
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.
Don't forget the copyright header.
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.