diff --git a/pkg/modular_test/analysis_options.yaml b/pkg/modular_test/analysis_options.yaml index c36c2c5d39f..572dd239d09 100644 --- a/pkg/modular_test/analysis_options.yaml +++ b/pkg/modular_test/analysis_options.yaml @@ -1 +1 @@ -include: package:lints/core.yaml +include: package:lints/recommended.yaml diff --git a/pkg/modular_test/lib/src/create_package_config.dart b/pkg/modular_test/lib/src/create_package_config.dart index db463ad2df1..2af7a94ee36 100644 --- a/pkg/modular_test/lib/src/create_package_config.dart +++ b/pkg/modular_test/lib/src/create_package_config.dart @@ -62,7 +62,7 @@ Future writePackageConfig( String _packageConfigEntry(String name, Uri root, {Uri? packageRoot, LanguageVersion? version}) { var fields = [ - '"name": "${name}"', + '"name": "$name"', '"rootUri": "$root"', if (packageRoot != null) '"packageUri": "$packageRoot"', if (version != null) '"languageVersion": "$version"' diff --git a/pkg/modular_test/lib/src/generic_runner.dart b/pkg/modular_test/lib/src/generic_runner.dart index 30d903c88b3..e797d9dce99 100644 --- a/pkg/modular_test/lib/src/generic_runner.dart +++ b/pkg/modular_test/lib/src/generic_runner.dart @@ -171,5 +171,5 @@ Future runSuite(List tests, RunnerOptions options) async { .writeAsStringSync(results.map((s) => '$s\n').join(), flush: true); File.fromUri(logsJsonUri) .writeAsStringSync(logs.map((s) => '$s\n').join(), flush: true); - print('log files emitted to ${resultJsonUri} and ${logsJsonUri}'); + print('log files emitted to $resultJsonUri and $logsJsonUri'); } diff --git a/pkg/modular_test/lib/src/io_pipeline.dart b/pkg/modular_test/lib/src/io_pipeline.dart index c3c2172b246..059272219c5 100644 --- a/pkg/modular_test/lib/src/io_pipeline.dart +++ b/pkg/modular_test/lib/src/io_pipeline.dart @@ -120,7 +120,7 @@ class IOPipeline extends Pipeline { // issues, we include one of the step data ids in the name of the folder. var stepId = step.resultData.first; var stepFolder = - await Directory.systemTemp.createTemp('modular_test_${stepId}-'); + await Directory.systemTemp.createTemp('modular_test_$stepId-'); for (var module in visibleData.keys) { for (var dataId in visibleData[module]!) { var assetUri = resultsFolderUri diff --git a/pkg/modular_test/lib/src/loader.dart b/pkg/modular_test/lib/src/loader.dart index 82a5339e81a..7621df4afaf 100644 --- a/pkg/modular_test/lib/src/loader.dart +++ b/pkg/modular_test/lib/src/loader.dart @@ -141,14 +141,14 @@ void _attachDependencies( if (module.dependencies.isNotEmpty) { _invalidTest("Module dependencies have already been declared on $name."); } - moduleDependencies.forEach((dependencyName) { + for (var dependencyName in moduleDependencies) { final moduleDependency = modules[dependencyName]; if (moduleDependency == null) { _invalidTest("'$name' declares a dependency on a nonexistent module " "named '$dependencyName'"); } module.dependencies.add(moduleDependency); - }); + } }); } @@ -273,6 +273,7 @@ Never _invalidTest(String message) { class InvalidTestError extends Error { final String message; InvalidTestError(this.message); + @override String toString() => "Invalid test: $message"; } diff --git a/pkg/modular_test/lib/src/memory_pipeline.dart b/pkg/modular_test/lib/src/memory_pipeline.dart index 8100440c24e..a8c87ac0d22 100644 --- a/pkg/modular_test/lib/src/memory_pipeline.dart +++ b/pkg/modular_test/lib/src/memory_pipeline.dart @@ -44,7 +44,7 @@ class MemoryPipeline extends Pipeline { @override Future run(ModularTest test) async { var results = _results = {}; - Map>? cache = null; + Map>? cache; if (cacheSharedModules) { int id = _registry!.computeConfigurationId(test); if (id < _resultCache.length) { @@ -94,10 +94,10 @@ class MemoryPipeline extends Pipeline { }); Map inputSources = {}; if (step.needsSources) { - module.sources.forEach((relativeUri) { + for (var relativeUri in module.sources) { var uri = module.rootUri.resolveUri(relativeUri); inputSources[uri] = _sources[uri]!; - }); + } } Map result = await step.execute( module, diff --git a/pkg/modular_test/lib/src/pipeline.dart b/pkg/modular_test/lib/src/pipeline.dart index b65eb1201e3..1b9d1bef5e8 100644 --- a/pkg/modular_test/lib/src/pipeline.dart +++ b/pkg/modular_test/lib/src/pipeline.dart @@ -110,14 +110,14 @@ abstract class Pipeline { for (var dataId in step.dependencyDataNeeded) { if (!previousKinds.containsKey(dataId)) { _validationError( - "Step '${step.runtimeType}' needs data '${dataId}', but the " + "Step '${step.runtimeType}' needs data '$dataId', but the " "data is not produced by this or a preceding step."); } } for (var dataId in step.moduleDataNeeded) { if (!previousKinds.containsKey(dataId)) { _validationError( - "Step '${step.runtimeType}' needs data '${dataId}', but the " + "Step '${step.runtimeType}' needs data '$dataId', but the " "data is not produced by a preceding step."); } if (dataId == resultKind) { @@ -160,14 +160,14 @@ abstract class Pipeline { // Include only requested data from transitive dependencies. Map> visibleData = {}; - deps.forEach((dep) { + for (var dep in deps) { visibleData[dep] = {}; for (var dataId in step.dependencyDataNeeded) { if (computedData[dep]!.contains(dataId)) { visibleData[dep]!.add(dataId); } } - }); + } visibleData[module] = {}; for (var dataId in step.moduleDataNeeded) { if (computedData[module]!.contains(dataId)) { @@ -185,5 +185,6 @@ abstract class Pipeline { class InvalidPipelineError extends Error { final String message; InvalidPipelineError(this.message); + @override String toString() => "Invalid pipeline: $message"; } diff --git a/pkg/modular_test/lib/src/runner.dart b/pkg/modular_test/lib/src/runner.dart index 4c01c051227..ef33748a683 100644 --- a/pkg/modular_test/lib/src/runner.dart +++ b/pkg/modular_test/lib/src/runner.dart @@ -39,6 +39,7 @@ Future runSuite(Uri suiteFolder, String suiteName, Options options, } class _PipelineTest implements generic.Test { + @override final String name; final Uri uri; final Options options; @@ -49,6 +50,7 @@ class _PipelineTest implements generic.Test { // from the suite and the trailing `/`. : name = uri.path.substring(suiteFolder.path.length, uri.path.length - 1); + @override Future run() async { ModularTest test = await loadTest(uri); if (options.verbose) print(test.debugString()); diff --git a/pkg/modular_test/lib/src/suite.dart b/pkg/modular_test/lib/src/suite.dart index 2ed07987788..21ae6311efc 100644 --- a/pkg/modular_test/lib/src/suite.dart +++ b/pkg/modular_test/lib/src/suite.dart @@ -148,7 +148,7 @@ Set computeTransitiveDependencies(Module module) { /// of flags (the same configuration), and thus pipelines could reuse the /// results of shared modules from the first test when running the second test. class ConfigurationRegistry { - Map _configurationId = {}; + final Map _configurationId = {}; /// Compute an id to identify the configuration of a modular test. /// @@ -164,5 +164,6 @@ class ConfigurationRegistry { class InvalidModularTestError extends Error { final String message; InvalidModularTestError(this.message); + @override String toString() => "Invalid modular test: $message"; } diff --git a/pkg/modular_test/lib/src/test_specification_parser.dart b/pkg/modular_test/lib/src/test_specification_parser.dart index 1a007d66eaa..2026ac7265b 100644 --- a/pkg/modular_test/lib/src/test_specification_parser.dart +++ b/pkg/modular_test/lib/src/test_specification_parser.dart @@ -76,12 +76,12 @@ TestSpecification parseTestSpecification(String contents) { if (value is String) { values.add(value); } else if (value is List) { - value.forEach((entry) { + for (var entry in value) { if (entry is! String) { _invalidSpecification("entry: '$entry' is not a string"); } values.add(entry); - }); + } } else { _invalidSpecification( "entry: '$value' is not a string or a list of strings"); @@ -144,5 +144,6 @@ _invalidSpecification(String message) { class InvalidSpecificationError extends Error { final String message; InvalidSpecificationError(this.message); + @override String toString() => "Invalid specification: $message"; } diff --git a/pkg/modular_test/test/io_pipeline_test.dart b/pkg/modular_test/test/io_pipeline_test.dart index af83b9f6c61..951cc0eda76 100644 --- a/pkg/modular_test/test/io_pipeline_test.dart +++ b/pkg/modular_test/test/io_pipeline_test.dart @@ -102,12 +102,19 @@ class IOPipelineTestStrategy implements PipelineTestStrategy { class SourceOnlyStep implements IOModularStep { final String Function(Map) action; final DataId resultId; + @override final bool needsSources; + @override List get dependencyDataNeeded => const []; + @override List get moduleDataNeeded => const []; + @override List get resultData => [resultId]; + @override bool get onlyOnMain => false; + @override bool get onlyOnSdk => false; + @override bool get notOnSdk => false; SourceOnlyStep(this.action, this.resultId, this.needsSources); @@ -131,14 +138,21 @@ class SourceOnlyStep implements IOModularStep { class ModuleDataStep implements IOModularStep { final String Function(String) action; + @override bool get needsSources => false; + @override List get dependencyDataNeeded => const []; + @override final List moduleDataNeeded; + @override List get resultData => [resultId]; final DataId resultId; final DataId inputId; + @override bool get onlyOnMain => false; + @override bool get onlyOnSdk => false; + @override bool get notOnSdk => false; ModuleDataStep(this.action, this.inputId, this.resultId, bool requestInput) @@ -161,15 +175,22 @@ class ModuleDataStep implements IOModularStep { class TwoOutputStep implements IOModularStep { final String Function(String) action1; final String Function(String) action2; + @override bool get needsSources => false; + @override List get dependencyDataNeeded => const []; + @override List get moduleDataNeeded => [inputId]; + @override List get resultData => [result1Id, result2Id]; final DataId result1Id; final DataId result2Id; final DataId inputId; + @override bool get onlyOnMain => false; + @override bool get onlyOnSdk => false; + @override bool get notOnSdk => false; TwoOutputStep( @@ -194,16 +215,23 @@ class TwoOutputStep implements IOModularStep { } class LinkStep implements IOModularStep { + @override bool get needsSources => false; + @override final List dependencyDataNeeded; + @override List get moduleDataNeeded => [inputId]; + @override List get resultData => [resultId]; final String Function(String, List) action; final DataId inputId; final DataId depId; final DataId resultId; + @override bool get onlyOnMain => false; + @override bool get onlyOnSdk => false; + @override bool get notOnSdk => false; LinkStep(this.action, this.inputId, this.depId, this.resultId, @@ -228,16 +256,23 @@ class LinkStep implements IOModularStep { } class MainOnlyStep implements IOModularStep { + @override bool get needsSources => false; + @override final List dependencyDataNeeded; + @override List get moduleDataNeeded => [inputId]; + @override List get resultData => [resultId]; final String Function(String, List) action; final DataId inputId; final DataId depId; final DataId resultId; + @override bool get onlyOnMain => true; + @override bool get onlyOnSdk => false; + @override bool get notOnSdk => false; MainOnlyStep(this.action, this.inputId, this.depId, this.resultId, diff --git a/pkg/modular_test/test/loader/loader_test.dart b/pkg/modular_test/test/loader/loader_test.dart index 395b4b70745..8e253900654 100644 --- a/pkg/modular_test/test/loader/loader_test.dart +++ b/pkg/modular_test/test/loader/loader_test.dart @@ -87,9 +87,9 @@ String _dumpAsText(ModularTest test) { } else if (module.isSdk) { buffer.write('\n (sdk sources omitted)'); } else { - module.sources.forEach((uri) { + for (var uri in module.sources) { buffer.write('\n $uri'); - }); + } } buffer.write('\n'); diff --git a/pkg/modular_test/test/memory_pipeline_test.dart b/pkg/modular_test/test/memory_pipeline_test.dart index cc145cf290b..40c1c7e39d7 100644 --- a/pkg/modular_test/test/memory_pipeline_test.dart +++ b/pkg/modular_test/test/memory_pipeline_test.dart @@ -76,22 +76,31 @@ class MemoryPipelineTestStrategy return pipeline.resultsForTesting![m]![dataId] as String?; } + @override FutureOr cleanup(Pipeline pipeline) => null; } class SourceOnlyStep implements MemoryModularStep { final String Function(Map) action; final DataId resultId; + @override final bool needsSources; + @override List get dependencyDataNeeded => const []; + @override List get moduleDataNeeded => const []; + @override List get resultData => [resultId]; + @override bool get onlyOnMain => false; + @override bool get onlyOnSdk => false; + @override bool get notOnSdk => false; SourceOnlyStep(this.action, this.resultId, this.needsSources); + @override Future> execute( Module module, SourceProvider sourceProvider, @@ -110,19 +119,27 @@ class SourceOnlyStep implements MemoryModularStep { class ModuleDataStep implements MemoryModularStep { final String Function(String) action; + @override bool get needsSources => false; + @override List get dependencyDataNeeded => const []; + @override final List moduleDataNeeded; + @override List get resultData => [resultId]; final DataId resultId; final DataId inputId; + @override bool get onlyOnMain => false; + @override bool get onlyOnSdk => false; + @override bool get notOnSdk => false; ModuleDataStep(this.action, this.inputId, this.resultId, bool requestInput) : moduleDataNeeded = requestInput ? [inputId] : []; + @override Future> execute( Module module, SourceProvider sourceProvider, @@ -142,20 +159,28 @@ class ModuleDataStep implements MemoryModularStep { class TwoOutputStep implements MemoryModularStep { final String Function(String) action1; final String Function(String) action2; + @override bool get needsSources => false; + @override List get dependencyDataNeeded => const []; + @override List get moduleDataNeeded => [inputId]; + @override List get resultData => [result1Id, result2Id]; final DataId result1Id; final DataId result2Id; final DataId inputId; + @override bool get onlyOnMain => false; + @override bool get onlyOnSdk => false; + @override bool get notOnSdk => false; TwoOutputStep( this.action1, this.action2, this.inputId, this.result1Id, this.result2Id); + @override Future> execute( Module module, SourceProvider sourceProvider, @@ -177,22 +202,30 @@ class TwoOutputStep implements MemoryModularStep { } class LinkStep implements MemoryModularStep { + @override bool get needsSources => false; + @override final List dependencyDataNeeded; + @override List get moduleDataNeeded => [inputId]; final String Function(String, List) action; final DataId inputId; final DataId depId; final DataId resultId; + @override List get resultData => [resultId]; + @override bool get onlyOnMain => false; + @override bool get onlyOnSdk => false; + @override bool get notOnSdk => false; LinkStep(this.action, this.inputId, this.depId, this.resultId, bool requestDependencies) : dependencyDataNeeded = requestDependencies ? [depId] : []; + @override Future> execute( Module module, SourceProvider sourceProvider, @@ -210,22 +243,30 @@ class LinkStep implements MemoryModularStep { } class MainOnlyStep implements MemoryModularStep { + @override bool get needsSources => false; + @override final List dependencyDataNeeded; + @override List get moduleDataNeeded => [inputId]; final String Function(String, List) action; final DataId inputId; final DataId depId; final DataId resultId; + @override List get resultData => [resultId]; + @override bool get onlyOnMain => true; + @override bool get onlyOnSdk => false; + @override bool get notOnSdk => false; MainOnlyStep(this.action, this.inputId, this.depId, this.resultId, bool requestDependencies) : dependencyDataNeeded = requestDependencies ? [depId] : []; + @override Future> execute( Module module, SourceProvider sourceProvider,