Skip to content

Remove test phases #4101

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

Draft
wants to merge 18 commits into
base: master
Choose a base branch
from
1 change: 1 addition & 0 deletions build_runner_core/lib/src/asset_graph/graph_loader.dart
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ class AssetGraphLoader {
final enabledExperimentsChanged =
cachedGraph.enabledExperiments != enabledExperiments.build();
if (buildPhasesChanged || pkgVersionsChanged || enabledExperimentsChanged) {
buildLog.debug('${buildPhases.digest} ${cachedGraph.buildPhasesDigest}');
buildLog.fullBuildBecause(FullBuildReason.incompatibleBuild);
await Future.wait([
writer.delete(assetGraphId),
Expand Down
1 change: 1 addition & 0 deletions build_runner_core/lib/src/generate/build_phases.dart
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ class BuildPhases {
inBuildPhases.length + (postBuildPhase.builderActions.isEmpty ? 0 : 1);

static Digest _computeDigest(Iterable<BuildPhase> phases) {
buildLog.debug(phases.toString());
final digestSink = AccumulatorSink<Digest>();
md5.startChunkedConversion(digestSink)
..add(phases.map((phase) => phase.identity).toList())
Expand Down
29 changes: 8 additions & 21 deletions build_runner_core/test/generate/build_configuration_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,20 @@

import 'package:_test_common/common.dart';
import 'package:build/build.dart';
import 'package:build_runner_core/build_runner_core.dart';
import 'package:test/test.dart';

void main() {
test('uses builder options', () async {
Builder copyBuilder(BuilderOptions options) => TestBuilder(
buildExtensions: replaceExtension(
options.config['inputExtension'] as String,
options.config['inputExtension'] as String? ?? '',
'.copy',
),
name: 'a:optioned_builder',
);

await testPhases(
[
apply('a:optioned_builder', [copyBuilder], toRoot(), hideOutput: false),
],
await testBuilderFactories(
[copyBuilder],
{
'a|lib/file.nomatch': 'a',
'a|lib/file.matches': 'b',
Expand All @@ -32,6 +30,7 @@ targets:
inputExtension: .matches
''',
},
testingBuilderConfig: false,
outputs: {'a|lib/file.copy': 'b'},
);
});
Expand All @@ -43,22 +42,10 @@ targets:
options.isRoot ? '.root.copy' : '.dep.copy',
),
);
var packageGraph = buildPackageGraph({
rootPackage('a'): ['b'],
package('b'): [],
});
await testPhases(
[
apply(
'a:optioned_builder',
[copyBuilder],
toAllPackages(),
hideOutput: true,
),
],
await testBuilderFactories(
[copyBuilder],
{'a|lib/a.txt': 'a', 'b|lib/b.txt': 'b'},
outputs: {r'$$a|lib/a.root.copy': 'a', r'$$b|lib/b.dep.copy': 'b'},
packageGraph: packageGraph,
outputs: {r'a|lib/a.root.copy': 'a', r'b|lib/b.dep.copy': 'b'},
);
});
}
142 changes: 64 additions & 78 deletions build_runner_core/test/generate/build_error_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,130 +26,116 @@ void main() {
});

test('should fail if a severe logged', () async {
await testPhases(
[applyToRoot(_LoggingBuilder(Level.SEVERE))],
{'a|lib/a.dart': ''},
packageGraph: buildPackageGraph({rootPackage('a'): []}),
checkBuildStatus: true,
status: BuildStatus.failure,
outputs: {'a|lib/a.dart.empty': ''},
expect(
(await testBuilders(
[_LoggingBuilder(Level.SEVERE)],
{'a|lib/a.dart': ''},
outputs: {'a|lib/a.dart.empty': ''},
)).buildResult.status,
BuildStatus.failure,
);
});

test('should fail if a severe was logged on a previous build', () async {
var packageGraph = buildPackageGraph({rootPackage('a'): []});
var builder = _LoggingBuilder(Level.SEVERE);
var builders = [applyToRoot(builder)];
final result = await testPhases(
builders,
var result = await testBuilders(
[_LoggingBuilder(Level.SEVERE)],
{'a|lib/a.dart': ''},
packageGraph: packageGraph,
checkBuildStatus: true,
status: BuildStatus.failure,
outputs: {'a|lib/a.dart.empty': ''},
);
await testPhases(
builders,
{},
resumeFrom: result,
packageGraph: packageGraph,
checkBuildStatus: true,
status: BuildStatus.failure,
outputs: {},
expect(result.buildResult.status, BuildStatus.failure);

final builder = _LoggingBuilder(Level.SEVERE);
result = await testBuilders(
[builder],
{'a|lib/a.dart': ''},
// Resume from the previous builld.
readerWriter: result.readerWriter,
outputs: {'a|lib/a.dart.empty': ''},
);
expect(result.buildResult.status, BuildStatus.failure);
// Should have failed without actually building again.
expect(builder.built, false);
});

test(
'should succeed if a severe log is fixed on a subsequent build',
() async {
var packageGraph = buildPackageGraph({rootPackage('a'): []});
var builder = _LoggingBuilder(Level.SEVERE);
var builders = [applyToRoot(builder)];
final result = await testPhases(
builders,
var result = await testBuilders(
[_LoggingBuilder(Level.SEVERE)],
{'a|lib/a.dart': ''},
packageGraph: packageGraph,
checkBuildStatus: true,
status: BuildStatus.failure,
outputs: {'a|lib/a.dart.empty': ''},
);
builder.level = Level.WARNING;
await testPhases(
builders,
expect(result.buildResult.status, BuildStatus.failure);

result = await testBuilders(
[_LoggingBuilder(Level.WARNING)],
{'a|lib/a.dart': 'changed'},
resumeFrom: result,
packageGraph: packageGraph,
checkBuildStatus: true,
status: BuildStatus.success,
// Resume from the previous builld.
readerWriter: result.readerWriter,
outputs: {'a|lib/a.dart.empty': ''},
);
expect(result.buildResult.status, BuildStatus.success);
},
);

test('should fail if an exception is thrown', () async {
await testPhases(
[
applyToRoot(
TestBuilder(build: (_, _) => throw Exception('Some build failure')),
),
],
{'a|lib/a.txt': ''},
packageGraph: buildPackageGraph({rootPackage('a'): []}),
status: BuildStatus.failure,
expect(
(await testBuilders(
[TestBuilder(build: (_, _) => throw Exception('Some build failure'))],
{'a|lib/a.txt': ''},
)).buildResult.status,
BuildStatus.failure,
);
});

test(
'should throw an exception if a read is attempted on a failed file',
() async {
await testPhases(
final result = await testBuilders(
[
applyToRoot(
TestBuilder(
buildExtensions: replaceExtension('.txt', '.failed'),
build: (buildStep, _) async {
await buildStep.writeAsString(
buildStep.inputId.changeExtension('.failed'),
'failed',
);
log.severe('Wrote an output then failed');
},
),
TestBuilder(
buildExtensions: replaceExtension('.txt', '.failed'),
build: (buildStep, _) async {
await buildStep.writeAsString(
buildStep.inputId.changeExtension('.failed'),
'failed',
);
log.severe('Wrote an output then failed');
},
),
applyToRoot(
TestBuilder(
buildExtensions: replaceExtension('.txt', '.success'),
build: expectAsync2((buildStep, _) async {
// Attempts to read the file that came from a failing build step
// and hides the exception.
var failedFile = buildStep.inputId.changeExtension('.failed');
await expectLater(
buildStep.readAsString(failedFile),
throwsA(anything),
);
await buildStep.writeAsString(
buildStep.inputId.changeExtension('.success'),
'success',
);
}),
),
TestBuilder(
buildExtensions: replaceExtension('.txt', '.success'),
build: expectAsync2((buildStep, _) async {
// Attempts to read the file that came from a failing build step
// and hides the exception.
var failedFile = buildStep.inputId.changeExtension('.failed');
await expectLater(
buildStep.readAsString(failedFile),
throwsA(anything),
);
await buildStep.writeAsString(
buildStep.inputId.changeExtension('.success'),
'success',
);
}),
),
],
{'a|lib/a.txt': ''},
packageGraph: buildPackageGraph({rootPackage('a'): []}),
status: BuildStatus.failure,
);
expect(result.buildResult.status, BuildStatus.failure);
},
);
}

class _LoggingBuilder implements Builder {
Level level;
bool built = false;

_LoggingBuilder(this.level);

@override
Future<void> build(BuildStep buildStep) async {
built = true;
log.log(level, buildStep.inputId.toString());
await buildStep.canRead(buildStep.inputId);
await buildStep.writeAsString(buildStep.inputId.addExtension('.empty'), '');
Expand Down
Loading
Loading