diff --git a/openapi-generator/example/example.dart b/openapi-generator/example/example.dart index 3a8104d..7553bcf 100644 --- a/openapi-generator/example/example.dart +++ b/openapi-generator/example/example.dart @@ -1,3 +1,4 @@ +// Openapi Generator last run: : 2024-11-04T10:28:15.653697 import 'package:openapi_generator_annotations/openapi_generator_annotations.dart'; @Openapi( diff --git a/openapi-generator/example/pubspec.yaml b/openapi-generator/example/pubspec.yaml index f16cc50..4ac39d7 100644 --- a/openapi-generator/example/pubspec.yaml +++ b/openapi-generator/example/pubspec.yaml @@ -21,10 +21,10 @@ dependency_overrides: # meta: ^1.2.2 openapi_generator_annotations: path: ../../openapi-generator-annotations - openapi_generator: - path: ../../openapi-generator - openapi_generator_cli: - path: ../../openapi-generator-cli +# openapi_generator: +# path: ../../openapi-generator +# openapi_generator_cli: +# path: ../../openapi-generator-cli dependencies: # flutter: @@ -35,8 +35,8 @@ dependencies: dev_dependencies: # flutter_test: # sdk: flutter - build_runner: - openapi_generator: ^4.10.0 +# build_runner: +# openapi_generator: ^4.10.0 # For information on the generic Dart part of this file, see the diff --git a/openapi-generator/pubspec.yaml b/openapi-generator/pubspec.yaml index 1402a24..cd39e12 100755 --- a/openapi-generator/pubspec.yaml +++ b/openapi-generator/pubspec.yaml @@ -15,7 +15,6 @@ dependencies: openapi_generator_cli: '>5.0.2 <7.0.0' yaml: ^3.1.2 http: '>=0.13.1 <=2.0.0' - build_runner: '>=1.0.0 <3.0.0' logging: '>=1.0.0 <=2.0.0' dev_dependencies: @@ -23,5 +22,6 @@ dev_dependencies: mockito: ^5.4.4 build_test: '>=1.2.0 <3.0.0' source_gen_test: + test_process: pedantic: coverage: ^1.6.3 diff --git a/openapi-generator/test/builder_test.dart b/openapi-generator/test/builder_test.dart index 991b987..dacd4bc 100644 --- a/openapi-generator/test/builder_test.dart +++ b/openapi-generator/test/builder_test.dart @@ -297,17 +297,20 @@ class TestClassConfig extends OpenapiGeneratorConfig {} useNextGen: true, cachePath: '${f.path}', outputDirectory: '${f.parent.path}/fvm', + updateAnnotatedFile: false, additionalProperties: AdditionalProperties( wrapper: Wrapper.fvm, ), ) '''); - expect( - generatedOutput, contains('Running source code generation.')); expect( generatedOutput, contains( - 'fvm pub run build_runner build --delete-conflicting-outputs')); + 'Installing dependencies with generated source. fvm pub get')); + // expect( + // generatedOutput, + // contains( + // 'fvm pub run build_runner build --delete-conflicting-outputs')); }); test('flutterw', () async { generatedOutput = await generate(''' @@ -324,12 +327,14 @@ class TestClassConfig extends OpenapiGeneratorConfig {} ), ) '''); - expect( - generatedOutput, contains('Running source code generation.')); expect( generatedOutput, contains( - './flutterw pub run build_runner build --delete-conflicting-outputs')); + 'Installing dependencies with generated source. ./flutterw pub get')); + // expect( + // generatedOutput, + // contains( + // './flutterw pub run build_runner build --delete-conflicting-outputs')); }); }); test('without wrapper', () async { diff --git a/openapi-generator/test/utils.dart b/openapi-generator/test/utils.dart index f5af68e..8d7cdcd 100644 --- a/openapi-generator/test/utils.dart +++ b/openapi-generator/test/utils.dart @@ -2,19 +2,16 @@ import 'dart:io'; import 'package:build/build.dart'; import 'package:build_test/build_test.dart'; -import 'package:mockito/annotations.dart'; -import 'package:mockito/mockito.dart'; import 'package:openapi_generator/src/models/output_message.dart'; import 'package:openapi_generator/src/openapi_generator_runner.dart'; import 'package:openapi_generator/src/process_runner.dart'; import 'package:source_gen/source_gen.dart'; - -@GenerateNiceMocks([MockSpec<ProcessRunner>()]) -import 'utils.mocks.dart'; +import 'package:test_process/test_process.dart'; final String pkgName = 'pkg'; -var _mockProcessRunner = MockProcessRunner(); -final Builder builder = LibraryBuilder(OpenapiGenerator(_mockProcessRunner), + +final Builder builder = LibraryBuilder( + OpenapiGenerator(ProcessRunnerForTests()), generatedExtension: '.openapi_generator'); final testSpecPath = '${Directory.current.path}${Platform.pathSeparator}test${Platform.pathSeparator}specs${Platform.pathSeparator}'; @@ -24,9 +21,6 @@ final testSpecPath = /// [path] available so an override for the adds generated comment test can /// compare the output. Future<String> generate(String source, {String path = 'lib/myapp.dart'}) async { - when(_mockProcessRunner.run(any, any, environment: anyNamed('environment'))) - .thenAnswer((_) async => ProcessResult(0, 0, 'Output', '')); - final spec = File('${testSpecPath}openapi.test.yaml').readAsStringSync(); var srcs = <String, String>{ 'openapi_generator_annotations|lib/src/openapi_generator_annotations_base.dart': @@ -35,7 +29,8 @@ Future<String> generate(String source, {String path = 'lib/myapp.dart'}) async { 'openapi_generator|$path': ''' import 'package:openapi_generator_annotations/src/openapi_generator_annotations_base.dart'; $source - class MyApp {} + class MyApp { + } ''', 'openapi_generator|openapi-spec.yaml': spec }; @@ -60,3 +55,20 @@ Future<String> generate(String source, {String path = 'lib/myapp.dart'}) async { String.fromCharCodes( writer.assets[AssetId(pkgName, 'lib/value.g.dart')] ?? []); } + +class ProcessRunnerForTests extends ProcessRunner { + @override + Future<ProcessResult> run(String executable, List<String> arguments, + {Map<String, String>? environment, + String? workingDirectory, + bool runInShell = false}) { + return TestProcess.start(executable, arguments, + environment: environment, + workingDirectory: workingDirectory, + runInShell: runInShell) + .then( + (value) async => ProcessResult( + value.pid, await value.exitCode, value.stdout, value.stderr), + ); + } +}