kevmoo / source_gen_test

Test APIs to make it easier to create robust test for package:source_gen Generators
https://pub.dev/packages/source_gen_test
MIT License
19 stars 10 forks source link
dart-build-system

Pub package Build Status package publisher

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.