diff --git a/test/vm_tests/builder/over_react_builder_test.dart b/test/vm_tests/builder/over_react_builder_test.dart index df99e7cb0..237ace541 100644 --- a/test/vm_tests/builder/over_react_builder_test.dart +++ b/test/vm_tests/builder/over_react_builder_test.dart @@ -112,6 +112,28 @@ main() { 'over_react|test_fixtures/source_files/backwards_compatible/basic_library.over_react.g.dart', '${p.absolute(p.current)}/test_fixtures/gold_output_files/backwards_compatible/basic_library.over_react.g.dart.goldFile'); }); + + test('builds for props mixins', () async { + await checkBuildForFile( + 'over_react|test_fixtures/source_files/backwards_compatible/props_mixin.dart', + 'over_react|test_fixtures/source_files/backwards_compatible/props_mixin.over_react.g.dart', + '${p.absolute(p.current)}/test_fixtures/gold_output_files/backwards_compatible/props_mixin.over_react.g.dart.goldFile'); + }); + + test('builds for state mixins', () async { + await checkBuildForFile( + 'over_react|test_fixtures/source_files/backwards_compatible/state_mixin.dart', + 'over_react|test_fixtures/source_files/backwards_compatible/state_mixin.over_react.g.dart', + '${p.absolute(p.current)}/test_fixtures/gold_output_files/backwards_compatible/state_mixin.over_react.g.dart.goldFile'); + }); + + test('does not produce a build output for just a part file', () async { + var basicAsset = makeAssetId('over_react|test_fixtures/source_files/backwards_compatible/part_of_basic_library.dart'); + await runBuilder(builder, [basicAsset], reader, writerSpy, AnalyzerResolvers(), logger: logger); + + expect(writerSpy.assetsWritten, isEmpty); + verifyNoErrorLogs(); + }); }); group('for Dart 2 only compatible boilerplate:', () { @@ -119,28 +141,28 @@ main() { await checkBuildForFile( 'over_react|test_fixtures/source_files/dart2_only/basic.dart', 'over_react|test_fixtures/source_files/dart2_only/basic.over_react.g.dart', - '${p.absolute(p.current)}/test_fixtures/gold_output_files/basic.over_react.g.dart.goldFile'); + '${p.absolute(p.current)}/test_fixtures/gold_output_files/dart2_only/basic.over_react.g.dart.goldFile'); }); test('builds from basic multi-part library', () async { await checkBuildForFile( 'over_react|test_fixtures/source_files/dart2_only/basic_library.dart', 'over_react|test_fixtures/source_files/dart2_only/basic_library.over_react.g.dart', - '${p.absolute(p.current)}/test_fixtures/gold_output_files/basic_library.over_react.g.dart.goldFile'); + '${p.absolute(p.current)}/test_fixtures/gold_output_files/dart2_only/basic_library.over_react.g.dart.goldFile'); }); test('builds for props mixins', () async { await checkBuildForFile( 'over_react|test_fixtures/source_files/dart2_only/props_mixin.dart', 'over_react|test_fixtures/source_files/dart2_only/props_mixin.over_react.g.dart', - '${p.absolute(p.current)}/test_fixtures/gold_output_files/props_mixin.over_react.g.dart.goldFile'); + '${p.absolute(p.current)}/test_fixtures/gold_output_files/dart2_only/props_mixin.over_react.g.dart.goldFile'); }); test('builds for state mixins', () async { await checkBuildForFile( 'over_react|test_fixtures/source_files/dart2_only/state_mixin.dart', 'over_react|test_fixtures/source_files/dart2_only/state_mixin.over_react.g.dart', - '${p.absolute(p.current)}/test_fixtures/gold_output_files/state_mixin.over_react.g.dart.goldFile'); + '${p.absolute(p.current)}/test_fixtures/gold_output_files/dart2_only/state_mixin.over_react.g.dart.goldFile'); }); test('does not produce a build output for just a part file', () async { @@ -161,20 +183,19 @@ main() { reason: 'Expected a SEVERE log for the missing over_react part.'); }); - group('for Component2:', () { test('builds from basic component file', () async { await checkBuildForFile( 'over_react|test_fixtures/source_files/dart2_only/component2/basic.dart', 'over_react|test_fixtures/source_files/dart2_only/component2/basic.over_react.g.dart', - '${p.absolute(p.current)}/test_fixtures/gold_output_files/component2/basic.over_react.g.dart.goldFile'); + '${p.absolute(p.current)}/test_fixtures/gold_output_files/dart2_only/component2/basic.over_react.g.dart.goldFile'); }); test('builds from basic multi-part library', () async { await checkBuildForFile( 'over_react|test_fixtures/source_files/dart2_only/component2/basic_library.dart', 'over_react|test_fixtures/source_files/dart2_only/component2/basic_library.over_react.g.dart', - '${p.absolute(p.current)}/test_fixtures/gold_output_files/component2/basic_library.over_react.g.dart.goldFile'); + '${p.absolute(p.current)}/test_fixtures/gold_output_files/dart2_only/component2/basic_library.over_react.g.dart.goldFile'); }); }); }); diff --git a/test_fixtures/gold_output_files/README.md b/test_fixtures/gold_output_files/README.md new file mode 100644 index 000000000..d44e8a763 --- /dev/null +++ b/test_fixtures/gold_output_files/README.md @@ -0,0 +1,11 @@ +## Updating golds + +To re-generate the gold files in this directory using the over_react builder, run: +```sh +dart tool/update_gold_output_files.dart +``` + +If that deletes other generated files throughout over_react (which usually only happens after it prompts you about conflicting outputs), you can restore them by running a build: +```sh +dart run build_runner build +``` diff --git a/test_fixtures/gold_output_files/backwards_compatible/props_mixin.over_react.g.dart.goldFile b/test_fixtures/gold_output_files/backwards_compatible/props_mixin.over_react.g.dart.goldFile new file mode 100644 index 000000000..7e4282250 --- /dev/null +++ b/test_fixtures/gold_output_files/backwards_compatible/props_mixin.over_react.g.dart.goldFile @@ -0,0 +1,78 @@ +//@dart=2.11 +// GENERATED CODE - DO NOT MODIFY BY HAND + +// ignore_for_file: deprecated_member_use_from_same_package, unnecessary_null_in_if_null_operators, prefer_null_aware_operators +part of 'props_mixin.dart'; + +// ************************************************************************** +// OverReactBuilder (package:over_react/src/builder.dart) +// ************************************************************************** + +abstract class $ExamplePropsMixinClass implements ExamplePropsMixinClass { + @override + Map get props; + + static const PropsMeta meta = _$metaForExamplePropsMixinClass; + + /// + @override + String get propMixin1 => + (props[_$key__propMixin1__ExamplePropsMixinClass] ?? null) as String; + + /// + @override + set propMixin1(String value) => + props[_$key__propMixin1__ExamplePropsMixinClass] = value; + /* GENERATED CONSTANTS */ + static const PropDescriptor _$prop__propMixin1__ExamplePropsMixinClass = + PropDescriptor(_$key__propMixin1__ExamplePropsMixinClass); + static const String _$key__propMixin1__ExamplePropsMixinClass = + 'ExamplePropsMixinClass.propMixin1'; + + static const List $props = [ + _$prop__propMixin1__ExamplePropsMixinClass + ]; + static const List $propKeys = [ + _$key__propMixin1__ExamplePropsMixinClass + ]; +} + +const PropsMeta _$metaForExamplePropsMixinClass = PropsMeta( + fields: $ExamplePropsMixinClass.$props, + keys: $ExamplePropsMixinClass.$propKeys, +); + +abstract class $MixesInOtherMixinMixin + implements MixesInOtherMixinMixin { + @override + Map get props; + + static const PropsMeta meta = _$metaForMixesInOtherMixinMixin; + + /// + @override + String get otherPropMixin => + (props[_$key__otherPropMixin__MixesInOtherMixinMixin] ?? null) as String; + + /// + @override + set otherPropMixin(String value) => + props[_$key__otherPropMixin__MixesInOtherMixinMixin] = value; + /* GENERATED CONSTANTS */ + static const PropDescriptor _$prop__otherPropMixin__MixesInOtherMixinMixin = + PropDescriptor(_$key__otherPropMixin__MixesInOtherMixinMixin); + static const String _$key__otherPropMixin__MixesInOtherMixinMixin = + 'MixesInOtherMixinMixin.otherPropMixin'; + + static const List $props = [ + _$prop__otherPropMixin__MixesInOtherMixinMixin + ]; + static const List $propKeys = [ + _$key__otherPropMixin__MixesInOtherMixinMixin + ]; +} + +const PropsMeta _$metaForMixesInOtherMixinMixin = PropsMeta( + fields: $MixesInOtherMixinMixin.$props, + keys: $MixesInOtherMixinMixin.$propKeys, +); diff --git a/test_fixtures/gold_output_files/backwards_compatible/state_mixin.over_react.g.dart.goldFile b/test_fixtures/gold_output_files/backwards_compatible/state_mixin.over_react.g.dart.goldFile new file mode 100644 index 000000000..894e12e73 --- /dev/null +++ b/test_fixtures/gold_output_files/backwards_compatible/state_mixin.over_react.g.dart.goldFile @@ -0,0 +1,43 @@ +//@dart=2.11 +// GENERATED CODE - DO NOT MODIFY BY HAND + +// ignore_for_file: deprecated_member_use_from_same_package, unnecessary_null_in_if_null_operators, prefer_null_aware_operators +part of 'state_mixin.dart'; + +// ************************************************************************** +// OverReactBuilder (package:over_react/src/builder.dart) +// ************************************************************************** + +abstract class $ExampleStateMixinClass implements ExampleStateMixinClass { + @override + Map get state; + + static const StateMeta meta = _$metaForExampleStateMixinClass; + + /// + @override + String get stateMixin1 => + (state[_$key__stateMixin1__ExampleStateMixinClass] ?? null) as String; + + /// + @override + set stateMixin1(String value) => + state[_$key__stateMixin1__ExampleStateMixinClass] = value; + /* GENERATED CONSTANTS */ + static const StateDescriptor _$prop__stateMixin1__ExampleStateMixinClass = + StateDescriptor(_$key__stateMixin1__ExampleStateMixinClass); + static const String _$key__stateMixin1__ExampleStateMixinClass = + 'ExampleStateMixinClass.stateMixin1'; + + static const List $state = [ + _$prop__stateMixin1__ExampleStateMixinClass + ]; + static const List $stateKeys = [ + _$key__stateMixin1__ExampleStateMixinClass + ]; +} + +const StateMeta _$metaForExampleStateMixinClass = StateMeta( + fields: $ExampleStateMixinClass.$state, + keys: $ExampleStateMixinClass.$stateKeys, +); diff --git a/test_fixtures/gold_output_files/basic.over_react.g.dart.goldFile b/test_fixtures/gold_output_files/dart2_only/basic.over_react.g.dart.goldFile similarity index 100% rename from test_fixtures/gold_output_files/basic.over_react.g.dart.goldFile rename to test_fixtures/gold_output_files/dart2_only/basic.over_react.g.dart.goldFile diff --git a/test_fixtures/gold_output_files/basic_library.over_react.g.dart.goldFile b/test_fixtures/gold_output_files/dart2_only/basic_library.over_react.g.dart.goldFile similarity index 100% rename from test_fixtures/gold_output_files/basic_library.over_react.g.dart.goldFile rename to test_fixtures/gold_output_files/dart2_only/basic_library.over_react.g.dart.goldFile diff --git a/test_fixtures/gold_output_files/component2/basic.over_react.g.dart.goldFile b/test_fixtures/gold_output_files/dart2_only/component2/basic.over_react.g.dart.goldFile similarity index 100% rename from test_fixtures/gold_output_files/component2/basic.over_react.g.dart.goldFile rename to test_fixtures/gold_output_files/dart2_only/component2/basic.over_react.g.dart.goldFile diff --git a/test_fixtures/gold_output_files/component2/basic_library.over_react.g.dart.goldFile b/test_fixtures/gold_output_files/dart2_only/component2/basic_library.over_react.g.dart.goldFile similarity index 100% rename from test_fixtures/gold_output_files/component2/basic_library.over_react.g.dart.goldFile rename to test_fixtures/gold_output_files/dart2_only/component2/basic_library.over_react.g.dart.goldFile diff --git a/test_fixtures/gold_output_files/dart2_only/missing_over_react_g_part/library.over_react.g.dart.goldFile b/test_fixtures/gold_output_files/dart2_only/missing_over_react_g_part/library.over_react.g.dart.goldFile new file mode 100644 index 000000000..cf674ce48 --- /dev/null +++ b/test_fixtures/gold_output_files/dart2_only/missing_over_react_g_part/library.over_react.g.dart.goldFile @@ -0,0 +1,116 @@ +//@dart=2.11 +// GENERATED CODE - DO NOT MODIFY BY HAND + +// ignore_for_file: deprecated_member_use_from_same_package, unnecessary_null_in_if_null_operators, prefer_null_aware_operators +part of 'library.dart'; + +// ************************************************************************** +// OverReactBuilder (package:over_react/src/builder.dart) +// ************************************************************************** + +// React component factory implementation. +// +// Registers component implementation and links type meta to builder factory. +final $BasicPartOfLibComponentFactory = registerComponent( + () => _$BasicPartOfLibComponent(), + builderFactory: _$BasicPartOfLib, + componentClass: BasicPartOfLibComponent, + isWrapper: false, + parentType: null, +); + +abstract class _$BasicPartOfLibPropsAccessorsMixin + implements _$BasicPartOfLibProps { + @override + Map get props; + + /// + @override + String get basicProp => + (props[_$key__basicProp___$BasicPartOfLibProps] ?? null) as String; + + /// + @override + set basicProp(String value) => + props[_$key__basicProp___$BasicPartOfLibProps] = value; + /* GENERATED CONSTANTS */ + static const PropDescriptor _$prop__basicProp___$BasicPartOfLibProps = + PropDescriptor(_$key__basicProp___$BasicPartOfLibProps); + static const String _$key__basicProp___$BasicPartOfLibProps = + 'BasicPartOfLibProps.basicProp'; + + static const List $props = [ + _$prop__basicProp___$BasicPartOfLibProps + ]; + static const List $propKeys = [ + _$key__basicProp___$BasicPartOfLibProps + ]; +} + +const PropsMeta _$metaForBasicPartOfLibProps = PropsMeta( + fields: _$BasicPartOfLibPropsAccessorsMixin.$props, + keys: _$BasicPartOfLibPropsAccessorsMixin.$propKeys, +); + +class BasicPartOfLibProps extends _$BasicPartOfLibProps + with _$BasicPartOfLibPropsAccessorsMixin { + static const PropsMeta meta = _$metaForBasicPartOfLibProps; +} + +_$$BasicPartOfLibProps _$BasicPartOfLib([Map backingProps]) => + _$$BasicPartOfLibProps(backingProps); + +// Concrete props implementation. +// +// Implements constructor and backing map, and links up to generated component factory. +class _$$BasicPartOfLibProps extends _$BasicPartOfLibProps + with _$BasicPartOfLibPropsAccessorsMixin + implements BasicPartOfLibProps { + // This initializer of `_props` to an empty map, as well as the reassignment + // of `_props` in the constructor body is necessary to work around a DDC bug: https://github.com/dart-lang/sdk/issues/36217 + _$$BasicPartOfLibProps(Map backingMap) : this._props = {} { + this._props = backingMap ?? {}; + } + + /// The backing props map proxied by this class. + @override + Map get props => _props; + Map _props; + + /// Let `UiProps` internals know that this class has been generated. + @override + bool get $isClassGenerated => true; + + /// The `ReactComponentFactory` associated with the component built by this class. + @override + ReactComponentFactoryProxy get componentFactory => + super.componentFactory ?? $BasicPartOfLibComponentFactory; + + /// The default namespace for the prop getters/setters generated for this class. + @override + String get propKeyNamespace => 'BasicPartOfLibProps.'; +} + +// Concrete component implementation mixin. +// +// Implements typed props/state factories, defaults `consumedPropKeys` to the keys +// generated for the associated props class. +class _$BasicPartOfLibComponent extends BasicPartOfLibComponent { + @override + _$$BasicPartOfLibProps typedPropsFactory(Map backingMap) => + _$$BasicPartOfLibProps(backingMap); + + /// Let `UiComponent` internals know that this class has been generated. + @override + bool get $isClassGenerated => true; + + @override + String get displayName => 'BasicPartOfLib'; + + /// The default consumed props, taken from _$BasicPartOfLibProps. + /// Used in `*ConsumedProps` methods if [consumedProps] is not overridden. + @override + final List $defaultConsumedProps = const [ + _$metaForBasicPartOfLibProps + ]; +} diff --git a/test_fixtures/gold_output_files/props_mixin.over_react.g.dart.goldFile b/test_fixtures/gold_output_files/dart2_only/props_mixin.over_react.g.dart.goldFile similarity index 100% rename from test_fixtures/gold_output_files/props_mixin.over_react.g.dart.goldFile rename to test_fixtures/gold_output_files/dart2_only/props_mixin.over_react.g.dart.goldFile diff --git a/test_fixtures/gold_output_files/state_mixin.over_react.g.dart.goldFile b/test_fixtures/gold_output_files/dart2_only/state_mixin.over_react.g.dart.goldFile similarity index 100% rename from test_fixtures/gold_output_files/state_mixin.over_react.g.dart.goldFile rename to test_fixtures/gold_output_files/dart2_only/state_mixin.over_react.g.dart.goldFile diff --git a/test_fixtures/gold_output_files/mixin_based/missing_over_react_g_part/library.over_react.g.dart.goldFile b/test_fixtures/gold_output_files/mixin_based/missing_over_react_g_part/library.over_react.g.dart.goldFile new file mode 100644 index 000000000..196a98a3f --- /dev/null +++ b/test_fixtures/gold_output_files/mixin_based/missing_over_react_g_part/library.over_react.g.dart.goldFile @@ -0,0 +1,188 @@ +//@dart=2.11 +// GENERATED CODE - DO NOT MODIFY BY HAND + +// ignore_for_file: deprecated_member_use_from_same_package, unnecessary_null_in_if_null_operators, prefer_null_aware_operators +part of 'library.dart'; + +// ************************************************************************** +// OverReactBuilder (package:over_react/src/builder.dart) +// ************************************************************************** + +// React component factory implementation. +// +// Registers component implementation and links type meta to builder factory. +@Deprecated('This API is for use only within generated code.' + ' Do not reference it in your code, as it may change at any time.') +final $BasicPartOfLibComponentFactory = registerComponent2( + () => _$BasicPartOfLibComponent(), + builderFactory: _$BasicPartOfLib, + componentClass: BasicPartOfLibComponent, + isWrapper: false, + parentType: null, +); + +_$$BasicPartOfLibProps _$BasicPartOfLib([Map backingProps]) => + backingProps == null + ? _$$BasicPartOfLibProps$JsMap(JsBackedMap()) + : _$$BasicPartOfLibProps(backingProps); + +// Concrete props implementation. +// +// Implements constructor and backing map, and links up to generated component factory. +@Deprecated('This API is for use only within generated code.' + ' Do not reference it in your code, as it may change at any time.') +abstract class _$$BasicPartOfLibProps extends UiProps + with + BasicPartOfLibProps, + // If this generated mixin is undefined, it's likely because BasicPartOfLibProps is not a valid `mixin`-based props mixin, or because it is but the generated mixin was not imported. Check the declaration of BasicPartOfLibProps, and check that $BasicPartOfLibProps is exported/imported properly. + $BasicPartOfLibProps { + _$$BasicPartOfLibProps._(); + + factory _$$BasicPartOfLibProps(Map backingMap) { + if (backingMap == null || backingMap is JsBackedMap) { + return _$$BasicPartOfLibProps$JsMap(backingMap as JsBackedMap); + } else { + return _$$BasicPartOfLibProps$PlainMap(backingMap); + } + } + + /// Let `UiProps` internals know that this class has been generated. + @override + bool get $isClassGenerated => true; + + /// The `ReactComponentFactory` associated with the component built by this class. + @override + ReactComponentFactoryProxy get componentFactory => + super.componentFactory ?? $BasicPartOfLibComponentFactory; + + /// The default namespace for the prop getters/setters generated for this class. + @override + String get propKeyNamespace => ''; + + @override + PropsMetaCollection get staticMeta => const PropsMetaCollection({ + // If this generated mixin is undefined, it's likely because BasicPartOfLibProps is not a valid `mixin`-based props mixin, or because it is but the generated mixin was not imported. Check the declaration of BasicPartOfLibProps, and check that $BasicPartOfLibProps is exported/imported properly. + BasicPartOfLibProps: $BasicPartOfLibProps.meta, + }); +} + +// Concrete props implementation that can be backed by any [Map]. +@Deprecated('This API is for use only within generated code.' + ' Do not reference it in your code, as it may change at any time.') +class _$$BasicPartOfLibProps$PlainMap extends _$$BasicPartOfLibProps { + // This initializer of `_props` to an empty map, as well as the reassignment + // of `_props` in the constructor body is necessary to work around a DDC bug: https://github.com/dart-lang/sdk/issues/36217 + _$$BasicPartOfLibProps$PlainMap(Map backingMap) + : this._props = {}, + super._() { + this._props = backingMap ?? {}; + } + + /// The backing props map proxied by this class. + @override + Map get props => _props; + Map _props; +} + +// Concrete props implementation that can only be backed by [JsMap], +// allowing dart2js to compile more optimal code for key-value pair reads/writes. +@Deprecated('This API is for use only within generated code.' + ' Do not reference it in your code, as it may change at any time.') +class _$$BasicPartOfLibProps$JsMap extends _$$BasicPartOfLibProps { + // This initializer of `_props` to an empty map, as well as the reassignment + // of `_props` in the constructor body is necessary to work around a DDC bug: https://github.com/dart-lang/sdk/issues/36217 + _$$BasicPartOfLibProps$JsMap(JsBackedMap backingMap) + : this._props = JsBackedMap(), + super._() { + this._props = backingMap ?? JsBackedMap(); + } + + /// The backing props map proxied by this class. + @override + JsBackedMap get props => _props; + JsBackedMap _props; +} + +// Concrete component implementation mixin. +// +// Implements typed props/state factories, defaults `consumedPropKeys` to the keys +// generated for the associated props class. +@Deprecated('This API is for use only within generated code.' + ' Do not reference it in your code, as it may change at any time.') +class _$BasicPartOfLibComponent extends BasicPartOfLibComponent { + _$$BasicPartOfLibProps$JsMap _cachedTypedProps; + + @override + _$$BasicPartOfLibProps$JsMap get props => _cachedTypedProps; + + @override + set props(Map value) { + assert( + getBackingMap(value) is JsBackedMap, + 'Component2.props should never be set directly in ' + 'production. If this is required for testing, the ' + 'component should be rendered within the test. If ' + 'that does not have the necessary result, the last ' + 'resort is to use typedPropsFactoryJs.'); + super.props = value; + _cachedTypedProps = + typedPropsFactoryJs(getBackingMap(value) as JsBackedMap); + } + + @override + _$$BasicPartOfLibProps$JsMap typedPropsFactoryJs(JsBackedMap backingMap) => + _$$BasicPartOfLibProps$JsMap(backingMap); + + @override + _$$BasicPartOfLibProps typedPropsFactory(Map backingMap) => + _$$BasicPartOfLibProps(backingMap); + + /// Let `UiComponent` internals know that this class has been generated. + @override + bool get $isClassGenerated => true; + + @override + String get displayName => 'BasicPartOfLib'; + + /// The default consumed props, comprising all props mixins used by BasicPartOfLibProps. + /// Used in `*ConsumedProps` methods if [consumedProps] is not overridden. + @override + get $defaultConsumedProps => propsMeta.all; + + @override + PropsMetaCollection get propsMeta => const PropsMetaCollection({ + // If this generated mixin is undefined, it's likely because BasicPartOfLibProps is not a valid `mixin`-based props mixin, or because it is but the generated mixin was not imported. Check the declaration of BasicPartOfLibProps, and check that $BasicPartOfLibProps is exported/imported properly. + BasicPartOfLibProps: $BasicPartOfLibProps.meta, + }); +} + +@Deprecated('This API is for use only within generated code.' + ' Do not reference it in your code, as it may change at any time.' + ' EXCEPTION: this may be used in legacy boilerplate until' + ' it is transitioned to the new mixin-based boilerplate.') +mixin $BasicPartOfLibProps on BasicPartOfLibProps { + static const PropsMeta meta = _$metaForBasicPartOfLibProps; + @override + String get basicProp => + (props[_$key__basicProp__BasicPartOfLibProps] ?? null) as String; + @override + set basicProp(String value) => + props[_$key__basicProp__BasicPartOfLibProps] = value; + /* GENERATED CONSTANTS */ + static const PropDescriptor _$prop__basicProp__BasicPartOfLibProps = + PropDescriptor(_$key__basicProp__BasicPartOfLibProps); + static const String _$key__basicProp__BasicPartOfLibProps = + 'BasicPartOfLibProps.basicProp'; + + static const List $props = [ + _$prop__basicProp__BasicPartOfLibProps + ]; + static const List $propKeys = [_$key__basicProp__BasicPartOfLibProps]; +} + +@Deprecated('This API is for use only within generated code.' + ' Do not reference it in your code, as it may change at any time.') +const PropsMeta _$metaForBasicPartOfLibProps = PropsMeta( + fields: $BasicPartOfLibProps.$props, + keys: $BasicPartOfLibProps.$propKeys, +); diff --git a/test_fixtures/gold_output_files/mixin_based/two_nine_with_multiple_factories.over_react.g.dart.goldfile b/test_fixtures/gold_output_files/mixin_based/two_nine_with_multiple_factories.over_react.g.dart.goldfile index 3ca3afaab..7176ed98b 100644 --- a/test_fixtures/gold_output_files/mixin_based/two_nine_with_multiple_factories.over_react.g.dart.goldfile +++ b/test_fixtures/gold_output_files/mixin_based/two_nine_with_multiple_factories.over_react.g.dart.goldfile @@ -148,7 +148,7 @@ class _$CounterComponent extends CounterComponent { bool get $isClassGenerated => true; @override - String get displayName => 'Counter'; + String get displayName => '_Counter'; /// The default consumed props, comprising all props mixins used by CounterProps. /// Used in `*ConsumedProps` methods if [consumedProps] is not overridden. diff --git a/tool/update_gold_output_files.dart b/tool/update_gold_output_files.dart new file mode 100644 index 000000000..1e15b4d07 --- /dev/null +++ b/tool/update_gold_output_files.dart @@ -0,0 +1,58 @@ +import 'dart:io'; + +import 'package:glob/glob.dart'; +import 'package:glob/list_local_fs.dart'; +import 'package:path/path.dart' as p; + +final sourceFixturesDir = Directory('test_fixtures/source_files'); +final goldsDir = Directory('test_fixtures/gold_output_files'); + +/// A temporary directory used to generate new golds. +final tmpSourceDir = Directory('test/tmp_test_files'); + +/// Updates gold files in [goldsDir] by re-generating them from a copy of the files in [sourceFixturesDir]. +Future main() async { + print('Copying files from ${sourceFixturesDir.path} to temporary directory ${tmpSourceDir.path}'); + if (tmpSourceDir.existsSync()) tmpSourceDir.deleteSync(recursive: true); + tmpSourceDir.createSync(recursive: true); + for (final file in Glob(p.join(sourceFixturesDir.path, '**')).listSync().whereType()) { + final newPath = p.join(tmpSourceDir.path, p.relative(file.path, from: sourceFixturesDir.path)); + File(newPath).parent.createSync(recursive: true); + file.copySync(newPath); + } + + print('Building files in temporary directory ${tmpSourceDir.path}'); + final buildProcess = await Process.start( + 'dart', ['run', 'build_runner', 'build', '--build-filter=${p.join(tmpSourceDir.path, '**')}'], + mode: ProcessStartMode.inheritStdio); + // Wait for build to complete. + final buildExitCode = await buildProcess.exitCode; + if (buildExitCode != 0) { + stderr.writeln( + '^ Build failures are expected for "missing_over_react_g_part" files, and can be ignored.'); + } + + print('Copying built files to golds directory ${goldsDir.path}'); + final generatedTmpFiles = + Glob(p.join(tmpSourceDir.path, '**.over_react.g.dart')).listSync().whereType().toList(); + if (generatedTmpFiles.isEmpty) { + throw Exception('No generated files were found in ${tmpSourceDir.path}.' + ' Ensure in build.yaml the over_react builder runs on directory with build_to:source'); + } + for (final file in generatedTmpFiles) { + final newPath = + p.join(goldsDir.path, p.relative(file.path, from: tmpSourceDir.path)) + '.goldFile'; + File(newPath).parent.createSync(recursive: true); + file.copySync(newPath); + } + + print('Cleaning up temporary directory ${tmpSourceDir.path}'); + tmpSourceDir.deleteSync(recursive: true); + + print('Done!'); + + print('\nIf non-gold generated files throughout this package got deleted' + ' (which usually only happens after it prompts you about conflicting outputs),' + ' you can restore them by running a build:\n\n' + ' dart run build_runner build'); +}