Skip to content

Commit

Permalink
Fix concurrency issue
Browse files Browse the repository at this point in the history
Use workaround for dart-lang/build#2634
by @eernstg
  • Loading branch information
nielsenko committed Oct 10, 2022
1 parent 945daca commit 3630924
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
2 changes: 1 addition & 1 deletion generator/lib/src/session.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const _sessionKey = #SessionKey;
// in case multiple libs are processed concurrently, we make session zone local
Session get session => Zone.current[_sessionKey] as Session;

Future<T> scopeSession<T>(
FutureOr<T> scopeSession<T>(
ResolvedLibraryResult resolvedLibrary,
FutureOr<T> Function() fn, {
String? prefix,
Expand Down
22 changes: 16 additions & 6 deletions generator/test/test_util.dart
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,18 @@ class GoldenFileMatcher extends Matcher {
return _matcher.describe(description);
}

@override
Description describeMismatch(
dynamic item,
Description mismatchDescription,
Map<dynamic, dynamic> matchState,
bool verbose,
) =>
_matcher.describeMismatch(item, mismatchDescription, matchState, verbose);

@override
bool matches(dynamic item, Map<dynamic, dynamic> matchState) {
// create golden, if missing
// create golden master, if missing
if (!golden.existsSync()) {
var bytes = <int>[];
if (item is File) {
Expand All @@ -72,19 +81,19 @@ class GoldenFileMatcher extends Matcher {

/// A special equality matcher for strings.
class LinesEqualsMatcher extends Matcher {
late final List<String> expectedLines;
final String expected;

LinesEqualsMatcher(String expected) {
expectedLines = expected.split("\n");
}
LinesEqualsMatcher(this.expected);

@override
Description describe(Description description) => description.add("LinesEqualsMatcher");
Description describe(Description description) => description.add(expected);

@override
// ignore: strict_raw_type
bool matches(dynamic actual, Map matchState) {
final actualValue = utf8.decode(actual as List<int>);

final expectedLines = expected.split("\n");
final actualLines = actualValue.split("\n");

if (actualLines.length > expectedLines.length) {
Expand All @@ -109,6 +118,7 @@ class LinesEqualsMatcher extends Matcher {

@override
Description describeMismatch(dynamic item, Description mismatchDescription, Map matchState, bool verbose) {
mismatchDescription.addDescriptionOf(item).replace(utf8.decode(item as List<int>));
if (matchState["Error"] != null) {
mismatchDescription.add(matchState["Error"] as String);
}
Expand Down

0 comments on commit 3630924

Please sign in to comment.