Skip to content

Commit

Permalink
fix(cli): Fixed additionalCommands in config not appending to generat…
Browse files Browse the repository at this point in the history
…or commands
  • Loading branch information
gibahjoe committed Nov 6, 2024
1 parent a4a8e56 commit 99f6bec
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
2 changes: 1 addition & 1 deletion openapi-generator-cli/bin/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,8 @@ Future<void> runMain({

// Prepare additional arguments, excluding the --config flag and its value
final filteredArguments = <String>[
...additionalCommands.split(' '),
...arguments.where((arg) => arg != '--config' && arg != configFilePath),
additionalCommands,
];

// Execute with classpath
Expand Down
44 changes: 44 additions & 0 deletions openapi-generator-cli/test/openapi_generator_cli_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,50 @@ void main() {
expect(exitCode, equals(1));
expect(logBuffer.toString(), contains('Error: FileSystemException'));
});

// New Test: Check execution of additional commands from config
test(
'additional commands in config are appended to end of generation command.',
() async {
final mockCommands = 'validate generate';
final configData = {
ConfigKeys.openapiGeneratorVersion: '5.0.0',
ConfigKeys.additionalCommands: mockCommands,
ConfigKeys.jarCachePath: '.dart_tool/openapi_generator_cache',
};

var executedCommands = <String>[];
Future<void> mockExecuteWithClasspath(
List<String> jarPaths, List<String> args) async {
executedCommands.addAll(args);
}

await runMain(
arguments: ['gen'],
loadConfig: (p0) async => configData,
downloadJar: (p0, p1) async {},
executeWithClasspath: mockExecuteWithClasspath,
log: (p0) => print(p0),
);

// Verify commands executed from config
expect(executedCommands, equals(['gen', 'validate generate']));
});

test('ProcessRunner run method executes and prints out dart version',
() async {
// Define the expected input arguments
const executable = 'dart';
final arguments = ['--version'];

// Create an instance of ProcessRunner
final processRunner = ProcessRunner();

// Execute the run method and verify the result
final result = await processRunner.run(executable, arguments);
expect(result.stdout, contains('Dart SDK version'));
expect(result.exitCode, equals(0));
});
}

class TestProcessRunner extends ProcessRunner {
Expand Down

0 comments on commit 99f6bec

Please sign in to comment.