|
| 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