Skip to content

Commit 62e7c9b

Browse files
authored
[hooks] testBuildHook: Emit output validation errors (#2735)
1 parent 43c5970 commit 62e7c9b

File tree

4 files changed

+61
-2
lines changed

4 files changed

+61
-2
lines changed

pkgs/hooks/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.20.6-wip
2+
3+
- Fix `testBuildHook` to emit output validation errors if there are any.
4+
15
## 0.20.5
26

37
- Document `input.packageRoot` in more places.

pkgs/hooks/lib/src/test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ Future<void> testBuildHook({
106106
];
107107
if (outputErrors.isNotEmpty) {
108108
throw ValidationFailure(
109-
'Encountered build output validation issues: $inputErrors',
109+
'Encountered build output validation issues: $outputErrors',
110110
);
111111
}
112112

pkgs/hooks/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ description: >-
33
A library that contains a Dart API for the JSON-based protocol for
44
`hook/build.dart` and `hook/link.dart`.
55
6-
version: 0.20.5
6+
version: 0.20.6-wip
77

88
repository: https://github.com/dart-lang/native/tree/main/pkgs/hooks
99

pkgs/hooks/test/test_test.dart

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
// Copyright (c) 2025, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
import 'package:code_assets/code_assets.dart';
6+
import 'package:hooks/hooks.dart';
7+
import 'package:hooks/src/validation.dart';
8+
import 'package:test/test.dart';
9+
10+
void main() {
11+
test('throws on output error', () async {
12+
final testResult = testBuildHook(
13+
mainMethod: (args) async {
14+
await build(args, (input, output) async {
15+
output.assets.code.add(
16+
CodeAsset(
17+
package: 'foreign_package',
18+
name: 'foo.dart',
19+
linkMode: DynamicLoadingSystem(Uri.parse('libbrokenstuff.so')),
20+
),
21+
);
22+
});
23+
},
24+
extensions: [
25+
CodeAssetExtension(
26+
targetArchitecture: Architecture.current,
27+
targetOS: OS.current,
28+
linkModePreference: LinkModePreference.preferDynamic,
29+
macOS: OS.current == OS.macOS
30+
? MacOSCodeConfig(targetVersion: 13)
31+
: null,
32+
),
33+
],
34+
check: expectAsync2((_, _) {}, count: 0),
35+
);
36+
37+
expect(
38+
testResult,
39+
throwsA(
40+
isA<ValidationFailure>().having(
41+
(e) => e.message,
42+
'message',
43+
contains(
44+
'output validation issues: [Code asset '
45+
'"package:foreign_package/foo.dart" does not start with '
46+
// We don't know the expected prefix here because this test can be
47+
// run from the hooks package or the workspace. We just want to
48+
// assert some message related to outputs gets thrown.
49+
'"package:',
50+
),
51+
),
52+
),
53+
);
54+
});
55+
}

0 commit comments

Comments
 (0)