testing library

Test helpers for D4rt bridge generator issue reproduction.

This library provides infrastructure for end-to-end testing of bridge generation issues. It creates temporary projects, generates bridges, and optionally executes D4rt scripts to verify issue reproduction.

Usage

import 'package:tom_d4rt_generator/testing.dart';

test('GEN-001: type erasure', () async {
  final result = await runIssueTest(
    issueId: 'GEN-001',
    sourceFiles: {
      'lib/src/my_class.dart': 'class MyClass<T> { ... }',
    },
    barrelContent: "export 'src/my_class.dart';",
    d4rtScript: 'import "package:test_pkg/test_pkg.dart"; main() { ... }',
  );
  expect(result.generatedCode, contains('<dynamic>'));
});

Classes

D4rtTester
Runs D4rt scripts and evaluations with in-memory bridge generation and subprocess-based test execution.
D4rtTestResult
Result of running a D4rt script or eval test via D4rtTester.
IssueTestHelper
Helper for creating end-to-end issue reproduction tests.
IssueTestResult
Result of running an issue test.
ResolutionMismatch
One package a fixture resolves differently from its host.
TestModuleConfig
Configuration for a bridge module in the test project.

Functions

compareFixtureResolution({required String hostProjectPath, required String fixtureProjectPath}) List<ResolutionMismatch>
Packages fixtureProjectPath resolves differently from hostProjectPath, in lock order.
describeMismatches(List<ResolutionMismatch> mismatches) String
A report naming each drifted package, why the fixture's lock governs, and the repair.
findD4rtgenProjects(String root) List<String>
Directories under root whose buildkit.yaml has a d4rtgen: section, relative to root and sorted. .dart_tool and build trees are skipped.
findDartProjects(String root) List<String>
Directories under root that contain a pubspec.yaml, relative to root and sorted. .dart_tool and build trees are skipped.
freshnessRatchetViolation(String project, BridgeFreshness freshness, {required bool knownStale}) String?
What is wrong with project's freshness under the ratchet, or null.
resolutionProblems(String projectPath) List<String>
What is wrong with projectPath's .dart_tool/package_config.json, as read from disk — without running pub. Empty means every package the config names is present.
resolveIfUnresolved(String projectPath) Future<String?>
Makes sure projectPath resolves, and returns what is wrong, or null.
runGenerationTest({required String issueId, String packageName = 'test_pkg', required Map<String, String> sourceFiles, required String barrelContent, TestModuleConfig moduleConfig = const TestModuleConfig(), bool verbose = false}) Future<IssueTestResult>
Convenience function to run only bridge generation (no D4rt execution).
runIssueTest({required String issueId, String packageName = 'test_pkg', required Map<String, String> sourceFiles, required String barrelContent, required String d4rtScript, TestModuleConfig moduleConfig = const TestModuleConfig(), bool verbose = false}) Future<IssueTestResult>
Convenience function to create and run an issue test.