From 59ad70865a5a9c704029d59763e7326fbd7b1c64 Mon Sep 17 00:00:00 2001 From: Marcel Ploch Date: Fri, 6 Jan 2023 16:14:09 +0100 Subject: [PATCH 1/7] Update to have optional path --- examples/envied_example/.env | 2 +- examples/envied_example/.env.test | 5 +++++ examples/envied_example/build.yaml | 7 +++++++ packages/envied_generator/lib/builder.dart | 2 +- packages/envied_generator/lib/src/generator.dart | 14 +++++++++++++- 5 files changed, 27 insertions(+), 3 deletions(-) create mode 100644 examples/envied_example/.env.test create mode 100644 examples/envied_example/build.yaml diff --git a/examples/envied_example/.env b/examples/envied_example/.env index e72d17e..b149ee7 100644 --- a/examples/envied_example/.env +++ b/examples/envied_example/.env @@ -1,2 +1,2 @@ KEY1=VALUE1 -KEY2=VALUE2 \ No newline at end of file +KEY2=VALUE2 diff --git a/examples/envied_example/.env.test b/examples/envied_example/.env.test new file mode 100644 index 0000000..de41a38 --- /dev/null +++ b/examples/envied_example/.env.test @@ -0,0 +1,5 @@ +KEY1=DEBUG1 +KEY2=DEBUG2 +key3=DEBUG3 +key4=1 +key5=true \ No newline at end of file diff --git a/examples/envied_example/build.yaml b/examples/envied_example/build.yaml new file mode 100644 index 0000000..98b7bd7 --- /dev/null +++ b/examples/envied_example/build.yaml @@ -0,0 +1,7 @@ +targets: + $default: + builders: + envied_generator|envied: + options: + path: .env.test + override: true \ No newline at end of file diff --git a/packages/envied_generator/lib/builder.dart b/packages/envied_generator/lib/builder.dart index 7d55579..da3bdd1 100644 --- a/packages/envied_generator/lib/builder.dart +++ b/packages/envied_generator/lib/builder.dart @@ -6,4 +6,4 @@ import 'package:source_gen/source_gen.dart'; /// Primary builder to build the generated code from the `EnviedGenerator` Builder enviedBuilder(BuilderOptions options) => - SharedPartBuilder([EnviedGenerator()], 'envied'); + SharedPartBuilder([EnviedGenerator(options.config)], 'envied'); diff --git a/packages/envied_generator/lib/src/generator.dart b/packages/envied_generator/lib/src/generator.dart index 6498050..36b6a64 100644 --- a/packages/envied_generator/lib/src/generator.dart +++ b/packages/envied_generator/lib/src/generator.dart @@ -14,6 +14,10 @@ import 'package:source_gen/source_gen.dart'; /// Will throw an [InvalidGenerationSourceError] if the annotated /// element is not a [classElement]. class EnviedGenerator extends GeneratorForAnnotation { + final Map _buildYamlConfigs; + + EnviedGenerator(this._buildYamlConfigs); + @override Future generateForAnnotatedElement( Element element, @@ -28,8 +32,16 @@ class EnviedGenerator extends GeneratorForAnnotation { ); } + var path = annotation.read('path').literalValue as String?; + if (_buildYamlConfigs['override'] && _buildYamlConfigs['path'] != '') { + log.info('Taking options from config options'); + path = _buildYamlConfigs['path']; + } + + log.info(path); + final config = Envied( - path: annotation.read('path').literalValue as String?, + path: path, requireEnvFile: annotation.read('requireEnvFile').literalValue as bool? ?? false, name: annotation.read('name').literalValue as String?, From 16eb8dca841aacfb3fd81d9d76d6ac2505826d84 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Klemen=20Tu=C5=A1ar?= Date: Tue, 28 Nov 2023 22:51:23 +0000 Subject: [PATCH 2/7] :twisted_rightwards_arrows: resolve merge conflicts --- examples/envied_example/pubspec.lock | 4 ++-- packages/envied_generator/lib/src/generator.dart | 10 ++++------ .../envied_generator/test/envy_generator_test.dart | 2 +- 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/examples/envied_example/pubspec.lock b/examples/envied_example/pubspec.lock index b1dbef8..f36c524 100644 --- a/examples/envied_example/pubspec.lock +++ b/examples/envied_example/pubspec.lock @@ -167,14 +167,14 @@ packages: path: "../../packages/envied" relative: true source: path - version: "0.5.1" + version: "0.5.2" envied_generator: dependency: "direct dev" description: path: "../../packages/envied_generator" relative: true source: path - version: "0.5.1" + version: "0.5.2" file: dependency: transitive description: diff --git a/packages/envied_generator/lib/src/generator.dart b/packages/envied_generator/lib/src/generator.dart index a783b8c..eb5984b 100644 --- a/packages/envied_generator/lib/src/generator.dart +++ b/packages/envied_generator/lib/src/generator.dart @@ -37,13 +37,11 @@ final class EnviedGenerator extends GeneratorForAnnotation { ); } - String? path = annotation.read('path').literalValue as String?; - if (_buildYamlConfigs['override'] && _buildYamlConfigs['path'] != '') { - path = _buildYamlConfigs['path']; - } - final Envied config = Envied( - path: path, + path: (_buildYamlConfigs['override'] as bool?) == true && + (_buildYamlConfigs['path'] as String?)?.isNotEmpty == true + ? _buildYamlConfigs['path'] as String? + : annotation.read('path').literalValue as String?, requireEnvFile: annotation.read('requireEnvFile').literalValue as bool? ?? false, name: annotation.read('name').literalValue as String?, diff --git a/packages/envied_generator/test/envy_generator_test.dart b/packages/envied_generator/test/envy_generator_test.dart index 831ea05..f4ac24f 100644 --- a/packages/envied_generator/test/envy_generator_test.dart +++ b/packages/envied_generator/test/envy_generator_test.dart @@ -13,6 +13,6 @@ Future main() async { testAnnotatedElements( reader, - EnviedGenerator(), + EnviedGenerator({}), ); } From 4fdca334fe63e8a4f2e6eea85cf7c6d6e9091f00 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Klemen=20Tu=C5=A1ar?= Date: Tue, 28 Nov 2023 23:14:25 +0000 Subject: [PATCH 3/7] :recycle: refactor code --- packages/envied_generator/lib/builder.dart | 11 ++++++-- .../lib/src/build_options.dart | 27 +++++++++++++++++++ .../envied_generator/lib/src/generator.dart | 11 ++++---- .../test/envy_generator_test.dart | 6 ++--- 4 files changed, 44 insertions(+), 11 deletions(-) create mode 100644 packages/envied_generator/lib/src/build_options.dart diff --git a/packages/envied_generator/lib/builder.dart b/packages/envied_generator/lib/builder.dart index da3bdd1..fdf75f1 100644 --- a/packages/envied_generator/lib/builder.dart +++ b/packages/envied_generator/lib/builder.dart @@ -2,8 +2,15 @@ library envied.builder; import 'package:build/build.dart'; import 'package:envied_generator/envied_generator.dart'; +import 'package:envied_generator/src/build_options.dart'; import 'package:source_gen/source_gen.dart'; /// Primary builder to build the generated code from the `EnviedGenerator` -Builder enviedBuilder(BuilderOptions options) => - SharedPartBuilder([EnviedGenerator(options.config)], 'envied'); +Builder enviedBuilder(BuilderOptions options) => SharedPartBuilder( + [ + EnviedGenerator( + BuildOptions.fromMap(options.config), + ) + ], + 'envied', + ); diff --git a/packages/envied_generator/lib/src/build_options.dart b/packages/envied_generator/lib/src/build_options.dart new file mode 100644 index 0000000..ac7411c --- /dev/null +++ b/packages/envied_generator/lib/src/build_options.dart @@ -0,0 +1,27 @@ +/// Represents the options passed to the build runner via build.yaml. +/// +/// For example +/// +/// ```yaml +/// targets: +/// $default: +/// builders: +/// envied_generator|envied: +/// options: +/// path: .env.test +/// override: true +/// ``` +class BuildOptions { + const BuildOptions({ + this.override, + this.path, + }); + + final String? path; + final bool? override; + + factory BuildOptions.fromMap(Map map) => BuildOptions( + override: map['override'] as bool?, + path: map['path'] as String?, + ); +} diff --git a/packages/envied_generator/lib/src/generator.dart b/packages/envied_generator/lib/src/generator.dart index eb5984b..dc3a4fb 100644 --- a/packages/envied_generator/lib/src/generator.dart +++ b/packages/envied_generator/lib/src/generator.dart @@ -8,6 +8,7 @@ import 'package:build/build.dart'; import 'package:code_builder/code_builder.dart'; import 'package:dart_style/dart_style.dart'; import 'package:envied/envied.dart'; +import 'package:envied_generator/src/build_options.dart'; import 'package:envied_generator/src/generate_field.dart'; import 'package:envied_generator/src/generate_field_encrypted.dart'; import 'package:envied_generator/src/load_envs.dart'; @@ -19,9 +20,9 @@ import 'package:source_gen/source_gen.dart'; /// Will throw an [InvalidGenerationSourceError] if the annotated /// element is not a [classElement]. final class EnviedGenerator extends GeneratorForAnnotation { - const EnviedGenerator(this._buildYamlConfigs); + const EnviedGenerator(this._buildOptions); - final Map _buildYamlConfigs; + final BuildOptions _buildOptions; @override Future generateForAnnotatedElement( @@ -38,9 +39,9 @@ final class EnviedGenerator extends GeneratorForAnnotation { } final Envied config = Envied( - path: (_buildYamlConfigs['override'] as bool?) == true && - (_buildYamlConfigs['path'] as String?)?.isNotEmpty == true - ? _buildYamlConfigs['path'] as String? + path: _buildOptions.override == true && + _buildOptions.path?.isNotEmpty == true + ? _buildOptions.path : annotation.read('path').literalValue as String?, requireEnvFile: annotation.read('requireEnvFile').literalValue as bool? ?? false, diff --git a/packages/envied_generator/test/envy_generator_test.dart b/packages/envied_generator/test/envy_generator_test.dart index f4ac24f..f02e285 100644 --- a/packages/envied_generator/test/envy_generator_test.dart +++ b/packages/envied_generator/test/envy_generator_test.dart @@ -1,4 +1,5 @@ import 'package:envied_generator/envied_generator.dart'; +import 'package:envied_generator/src/build_options.dart'; import 'package:source_gen_test/source_gen_test.dart'; Future main() async { @@ -11,8 +12,5 @@ Future main() async { // print(Platform.environment['SYSTEM_VAR']); - testAnnotatedElements( - reader, - EnviedGenerator({}), - ); + testAnnotatedElements(reader, EnviedGenerator(BuildOptions.fromMap({}))); } From dd9cafffbedce8fd7b73b0d56fade61587ff2e8f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Klemen=20Tu=C5=A1ar?= Date: Tue, 28 Nov 2023 23:23:06 +0000 Subject: [PATCH 4/7] :recycle: refactor code --- packages/envied_generator/test/envy_generator_test.dart | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/envied_generator/test/envy_generator_test.dart b/packages/envied_generator/test/envy_generator_test.dart index f02e285..57fc7e3 100644 --- a/packages/envied_generator/test/envy_generator_test.dart +++ b/packages/envied_generator/test/envy_generator_test.dart @@ -12,5 +12,8 @@ Future main() async { // print(Platform.environment['SYSTEM_VAR']); - testAnnotatedElements(reader, EnviedGenerator(BuildOptions.fromMap({}))); + testAnnotatedElements( + reader, + EnviedGenerator(BuildOptions.fromMap({})), + ); } From 1351dd9ad076f8bd16b24b4f22fb7d1fd07c8610 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Klemen=20Tu=C5=A1ar?= Date: Tue, 28 Nov 2023 23:41:25 +0000 Subject: [PATCH 5/7] :white_check_mark: add path override tests --- .../test/.env.example_with_path_override | 21 + .../test/envy_generator_test.dart | 26 +- .../generator_tests_with_path_override.dart | 1089 +++++++++++++++++ 3 files changed, 1130 insertions(+), 6 deletions(-) create mode 100644 packages/envied_generator/test/.env.example_with_path_override create mode 100644 packages/envied_generator/test/src/generator_tests_with_path_override.dart diff --git a/packages/envied_generator/test/.env.example_with_path_override b/packages/envied_generator/test/.env.example_with_path_override new file mode 100644 index 0000000..9d0ee45 --- /dev/null +++ b/packages/envied_generator/test/.env.example_with_path_override @@ -0,0 +1,21 @@ +test_string=test_string +testString=testString +TEST_STRING=TEST_STRING +testInt=123 +TEST_INT=123 +testDouble=1.23 +testNum=1.23 +TEST_DOUBLE=1.23 +TEST_BOOL=true +testBool=true +testDynamic=123abc +TEST_DYNAMIC=123_ABC +testUrl=https://foo.bar/baz +emptyTestUrl= +invalidTestUrl="::Not valid URI::" +testDateTime=2023-11-06T22:32:55.287Z +invalidTestDateTime=2023-11-06X22:32:55.287Z +testDate=2023-11-06 +invalidTestDate=2023 +testEnum=ipsum +invalidTestEnum=foo \ No newline at end of file diff --git a/packages/envied_generator/test/envy_generator_test.dart b/packages/envied_generator/test/envy_generator_test.dart index 57fc7e3..9ab4863 100644 --- a/packages/envied_generator/test/envy_generator_test.dart +++ b/packages/envied_generator/test/envy_generator_test.dart @@ -5,15 +5,29 @@ import 'package:source_gen_test/source_gen_test.dart'; Future main() async { // for annotated elements initializeBuildLogTracking(); - final reader = await initializeLibraryReaderForDirectory( - 'test/src', - 'generator_tests.dart', - ); // print(Platform.environment['SYSTEM_VAR']); testAnnotatedElements( - reader, - EnviedGenerator(BuildOptions.fromMap({})), + await initializeLibraryReaderForDirectory( + 'test/src', + 'generator_tests.dart', + ), + EnviedGenerator( + const BuildOptions(), + ), + ); + + testAnnotatedElements( + await initializeLibraryReaderForDirectory( + 'test/src', + 'generator_tests_with_path_override.dart', + ), + EnviedGenerator( + const BuildOptions( + path: 'test/.env.example_with_path_override', + override: true, + ), + ), ); } diff --git a/packages/envied_generator/test/src/generator_tests_with_path_override.dart b/packages/envied_generator/test/src/generator_tests_with_path_override.dart new file mode 100644 index 0000000..4e39da2 --- /dev/null +++ b/packages/envied_generator/test/src/generator_tests_with_path_override.dart @@ -0,0 +1,1089 @@ +// ignore_for_file: unnecessary_nullable_for_final_variable_declarations + +import 'dart:io'; + +import 'package:envied/envied.dart'; +import 'package:source_gen_test/annotations.dart'; + +import 'example_enum.dart'; + +@ShouldThrow('`@Envied` can only be used on classes.') +@Envied() +const foo = 'bar'; + +@ShouldGenerate(''' +// coverage:ignore-file +// ignore_for_file: type=lint +final class _Env0 {} +''') +@Envied() +abstract class Env0 {} + +@ShouldGenerate(''' +// coverage:ignore-file +// ignore_for_file: type=lint +final class _Env1 {} +''') +@Envied(requireEnvFile: true) +abstract class Env1 {} + +@ShouldThrow('Environment variable not found for field `foo`.') +@Envied() +abstract class Env2 { + @EnviedField() + static const dynamic foo = null; +} + +@ShouldThrow( + 'Envied requires types to be explicitly declared. `foo` does not declare a type.', +) +@Envied() +abstract class Env2b { + @EnviedField() + // ignore: undefined_class + static final Foo foo = null; +} + +@ShouldThrow( + 'Envied can only handle types such as `int`, `double`, `num`, `bool`, `Uri`, `DateTime`, `Enum` and `String`. Type `File` is not one of them.', +) +@Envied(allowOptionalFields: true) +abstract class Env2c { + @EnviedField() + static const File? foo = null; +} + +@ShouldThrow( + 'Obfuscated envied can only handle types such as `int`, `double`, `num`, `bool`, `Uri`, `DateTime`, `Enum` and `String`. Type `File` is not one of them.', +) +@Envied(allowOptionalFields: true) +abstract class Env2d { + @EnviedField(obfuscate: true) + static const File? foo = null; +} + +@ShouldThrow( + 'Envied can only handle types such as `int`, `double`, `num`, `bool`, `Uri`, `DateTime`, `Enum` and `String`. Type `Symbol` is not one of them.', +) +@Envied() +abstract class Env3 { + @EnviedField() + static const Symbol? testString = null; +} + +@ShouldThrow('Type `int` does not align with value `testString`.') +@Envied() +abstract class Env4 { + @EnviedField() + static const int? testString = null; +} + +@ShouldThrow('Type `double` does not align with value `testString`.') +@Envied() +abstract class Env5 { + @EnviedField() + static const double? testString = null; +} + +@ShouldThrow('Type `num` does not align with value `testString`.') +@Envied() +abstract class Env6 { + @EnviedField() + static const num? testString = null; +} + +@ShouldThrow('Type `bool` does not align with value `testString`.') +@Envied() +abstract class Env7 { + @EnviedField() + static const bool? testString = null; +} + +@ShouldGenerate(''' +// coverage:ignore-file +// ignore_for_file: type=lint +final class _Env8 { + static const String testString = 'testString'; + + static const int testInt = 123; + + static const double testDouble = 1.23; + + static const bool testBool = true; + + static const testDynamic = '123abc'; +} +''') +@Envied() +abstract class Env8 { + @EnviedField() + static const String? testString = null; + @EnviedField() + static const int? testInt = null; + @EnviedField() + static const double? testDouble = null; + @EnviedField() + static const bool? testBool = null; + @EnviedField() + static const testDynamic = null; +} + +@ShouldGenerate(''' +// coverage:ignore-file +// ignore_for_file: type=lint +final class _Env8b { + static const String? testString = 'testString'; + + static const int? testInt = 123; + + static const double? testDouble = 1.23; + + static const bool? testBool = true; + + static const testDynamic = '123abc'; +} +''') +@Envied(allowOptionalFields: true) +abstract class Env8b { + @EnviedField() + static const String? testString = null; + @EnviedField() + static const int? testInt = null; + @EnviedField() + static const double? testDouble = null; + @EnviedField() + static const bool? testBool = null; + @EnviedField() + static const testDynamic = null; +} + +@ShouldGenerate(''' +// coverage:ignore-file +// ignore_for_file: type=lint +final class _Env9 { + static const String testString = 'test_string'; +} +''') +@Envied() +abstract class Env9 { + @EnviedField(varName: 'test_string') + static const String? testString = null; +} + +@ShouldGenerate(''' +// coverage:ignore-file +// ignore_for_file: type=lint +final class _Env9b { + static const String? testString = 'test_string'; +} +''') +@Envied(allowOptionalFields: true) +abstract class Env9b { + @EnviedField(varName: 'test_string') + static const String? testString = null; +} + +@ShouldGenerate(''' +// coverage:ignore-file +// ignore_for_file: type=lint +final class _Env10 { + static const String systemVar = 'system_var'; +} +''') +@Envied() +abstract class Env10 { + @EnviedField(varName: 'SYSTEM_VAR') + static const String? systemVar = null; +} + +@ShouldGenerate(''' +// coverage:ignore-file +// ignore_for_file: type=lint +final class _Env10b { + static const String? systemVar = 'system_var'; +} +''') +@Envied(allowOptionalFields: true) +abstract class Env10b { + @EnviedField(varName: 'SYSTEM_VAR') + static const String? systemVar = null; +} + +@ShouldGenerate(''' +// coverage:ignore-file +// ignore_for_file: type=lint +final class _Foo { + static const String testString = 'test_string'; +} +''') +@Envied(name: 'Foo') +abstract class Env11 { + @EnviedField(varName: 'test_string') + static const String? testString = null; +} + +@ShouldGenerate(''' +// coverage:ignore-file +// ignore_for_file: type=lint +final class _Foo { + static const String? testString = 'test_string'; +} +''') +@Envied(name: 'Foo', allowOptionalFields: true) +abstract class Env11b { + @EnviedField(varName: 'test_string') + static const String? testString = null; +} + +@ShouldGenerate('static const List _enviedkeytestString', contains: true) +@ShouldGenerate('static const List _envieddatatestString', contains: true) +@ShouldGenerate(''' + static final String testString = String.fromCharCodes(List.generate( + _envieddatatestString.length, + (int i) => i, + growable: false, + ).map((int i) => _envieddatatestString[i] ^ _enviedkeytestString[i])); +''', contains: true) +@Envied(obfuscate: true) +abstract class Env12 { + @EnviedField() + static const String? testString = null; +} + +@ShouldGenerate('static const List _enviedkeytestString', contains: true) +@ShouldGenerate('static const List _envieddatatestString', contains: true) +@ShouldGenerate(''' + static final String? testString = String.fromCharCodes(List.generate( + _envieddatatestString.length, + (int i) => i, + growable: false, + ).map((int i) => _envieddatatestString[i] ^ _enviedkeytestString[i])); +''', contains: true) +@Envied(obfuscate: true, allowOptionalFields: true) +abstract class Env12b { + @EnviedField() + static const String? testString = null; +} + +@ShouldGenerate('static const List _enviedkeytestString', contains: true) +@ShouldGenerate('static const List _envieddatatestString', contains: true) +@ShouldGenerate(''' + static final String testString = String.fromCharCodes(List.generate( + _envieddatatestString.length, + (int i) => i, + growable: false, + ).map((int i) => _envieddatatestString[i] ^ _enviedkeytestString[i])); +''', contains: true) +@Envied(obfuscate: false) +abstract class Env13 { + @EnviedField(obfuscate: true) + static const String? testString = null; +} + +@ShouldGenerate('static const List _enviedkeytestString', contains: true) +@ShouldGenerate('static const List _envieddatatestString', contains: true) +@ShouldGenerate(''' + static final String? testString = String.fromCharCodes(List.generate( + _envieddatatestString.length, + (int i) => i, + growable: false, + ).map((int i) => _envieddatatestString[i] ^ _enviedkeytestString[i])); +''', contains: true) +@Envied(obfuscate: false, allowOptionalFields: true) +abstract class Env13b { + @EnviedField(obfuscate: true) + static const String? testString = null; +} + +@ShouldThrow('Environment variable not found for field `testDefaultParam`.') +@Envied() +abstract class Env14 { + @EnviedField(defaultValue: null) + static const String? testDefaultParam = null; +} + +@ShouldGenerate(''' +// coverage:ignore-file +// ignore_for_file: type=lint +final class _Env14b { + static const String? testDefaultParam = null; +} +''') +@Envied(allowOptionalFields: true) +abstract class Env14b { + @EnviedField(defaultValue: null) + static const String? testDefaultParam = null; +} + +@ShouldGenerate(''' +// coverage:ignore-file +// ignore_for_file: type=lint +final class _Env15 { + static const String testDefaultParam = 'test_'; + + static const String testString = 'testString'; + + static const int testInt = 123; + + static const double testDouble = 1.23; + + static const bool testBool = true; + + static const testDynamic = '123abc'; +} +''') +@Envied() +abstract class Env15 { + @EnviedField(defaultValue: 'test_') + static const String? testDefaultParam = null; + @EnviedField() + static const String testString = 'testString'; + @EnviedField() + static const int testInt = 123; + @EnviedField() + static const double testDouble = 1.23; + @EnviedField() + static const bool testBool = true; + @EnviedField() + static const dynamic testDynamic = '123abc'; +} + +@ShouldGenerate(''' +// coverage:ignore-file +// ignore_for_file: type=lint +final class _Env15b { + static const String? testDefaultParam = 'test_'; + + static const String testString = 'testString'; + + static const int testInt = 123; + + static const double testDouble = 1.23; + + static const bool testBool = true; +} +''') +@Envied(allowOptionalFields: true) +abstract class Env15b { + @EnviedField(defaultValue: 'test_') + static const String? testDefaultParam = null; + @EnviedField() + static const String testString = 'testString'; + @EnviedField() + static const int testInt = 123; + @EnviedField() + static const double testDouble = 1.23; + @EnviedField() + static const bool testBool = true; +} + +@ShouldGenerate(''' +// coverage:ignore-file +// ignore_for_file: type=lint +final class _Env16 { + static const String testDefaultParam = 'test_'; +} +''') +@Envied() +abstract class Env16 { + @EnviedField(defaultValue: 'test_') + static const String? testDefaultParam = null; +} + +@ShouldGenerate(''' +// coverage:ignore-file +// ignore_for_file: type=lint +final class _Env16b { + static const String? testDefaultParam = 'test_'; +} +''') +@Envied(allowOptionalFields: true) +abstract class Env16b { + @EnviedField(defaultValue: 'test_') + static const String? testDefaultParam = null; +} + +@ShouldGenerate('static const List _enviedkeytestString', contains: true) +@ShouldGenerate('static const List _envieddatatestString', contains: true) +@ShouldGenerate(''' + static final String testString = String.fromCharCodes(List.generate( + _envieddatatestString.length, + (int i) => i, + growable: false, + ).map((int i) => _envieddatatestString[i] ^ _enviedkeytestString[i])); +''', contains: true) +@Envied(obfuscate: true) +abstract class Env17 { + @EnviedField(defaultValue: 'test_') + static const String? testString = null; +} + +@ShouldGenerate('static const List _enviedkeytestString', contains: true) +@ShouldGenerate('static const List _envieddatatestString', contains: true) +@ShouldGenerate(''' + static final String? testString = String.fromCharCodes(List.generate( + _envieddatatestString.length, + (int i) => i, + growable: false, + ).map((int i) => _envieddatatestString[i] ^ _enviedkeytestString[i])); +''', contains: true) +@Envied(obfuscate: true, allowOptionalFields: true) +abstract class Env17b { + @EnviedField(defaultValue: 'test_') + static const String? testString = null; +} + +@ShouldGenerate('static const List _enviedkeytestString', contains: true) +@ShouldGenerate('static const List _envieddatatestString', contains: true) +@ShouldGenerate(''' + static final String testString = String.fromCharCodes(List.generate( + _envieddatatestString.length, + (int i) => i, + growable: false, + ).map((int i) => _envieddatatestString[i] ^ _enviedkeytestString[i])); +''', contains: true) +@Envied(obfuscate: false) +abstract class Env18 { + @EnviedField(obfuscate: true) + static const String testString = "test_"; +} + +@ShouldGenerate('static const List _enviedkeytestString', contains: true) +@ShouldGenerate('static const List _envieddatatestString', contains: true) +@ShouldGenerate(''' + static final String? testString = String.fromCharCodes(List.generate( + _envieddatatestString.length, + (int i) => i, + growable: false, + ).map((int i) => _envieddatatestString[i] ^ _enviedkeytestString[i])); +''', contains: true) +@Envied(obfuscate: false, allowOptionalFields: true) +abstract class Env18b { + @EnviedField(obfuscate: true, defaultValue: 'test_') + static const String? testString = null; +} + +@ShouldGenerate('static const List _enviedkeytestString', contains: true) +@ShouldGenerate('static const List _envieddatatestString', contains: true) +@ShouldGenerate(''' + static final String? testString = String.fromCharCodes(List.generate( + _envieddatatestString.length, + (int i) => i, + growable: false, + ).map((int i) => _envieddatatestString[i] ^ _enviedkeytestString[i])); +''', contains: true) +@Envied(obfuscate: false, allowOptionalFields: true) +abstract class Env18c { + @EnviedField(obfuscate: true) + static const String? testString = null; +} + +@ShouldGenerate('static final int _enviedkeytestInt', contains: true) +@ShouldGenerate( + 'static final int testInt = _enviedkeytestInt ^', + contains: true, +) +@Envied() +abstract class Env19 { + @EnviedField(obfuscate: true) + static const int testInt = 123; +} + +@ShouldGenerate('static final int _enviedkeytestInt', contains: true) +@ShouldGenerate( + 'static final int? testInt = _enviedkeytestInt ^', + contains: true, +) +@Envied(allowOptionalFields: true) +abstract class Env19b { + @EnviedField(obfuscate: true) + static const int? testInt = 123; +} + +@ShouldGenerate('static final bool _enviedkeytestBool', contains: true) +@ShouldGenerate( + 'static final bool testBool = _enviedkeytestBool ^', + contains: true, +) +@Envied() +abstract class Env20 { + @EnviedField(obfuscate: true) + static const bool testBool = true; +} + +@ShouldGenerate('static final bool _enviedkeytestBool', contains: true) +@ShouldGenerate( + 'static final bool? testBool = _enviedkeytestBool ^', + contains: true, +) +@Envied(allowOptionalFields: true) +abstract class Env20b { + @EnviedField(obfuscate: true) + static const bool? testBool = true; +} + +@ShouldGenerate('static const List _enviedkeytestDynamic', contains: true) +@ShouldGenerate('static const List _envieddatatestDynamic', contains: true) +@ShouldGenerate(''' + static final testDynamic = String.fromCharCodes(List.generate( + _envieddatatestDynamic.length, + (int i) => i, + growable: false, + ).map((int i) => _envieddatatestDynamic[i] ^ _enviedkeytestDynamic[i])); +''', contains: true) +@Envied() +abstract class Env21 { + @EnviedField(obfuscate: true) + static const dynamic testDynamic = '123abc'; +} + +@ShouldThrow( + 'Obfuscated envied can only handle types such as `int`, `double`, `num`, `bool`, `Uri`, `DateTime` and `String`. Type `Symbol` is not one of them.', +) +@Envied() +abstract class Env22 { + @EnviedField(obfuscate: true) + static const Symbol? testString = null; +} + +@ShouldThrow('Type `int` does not align with value `testString`.') +@Envied() +abstract class Env23 { + @EnviedField(obfuscate: true) + static const int? testString = null; +} + +@ShouldThrow('Type `bool` does not align with value `testString`.') +@Envied() +abstract class Env24 { + @EnviedField(obfuscate: true) + static const bool? testString = null; +} + +@ShouldThrow('Environment variable not found for field `foo`.') +@Envied() +abstract class Env25 { + @EnviedField(obfuscate: true) + static const dynamic foo = null; +} + +@ShouldGenerate(''' + static final foo = null; +''', contains: true) +@Envied(allowOptionalFields: true) +abstract class Env25b { + @EnviedField(obfuscate: true) + static const dynamic foo = null; +} + +@ShouldGenerate(''' +// coverage:ignore-file +// ignore_for_file: type=lint +final class _Env26 { + static final String? foo = null; +} +''') +@Envied(allowOptionalFields: true) +abstract class Env26 { + @EnviedField(obfuscate: true) + static const String? foo = null; +} + +@ShouldGenerate(''' +// coverage:ignore-file +// ignore_for_file: type=lint +final class _Env27 { + static final int? foo = null; +} +''') +@Envied(allowOptionalFields: true) +abstract class Env27 { + @EnviedField(obfuscate: true) + static const int? foo = null; +} + +@ShouldGenerate(''' +// coverage:ignore-file +// ignore_for_file: type=lint +final class _Env28 { + static final bool? foo = null; +} +''') +@Envied(allowOptionalFields: true) +abstract class Env28 { + @EnviedField(obfuscate: true) + static const bool? foo = null; +} + +@ShouldGenerate(''' +// coverage:ignore-file +// ignore_for_file: type=lint +final class _Env29 { + static final Uri testUrl = Uri.parse('https://foo.bar/baz'); +} +''') +@Envied() +abstract class Env29 { + @EnviedField() + static final Uri? testUrl = null; +} + +@ShouldThrow('Type `Uri` does not align with value `::Not valid URI::`.') +@Envied() +abstract class Env29invalid { + @EnviedField() + static final Uri? invalidTestUrl = null; +} + +@ShouldGenerate(''' +// coverage:ignore-file +// ignore_for_file: type=lint +final class _Env29b { + static final Uri? testUrl = Uri.parse('https://foo.bar/baz'); +} +''') +@Envied(allowOptionalFields: true) +abstract class Env29b { + @EnviedField() + static final Uri? testUrl = null; +} + +@ShouldThrow('Type `Uri` does not align with value `::Not valid URI::`.') +@Envied(allowOptionalFields: true) +abstract class Env29bInvalid { + @EnviedField() + static final Uri? invalidTestUrl = null; +} + +@ShouldGenerate('static const List _enviedkeytestUrl', contains: true) +@ShouldGenerate('static const List _envieddatatestUrl', contains: true) +@ShouldGenerate(''' + static final Uri testUrl = Uri.parse(String.fromCharCodes(List.generate( + _envieddatatestUrl.length, + (int i) => i, + growable: false, + ).map((int i) => _envieddatatestUrl[i] ^ _enviedkeytestUrl[i]))); +''', contains: true) +@Envied() +abstract class Env29c { + @EnviedField(obfuscate: true) + static final Uri? testUrl = null; +} + +@ShouldThrow('Type `Uri` does not align with value `::Not valid URI::`.') +@Envied() +abstract class Env29cInvalid { + @EnviedField(obfuscate: true) + static final Uri? invalidTestUrl = null; +} + +@ShouldGenerate('static const List _enviedkeytestUrl', contains: true) +@ShouldGenerate('static const List _envieddatatestUrl', contains: true) +@ShouldGenerate(''' + static final Uri? testUrl = Uri.parse(String.fromCharCodes(List.generate( + _envieddatatestUrl.length, + (int i) => i, + growable: false, + ).map((int i) => _envieddatatestUrl[i] ^ _enviedkeytestUrl[i]))); +''', contains: true) +@Envied(allowOptionalFields: true) +abstract class Env29d { + @EnviedField(obfuscate: true) + static final Uri? testUrl = null; +} + +@ShouldThrow('Type `Uri` does not align with value `::Not valid URI::`.') +@Envied(allowOptionalFields: true) +abstract class Env29dInvalid { + @EnviedField(obfuscate: true) + static final Uri? invalidTestUrl = null; +} + +@ShouldGenerate(''' +// coverage:ignore-file +// ignore_for_file: type=lint +final class _Env29empty { + static final Uri emptyTestUrl = Uri.parse(''); +} +''') +@Envied() +abstract class Env29empty { + @EnviedField() + static final Uri? emptyTestUrl = null; +} + +@ShouldGenerate(''' +// coverage:ignore-file +// ignore_for_file: type=lint +final class _Env30 { + static final DateTime testDateTime = + DateTime.parse('2023-11-06T22:32:55.287Z'); +} +''') +@Envied() +abstract class Env30 { + @EnviedField() + static final DateTime? testDateTime = null; +} + +@ShouldGenerate(''' +// coverage:ignore-file +// ignore_for_file: type=lint +final class _Env30b { + static final DateTime? testDateTime = + DateTime.parse('2023-11-06T22:32:55.287Z'); +} +''') +@Envied(allowOptionalFields: true) +abstract class Env30b { + @EnviedField() + static final DateTime? testDateTime = null; +} + +@ShouldGenerate('static const List _enviedkeytestDateTime', contains: true) +@ShouldGenerate('static const List _envieddatatestDateTime', + contains: true) +@ShouldGenerate(''' + static final DateTime testDateTime = + DateTime.parse(String.fromCharCodes(List.generate( + _envieddatatestDateTime.length, + (int i) => i, + growable: false, + ).map((int i) => _envieddatatestDateTime[i] ^ _enviedkeytestDateTime[i]))); +''', contains: true) +@Envied() +abstract class Env30c { + @EnviedField(obfuscate: true) + static final DateTime? testDateTime = null; +} + +@ShouldGenerate('static const List _enviedkeytestDateTime', contains: true) +@ShouldGenerate('static const List _envieddatatestDateTime', + contains: true) +@ShouldGenerate(''' + static final DateTime? testDateTime = + DateTime.parse(String.fromCharCodes(List.generate( + _envieddatatestDateTime.length, + (int i) => i, + growable: false, + ).map((int i) => _envieddatatestDateTime[i] ^ _enviedkeytestDateTime[i]))); +''', contains: true) +@Envied(allowOptionalFields: true) +abstract class Env30d { + @EnviedField(obfuscate: true) + static final DateTime? testDateTime = null; +} + +@ShouldThrow( + 'Type `DateTime` does not align with value `2023-11-06X22:32:55.287Z`.', +) +@Envied() +abstract class Env30invalid { + @EnviedField() + static final DateTime? invalidTestDateTime = null; +} + +@ShouldThrow( + 'Type `DateTime` does not align with value `2023-11-06X22:32:55.287Z`.', +) +@Envied(allowOptionalFields: true) +abstract class Env30bInvalid { + @EnviedField() + static final DateTime? invalidTestDateTime = null; +} + +@ShouldThrow( + 'Type `DateTime` does not align with value `2023-11-06X22:32:55.287Z`.', +) +@Envied() +abstract class Env30cInvalid { + @EnviedField(obfuscate: true) + static final DateTime? invalidTestDateTime = null; +} + +@ShouldThrow( + 'Type `DateTime` does not align with value `2023-11-06X22:32:55.287Z`.', +) +@Envied(allowOptionalFields: true) +abstract class Env30dInvalid { + @EnviedField(obfuscate: true) + static final DateTime? invalidTestDateTime = null; +} + +@ShouldGenerate(''' +// coverage:ignore-file +// ignore_for_file: type=lint +final class _Env31 { + static final DateTime testDate = DateTime.parse('2023-11-06'); +} +''') +@Envied() +abstract class Env31 { + @EnviedField() + static final DateTime? testDate = null; +} + +@ShouldGenerate(''' +// coverage:ignore-file +// ignore_for_file: type=lint +final class _Env31b { + static final DateTime? testDate = DateTime.parse('2023-11-06'); +} +''') +@Envied(allowOptionalFields: true) +abstract class Env31b { + @EnviedField() + static final DateTime? testDate = null; +} + +@ShouldGenerate('static const List _enviedkeytestDate', contains: true) +@ShouldGenerate('static const List _envieddatatestDate', contains: true) +@ShouldGenerate(''' + static final DateTime testDate = + DateTime.parse(String.fromCharCodes(List.generate( + _envieddatatestDate.length, + (int i) => i, + growable: false, + ).map((int i) => _envieddatatestDate[i] ^ _enviedkeytestDate[i]))); +''', contains: true) +@Envied() +abstract class Env31c { + @EnviedField(obfuscate: true) + static final DateTime? testDate = null; +} + +@ShouldGenerate('static const List _enviedkeytestDate', contains: true) +@ShouldGenerate('static const List _envieddatatestDate', contains: true) +@ShouldGenerate(''' + static final DateTime? testDate = + DateTime.parse(String.fromCharCodes(List.generate( + _envieddatatestDate.length, + (int i) => i, + growable: false, + ).map((int i) => _envieddatatestDate[i] ^ _enviedkeytestDate[i]))); +''', contains: true) +@Envied(allowOptionalFields: true) +abstract class Env31d { + @EnviedField(obfuscate: true) + static final DateTime? testDate = null; +} + +@ShouldThrow('Type `DateTime` does not align with value `2023`.') +@Envied() +abstract class Env31invalid { + @EnviedField() + static final DateTime? invalidTestDate = null; +} + +@ShouldThrow('Type `DateTime` does not align with value `2023`.') +@Envied(allowOptionalFields: true) +abstract class Env31bInvalid { + @EnviedField() + static final DateTime? invalidTestDate = null; +} + +@ShouldThrow('Type `DateTime` does not align with value `2023`.') +@Envied() +abstract class Env31cInvalid { + @EnviedField(obfuscate: true) + static final DateTime? invalidTestDate = null; +} + +@ShouldThrow('Type `DateTime` does not align with value `2023`.') +@Envied(allowOptionalFields: true) +abstract class Env31dInvalid { + @EnviedField(obfuscate: true) + static final DateTime? invalidTestDate = null; +} + +@ShouldGenerate('static const List _enviedkeytestDouble', contains: true) +@ShouldGenerate('static const List _envieddatatestDouble', contains: true) +@ShouldGenerate(''' + static final double testDouble = + double.parse(String.fromCharCodes(List.generate( + _envieddatatestDouble.length, + (int i) => i, + growable: false, + ).map((int i) => _envieddatatestDouble[i] ^ _enviedkeytestDouble[i]))); +''', contains: true) +@Envied() +abstract class Env32a { + @EnviedField(obfuscate: true) + static const double testDouble = 1.23; +} + +@ShouldGenerate('static const List _enviedkeytestDouble', contains: true) +@ShouldGenerate('static const List _envieddatatestDouble', contains: true) +@ShouldGenerate(''' + static final double? testDouble = + double.parse(String.fromCharCodes(List.generate( + _envieddatatestDouble.length, + (int i) => i, + growable: false, + ).map((int i) => _envieddatatestDouble[i] ^ _enviedkeytestDouble[i]))); +''', contains: true) +@Envied(allowOptionalFields: true) +abstract class Env32b { + @EnviedField(obfuscate: true) + static const double? testDouble = 1.23; +} + +@ShouldGenerate('static const List _enviedkeytestNum', contains: true) +@ShouldGenerate('static const List _envieddatatestNum', contains: true) +@ShouldGenerate(''' + static final num testNum = num.parse(String.fromCharCodes(List.generate( + _envieddatatestNum.length, + (int i) => i, + growable: false, + ).map((int i) => _envieddatatestNum[i] ^ _enviedkeytestNum[i]))); +''', contains: true) +@Envied() +abstract class Env33a { + @EnviedField(obfuscate: true) + static const num testNum = 1.23; +} + +@ShouldGenerate('static const List _enviedkeytestNum', contains: true) +@ShouldGenerate('static const List _envieddatatestNum', contains: true) +@ShouldGenerate(''' + static final num? testNum = num.parse(String.fromCharCodes(List.generate( + _envieddatatestNum.length, + (int i) => i, + growable: false, + ).map((int i) => _envieddatatestNum[i] ^ _enviedkeytestNum[i]))); +''', contains: true) +@Envied(allowOptionalFields: true) +abstract class Env33b { + @EnviedField(obfuscate: true) + static const num? testNum = 1.23; +} + +@ShouldGenerate(''' +// coverage:ignore-file +// ignore_for_file: type=lint +final class _Env34 { + static const String? testDefaultParam = 'test_'; + + static const String testString = 'TEST_STRING'; + + static const int testInt = 123; + + static const double testDouble = 1.23; + + static const bool testBool = true; + + static const String testDynamic = '123_ABC'; +} +''') +@Envied( + useConstantCase: true, + allowOptionalFields: true, +) +abstract class Env34 { + @EnviedField(defaultValue: 'test_') + static const String? testDefaultParam = null; + @EnviedField() + static const String testString = 'TEST_STRING'; + @EnviedField() + static const int testInt = 123; + @EnviedField() + static const double testDouble = 1.23; + @EnviedField() + static const bool testBool = true; + @EnviedField() + static const String testDynamic = '123_ABC'; +} + +@ShouldGenerate(''' +// coverage:ignore-file +// ignore_for_file: type=lint +final class _Env35 { + static final ExampleEnum testEnum = ExampleEnum.values.byName('ipsum'); +} +''') +@Envied() +abstract class Env35 { + @EnviedField() + static final ExampleEnum? testEnum = null; +} + +@ShouldGenerate(''' +// coverage:ignore-file +// ignore_for_file: type=lint +final class _Env35b { + static final ExampleEnum? testEnum = ExampleEnum.values.byName('ipsum'); +} +''') +@Envied(allowOptionalFields: true) +abstract class Env35b { + @EnviedField() + static final ExampleEnum? testEnum = null; +} + +@ShouldGenerate('static const List _enviedkeytestEnum', contains: true) +@ShouldGenerate('static const List _envieddatatestEnum', contains: true) +@ShouldGenerate(''' + static final ExampleEnum testEnum = + ExampleEnum.values.byName(String.fromCharCodes(List.generate( + _envieddatatestEnum.length, + (int i) => i, + growable: false, + ).map((int i) => _envieddatatestEnum[i] ^ _enviedkeytestEnum[i]))); +''', contains: true) +@Envied() +abstract class Env35c { + @EnviedField(obfuscate: true) + static final ExampleEnum? testEnum = null; +} + +@ShouldGenerate('static const List _enviedkeytestEnum', contains: true) +@ShouldGenerate('static const List _envieddatatestEnum', contains: true) +@ShouldGenerate(''' + static final ExampleEnum? testEnum = + ExampleEnum.values.byName(String.fromCharCodes(List.generate( + _envieddatatestEnum.length, + (int i) => i, + growable: false, + ).map((int i) => _envieddatatestEnum[i] ^ _enviedkeytestEnum[i]))); +''', contains: true) +@Envied(allowOptionalFields: true) +abstract class Env35d { + @EnviedField(obfuscate: true) + static final ExampleEnum? testEnum = null; +} + +@ShouldThrow( + 'Enumerated type `ExampleEnum` does not contain value `foo`. Possible values are: `lorem`, `ipsum`, `dolor`.', +) +@Envied() +abstract class Env35invalid { + @EnviedField() + static final ExampleEnum? invalidTestEnum = null; +} + +@ShouldThrow( + 'Enumerated type `ExampleEnum` does not contain value `foo`. Possible values are: `lorem`, `ipsum`, `dolor`.', +) +@Envied(allowOptionalFields: true) +abstract class Env35bInvalid { + @EnviedField() + static final ExampleEnum? invalidTestEnum = null; +} + +@ShouldThrow( + 'Enumerated type `ExampleEnum` does not contain value `foo`. Possible values are: `lorem`, `ipsum`, `dolor`.', +) +@Envied() +abstract class Env35cInvalid { + @EnviedField(obfuscate: true) + static final ExampleEnum? invalidTestEnum = null; +} + +@ShouldThrow( + 'Enumerated type `ExampleEnum` does not contain value `foo`. Possible values are: `lorem`, `ipsum`, `dolor`.', +) +@Envied(allowOptionalFields: true) +abstract class Env35dInvalid { + @EnviedField(obfuscate: true) + static final ExampleEnum? invalidTestEnum = null; +} From 32d3933ca84da21771ed91da4ca24c051dfe6cbc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Klemen=20Tu=C5=A1ar?= Date: Wed, 29 Nov 2023 19:25:17 +0000 Subject: [PATCH 6/7] :white_check_mark: add path override tests --- .../test/.env.example_with_path_override | 23 +- .../generator_tests_with_path_override.dart | 1070 +---------------- 2 files changed, 11 insertions(+), 1082 deletions(-) diff --git a/packages/envied_generator/test/.env.example_with_path_override b/packages/envied_generator/test/.env.example_with_path_override index 9d0ee45..fc4e5fd 100644 --- a/packages/envied_generator/test/.env.example_with_path_override +++ b/packages/envied_generator/test/.env.example_with_path_override @@ -1,21 +1,2 @@ -test_string=test_string -testString=testString -TEST_STRING=TEST_STRING -testInt=123 -TEST_INT=123 -testDouble=1.23 -testNum=1.23 -TEST_DOUBLE=1.23 -TEST_BOOL=true -testBool=true -testDynamic=123abc -TEST_DYNAMIC=123_ABC -testUrl=https://foo.bar/baz -emptyTestUrl= -invalidTestUrl="::Not valid URI::" -testDateTime=2023-11-06T22:32:55.287Z -invalidTestDateTime=2023-11-06X22:32:55.287Z -testDate=2023-11-06 -invalidTestDate=2023 -testEnum=ipsum -invalidTestEnum=foo \ No newline at end of file +foo=bar +baz=qux diff --git a/packages/envied_generator/test/src/generator_tests_with_path_override.dart b/packages/envied_generator/test/src/generator_tests_with_path_override.dart index 4e39da2..d25bd2d 100644 --- a/packages/envied_generator/test/src/generator_tests_with_path_override.dart +++ b/packages/envied_generator/test/src/generator_tests_with_path_override.dart @@ -1,1089 +1,37 @@ // ignore_for_file: unnecessary_nullable_for_final_variable_declarations -import 'dart:io'; - import 'package:envied/envied.dart'; import 'package:source_gen_test/annotations.dart'; -import 'example_enum.dart'; - -@ShouldThrow('`@Envied` can only be used on classes.') -@Envied() -const foo = 'bar'; - @ShouldGenerate(''' // coverage:ignore-file // ignore_for_file: type=lint -final class _Env0 {} +final class _EnvWithPathOverride0 {} ''') @Envied() -abstract class Env0 {} +abstract class EnvWithPathOverride0 {} @ShouldGenerate(''' // coverage:ignore-file // ignore_for_file: type=lint -final class _Env1 {} +final class _EnvWithPathOverride1 {} ''') @Envied(requireEnvFile: true) -abstract class Env1 {} - -@ShouldThrow('Environment variable not found for field `foo`.') -@Envied() -abstract class Env2 { - @EnviedField() - static const dynamic foo = null; -} - -@ShouldThrow( - 'Envied requires types to be explicitly declared. `foo` does not declare a type.', -) -@Envied() -abstract class Env2b { - @EnviedField() - // ignore: undefined_class - static final Foo foo = null; -} - -@ShouldThrow( - 'Envied can only handle types such as `int`, `double`, `num`, `bool`, `Uri`, `DateTime`, `Enum` and `String`. Type `File` is not one of them.', -) -@Envied(allowOptionalFields: true) -abstract class Env2c { - @EnviedField() - static const File? foo = null; -} - -@ShouldThrow( - 'Obfuscated envied can only handle types such as `int`, `double`, `num`, `bool`, `Uri`, `DateTime`, `Enum` and `String`. Type `File` is not one of them.', -) -@Envied(allowOptionalFields: true) -abstract class Env2d { - @EnviedField(obfuscate: true) - static const File? foo = null; -} - -@ShouldThrow( - 'Envied can only handle types such as `int`, `double`, `num`, `bool`, `Uri`, `DateTime`, `Enum` and `String`. Type `Symbol` is not one of them.', -) -@Envied() -abstract class Env3 { - @EnviedField() - static const Symbol? testString = null; -} - -@ShouldThrow('Type `int` does not align with value `testString`.') -@Envied() -abstract class Env4 { - @EnviedField() - static const int? testString = null; -} - -@ShouldThrow('Type `double` does not align with value `testString`.') -@Envied() -abstract class Env5 { - @EnviedField() - static const double? testString = null; -} - -@ShouldThrow('Type `num` does not align with value `testString`.') -@Envied() -abstract class Env6 { - @EnviedField() - static const num? testString = null; -} - -@ShouldThrow('Type `bool` does not align with value `testString`.') -@Envied() -abstract class Env7 { - @EnviedField() - static const bool? testString = null; -} - -@ShouldGenerate(''' -// coverage:ignore-file -// ignore_for_file: type=lint -final class _Env8 { - static const String testString = 'testString'; - - static const int testInt = 123; - - static const double testDouble = 1.23; - - static const bool testBool = true; - - static const testDynamic = '123abc'; -} -''') -@Envied() -abstract class Env8 { - @EnviedField() - static const String? testString = null; - @EnviedField() - static const int? testInt = null; - @EnviedField() - static const double? testDouble = null; - @EnviedField() - static const bool? testBool = null; - @EnviedField() - static const testDynamic = null; -} - -@ShouldGenerate(''' -// coverage:ignore-file -// ignore_for_file: type=lint -final class _Env8b { - static const String? testString = 'testString'; - - static const int? testInt = 123; - - static const double? testDouble = 1.23; - - static const bool? testBool = true; - - static const testDynamic = '123abc'; -} -''') -@Envied(allowOptionalFields: true) -abstract class Env8b { - @EnviedField() - static const String? testString = null; - @EnviedField() - static const int? testInt = null; - @EnviedField() - static const double? testDouble = null; - @EnviedField() - static const bool? testBool = null; - @EnviedField() - static const testDynamic = null; -} - -@ShouldGenerate(''' -// coverage:ignore-file -// ignore_for_file: type=lint -final class _Env9 { - static const String testString = 'test_string'; -} -''') -@Envied() -abstract class Env9 { - @EnviedField(varName: 'test_string') - static const String? testString = null; -} - -@ShouldGenerate(''' -// coverage:ignore-file -// ignore_for_file: type=lint -final class _Env9b { - static const String? testString = 'test_string'; -} -''') -@Envied(allowOptionalFields: true) -abstract class Env9b { - @EnviedField(varName: 'test_string') - static const String? testString = null; -} - -@ShouldGenerate(''' -// coverage:ignore-file -// ignore_for_file: type=lint -final class _Env10 { - static const String systemVar = 'system_var'; -} -''') -@Envied() -abstract class Env10 { - @EnviedField(varName: 'SYSTEM_VAR') - static const String? systemVar = null; -} - -@ShouldGenerate(''' -// coverage:ignore-file -// ignore_for_file: type=lint -final class _Env10b { - static const String? systemVar = 'system_var'; -} -''') -@Envied(allowOptionalFields: true) -abstract class Env10b { - @EnviedField(varName: 'SYSTEM_VAR') - static const String? systemVar = null; -} - -@ShouldGenerate(''' -// coverage:ignore-file -// ignore_for_file: type=lint -final class _Foo { - static const String testString = 'test_string'; -} -''') -@Envied(name: 'Foo') -abstract class Env11 { - @EnviedField(varName: 'test_string') - static const String? testString = null; -} +abstract class EnvWithPathOverride1 {} @ShouldGenerate(''' // coverage:ignore-file // ignore_for_file: type=lint -final class _Foo { - static const String? testString = 'test_string'; -} -''') -@Envied(name: 'Foo', allowOptionalFields: true) -abstract class Env11b { - @EnviedField(varName: 'test_string') - static const String? testString = null; -} - -@ShouldGenerate('static const List _enviedkeytestString', contains: true) -@ShouldGenerate('static const List _envieddatatestString', contains: true) -@ShouldGenerate(''' - static final String testString = String.fromCharCodes(List.generate( - _envieddatatestString.length, - (int i) => i, - growable: false, - ).map((int i) => _envieddatatestString[i] ^ _enviedkeytestString[i])); -''', contains: true) -@Envied(obfuscate: true) -abstract class Env12 { - @EnviedField() - static const String? testString = null; -} +final class _EnvWithPathOverride2 { + static const String foo = 'bar'; -@ShouldGenerate('static const List _enviedkeytestString', contains: true) -@ShouldGenerate('static const List _envieddatatestString', contains: true) -@ShouldGenerate(''' - static final String? testString = String.fromCharCodes(List.generate( - _envieddatatestString.length, - (int i) => i, - growable: false, - ).map((int i) => _envieddatatestString[i] ^ _enviedkeytestString[i])); -''', contains: true) -@Envied(obfuscate: true, allowOptionalFields: true) -abstract class Env12b { - @EnviedField() - static const String? testString = null; -} - -@ShouldGenerate('static const List _enviedkeytestString', contains: true) -@ShouldGenerate('static const List _envieddatatestString', contains: true) -@ShouldGenerate(''' - static final String testString = String.fromCharCodes(List.generate( - _envieddatatestString.length, - (int i) => i, - growable: false, - ).map((int i) => _envieddatatestString[i] ^ _enviedkeytestString[i])); -''', contains: true) -@Envied(obfuscate: false) -abstract class Env13 { - @EnviedField(obfuscate: true) - static const String? testString = null; -} - -@ShouldGenerate('static const List _enviedkeytestString', contains: true) -@ShouldGenerate('static const List _envieddatatestString', contains: true) -@ShouldGenerate(''' - static final String? testString = String.fromCharCodes(List.generate( - _envieddatatestString.length, - (int i) => i, - growable: false, - ).map((int i) => _envieddatatestString[i] ^ _enviedkeytestString[i])); -''', contains: true) -@Envied(obfuscate: false, allowOptionalFields: true) -abstract class Env13b { - @EnviedField(obfuscate: true) - static const String? testString = null; -} - -@ShouldThrow('Environment variable not found for field `testDefaultParam`.') -@Envied() -abstract class Env14 { - @EnviedField(defaultValue: null) - static const String? testDefaultParam = null; -} - -@ShouldGenerate(''' -// coverage:ignore-file -// ignore_for_file: type=lint -final class _Env14b { - static const String? testDefaultParam = null; -} -''') -@Envied(allowOptionalFields: true) -abstract class Env14b { - @EnviedField(defaultValue: null) - static const String? testDefaultParam = null; -} - -@ShouldGenerate(''' -// coverage:ignore-file -// ignore_for_file: type=lint -final class _Env15 { - static const String testDefaultParam = 'test_'; - - static const String testString = 'testString'; - - static const int testInt = 123; - - static const double testDouble = 1.23; - - static const bool testBool = true; - - static const testDynamic = '123abc'; + static const String baz = 'qux'; } ''') @Envied() -abstract class Env15 { - @EnviedField(defaultValue: 'test_') - static const String? testDefaultParam = null; - @EnviedField() - static const String testString = 'testString'; - @EnviedField() - static const int testInt = 123; - @EnviedField() - static const double testDouble = 1.23; - @EnviedField() - static const bool testBool = true; - @EnviedField() - static const dynamic testDynamic = '123abc'; -} - -@ShouldGenerate(''' -// coverage:ignore-file -// ignore_for_file: type=lint -final class _Env15b { - static const String? testDefaultParam = 'test_'; - - static const String testString = 'testString'; - - static const int testInt = 123; - - static const double testDouble = 1.23; - - static const bool testBool = true; -} -''') -@Envied(allowOptionalFields: true) -abstract class Env15b { - @EnviedField(defaultValue: 'test_') - static const String? testDefaultParam = null; - @EnviedField() - static const String testString = 'testString'; +abstract class EnvWithPathOverride2 { @EnviedField() - static const int testInt = 123; - @EnviedField() - static const double testDouble = 1.23; - @EnviedField() - static const bool testBool = true; -} - -@ShouldGenerate(''' -// coverage:ignore-file -// ignore_for_file: type=lint -final class _Env16 { - static const String testDefaultParam = 'test_'; -} -''') -@Envied() -abstract class Env16 { - @EnviedField(defaultValue: 'test_') - static const String? testDefaultParam = null; -} - -@ShouldGenerate(''' -// coverage:ignore-file -// ignore_for_file: type=lint -final class _Env16b { - static const String? testDefaultParam = 'test_'; -} -''') -@Envied(allowOptionalFields: true) -abstract class Env16b { - @EnviedField(defaultValue: 'test_') - static const String? testDefaultParam = null; -} - -@ShouldGenerate('static const List _enviedkeytestString', contains: true) -@ShouldGenerate('static const List _envieddatatestString', contains: true) -@ShouldGenerate(''' - static final String testString = String.fromCharCodes(List.generate( - _envieddatatestString.length, - (int i) => i, - growable: false, - ).map((int i) => _envieddatatestString[i] ^ _enviedkeytestString[i])); -''', contains: true) -@Envied(obfuscate: true) -abstract class Env17 { - @EnviedField(defaultValue: 'test_') - static const String? testString = null; -} - -@ShouldGenerate('static const List _enviedkeytestString', contains: true) -@ShouldGenerate('static const List _envieddatatestString', contains: true) -@ShouldGenerate(''' - static final String? testString = String.fromCharCodes(List.generate( - _envieddatatestString.length, - (int i) => i, - growable: false, - ).map((int i) => _envieddatatestString[i] ^ _enviedkeytestString[i])); -''', contains: true) -@Envied(obfuscate: true, allowOptionalFields: true) -abstract class Env17b { - @EnviedField(defaultValue: 'test_') - static const String? testString = null; -} - -@ShouldGenerate('static const List _enviedkeytestString', contains: true) -@ShouldGenerate('static const List _envieddatatestString', contains: true) -@ShouldGenerate(''' - static final String testString = String.fromCharCodes(List.generate( - _envieddatatestString.length, - (int i) => i, - growable: false, - ).map((int i) => _envieddatatestString[i] ^ _enviedkeytestString[i])); -''', contains: true) -@Envied(obfuscate: false) -abstract class Env18 { - @EnviedField(obfuscate: true) - static const String testString = "test_"; -} - -@ShouldGenerate('static const List _enviedkeytestString', contains: true) -@ShouldGenerate('static const List _envieddatatestString', contains: true) -@ShouldGenerate(''' - static final String? testString = String.fromCharCodes(List.generate( - _envieddatatestString.length, - (int i) => i, - growable: false, - ).map((int i) => _envieddatatestString[i] ^ _enviedkeytestString[i])); -''', contains: true) -@Envied(obfuscate: false, allowOptionalFields: true) -abstract class Env18b { - @EnviedField(obfuscate: true, defaultValue: 'test_') - static const String? testString = null; -} - -@ShouldGenerate('static const List _enviedkeytestString', contains: true) -@ShouldGenerate('static const List _envieddatatestString', contains: true) -@ShouldGenerate(''' - static final String? testString = String.fromCharCodes(List.generate( - _envieddatatestString.length, - (int i) => i, - growable: false, - ).map((int i) => _envieddatatestString[i] ^ _enviedkeytestString[i])); -''', contains: true) -@Envied(obfuscate: false, allowOptionalFields: true) -abstract class Env18c { - @EnviedField(obfuscate: true) - static const String? testString = null; -} - -@ShouldGenerate('static final int _enviedkeytestInt', contains: true) -@ShouldGenerate( - 'static final int testInt = _enviedkeytestInt ^', - contains: true, -) -@Envied() -abstract class Env19 { - @EnviedField(obfuscate: true) - static const int testInt = 123; -} - -@ShouldGenerate('static final int _enviedkeytestInt', contains: true) -@ShouldGenerate( - 'static final int? testInt = _enviedkeytestInt ^', - contains: true, -) -@Envied(allowOptionalFields: true) -abstract class Env19b { - @EnviedField(obfuscate: true) - static const int? testInt = 123; -} - -@ShouldGenerate('static final bool _enviedkeytestBool', contains: true) -@ShouldGenerate( - 'static final bool testBool = _enviedkeytestBool ^', - contains: true, -) -@Envied() -abstract class Env20 { - @EnviedField(obfuscate: true) - static const bool testBool = true; -} - -@ShouldGenerate('static final bool _enviedkeytestBool', contains: true) -@ShouldGenerate( - 'static final bool? testBool = _enviedkeytestBool ^', - contains: true, -) -@Envied(allowOptionalFields: true) -abstract class Env20b { - @EnviedField(obfuscate: true) - static const bool? testBool = true; -} - -@ShouldGenerate('static const List _enviedkeytestDynamic', contains: true) -@ShouldGenerate('static const List _envieddatatestDynamic', contains: true) -@ShouldGenerate(''' - static final testDynamic = String.fromCharCodes(List.generate( - _envieddatatestDynamic.length, - (int i) => i, - growable: false, - ).map((int i) => _envieddatatestDynamic[i] ^ _enviedkeytestDynamic[i])); -''', contains: true) -@Envied() -abstract class Env21 { - @EnviedField(obfuscate: true) - static const dynamic testDynamic = '123abc'; -} - -@ShouldThrow( - 'Obfuscated envied can only handle types such as `int`, `double`, `num`, `bool`, `Uri`, `DateTime` and `String`. Type `Symbol` is not one of them.', -) -@Envied() -abstract class Env22 { - @EnviedField(obfuscate: true) - static const Symbol? testString = null; -} - -@ShouldThrow('Type `int` does not align with value `testString`.') -@Envied() -abstract class Env23 { - @EnviedField(obfuscate: true) - static const int? testString = null; -} - -@ShouldThrow('Type `bool` does not align with value `testString`.') -@Envied() -abstract class Env24 { - @EnviedField(obfuscate: true) - static const bool? testString = null; -} - -@ShouldThrow('Environment variable not found for field `foo`.') -@Envied() -abstract class Env25 { - @EnviedField(obfuscate: true) - static const dynamic foo = null; -} - -@ShouldGenerate(''' - static final foo = null; -''', contains: true) -@Envied(allowOptionalFields: true) -abstract class Env25b { - @EnviedField(obfuscate: true) - static const dynamic foo = null; -} - -@ShouldGenerate(''' -// coverage:ignore-file -// ignore_for_file: type=lint -final class _Env26 { - static final String? foo = null; -} -''') -@Envied(allowOptionalFields: true) -abstract class Env26 { - @EnviedField(obfuscate: true) static const String? foo = null; -} - -@ShouldGenerate(''' -// coverage:ignore-file -// ignore_for_file: type=lint -final class _Env27 { - static final int? foo = null; -} -''') -@Envied(allowOptionalFields: true) -abstract class Env27 { - @EnviedField(obfuscate: true) - static const int? foo = null; -} - -@ShouldGenerate(''' -// coverage:ignore-file -// ignore_for_file: type=lint -final class _Env28 { - static final bool? foo = null; -} -''') -@Envied(allowOptionalFields: true) -abstract class Env28 { - @EnviedField(obfuscate: true) - static const bool? foo = null; -} - -@ShouldGenerate(''' -// coverage:ignore-file -// ignore_for_file: type=lint -final class _Env29 { - static final Uri testUrl = Uri.parse('https://foo.bar/baz'); -} -''') -@Envied() -abstract class Env29 { - @EnviedField() - static final Uri? testUrl = null; -} - -@ShouldThrow('Type `Uri` does not align with value `::Not valid URI::`.') -@Envied() -abstract class Env29invalid { - @EnviedField() - static final Uri? invalidTestUrl = null; -} - -@ShouldGenerate(''' -// coverage:ignore-file -// ignore_for_file: type=lint -final class _Env29b { - static final Uri? testUrl = Uri.parse('https://foo.bar/baz'); -} -''') -@Envied(allowOptionalFields: true) -abstract class Env29b { - @EnviedField() - static final Uri? testUrl = null; -} - -@ShouldThrow('Type `Uri` does not align with value `::Not valid URI::`.') -@Envied(allowOptionalFields: true) -abstract class Env29bInvalid { - @EnviedField() - static final Uri? invalidTestUrl = null; -} - -@ShouldGenerate('static const List _enviedkeytestUrl', contains: true) -@ShouldGenerate('static const List _envieddatatestUrl', contains: true) -@ShouldGenerate(''' - static final Uri testUrl = Uri.parse(String.fromCharCodes(List.generate( - _envieddatatestUrl.length, - (int i) => i, - growable: false, - ).map((int i) => _envieddatatestUrl[i] ^ _enviedkeytestUrl[i]))); -''', contains: true) -@Envied() -abstract class Env29c { - @EnviedField(obfuscate: true) - static final Uri? testUrl = null; -} - -@ShouldThrow('Type `Uri` does not align with value `::Not valid URI::`.') -@Envied() -abstract class Env29cInvalid { - @EnviedField(obfuscate: true) - static final Uri? invalidTestUrl = null; -} - -@ShouldGenerate('static const List _enviedkeytestUrl', contains: true) -@ShouldGenerate('static const List _envieddatatestUrl', contains: true) -@ShouldGenerate(''' - static final Uri? testUrl = Uri.parse(String.fromCharCodes(List.generate( - _envieddatatestUrl.length, - (int i) => i, - growable: false, - ).map((int i) => _envieddatatestUrl[i] ^ _enviedkeytestUrl[i]))); -''', contains: true) -@Envied(allowOptionalFields: true) -abstract class Env29d { - @EnviedField(obfuscate: true) - static final Uri? testUrl = null; -} - -@ShouldThrow('Type `Uri` does not align with value `::Not valid URI::`.') -@Envied(allowOptionalFields: true) -abstract class Env29dInvalid { - @EnviedField(obfuscate: true) - static final Uri? invalidTestUrl = null; -} - -@ShouldGenerate(''' -// coverage:ignore-file -// ignore_for_file: type=lint -final class _Env29empty { - static final Uri emptyTestUrl = Uri.parse(''); -} -''') -@Envied() -abstract class Env29empty { - @EnviedField() - static final Uri? emptyTestUrl = null; -} - -@ShouldGenerate(''' -// coverage:ignore-file -// ignore_for_file: type=lint -final class _Env30 { - static final DateTime testDateTime = - DateTime.parse('2023-11-06T22:32:55.287Z'); -} -''') -@Envied() -abstract class Env30 { - @EnviedField() - static final DateTime? testDateTime = null; -} - -@ShouldGenerate(''' -// coverage:ignore-file -// ignore_for_file: type=lint -final class _Env30b { - static final DateTime? testDateTime = - DateTime.parse('2023-11-06T22:32:55.287Z'); -} -''') -@Envied(allowOptionalFields: true) -abstract class Env30b { - @EnviedField() - static final DateTime? testDateTime = null; -} - -@ShouldGenerate('static const List _enviedkeytestDateTime', contains: true) -@ShouldGenerate('static const List _envieddatatestDateTime', - contains: true) -@ShouldGenerate(''' - static final DateTime testDateTime = - DateTime.parse(String.fromCharCodes(List.generate( - _envieddatatestDateTime.length, - (int i) => i, - growable: false, - ).map((int i) => _envieddatatestDateTime[i] ^ _enviedkeytestDateTime[i]))); -''', contains: true) -@Envied() -abstract class Env30c { - @EnviedField(obfuscate: true) - static final DateTime? testDateTime = null; -} - -@ShouldGenerate('static const List _enviedkeytestDateTime', contains: true) -@ShouldGenerate('static const List _envieddatatestDateTime', - contains: true) -@ShouldGenerate(''' - static final DateTime? testDateTime = - DateTime.parse(String.fromCharCodes(List.generate( - _envieddatatestDateTime.length, - (int i) => i, - growable: false, - ).map((int i) => _envieddatatestDateTime[i] ^ _enviedkeytestDateTime[i]))); -''', contains: true) -@Envied(allowOptionalFields: true) -abstract class Env30d { - @EnviedField(obfuscate: true) - static final DateTime? testDateTime = null; -} - -@ShouldThrow( - 'Type `DateTime` does not align with value `2023-11-06X22:32:55.287Z`.', -) -@Envied() -abstract class Env30invalid { - @EnviedField() - static final DateTime? invalidTestDateTime = null; -} - -@ShouldThrow( - 'Type `DateTime` does not align with value `2023-11-06X22:32:55.287Z`.', -) -@Envied(allowOptionalFields: true) -abstract class Env30bInvalid { - @EnviedField() - static final DateTime? invalidTestDateTime = null; -} - -@ShouldThrow( - 'Type `DateTime` does not align with value `2023-11-06X22:32:55.287Z`.', -) -@Envied() -abstract class Env30cInvalid { - @EnviedField(obfuscate: true) - static final DateTime? invalidTestDateTime = null; -} - -@ShouldThrow( - 'Type `DateTime` does not align with value `2023-11-06X22:32:55.287Z`.', -) -@Envied(allowOptionalFields: true) -abstract class Env30dInvalid { - @EnviedField(obfuscate: true) - static final DateTime? invalidTestDateTime = null; -} - -@ShouldGenerate(''' -// coverage:ignore-file -// ignore_for_file: type=lint -final class _Env31 { - static final DateTime testDate = DateTime.parse('2023-11-06'); -} -''') -@Envied() -abstract class Env31 { - @EnviedField() - static final DateTime? testDate = null; -} - -@ShouldGenerate(''' -// coverage:ignore-file -// ignore_for_file: type=lint -final class _Env31b { - static final DateTime? testDate = DateTime.parse('2023-11-06'); -} -''') -@Envied(allowOptionalFields: true) -abstract class Env31b { - @EnviedField() - static final DateTime? testDate = null; -} - -@ShouldGenerate('static const List _enviedkeytestDate', contains: true) -@ShouldGenerate('static const List _envieddatatestDate', contains: true) -@ShouldGenerate(''' - static final DateTime testDate = - DateTime.parse(String.fromCharCodes(List.generate( - _envieddatatestDate.length, - (int i) => i, - growable: false, - ).map((int i) => _envieddatatestDate[i] ^ _enviedkeytestDate[i]))); -''', contains: true) -@Envied() -abstract class Env31c { - @EnviedField(obfuscate: true) - static final DateTime? testDate = null; -} - -@ShouldGenerate('static const List _enviedkeytestDate', contains: true) -@ShouldGenerate('static const List _envieddatatestDate', contains: true) -@ShouldGenerate(''' - static final DateTime? testDate = - DateTime.parse(String.fromCharCodes(List.generate( - _envieddatatestDate.length, - (int i) => i, - growable: false, - ).map((int i) => _envieddatatestDate[i] ^ _enviedkeytestDate[i]))); -''', contains: true) -@Envied(allowOptionalFields: true) -abstract class Env31d { - @EnviedField(obfuscate: true) - static final DateTime? testDate = null; -} - -@ShouldThrow('Type `DateTime` does not align with value `2023`.') -@Envied() -abstract class Env31invalid { - @EnviedField() - static final DateTime? invalidTestDate = null; -} - -@ShouldThrow('Type `DateTime` does not align with value `2023`.') -@Envied(allowOptionalFields: true) -abstract class Env31bInvalid { - @EnviedField() - static final DateTime? invalidTestDate = null; -} - -@ShouldThrow('Type `DateTime` does not align with value `2023`.') -@Envied() -abstract class Env31cInvalid { - @EnviedField(obfuscate: true) - static final DateTime? invalidTestDate = null; -} - -@ShouldThrow('Type `DateTime` does not align with value `2023`.') -@Envied(allowOptionalFields: true) -abstract class Env31dInvalid { - @EnviedField(obfuscate: true) - static final DateTime? invalidTestDate = null; -} - -@ShouldGenerate('static const List _enviedkeytestDouble', contains: true) -@ShouldGenerate('static const List _envieddatatestDouble', contains: true) -@ShouldGenerate(''' - static final double testDouble = - double.parse(String.fromCharCodes(List.generate( - _envieddatatestDouble.length, - (int i) => i, - growable: false, - ).map((int i) => _envieddatatestDouble[i] ^ _enviedkeytestDouble[i]))); -''', contains: true) -@Envied() -abstract class Env32a { - @EnviedField(obfuscate: true) - static const double testDouble = 1.23; -} - -@ShouldGenerate('static const List _enviedkeytestDouble', contains: true) -@ShouldGenerate('static const List _envieddatatestDouble', contains: true) -@ShouldGenerate(''' - static final double? testDouble = - double.parse(String.fromCharCodes(List.generate( - _envieddatatestDouble.length, - (int i) => i, - growable: false, - ).map((int i) => _envieddatatestDouble[i] ^ _enviedkeytestDouble[i]))); -''', contains: true) -@Envied(allowOptionalFields: true) -abstract class Env32b { - @EnviedField(obfuscate: true) - static const double? testDouble = 1.23; -} - -@ShouldGenerate('static const List _enviedkeytestNum', contains: true) -@ShouldGenerate('static const List _envieddatatestNum', contains: true) -@ShouldGenerate(''' - static final num testNum = num.parse(String.fromCharCodes(List.generate( - _envieddatatestNum.length, - (int i) => i, - growable: false, - ).map((int i) => _envieddatatestNum[i] ^ _enviedkeytestNum[i]))); -''', contains: true) -@Envied() -abstract class Env33a { - @EnviedField(obfuscate: true) - static const num testNum = 1.23; -} - -@ShouldGenerate('static const List _enviedkeytestNum', contains: true) -@ShouldGenerate('static const List _envieddatatestNum', contains: true) -@ShouldGenerate(''' - static final num? testNum = num.parse(String.fromCharCodes(List.generate( - _envieddatatestNum.length, - (int i) => i, - growable: false, - ).map((int i) => _envieddatatestNum[i] ^ _enviedkeytestNum[i]))); -''', contains: true) -@Envied(allowOptionalFields: true) -abstract class Env33b { - @EnviedField(obfuscate: true) - static const num? testNum = 1.23; -} - -@ShouldGenerate(''' -// coverage:ignore-file -// ignore_for_file: type=lint -final class _Env34 { - static const String? testDefaultParam = 'test_'; - - static const String testString = 'TEST_STRING'; - - static const int testInt = 123; - - static const double testDouble = 1.23; - - static const bool testBool = true; - - static const String testDynamic = '123_ABC'; -} -''') -@Envied( - useConstantCase: true, - allowOptionalFields: true, -) -abstract class Env34 { - @EnviedField(defaultValue: 'test_') - static const String? testDefaultParam = null; - @EnviedField() - static const String testString = 'TEST_STRING'; @EnviedField() - static const int testInt = 123; - @EnviedField() - static const double testDouble = 1.23; - @EnviedField() - static const bool testBool = true; - @EnviedField() - static const String testDynamic = '123_ABC'; -} - -@ShouldGenerate(''' -// coverage:ignore-file -// ignore_for_file: type=lint -final class _Env35 { - static final ExampleEnum testEnum = ExampleEnum.values.byName('ipsum'); -} -''') -@Envied() -abstract class Env35 { - @EnviedField() - static final ExampleEnum? testEnum = null; -} - -@ShouldGenerate(''' -// coverage:ignore-file -// ignore_for_file: type=lint -final class _Env35b { - static final ExampleEnum? testEnum = ExampleEnum.values.byName('ipsum'); -} -''') -@Envied(allowOptionalFields: true) -abstract class Env35b { - @EnviedField() - static final ExampleEnum? testEnum = null; -} - -@ShouldGenerate('static const List _enviedkeytestEnum', contains: true) -@ShouldGenerate('static const List _envieddatatestEnum', contains: true) -@ShouldGenerate(''' - static final ExampleEnum testEnum = - ExampleEnum.values.byName(String.fromCharCodes(List.generate( - _envieddatatestEnum.length, - (int i) => i, - growable: false, - ).map((int i) => _envieddatatestEnum[i] ^ _enviedkeytestEnum[i]))); -''', contains: true) -@Envied() -abstract class Env35c { - @EnviedField(obfuscate: true) - static final ExampleEnum? testEnum = null; -} - -@ShouldGenerate('static const List _enviedkeytestEnum', contains: true) -@ShouldGenerate('static const List _envieddatatestEnum', contains: true) -@ShouldGenerate(''' - static final ExampleEnum? testEnum = - ExampleEnum.values.byName(String.fromCharCodes(List.generate( - _envieddatatestEnum.length, - (int i) => i, - growable: false, - ).map((int i) => _envieddatatestEnum[i] ^ _enviedkeytestEnum[i]))); -''', contains: true) -@Envied(allowOptionalFields: true) -abstract class Env35d { - @EnviedField(obfuscate: true) - static final ExampleEnum? testEnum = null; -} - -@ShouldThrow( - 'Enumerated type `ExampleEnum` does not contain value `foo`. Possible values are: `lorem`, `ipsum`, `dolor`.', -) -@Envied() -abstract class Env35invalid { - @EnviedField() - static final ExampleEnum? invalidTestEnum = null; -} - -@ShouldThrow( - 'Enumerated type `ExampleEnum` does not contain value `foo`. Possible values are: `lorem`, `ipsum`, `dolor`.', -) -@Envied(allowOptionalFields: true) -abstract class Env35bInvalid { - @EnviedField() - static final ExampleEnum? invalidTestEnum = null; -} - -@ShouldThrow( - 'Enumerated type `ExampleEnum` does not contain value `foo`. Possible values are: `lorem`, `ipsum`, `dolor`.', -) -@Envied() -abstract class Env35cInvalid { - @EnviedField(obfuscate: true) - static final ExampleEnum? invalidTestEnum = null; -} - -@ShouldThrow( - 'Enumerated type `ExampleEnum` does not contain value `foo`. Possible values are: `lorem`, `ipsum`, `dolor`.', -) -@Envied(allowOptionalFields: true) -abstract class Env35dInvalid { - @EnviedField(obfuscate: true) - static final ExampleEnum? invalidTestEnum = null; + static const String? baz = null; } From 45ab85ea4c0835686f10fba566ad51ab1cf1a306 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Klemen=20Tu=C5=A1ar?= Date: Wed, 29 Nov 2023 19:32:44 +0000 Subject: [PATCH 7/7] :memo: update readme --- examples/envied_example/.env.test | 5 ----- examples/envied_example/build.yaml | 7 ------- packages/envied/README.md | 16 ++++++++++++++++ 3 files changed, 16 insertions(+), 12 deletions(-) delete mode 100644 examples/envied_example/.env.test delete mode 100644 examples/envied_example/build.yaml diff --git a/examples/envied_example/.env.test b/examples/envied_example/.env.test deleted file mode 100644 index de41a38..0000000 --- a/examples/envied_example/.env.test +++ /dev/null @@ -1,5 +0,0 @@ -KEY1=DEBUG1 -KEY2=DEBUG2 -key3=DEBUG3 -key4=1 -key5=true \ No newline at end of file diff --git a/examples/envied_example/build.yaml b/examples/envied_example/build.yaml deleted file mode 100644 index 98b7bd7..0000000 --- a/examples/envied_example/build.yaml +++ /dev/null @@ -1,7 +0,0 @@ -targets: - $default: - builders: - envied_generator|envied: - options: - path: .env.test - override: true \ No newline at end of file diff --git a/packages/envied/README.md b/packages/envied/README.md index b97ced3..5246aa0 100644 --- a/packages/envied/README.md +++ b/packages/envied/README.md @@ -221,6 +221,22 @@ static const String apiKey; // Searches for a variable named 'DEBUG_API_KEY' ins These example illustrates how the field name `apiKey` is automatically transformed to `API_KEY`, adhering to the `CONSTANT_CASE` convention commonly used as the variable name inside the `.env` file. This feature contributes to improved code consistency and readability, while also aligning with [Effective Dart](https://dart.dev/effective-dart) naming conventions. +### **Build configuration overrides** + +You can override the default `.env` file path by creating a `build.yaml` file in the root of your project. + +```yaml +targets: + $default: + builders: + envied_generator|envied: + options: + path: .env.custom + override: true +``` + +Note that **both** `path` and `override` must be set for the override to work. +
## License