KS

kevmoo/source_gen_test

开发工具

本页由 AI 翻译,技术细节请以原文为准。 查看原文

20 stars 质量 63 趋势 30MIT

测试 API,以便更容易创建 package:source_gen 生成器的稳健测试

概览

通过注释测试文件,使测试生成器source_gen得以轻松测试。 如果你也想对输出本身写测试,可以用金色输出文件来测试。 使用 cartesianProduct 和 verifyGeneratorBatch 在单个共享 package:analyzer context 和 batched Isolate.spawnUri 运行时通过中,验证大量 AST/声明排列矩阵与生成器或 GeneratorForAnnotation 的对照: package:source_gen_test 捆绑了 source-gen-test-fuzz agent 技能,用于压力测试 Generator 和 GeneratorForAnnotation 实现,支持 CaresianProduct 和 verifyGeneratorBatch。 如果你的软件包依赖于dev_dependencies中的source_gen_test,请用package:skills安装依赖中所有捆绑的技能: 或者直接从 GitHub 安装技能:

概述(AI 翻译)

通过以下方式轻松测试从 package:source_gen 导出的 Generators 注释测试文件。

如果你也想对输出写测试,可以用 golden 输出文件做测试 就是它自己。

还有其他帮手。

组合批验证(verifyGeneratorBatch)

使用 cartesianProduct 和 verifyGeneratorBatch 来验证 的大型矩阵 针对Generator或GeneratorForAnnotation的AST/声明排列。 在单一共享的package:analyzer上下文中,并以批处理的Isolate.spawnUri 运行时间:

AI特工技能(source-gen-test-fuzz)

package:source_gen_test 一捆 source-gen-test-fuzz 特工技能 压力测试 Generator 和 GeneratorForAnnotation 实现 cartesianProduct 和 verifyGeneratorBatch。

如果你的软件包依赖于dev_dependencies中的source_gen_test,请全部安装 将依赖技能捆绑成 package:skills:

或者直接从 GitHub 安装技能:

本页由 AI 翻译,技术细节请以原文为准。

README

Make it easy to test Generators derived from package:source_gen by annotating test files.

@ShouldGenerate(
  r'''
const TestClass1NameLength = 10;

const TestClass1NameLowerCase = 'testclass1';
''',
  configurations: ['default', 'no-prefix-required'],
)
@ShouldThrow(
  'Uh...',
  configurations: ['vague'],
  element: false,
)
@TestAnnotation()
class TestClass1 {}

Test against a golden output file if you also want to write tests on the output itself.

part 'goldens/testclass2.dart';

@ShouldGenerateFile(
  'goldens/testclass2.dart',
  partOfCurrent: true,
  configurations: ['default', 'no-prefix-required'],
)
@ShouldThrow(
  'Uh...',
  configurations: ['vague'],
  element: false,
)
@TestAnnotation()
class TestClass2 {}

Other helpers are also provided.

Combinatorial Batch Verification (verifyGeneratorBatch)

Use cartesianProduct and verifyGeneratorBatch to validate large matrices of AST/declaration permutations against a Generator or GeneratorForAnnotation in a single shared package:analyzer context and batched Isolate.spawnUri runtime pass:

final axes = cartesianProduct({
  'fieldType': ['int', 'int?', 'List'],
  'includeIfNull': ['true', 'false'],
});

final report = await verifyGeneratorBatch(
  generator: MyGenerator(),
  imports: const ["import 'package:my_pkg/annotations.dart';"],
  cases: [
    for (var i = 0; i < axes.length; i++)
      CodegenCase(
        id: 'case_$i',
        declarations: '''
@MyAnnotation(includeIfNull: ${axes[i]['includeIfNull']})
class Case$i {
  final ${axes[i]['fieldType']} value;
  Case$i(this.value);
}
''',
        runtimeCheck: 'final c = Case$i(null);',
      ),
  ],
);

AI Agent Skill (source-gen-test-fuzz)

package:source_gen_test ships a bundled source-gen-test-fuzz agent skill for stress-testing Generator and GeneratorForAnnotation implementations with cartesianProduct and verifyGeneratorBatch.

If your package depends on source_gen_test in dev_dependencies, install all bundled skills from your dependencies with package:skills:

dart run skills@ get

Or install the skill directly from GitHub:

dart run skills@ add kevmoo/source_gen_test --skill source-gen-test-fuzz
# or
npx skills add kevmoo/source_gen_test --skill source-gen-test-fuzz
在 GitHub 查看完整 README

推荐工具

换一个关键词,或者移除筛选条件。

安装

npx skillfish add kevmoo/source_gen_test
新手?先看 mcpskill.org 教程 →