@@ -2,19 +2,16 @@ import 'dart:io';
2
2
3
3
import 'package:build/build.dart' ;
4
4
import 'package:build_test/build_test.dart' ;
5
- import 'package:mockito/annotations.dart' ;
6
- import 'package:mockito/mockito.dart' ;
7
5
import 'package:openapi_generator/src/models/output_message.dart' ;
8
6
import 'package:openapi_generator/src/openapi_generator_runner.dart' ;
9
7
import 'package:openapi_generator/src/process_runner.dart' ;
10
8
import 'package:source_gen/source_gen.dart' ;
11
-
12
- @GenerateNiceMocks ([MockSpec <ProcessRunner >()])
13
- import 'utils.mocks.dart' ;
9
+ import 'package:test_process/test_process.dart' ;
14
10
15
11
final String pkgName = 'pkg' ;
16
- var _mockProcessRunner = MockProcessRunner ();
17
- final Builder builder = LibraryBuilder (OpenapiGenerator (_mockProcessRunner),
12
+
13
+ final Builder builder = LibraryBuilder (
14
+ OpenapiGenerator (ProcessRunnerForTests ()),
18
15
generatedExtension: '.openapi_generator' );
19
16
final testSpecPath =
20
17
'${Directory .current .path }${Platform .pathSeparator }test${Platform .pathSeparator }specs${Platform .pathSeparator }' ;
@@ -24,9 +21,6 @@ final testSpecPath =
24
21
/// [path] available so an override for the adds generated comment test can
25
22
/// compare the output.
26
23
Future <String > generate (String source, {String path = 'lib/myapp.dart' }) async {
27
- when (_mockProcessRunner.run (any, any, environment: anyNamed ('environment' )))
28
- .thenAnswer ((_) async => ProcessResult (0 , 0 , 'Output' , '' ));
29
-
30
24
final spec = File ('${testSpecPath }openapi.test.yaml' ).readAsStringSync ();
31
25
var srcs = < String , String > {
32
26
'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 {
35
29
'openapi_generator|$path ' : '''
36
30
import 'package:openapi_generator_annotations/src/openapi_generator_annotations_base.dart';
37
31
$source
38
- class MyApp {}
32
+ class MyApp {
33
+ }
39
34
''' ,
40
35
'openapi_generator|openapi-spec.yaml' : spec
41
36
};
@@ -60,3 +55,20 @@ Future<String> generate(String source, {String path = 'lib/myapp.dart'}) async {
60
55
String .fromCharCodes (
61
56
writer.assets[AssetId (pkgName, 'lib/value.g.dart' )] ?? []);
62
57
}
58
+
59
+ class ProcessRunnerForTests extends ProcessRunner {
60
+ @override
61
+ Future <ProcessResult > run (String executable, List <String > arguments,
62
+ {Map <String , String >? environment,
63
+ String ? workingDirectory,
64
+ bool runInShell = false }) {
65
+ return TestProcess .start (executable, arguments,
66
+ environment: environment,
67
+ workingDirectory: workingDirectory,
68
+ runInShell: runInShell)
69
+ .then (
70
+ (value) async => ProcessResult (
71
+ value.pid, await value.exitCode, value.stdout, value.stderr),
72
+ );
73
+ }
74
+ }
0 commit comments