Skip to content

Commit c0b6313

Browse files
authored
Fixes for build_test 3.0.0. (#86)
* Bump SDK version. * Prepare for release as 1.2.0.
1 parent fd03a27 commit c0b6313

14 files changed

+127
-164
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ jobs:
4747
matrix:
4848
# Add macos-latest and/or windows-latest if relevant for this package.
4949
os: [ubuntu-latest]
50-
sdk: [3.4, dev]
50+
sdk: [3.7, dev]
5151
steps:
5252
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
5353
- uses: dart-lang/setup-dart@e51d8e571e22473a2ddebf0ef8a2123f0ab2c02c

CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1-
## 1.1.2-wip
1+
## 1.2.0
22

3+
- Require `build: ^2.5.0`.
4+
- Require `build_test: ^3.2.0`.
5+
- Require `sdk: ^3.7.0`
36
- Fixed some doc comment references.
47

58
## 1.1.1

example/example_generator.dart

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@ import 'src/example_annotation.dart';
77
class ExampleGenerator extends GeneratorForAnnotation<ExampleAnnotation> {
88
final bool requireTestClassPrefix;
99

10-
const ExampleGenerator({
11-
this.requireTestClassPrefix = true,
12-
});
10+
const ExampleGenerator({this.requireTestClassPrefix = true});
1311

1412
@override
1513
Iterable<String> generateForAnnotatedElement(

lib/src/annotations.dart

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ abstract class TestExpectation {
99
final List<String> expectedLogItems;
1010

1111
const TestExpectation._(this.configurations, List<String>? expectedLogItems)
12-
: expectedLogItems = expectedLogItems ?? const [];
12+
: expectedLogItems = expectedLogItems ?? const [];
1313

1414
TestExpectation replaceConfiguration(Iterable<String> newConfiguration);
1515
}
@@ -74,11 +74,11 @@ class ShouldGenerateFile extends TestExpectation {
7474
this.partOfCurrent = false,
7575
Iterable<String>? configurations,
7676
List<String>? expectedLogItems,
77-
}) : assert(
78-
partOf == null || !partOfCurrent,
79-
'Cannot have both partOf and partOfCurrent',
80-
),
81-
super._(configurations, expectedLogItems);
77+
}) : assert(
78+
partOf == null || !partOfCurrent,
79+
'Cannot have both partOf and partOfCurrent',
80+
),
81+
super._(configurations, expectedLogItems);
8282

8383
@override
8484
TestExpectation replaceConfiguration(Iterable<String> newConfiguration) =>
@@ -118,8 +118,8 @@ class ShouldThrow extends TestExpectation {
118118
Object? element = true,
119119
Iterable<String>? configurations,
120120
List<String>? expectedLogItems,
121-
}) : element = element ?? true,
122-
super._(configurations, expectedLogItems);
121+
}) : element = element ?? true,
122+
super._(configurations, expectedLogItems);
123123

124124
@override
125125
TestExpectation replaceConfiguration(Iterable<String> newConfiguration) =>

