[checks_codegen] Generate full field types with imports (#2781) Generated getters referenced the field type by the name of its element only, so type arguments were never imported and function typed fields were skipped entirely. Imports were also searched only among the test library's direct imports, so types reached by the checked class through a re-export fell back to `src/` libraries or uncompilable `dart:_*` SDK libraries. First walk the checked classes and their field types to collect every referenced interface element and resolve an import URI for each, then emit type references synchronously from the analyzer `DartType`: - Interface types import the library for each element, including within type arguments. - Function types, including generic function types with bounds, and record types are emitted structurally. - `dynamic`, `void`, and `Never` are emitted directly. - Type parameters of the checked class are replaced with their bounds by reading getter types from the class instantiated to bounds. The extension is on the raw type, so this matches the static type of `v.field`. - Unresolvable types (`InvalidType`) fail naming the class and field, with a source span on the field and a hint to check for a missing build dependency. Function typed fields now get getters. Fields without a getter, such as those introduced by a lone setter, are skipped. Import resolution searches for a library exporting each non-public-SDK element in order: 1. The imports of the test library. 2. The imports of every library declaring a referenced element. 3. For elements declared in `dart:_*` libraries, public SDK libraries: first those reachable through imports and exports from the test and declaring libraries (so e.g. `HttpStatus` prefers `dart:io` over `dart:html` in a VM program), then any remaining public SDK libraries, each sorted by URI. The first two groups prefer libraries outside `src/`. If no library exports an element, fall back to its declaring library (which may be in `src/`), or fail if that is a `dart:_*` library. Note on conditional directives: `build_runner` resolves code with empty `DeclaredVariables`, so conditional `import`/`export` directives always follow their default URI during codegen, never an `if (dart.library.*)` branch. When a barrel conditionally exports `src/` implementations, codegen now imports the barrel rather than the default `src/` stub, so test compilation evaluates the condition for the target platform. When a declaring library uses a conditional `import` directly, codegen still sees only the default branch: a stub default yields the stub's types as before, while an IO default exposing types like `HttpHeaders` or `HttpStatus` now emits `dart:io` (compiling on VM, instead of emitting `dart:_http`/`dart:_internal` which failed everywhere) but still will not compile for web unless the test library imports a compatible exporter.
Welcome! package:test is the standard testing library for Dart and Flutter. If you have questions about Dart testing, please see the docs for package:test. package:test_api and package:test_core are implementation details and generally not user-facing.
package:checks is a relatively new library for expressing test expectations. It's a more modern version of package:matcher and features a literate API.
| Package | Description | Issues | Version |
|---|---|---|---|
| checks | A framework for checking values against expectations and building custom expectations. | ||
| fake_async | Fake asynchronous events such as timers and microtasks for deterministic testing. | ||
| matcher | Support for specifying test expectations via an extensible Matcher class. Also includes a number of built-in Matcher implementations for common cases. | ||
| test | A full featured library for writing and running Dart tests across platforms. | ||
| test_api | The user facing API for structuring Dart tests and checking expectations. | ||
| test_core | A basic library for writing tests and running them on the VM. | ||
| test_descriptor | An API for defining and verifying files and directory structures. | ||
| test_process | Test processes: starting; validating stdout and stderr; checking exit code. |