lib/src/expectation_element.dart

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,8 @@ List<ExpectationElement> genAnnotatedElements(
1010
Set<String> configDefaults,
1111
) {
1212
final allElements = libraryReader.allElements
13-
.where((element) => element.name != null)
14-
.toList(growable: false)
15-
..sort((a, b) => a.name!.compareTo(b.name!));
13+
.where((element) => element.name != null)
14+
.toList(growable: false)..sort((a, b) => a.name!.compareTo(b.name!));
1615

1716
return allElements.expand((element) {
1817
final initialValues = _expectationElements(element).toList();
@@ -21,9 +20,10 @@ List<ExpectationElement> genAnnotatedElements(
2120

2221
final duplicateConfigs = <String>{};
2322

24-
for (var configs in initialValues
25-
.map((e) => e.configurations)
26-
.whereType<Iterable<String>>()) {
23+
for (var configs
24+
in initialValues
25+
.map((e) => e.configurations)
26+
.whereType<Iterable<String>>()) {
2727
if (configs.isEmpty) {
2828
throw InvalidGenerationSourceError(
2929
'`configuration` cannot be empty.',
@@ -123,11 +123,12 @@ ShouldThrow _shouldThrow(DartObject obj) {
123123
);
124124
}
125125

126-
List<String> _expectedLogItems(ConstantReader reader) => reader
127-
.read('expectedLogItems')
128-
.listValue
129-
.map((obj) => obj.toStringValue()!)
130-
.toList();
126+
List<String> _expectedLogItems(ConstantReader reader) =>
127+
reader
128+
.read('expectedLogItems')
129+
.listValue
130+
.map((obj) => obj.toStringValue()!)
131+
.toList();
131132

132133
Set<String>? _configurations(ConstantReader reader) {
133134
final field = reader.read('configurations');

lib/src/generate_for_element.dart

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -47,19 +47,20 @@ Future<String> generateForElement<T>(
4747
var annotation = generator.typeChecker.firstAnnotationOf(element);
4848

4949
if (annotation == null) {
50-
final annotationFromTestLib = element.metadata
51-
.map((ea) => ea.computeConstantValue()!)
52-
.where((obj) {
53-
if (obj.type is InterfaceType) {
54-
final uri = (obj.type as InterfaceType).element.source.uri;
55-
return uri.isScheme('package') &&
56-
uri.pathSegments.first == testPackageName;
57-
}
58-
59-
return false;
60-
})
61-
.where((obj) => obj.type!.element!.name == T.toString())
62-
.toList();
50+
final annotationFromTestLib =
51+
element.metadata
52+
.map((ea) => ea.computeConstantValue()!)
53+
.where((obj) {
54+
if (obj.type is InterfaceType) {
55+
final uri = (obj.type as InterfaceType).element.source.uri;
56+
return uri.isScheme('package') &&
57+
uri.pathSegments.first == testPackageName;
58+
}
59+
60+
return false;
61+
})
62+
.where((obj) => obj.type!.element!.name == T.toString())
63+
.toList();
6364

6465
String msg;
6566
if (annotationFromTestLib.length == 1) {
@@ -99,7 +100,6 @@ Future<String> generateForElement<T>(
99100
return formatter.format(generated);
100101
}
101102

102-
// ignore: subtype_of_sealed_class
103103
class _MockBuildStep extends BuildStep {
104104
@override
105105
dynamic noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation);

lib/src/init_library_reader.dart

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,9 @@ Future<PathAwareLibraryReader> initializeLibraryReaderForDirectory(
1616
String targetLibraryFileName,
1717
) async {
1818
final map = Map.fromEntries(
19-
Directory(sourceDirectory)
20-
.listSync()
21-
.whereType<File>()
22-
.map((f) => MapEntry(p.basename(f.path), f.readAsStringSync())),
19+
Directory(sourceDirectory).listSync().whereType<File>().map(
20+
(f) => MapEntry(p.basename(f.path), f.readAsStringSync()),
21+
),
2322
);
2423

2524
try {
@@ -64,8 +63,9 @@ Future<LibraryReader> initializeLibraryReader(
6463

6564
final targetLibraryAssetId = assetIdForFile(targetLibraryFileName);
6665

67-
final assetMap = contentMap
68-
.map((file, content) => MapEntry(assetIdForFile(file), content));
66+
final assetMap = contentMap.map(
67+
(file, content) => MapEntry(assetIdForFile(file), content),
68+
);
6969

7070
final library = await resolveSources(
7171
assetMap,
@@ -74,6 +74,7 @@ Future<LibraryReader> initializeLibraryReader(
7474
return item.libraryFor(assetId);
7575
},
7676
resolverFor: targetLibraryAssetId,
77+
readAllSourcesFromFilesystem: true,
7778
);
7879

7980
return LibraryReader(library);

lib/src/matchers.dart

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,11 @@ Matcher throwsInvalidGenerationSourceError(
1010
Object? todoMatcher,
1111
Object? elementMatcher,
1212
}) {
13-
var matcher = const TypeMatcher<InvalidGenerationSource>()
14-
.having((e) => e.message, 'message', messageMatcher);
13+
var matcher = const TypeMatcher<InvalidGenerationSource>().having(
14+
(e) => e.message,
15+
'message',
16+
messageMatcher,
17+
);
1518

1619
if (elementMatcher != null) {
1720
matcher = matcher.having((e) => e.element, 'element', elementMatcher);

lib/src/test_annotated_classes.dart

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -104,13 +104,16 @@ List<AnnotatedTest<T>> getAnnotatedClasses<T>(
104104
defaultConfigSet = generators.keys.toSet();
105105
}
106106

107-
final annotatedElements =
108-
genAnnotatedElements(libraryReader, defaultConfigSet);
107+
final annotatedElements = genAnnotatedElements(
108+
libraryReader,
109+
defaultConfigSet,
110+
);
109111

110112
final unusedConfigurations = generators.keys.toSet();
111113
for (var annotatedElement in annotatedElements) {
112-
unusedConfigurations
113-
.removeAll(annotatedElement.expectation.configurations!);
114+
unusedConfigurations.removeAll(
115+
annotatedElement.expectation.configurations!,
116+
);
114117
}
115118
if (unusedConfigurations.isNotEmpty) {
116119
if (unusedConfigurations.contains(_defaultConfigurationName)) {
@@ -184,14 +187,18 @@ List<AnnotatedTest<T>> getAnnotatedClasses<T>(
184187
}
185188

186189
if (mapMissingConfigs.isNotEmpty) {
187-
final elements = mapMissingConfigs.entries.toList()
188-
..sort((a, b) => a.key.compareTo(b.key));
189-
190-
final message = elements.map((e) {
191-
final sortedConfigs =
192-
(e.value.toList()..sort()).map((v) => '"$v"').join(', ');
193-
return '`${e.key}`: $sortedConfigs';
194-
}).join('; ');
190+
final elements =
191+
mapMissingConfigs.entries.toList()
192+
..sort((a, b) => a.key.compareTo(b.key));
193+
194+
final message = elements
195+
.map((e) {
196+
final sortedConfigs = (e.value.toList()..sort())
197+
.map((v) => '"$v"')
198+
.join(', ');
199+
return '`${e.key}`: $sortedConfigs';
200+
})
201+
.join('; ');
195202

196203
throw ArgumentError(
197204
'There are elements defined with configurations with no associated '
@@ -288,10 +295,7 @@ class AnnotatedTest<T> {
288295
File(path).writeAsStringSync(testOutput);
289296
} else {
290297
final content = File(path).readAsStringSync();
291-
expect(
292-
testOutput,
293-
exp.contains ? contains(content) : equals(content),
294-
);
298+
expect(testOutput, exp.contains ? contains(content) : equals(content));
295299
}
296300
} on FileSystemException catch (ex) {
297301
throw TestFailure(
@@ -331,10 +335,7 @@ class AnnotatedTest<T> {
331335
final outputDirectory =
332336
File(p.join(reader.directory, exp.expectedOutputFileName)).parent;
333337

334-
final path = p.relative(
335-
reader.path,
336-
from: outputDirectory.path,
337-
);
338+
final path = p.relative(reader.path, from: outputDirectory.path);
338339
return "part of '$path';\n\n$output";
339340
}
340341

@@ -355,8 +356,11 @@ class AnnotatedTest<T> {
355356
expectedElementName = exp.element as String;
356357
}
357358
// ignore: deprecated_member_use
358-
elementMatcher = const TypeMatcher<Element>()
359-
.having((e) => e.name, 'name', expectedElementName);
359+
elementMatcher = const TypeMatcher<Element>().having(
360+
(e) => e.name,
361+
'name',
362+
expectedElementName,
363+
);
360364
} else if (exp.element == true) {
361365
elementMatcher = isNotNull;
362366
} else {

pubspec.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
name: source_gen_test
2-
version: 1.1.2-wip
2+
version: 1.2.0
33
description: >-
44
Test support for the source_gen package.
55
Includes helpers to make it easy to validate both success and failure cases.
66
repository: https://github.com/kevmoo/source_gen_test
77

88
environment:
9-
sdk: ^3.4.0
9+
sdk: ^3.7.0
1010

1111
dependencies:
1212
analyzer: ">=6.5.0 <8.0.0"
13-
build: ^2.4.1
14-
build_test: ^2.1.7
13+
build: ^2.5.0
14+
build_test: ^3.2.0
1515
dart_style: '>=2.3.7 <4.0.0'
1616
meta: ^1.15.0
1717
path: ^1.9.0

0 commit comments

Comments
 (0)