From f958b3fd040b630d05429c4a7eddd71f6ee4e6ad Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 6 Jun 2025 15:04:05 +0000 Subject: [PATCH 1/5] chore(deps): bump very_good_analysis from 7.0.0 to 9.0.0 Bumps [very_good_analysis](https://github.com/VeryGoodOpenSource/very_good_analysis) from 7.0.0 to 9.0.0. - [Release notes](https://github.com/VeryGoodOpenSource/very_good_analysis/releases) - [Changelog](https://github.com/VeryGoodOpenSource/very_good_analysis/blob/main/CHANGELOG.md) - [Commits](https://github.com/VeryGoodOpenSource/very_good_analysis/compare/v7.0.0...v9.0.0) --- updated-dependencies: - dependency-name: very_good_analysis dependency-version: 9.0.0 dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- pubspec.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pubspec.yaml b/pubspec.yaml index 6c14e71..12bcc52 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -21,4 +21,4 @@ dependencies: dev_dependencies: mocktail: ^1.0.4 test: ^1.25.8 - very_good_analysis: ^7.0.0 + very_good_analysis: ">=7.0.0 <10.0.0" From 74af4f55dc889635e53bcfa7597e4ec43ace2f65 Mon Sep 17 00:00:00 2001 From: Marcos Sevilla Date: Thu, 10 Jul 2025 14:01:51 +0200 Subject: [PATCH 2/5] fix: lints --- analysis_options.yaml | 2 +- example/analysis_options.yaml | 2 +- example/pubspec.yaml | 2 +- lib/src/command_runner/completion_command_runner.dart | 2 +- pubspec.yaml | 4 ++-- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/analysis_options.yaml b/analysis_options.yaml index c2f4cbb..9df80aa 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -1 +1 @@ -include: package:very_good_analysis/analysis_options.7.0.0.yaml +include: package:very_good_analysis/analysis_options.yaml diff --git a/example/analysis_options.yaml b/example/analysis_options.yaml index c59316b..ce42cd4 100644 --- a/example/analysis_options.yaml +++ b/example/analysis_options.yaml @@ -1,4 +1,4 @@ -include: package:very_good_analysis/analysis_options.7.0.0.yaml +include: package:very_good_analysis/analysis_options.yaml linter: rules: public_member_api_docs: false diff --git a/example/pubspec.yaml b/example/pubspec.yaml index 0e10eb3..d61d984 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -15,7 +15,7 @@ dependencies: dev_dependencies: mocktail: ^1.0.4 test: ^1.25.8 - very_good_analysis: ^7.0.0 + very_good_analysis: ^9.0.0 executables: example_cli: diff --git a/lib/src/command_runner/completion_command_runner.dart b/lib/src/command_runner/completion_command_runner.dart index b226ea7..8303754 100644 --- a/lib/src/command_runner/completion_command_runner.dart +++ b/lib/src/command_runner/completion_command_runner.dart @@ -71,7 +71,7 @@ abstract class CompletionCommandRunner extends CommandRunner { } /// The list of commands that should not trigger the auto installation. - static const _reservedCommands = { + static const Set _reservedCommands = { HandleCompletionRequestCommand.commandName, InstallCompletionFilesCommand.commandName, UnistallCompletionFilesCommand.commandName, diff --git a/pubspec.yaml b/pubspec.yaml index 12bcc52..f2fec3a 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -9,7 +9,7 @@ screenshots: path: doc/screen.png environment: - sdk: ^3.5.0 + sdk: ^3.8.0 dependencies: args: ^2.5.0 @@ -21,4 +21,4 @@ dependencies: dev_dependencies: mocktail: ^1.0.4 test: ^1.25.8 - very_good_analysis: ">=7.0.0 <10.0.0" + very_good_analysis: ^9.0.0 From 0f076a769d46c7473888f407e13b499bf9066b46 Mon Sep 17 00:00:00 2001 From: Marcos Sevilla Date: Thu, 10 Jul 2025 14:03:19 +0200 Subject: [PATCH 3/5] chore: bump example sdk to 3.8.0 --- example/pubspec.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/example/pubspec.yaml b/example/pubspec.yaml index d61d984..cd64579 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -4,7 +4,7 @@ version: 0.0.1 publish_to: none environment: - sdk: ^3.5.0 + sdk: ^3.8.0 dependencies: args: ^2.5.0 From 8a55bc19e3205d060e1ec1b578a6e58a438f89c3 Mon Sep 17 00:00:00 2001 From: Marcos Sevilla Date: Thu, 10 Jul 2025 14:04:12 +0200 Subject: [PATCH 4/5] fix: format --- .../installer/completion_configuration.dart | 8 +- .../installer/completion_installation.dart | 19 +- lib/src/installer/exceptions.dart | 3 +- .../installer/script_configuration_entry.dart | 4 +- lib/src/parser/arg_parser_extension.dart | 5 +- lib/src/parser/completion_level.dart | 9 +- lib/src/parser/completion_result.dart | 8 +- lib/src/parser/parser.dart | 5 +- ...install_completion_files_command_test.dart | 6 +- ...install_completion_files_command_test.dart | 10 +- .../completion_command_runner_test.dart | 42 +- .../completion_configuration_test.dart | 189 +++-- .../completion_installation_test.dart | 772 +++++++++--------- .../script_configuration_entry_test.dart | 85 +- .../shell_completion_configuration_test.dart | 10 +- test/src/parser/completion_level_test.dart | 16 +- test/src/parser/parser_test.dart | 24 +- 17 files changed, 652 insertions(+), 563 deletions(-) diff --git a/lib/src/installer/completion_configuration.dart b/lib/src/installer/completion_configuration.dart index d4c6747..a524450 100644 --- a/lib/src/installer/completion_configuration.dart +++ b/lib/src/installer/completion_configuration.dart @@ -10,8 +10,8 @@ import 'package:meta/meta.dart'; /// /// The map and its content are unmodifiable. This is to ensure that /// [CompletionConfiguration]s is fully immutable. -typedef ShellCommandsMap - = UnmodifiableMapView>; +typedef ShellCommandsMap = + UnmodifiableMapView>; /// {@template completion_configuration} /// A configuration that stores information on how to handle command @@ -28,8 +28,8 @@ class CompletionConfiguration { /// Creates an empty [CompletionConfiguration]. @visibleForTesting CompletionConfiguration.empty() - : uninstalls = ShellCommandsMap({}), - installs = ShellCommandsMap({}); + : uninstalls = ShellCommandsMap({}), + installs = ShellCommandsMap({}); /// Creates a [CompletionConfiguration] from the given [file] content. /// diff --git a/lib/src/installer/completion_installation.dart b/lib/src/installer/completion_installation.dart index 9cb0d4d..b0e0943 100644 --- a/lib/src/installer/completion_installation.dart +++ b/lib/src/installer/completion_installation.dart @@ -139,8 +139,9 @@ class CompletionInstallation { _logSourceInstructions(rootCommand); } - final completionConfiguration = - CompletionConfiguration.fromFile(completionConfigurationFile); + final completionConfiguration = CompletionConfiguration.fromFile( + completionConfigurationFile, + ); completionConfiguration .copyWith( uninstalls: completionConfiguration.uninstalls.exclude( @@ -305,7 +306,8 @@ class CompletionInstallation { _sourceScriptOnFile( configFile: shellRCFile, scriptName: 'Completion', - description: 'Completion scripts setup. ' + description: + 'Completion scripts setup. ' 'Remove the following line to uninstall', scriptPath: path.join( completionConfigDir.path, @@ -344,7 +346,8 @@ class CompletionInstallation { description ??= 'Completion config for "$scriptName"'; - final content = ''' + final content = + ''' ## $description ${configuration!.sourceLineTemplate(scriptPath)}'''; ScriptConfigurationEntry(scriptName).appendTo( @@ -429,14 +432,16 @@ ${configuration!.sourceLineTemplate(scriptPath)}'''; completionEntry.removeFrom(shellRCFile); } final completionConfigDirContent = completionConfigDir.listSync(); - final onlyHasConfigurationFile = completionConfigDirContent.length == 1 && + final onlyHasConfigurationFile = + completionConfigDirContent.length == 1 && path.absolute(completionConfigDirContent.first.path) == path.absolute(completionConfigurationFile.path); if (completionConfigDirContent.isEmpty || onlyHasConfigurationFile) { completionConfigDir.deleteSync(recursive: true); } else { - final completionConfiguration = - CompletionConfiguration.fromFile(completionConfigurationFile); + final completionConfiguration = CompletionConfiguration.fromFile( + completionConfigurationFile, + ); completionConfiguration .copyWith( uninstalls: completionConfiguration.uninstalls.include( diff --git a/lib/src/installer/exceptions.dart b/lib/src/installer/exceptions.dart index c29b82e..583071f 100644 --- a/lib/src/installer/exceptions.dart +++ b/lib/src/installer/exceptions.dart @@ -15,7 +15,8 @@ class CompletionInstallationException implements Exception { final String rootCommand; @override - String toString() => 'Could not install completion scripts for $rootCommand: ' + String toString() => + 'Could not install completion scripts for $rootCommand: ' '$message'; } diff --git a/lib/src/installer/script_configuration_entry.dart b/lib/src/installer/script_configuration_entry.dart index 3eb38f7..b4c8c82 100644 --- a/lib/src/installer/script_configuration_entry.dart +++ b/lib/src/installer/script_configuration_entry.dart @@ -7,8 +7,8 @@ import 'dart:io'; class ScriptConfigurationEntry { /// {@macro script_entry} const ScriptConfigurationEntry(this.name) - : _startComment = '## [$name]', - _endComment = '## [/$name]'; + : _startComment = '## [$name]', + _endComment = '## [/$name]'; /// The name of the entry. final String name; diff --git a/lib/src/parser/arg_parser_extension.dart b/lib/src/parser/arg_parser_extension.dart index 57f2962..677b100 100644 --- a/lib/src/parser/arg_parser_extension.dart +++ b/lib/src/parser/arg_parser_extension.dart @@ -46,8 +46,9 @@ extension ArgParserExtension on ArgParser { }); try { - return commandsOnlyGrammar - .parse(filteredArgs.where((element) => element.isNotEmpty)); + return commandsOnlyGrammar.parse( + filteredArgs.where((element) => element.isNotEmpty), + ); } on ArgParserException { return null; } diff --git a/lib/src/parser/completion_level.dart b/lib/src/parser/completion_level.dart index 5ab62fa..e80e9f2 100644 --- a/lib/src/parser/completion_level.dart +++ b/lib/src/parser/completion_level.dart @@ -85,15 +85,18 @@ class CompletionLevel { // rawArgs should be only the args after the last parsed command final List rawArgs; if (commandName != null) { - rawArgs = - rootArgs.skipWhile((value) => value != commandName).skip(1).toList(); + rawArgs = rootArgs + .skipWhile((value) => value != commandName) + .skip(1) + .toList(); } else { rawArgs = rootArgs.toList(); } final validOptionsResult = originalGrammar.findValidOptions(rawArgs); - final visibleSubcommands = subcommands?.values.where((command) { + final visibleSubcommands = + subcommands?.values.where((command) { return !command.hidden; }).toList() ?? []; diff --git a/lib/src/parser/completion_result.dart b/lib/src/parser/completion_result.dart index 723beda..378c283 100644 --- a/lib/src/parser/completion_result.dart +++ b/lib/src/parser/completion_result.dart @@ -195,8 +195,8 @@ class OptionValuesCompletionResult extends CompletionResult { required this.completionLevel, required this.optionName, this.pattern, - }) : isAbbr = false, - includeAbbrName = false; + }) : isAbbr = false, + includeAbbrName = false; /// {@macro option_values_completion_result} const OptionValuesCompletionResult.abbr({ @@ -204,8 +204,8 @@ class OptionValuesCompletionResult extends CompletionResult { required String abbrName, this.pattern, this.includeAbbrName = false, - }) : isAbbr = true, - optionName = abbrName; + }) : isAbbr = true, + optionName = abbrName; /// The [CompletionLevel] in which the suggested option is supposed to be /// located at. diff --git a/lib/src/parser/parser.dart b/lib/src/parser/parser.dart index 70ff3f4..0e5bb8f 100644 --- a/lib/src/parser/parser.dart +++ b/lib/src/parser/parser.dart @@ -66,8 +66,9 @@ class CompletionParser { // option with "allowed" values // e.g. `my_cli --option valueNam|` or `my_cli -o valueNam|` if (nonEmptyArgs.length > 1) { - final secondLastNonEmpty = - nonEmptyArgs.elementAt(nonEmptyArgs.length - 2); + final secondLastNonEmpty = nonEmptyArgs.elementAt( + nonEmptyArgs.length - 2, + ); final resultForValues = _getOptionValues(secondLastNonEmpty, argOnCursor); diff --git a/test/src/command_runner/commands/install_completion_files_command_test.dart b/test/src/command_runner/commands/install_completion_files_command_test.dart index ff58d91..c64eb4d 100644 --- a/test/src/command_runner/commands/install_completion_files_command_test.dart +++ b/test/src/command_runner/commands/install_completion_files_command_test.dart @@ -50,8 +50,10 @@ void main() { await commandRunner.run(['install-completion-files']); verify( - () => commandRunner.completionInstallation - .install(commandRunner.executableName, force: true), + () => commandRunner.completionInstallation.install( + commandRunner.executableName, + force: true, + ), ).called(1); }); diff --git a/test/src/command_runner/commands/uninstall_completion_files_command_test.dart b/test/src/command_runner/commands/uninstall_completion_files_command_test.dart index f9cfee3..e771a89 100644 --- a/test/src/command_runner/commands/uninstall_completion_files_command_test.dart +++ b/test/src/command_runner/commands/uninstall_completion_files_command_test.dart @@ -53,8 +53,9 @@ void main() { () => commandRunner.completionInstallationLogger.level = Level.info, ).called(1); verify( - () => commandRunner.completionInstallation - .uninstall(commandRunner.executableName), + () => commandRunner.completionInstallation.uninstall( + commandRunner.executableName, + ), ).called(1); }); @@ -68,8 +69,9 @@ void main() { }, ).called(1); verify( - () => commandRunner.completionInstallation - .uninstall(commandRunner.executableName), + () => commandRunner.completionInstallation.uninstall( + commandRunner.executableName, + ), ).called(1); }); }); diff --git a/test/src/command_runner/completion_command_runner_test.dart b/test/src/command_runner/completion_command_runner_test.dart index cec6280..3ab73e2 100644 --- a/test/src/command_runner/completion_command_runner_test.dart +++ b/test/src/command_runner/completion_command_runner_test.dart @@ -179,26 +179,30 @@ void main() { await commandRunner.run(['ahoy']); - verify(() => commandRunner.completionInstallationLogger.warn(any())) - .called(1); + verify( + () => commandRunner.completionInstallationLogger.warn(any()), + ).called(1); }, ); - test('When an unknown exception happens during a install, it logs as error', - () async { - final commandRunner = _TestCompletionCommandRunner() - ..addCommand(_TestUserCommand()) - ..mockCompletionInstallation = _MockCompletionInstallation(); + test( + 'When an unknown exception happens during a install, it logs as error', + () async { + final commandRunner = _TestCompletionCommandRunner() + ..addCommand(_TestUserCommand()) + ..mockCompletionInstallation = _MockCompletionInstallation(); - when( - () => commandRunner.completionInstallation.install('test'), - ).thenThrow(Exception('oops')); + when( + () => commandRunner.completionInstallation.install('test'), + ).thenThrow(Exception('oops')); - await commandRunner.run(['ahoy']); + await commandRunner.run(['ahoy']); - verify(() => commandRunner.completionInstallationLogger.err(any())) - .called(1); - }); + verify( + () => commandRunner.completionInstallationLogger.err(any()), + ).called(1); + }, + ); group('tryUninstallCompletionFiles', () { test( @@ -218,8 +222,9 @@ void main() { commandRunner.tryUninstallCompletionFiles(Level.verbose); - verify(() => commandRunner.completionInstallationLogger.warn(any())) - .called(1); + verify( + () => commandRunner.completionInstallationLogger.warn(any()), + ).called(1); }, ); @@ -235,8 +240,9 @@ void main() { commandRunner.tryUninstallCompletionFiles(Level.verbose); - verify(() => commandRunner.completionInstallationLogger.err(any())) - .called(1); + verify( + () => commandRunner.completionInstallationLogger.err(any()), + ).called(1); }, ); }); diff --git a/test/src/installer/completion_configuration_test.dart b/test/src/installer/completion_configuration_test.dart index a8c954e..351ec54 100644 --- a/test/src/installer/completion_configuration_test.dart +++ b/test/src/installer/completion_configuration_test.dart @@ -31,8 +31,9 @@ void main() { reason: 'File should not exist', ); - final completionConfiguration = - CompletionConfiguration.fromFile(file); + final completionConfiguration = CompletionConfiguration.fromFile( + file, + ); expect( completionConfiguration.uninstalls, isEmpty, @@ -56,30 +57,32 @@ void main() { ); }); - test("returns a $CompletionConfiguration with the file's defined members", - () { - final tempDirectory = Directory.systemTemp.createTempSync(); - addTearDown(() => tempDirectory.deleteSync(recursive: true)); + test( + "returns a $CompletionConfiguration with the file's defined members", + () { + final tempDirectory = Directory.systemTemp.createTempSync(); + addTearDown(() => tempDirectory.deleteSync(recursive: true)); - final file = File(path.join(tempDirectory.path, 'config.json')); - final completionConfiguration = - CompletionConfiguration.empty().copyWith( - installs: testInstalls, - uninstalls: testUninstalls, - )..writeTo(file); + final file = File(path.join(tempDirectory.path, 'config.json')); + final completionConfiguration = + CompletionConfiguration.empty().copyWith( + installs: testInstalls, + uninstalls: testUninstalls, + )..writeTo(file); - final newConfiguration = CompletionConfiguration.fromFile(file); - expect( - newConfiguration.installs, - equals(completionConfiguration.installs), - reason: 'Installs should match those defined in the file', - ); - expect( - newConfiguration.uninstalls, - equals(completionConfiguration.uninstalls), - reason: 'Uninstalls should match those defined in the file', - ); - }); + final newConfiguration = CompletionConfiguration.fromFile(file); + expect( + newConfiguration.installs, + equals(completionConfiguration.installs), + reason: 'Installs should match those defined in the file', + ); + expect( + newConfiguration.uninstalls, + equals(completionConfiguration.uninstalls), + reason: 'Uninstalls should match those defined in the file', + ); + }, + ); test( '''returns a $CompletionConfiguration with empty uninstalls if the file's JSON uninstalls key has a string value''', @@ -92,8 +95,9 @@ void main() { final file = File(path.join(tempDirectory.path, 'config.json')) ..writeAsStringSync(json); - final completionConfiguration = - CompletionConfiguration.fromFile(file); + final completionConfiguration = CompletionConfiguration.fromFile( + file, + ); expect( completionConfiguration.uninstalls, isEmpty, @@ -114,8 +118,9 @@ void main() { final file = File(path.join(tempDirectory.path, 'config.json')) ..writeAsStringSync(json); - final completionConfiguration = - CompletionConfiguration.fromFile(file); + final completionConfiguration = CompletionConfiguration.fromFile( + file, + ); expect( completionConfiguration.installs, isEmpty, @@ -135,8 +140,9 @@ void main() { final file = File(path.join(tempDirectory.path, 'config.json')) ..writeAsStringSync(json); - final completionConfiguration = - CompletionConfiguration.fromFile(file); + final completionConfiguration = CompletionConfiguration.fromFile( + file, + ); expect( completionConfiguration.uninstalls, isEmpty, @@ -156,8 +162,9 @@ void main() { final file = File(path.join(tempDirectory.path, 'config.json')) ..writeAsStringSync(json); - final completionConfiguration = - CompletionConfiguration.fromFile(file); + final completionConfiguration = CompletionConfiguration.fromFile( + file, + ); expect( completionConfiguration.installs, isEmpty, @@ -215,12 +222,13 @@ void main() { final file = File(path.join(tempDirectory.path, 'config.json')); final completionConfiguration = CompletionConfiguration.empty().copyWith( - installs: testInstalls, - uninstalls: testUninstalls, - )..writeTo(file); + installs: testInstalls, + uninstalls: testUninstalls, + )..writeTo(file); - final newcompletionConfiguration = - CompletionConfiguration.fromFile(file); + final newcompletionConfiguration = CompletionConfiguration.fromFile( + file, + ); expect( newcompletionConfiguration.installs, completionConfiguration.installs, @@ -249,8 +257,9 @@ void main() { test('modifies uninstalls when specified', () { final completionConfiguration = CompletionConfiguration.empty(); final uninstalls = testUninstalls; - final newcompletionConfiguration = - completionConfiguration.copyWith(uninstalls: uninstalls); + final newcompletionConfiguration = completionConfiguration.copyWith( + uninstalls: uninstalls, + ); expect( newcompletionConfiguration.uninstalls, @@ -262,8 +271,9 @@ void main() { test('modifies installs when specified', () { final completionConfiguration = CompletionConfiguration.empty(); final installs = testUninstalls; - final newcompletionConfiguration = - completionConfiguration.copyWith(installs: installs); + final newcompletionConfiguration = completionConfiguration.copyWith( + installs: installs, + ); expect( newcompletionConfiguration.installs, @@ -377,63 +387,66 @@ void main() { }); test( - '''remains the same when command in $ShellCommandsMap is on a different shell''', - () { - const testCommand = 'test_command'; - const testShell = SystemShell.bash; - final shellCommandsMap = ShellCommandsMap({ - testShell: UnmodifiableSetView({testCommand}), - }); - - const anotherShell = SystemShell.zsh; - final newShellCommadsMap = shellCommandsMap.exclude( - command: testCommand, - systemShell: anotherShell, - ); + '''remains the same when command in $ShellCommandsMap is on a different shell''', + () { + const testCommand = 'test_command'; + const testShell = SystemShell.bash; + final shellCommandsMap = ShellCommandsMap({ + testShell: UnmodifiableSetView({testCommand}), + }); + + const anotherShell = SystemShell.zsh; + final newShellCommadsMap = shellCommandsMap.exclude( + command: testCommand, + systemShell: anotherShell, + ); - expect(newShellCommadsMap, equals(shellCommandsMap)); - }); + expect(newShellCommadsMap, equals(shellCommandsMap)); + }, + ); }); group('contains', () { test( - '''returns true when command is in $ShellCommandsMap for the given shell''', - () { - const testCommand = 'test_command'; - const testShell = SystemShell.bash; - final shellCommandsMap = ShellCommandsMap({ - testShell: UnmodifiableSetView({testCommand}), - }); + '''returns true when command is in $ShellCommandsMap for the given shell''', + () { + const testCommand = 'test_command'; + const testShell = SystemShell.bash; + final shellCommandsMap = ShellCommandsMap({ + testShell: UnmodifiableSetView({testCommand}), + }); - expect( - shellCommandsMap.contains( - command: testCommand, - systemShell: testShell, - ), - isTrue, - ); - }); + expect( + shellCommandsMap.contains( + command: testCommand, + systemShell: testShell, + ), + isTrue, + ); + }, + ); test( - '''returns false when command is in $ShellCommandsMap for another shell''', - () { - const testCommand = 'test_command'; - const testShell = SystemShell.bash; - final shellCommandsMap = ShellCommandsMap({ - testShell: UnmodifiableSetView({testCommand}), - }); + '''returns false when command is in $ShellCommandsMap for another shell''', + () { + const testCommand = 'test_command'; + const testShell = SystemShell.bash; + final shellCommandsMap = ShellCommandsMap({ + testShell: UnmodifiableSetView({testCommand}), + }); - const anotherShell = SystemShell.zsh; - expect(testShell, isNot(equals(anotherShell))); + const anotherShell = SystemShell.zsh; + expect(testShell, isNot(equals(anotherShell))); - expect( - shellCommandsMap.contains( - command: testCommand, - systemShell: anotherShell, - ), - isFalse, - ); - }); + expect( + shellCommandsMap.contains( + command: testCommand, + systemShell: anotherShell, + ), + isFalse, + ); + }, + ); }); }); } diff --git a/test/src/installer/completion_installation_test.dart b/test/src/installer/completion_installation_test.dart index a720a40..68b9903 100644 --- a/test/src/installer/completion_installation_test.dart +++ b/test/src/installer/completion_installation_test.dart @@ -541,417 +541,449 @@ void main() { ); test( - '''doesn't remove command from $CompletionConfiguration uninstalls when not forced to install''', - () { - const systemShell = SystemShell.zsh; - final installation = CompletionInstallation.fromSystemShell( - logger: logger, - isWindowsOverride: false, - environmentOverride: { - 'HOME': tempDir.path, - }, - systemShell: systemShell, - ); - - File(path.join(tempDir.path, '.zshrc')).createSync(); + '''doesn't remove command from $CompletionConfiguration uninstalls when not forced to install''', + () { + const systemShell = SystemShell.zsh; + final installation = CompletionInstallation.fromSystemShell( + logger: logger, + isWindowsOverride: false, + environmentOverride: { + 'HOME': tempDir.path, + }, + systemShell: systemShell, + ); - const command = 'very_good'; - final completionConfigurationFile = - installation.completionConfigurationFile; + File(path.join(tempDir.path, '.zshrc')).createSync(); - final uninstalls = ShellCommandsMap({ - systemShell: UnmodifiableSetView({command}), - }); - CompletionConfiguration.empty() - .copyWith(uninstalls: uninstalls) - .writeTo(completionConfigurationFile); - final completionConfiguration = - CompletionConfiguration.fromFile(completionConfigurationFile); - expect( - completionConfiguration.uninstalls - .contains(command: command, systemShell: systemShell), - isTrue, - reason: - '''The completion configuration should contain the uninstall for the command before install''', - ); + const command = 'very_good'; + final completionConfigurationFile = + installation.completionConfigurationFile; + + final uninstalls = ShellCommandsMap({ + systemShell: UnmodifiableSetView({command}), + }); + CompletionConfiguration.empty() + .copyWith(uninstalls: uninstalls) + .writeTo(completionConfigurationFile); + final completionConfiguration = CompletionConfiguration.fromFile( + completionConfigurationFile, + ); + expect( + completionConfiguration.uninstalls.contains( + command: command, + systemShell: systemShell, + ), + isTrue, + reason: + '''The completion configuration should contain the uninstall for the command before install''', + ); - installation.install(command); + installation.install(command); - final newCompletionConfiguration = - CompletionConfiguration.fromFile(completionConfigurationFile); - expect( - newCompletionConfiguration.uninstalls - .contains(command: command, systemShell: systemShell), - isTrue, - reason: - '''The completion configuration should still contain the uninstall for the command after soft install''', - ); - }); + final newCompletionConfiguration = CompletionConfiguration.fromFile( + completionConfigurationFile, + ); + expect( + newCompletionConfiguration.uninstalls.contains( + command: command, + systemShell: systemShell, + ), + isTrue, + reason: + '''The completion configuration should still contain the uninstall for the command after soft install''', + ); + }, + ); test( - '''removes command from $CompletionConfiguration uninstalls when forced to install''', - () { - const systemShell = SystemShell.zsh; - final installation = CompletionInstallation.fromSystemShell( - logger: logger, - isWindowsOverride: false, - environmentOverride: { - 'HOME': tempDir.path, - }, - systemShell: systemShell, - ); - - File(path.join(tempDir.path, '.zshrc')).createSync(); + '''removes command from $CompletionConfiguration uninstalls when forced to install''', + () { + const systemShell = SystemShell.zsh; + final installation = CompletionInstallation.fromSystemShell( + logger: logger, + isWindowsOverride: false, + environmentOverride: { + 'HOME': tempDir.path, + }, + systemShell: systemShell, + ); - const command = 'very_good'; - final completionConfigurationFile = - installation.completionConfigurationFile; + File(path.join(tempDir.path, '.zshrc')).createSync(); - final uninstalls = ShellCommandsMap({ - systemShell: UnmodifiableSetView({command}), - }); - CompletionConfiguration.empty() - .copyWith(uninstalls: uninstalls) - .writeTo(completionConfigurationFile); - final completionConfiguration = - CompletionConfiguration.fromFile(completionConfigurationFile); - expect( - completionConfiguration.uninstalls - .contains(command: command, systemShell: systemShell), - isTrue, - reason: - '''The completion configuration should contain the uninstall for the command before install''', - ); + const command = 'very_good'; + final completionConfigurationFile = + installation.completionConfigurationFile; + + final uninstalls = ShellCommandsMap({ + systemShell: UnmodifiableSetView({command}), + }); + CompletionConfiguration.empty() + .copyWith(uninstalls: uninstalls) + .writeTo(completionConfigurationFile); + final completionConfiguration = CompletionConfiguration.fromFile( + completionConfigurationFile, + ); + expect( + completionConfiguration.uninstalls.contains( + command: command, + systemShell: systemShell, + ), + isTrue, + reason: + '''The completion configuration should contain the uninstall for the command before install''', + ); - installation.install(command, force: true); + installation.install(command, force: true); - final newCompletionConfiguration = - CompletionConfiguration.fromFile(completionConfigurationFile); - expect( - newCompletionConfiguration.uninstalls - .contains(command: command, systemShell: systemShell), - isFalse, - reason: - '''The completion configuration should not contain the uninstall for the command after install''', - ); - }); + final newCompletionConfiguration = CompletionConfiguration.fromFile( + completionConfigurationFile, + ); + expect( + newCompletionConfiguration.uninstalls.contains( + command: command, + systemShell: systemShell, + ), + isFalse, + reason: + '''The completion configuration should not contain the uninstall for the command after install''', + ); + }, + ); test( - '''adds command to $CompletionConfiguration installs when installed''', - () { - const systemShell = SystemShell.zsh; - final installation = CompletionInstallation.fromSystemShell( - logger: logger, - isWindowsOverride: false, - environmentOverride: { - 'HOME': tempDir.path, - }, - systemShell: systemShell, - ); + '''adds command to $CompletionConfiguration installs when installed''', + () { + const systemShell = SystemShell.zsh; + final installation = CompletionInstallation.fromSystemShell( + logger: logger, + isWindowsOverride: false, + environmentOverride: { + 'HOME': tempDir.path, + }, + systemShell: systemShell, + ); - File(path.join(tempDir.path, '.zshrc')).createSync(); + File(path.join(tempDir.path, '.zshrc')).createSync(); - const command = 'very_good'; + const command = 'very_good'; - installation.install(command); + installation.install(command); - final newCompletionConfiguration = CompletionConfiguration.fromFile( - installation.completionConfigurationFile, - ); - expect( - newCompletionConfiguration.installs - .contains(command: command, systemShell: systemShell), - isTrue, - reason: - '''The completion configuration installs should contain the command after install''', - ); - }); + final newCompletionConfiguration = CompletionConfiguration.fromFile( + installation.completionConfigurationFile, + ); + expect( + newCompletionConfiguration.installs.contains( + command: command, + systemShell: systemShell, + ), + isTrue, + reason: + '''The completion configuration installs should contain the command after install''', + ); + }, + ); test( - '''command still in $CompletionConfiguration installs when already installed''', - () { - const systemShell = SystemShell.zsh; - final installation = CompletionInstallation.fromSystemShell( - logger: logger, - isWindowsOverride: false, - environmentOverride: { - 'HOME': tempDir.path, - }, - systemShell: systemShell, - ); + '''command still in $CompletionConfiguration installs when already installed''', + () { + const systemShell = SystemShell.zsh; + final installation = CompletionInstallation.fromSystemShell( + logger: logger, + isWindowsOverride: false, + environmentOverride: { + 'HOME': tempDir.path, + }, + systemShell: systemShell, + ); - File(path.join(tempDir.path, '.zshrc')).createSync(); + File(path.join(tempDir.path, '.zshrc')).createSync(); - const command = 'very_good'; - installation.install(command); + const command = 'very_good'; + installation.install(command); - var completionConfiguration = CompletionConfiguration.fromFile( - installation.completionConfigurationFile, - ); - expect( - completionConfiguration.installs - .contains(command: command, systemShell: systemShell), - isTrue, - reason: - '''The completion configuration installs should contain the command after install''', - ); + var completionConfiguration = CompletionConfiguration.fromFile( + installation.completionConfigurationFile, + ); + expect( + completionConfiguration.installs.contains( + command: command, + systemShell: systemShell, + ), + isTrue, + reason: + '''The completion configuration installs should contain the command after install''', + ); - // Install again. - installation.install(command); + // Install again. + installation.install(command); - completionConfiguration = CompletionConfiguration.fromFile( - installation.completionConfigurationFile, - ); - expect( - completionConfiguration.installs - .contains(command: command, systemShell: systemShell), - isTrue, - reason: - '''The completion configuration installs should still contain the command after install''', - ); - }); + completionConfiguration = CompletionConfiguration.fromFile( + installation.completionConfigurationFile, + ); + expect( + completionConfiguration.installs.contains( + command: command, + systemShell: systemShell, + ), + isTrue, + reason: + '''The completion configuration installs should still contain the command after install''', + ); + }, + ); }); group('uninstall', () { test( - '''deletes entire completion configuration when there is a single command''', - () { - final tempDirectory = Directory.systemTemp.createTempSync(); - addTearDown(() => tempDirectory.deleteSync(recursive: true)); + '''deletes entire completion configuration when there is a single command''', + () { + final tempDirectory = Directory.systemTemp.createTempSync(); + addTearDown(() => tempDirectory.deleteSync(recursive: true)); - final configuration = zshConfiguration; - final rcFile = File(path.join(tempDirectory.path, '.zshrc')) - ..createSync(); + final configuration = zshConfiguration; + final rcFile = File(path.join(tempDirectory.path, '.zshrc')) + ..createSync(); - const rootCommand = 'very_good'; - final installation = CompletionInstallation( - logger: logger, - isWindows: false, - environment: { - 'HOME': tempDirectory.path, - }, - configuration: configuration, - ) - ..install(rootCommand) - ..uninstall(rootCommand); + const rootCommand = 'very_good'; + final installation = + CompletionInstallation( + logger: logger, + isWindows: false, + environment: { + 'HOME': tempDirectory.path, + }, + configuration: configuration, + ) + ..install(rootCommand) + ..uninstall(rootCommand); - expect( - rcFile.existsSync(), - isTrue, - reason: 'RC file should not be deleted.', - ); - expect( - const ScriptConfigurationEntry('Completion').existsIn(rcFile), - isFalse, - reason: 'Completion config entry should be removed from RC file.', - ); - expect(installation.completionConfigDir.existsSync(), isFalse); - }); + expect( + rcFile.existsSync(), + isTrue, + reason: 'RC file should not be deleted.', + ); + expect( + const ScriptConfigurationEntry('Completion').existsIn(rcFile), + isFalse, + reason: 'Completion config entry should be removed from RC file.', + ); + expect(installation.completionConfigDir.existsSync(), isFalse); + }, + ); test( - '''only deletes shell configuration when there is a single command in multiple shells''', - () { - final tempDirectory = Directory.systemTemp.createTempSync(); - addTearDown(() => tempDirectory.deleteSync(recursive: true)); - - final zshConfig = zshConfiguration; - final zshRCFile = File(path.join(tempDirectory.path, '.zshrc')) - ..createSync(); - - final bashConfig = bashConfiguration; - final bashRCFile = File(path.join(tempDirectory.path, '.bash_profile')) - ..createSync(); + '''only deletes shell configuration when there is a single command in multiple shells''', + () { + final tempDirectory = Directory.systemTemp.createTempSync(); + addTearDown(() => tempDirectory.deleteSync(recursive: true)); - const rootCommand = 'very_good'; + final zshConfig = zshConfiguration; + final zshRCFile = File(path.join(tempDirectory.path, '.zshrc')) + ..createSync(); - final bashInstallation = CompletionInstallation( - logger: logger, - isWindows: false, - environment: { - 'HOME': tempDirectory.path, - }, - configuration: bashConfig, - )..install(rootCommand); + final bashConfig = bashConfiguration; + final bashRCFile = File( + path.join(tempDirectory.path, '.bash_profile'), + )..createSync(); - final zshInstallation = CompletionInstallation( - logger: logger, - isWindows: false, - environment: { - 'HOME': tempDirectory.path, - }, - configuration: zshConfig, - ) - ..install(rootCommand) - ..uninstall(rootCommand); + const rootCommand = 'very_good'; - // Zsh should be uninstalled - expect( - zshRCFile.existsSync(), - isTrue, - reason: 'Zsh RC file should still exist.', - ); - expect( - const ScriptConfigurationEntry('Completion').existsIn(zshRCFile), - isFalse, - reason: 'Zsh should not have completion entry.', - ); + final bashInstallation = CompletionInstallation( + logger: logger, + isWindows: false, + environment: { + 'HOME': tempDirectory.path, + }, + configuration: bashConfig, + )..install(rootCommand); + + final zshInstallation = + CompletionInstallation( + logger: logger, + isWindows: false, + environment: { + 'HOME': tempDirectory.path, + }, + configuration: zshConfig, + ) + ..install(rootCommand) + ..uninstall(rootCommand); + + // Zsh should be uninstalled + expect( + zshRCFile.existsSync(), + isTrue, + reason: 'Zsh RC file should still exist.', + ); + expect( + const ScriptConfigurationEntry('Completion').existsIn(zshRCFile), + isFalse, + reason: 'Zsh should not have completion entry.', + ); - final zshCompletionConfigurationFile = File( - path.join( - zshInstallation.completionConfigDir.path, - zshConfig.completionConfigForShellFileName, - ), - ); - expect( - zshCompletionConfigurationFile.existsSync(), - isFalse, - reason: 'Zsh completion configuration should be deleted.', - ); + final zshCompletionConfigurationFile = File( + path.join( + zshInstallation.completionConfigDir.path, + zshConfig.completionConfigForShellFileName, + ), + ); + expect( + zshCompletionConfigurationFile.existsSync(), + isFalse, + reason: 'Zsh completion configuration should be deleted.', + ); - final zshCommandCompletionConfigurationFile = File( - path.join( - zshInstallation.completionConfigDir.path, - '$rootCommand.zsh', - ), - ); - expect( - zshCommandCompletionConfigurationFile.existsSync(), - isFalse, - reason: 'Zsh command completion configuration should be deleted.', - ); + final zshCommandCompletionConfigurationFile = File( + path.join( + zshInstallation.completionConfigDir.path, + '$rootCommand.zsh', + ), + ); + expect( + zshCommandCompletionConfigurationFile.existsSync(), + isFalse, + reason: 'Zsh command completion configuration should be deleted.', + ); - // Bash should still be installed - expect( - bashRCFile.existsSync(), - isTrue, - reason: 'Bash RC file should still exist.', - ); - expect( - const ScriptConfigurationEntry('Completion').existsIn(bashRCFile), - isTrue, - reason: 'Bash should have completion entry.', - ); + // Bash should still be installed + expect( + bashRCFile.existsSync(), + isTrue, + reason: 'Bash RC file should still exist.', + ); + expect( + const ScriptConfigurationEntry('Completion').existsIn(bashRCFile), + isTrue, + reason: 'Bash should have completion entry.', + ); - final bashCompletionConfigurationFile = File( - path.join( - bashInstallation.completionConfigDir.path, - bashConfig.completionConfigForShellFileName, - ), - ); - expect( - bashCompletionConfigurationFile.existsSync(), - isTrue, - reason: 'Bash completion configuration should still exist.', - ); + final bashCompletionConfigurationFile = File( + path.join( + bashInstallation.completionConfigDir.path, + bashConfig.completionConfigForShellFileName, + ), + ); + expect( + bashCompletionConfigurationFile.existsSync(), + isTrue, + reason: 'Bash completion configuration should still exist.', + ); - final bashCommandCompletionConfigurationFile = File( - path.join( - bashInstallation.completionConfigDir.path, - '$rootCommand.bash', - ), - ); - expect( - bashCommandCompletionConfigurationFile.existsSync(), - isTrue, - reason: 'Bash command completion configuration should still exist.', - ); + final bashCommandCompletionConfigurationFile = File( + path.join( + bashInstallation.completionConfigDir.path, + '$rootCommand.bash', + ), + ); + expect( + bashCommandCompletionConfigurationFile.existsSync(), + isTrue, + reason: 'Bash command completion configuration should still exist.', + ); - expect( - bashInstallation.completionConfigDir.existsSync(), - isTrue, - reason: 'Completion configuration directory should still exist.', - ); - }); + expect( + bashInstallation.completionConfigDir.existsSync(), + isTrue, + reason: 'Completion configuration directory should still exist.', + ); + }, + ); test( - '''only deletes command completion configuration when there are multiple installed commands''', - () { - final tempDirectory = Directory.systemTemp.createTempSync(); - addTearDown(() => tempDirectory.deleteSync(recursive: true)); + '''only deletes command completion configuration when there are multiple installed commands''', + () { + final tempDirectory = Directory.systemTemp.createTempSync(); + addTearDown(() => tempDirectory.deleteSync(recursive: true)); - final configuration = zshConfiguration; - const commandName = 'very_good'; - const anotherCommandName = 'not_good'; + final configuration = zshConfiguration; + const commandName = 'very_good'; + const anotherCommandName = 'not_good'; - final rcFile = File(path.join(tempDirectory.path, '.zshrc')) - ..createSync(); - final installation = CompletionInstallation( - logger: logger, - isWindows: false, - environment: { - 'HOME': tempDirectory.path, - }, - configuration: configuration, - ) - ..install(commandName) - ..install(anotherCommandName); + final rcFile = File(path.join(tempDirectory.path, '.zshrc')) + ..createSync(); + final installation = + CompletionInstallation( + logger: logger, + isWindows: false, + environment: { + 'HOME': tempDirectory.path, + }, + configuration: configuration, + ) + ..install(commandName) + ..install(anotherCommandName); - final shellCompletionConfigurationFile = File( - path.join( - installation.completionConfigDir.path, - configuration.completionConfigForShellFileName, - ), - ); + final shellCompletionConfigurationFile = File( + path.join( + installation.completionConfigDir.path, + configuration.completionConfigForShellFileName, + ), + ); - installation.uninstall(commandName); + installation.uninstall(commandName); - expect( - rcFile.existsSync(), - isTrue, - reason: 'RC file should not be deleted.', - ); - expect( - const ScriptConfigurationEntry('Completion').existsIn(rcFile), - isTrue, - reason: 'Completion config entry should not be removed from RC file.', - ); + expect( + rcFile.existsSync(), + isTrue, + reason: 'RC file should not be deleted.', + ); + expect( + const ScriptConfigurationEntry('Completion').existsIn(rcFile), + isTrue, + reason: + 'Completion config entry should not be removed from RC file.', + ); - expect( - shellCompletionConfigurationFile.existsSync(), - isTrue, - reason: 'Shell completion configuration should still exist.', - ); + expect( + shellCompletionConfigurationFile.existsSync(), + isTrue, + reason: 'Shell completion configuration should still exist.', + ); - expect( - const ScriptConfigurationEntry(commandName) - .existsIn(shellCompletionConfigurationFile), - isFalse, - reason: - '''Command completion for $commandName configuration should be removed.''', - ); - final commandCompletionConfigurationFile = File( - path.join( - installation.completionConfigDir.path, - '$commandName.zsh', - ), - ); - expect( - commandCompletionConfigurationFile.existsSync(), - false, - reason: - '''Command completion configuration for $commandName should be deleted.''', - ); + expect( + const ScriptConfigurationEntry( + commandName, + ).existsIn(shellCompletionConfigurationFile), + isFalse, + reason: + '''Command completion for $commandName configuration should be removed.''', + ); + final commandCompletionConfigurationFile = File( + path.join( + installation.completionConfigDir.path, + '$commandName.zsh', + ), + ); + expect( + commandCompletionConfigurationFile.existsSync(), + false, + reason: + '''Command completion configuration for $commandName should be deleted.''', + ); - expect( - const ScriptConfigurationEntry(anotherCommandName) - .existsIn(shellCompletionConfigurationFile), - isTrue, - reason: - '''Command completion configuration for $anotherCommandName should still exist.''', - ); - final anotherCommandCompletionConfigurationFile = File( - path.join( - installation.completionConfigDir.path, - '$anotherCommandName.zsh', - ), - ); - expect( - anotherCommandCompletionConfigurationFile.existsSync(), - isTrue, - reason: - '''Command completion configuration for $anotherCommandName should still exist.''', - ); - }); + expect( + const ScriptConfigurationEntry( + anotherCommandName, + ).existsIn(shellCompletionConfigurationFile), + isTrue, + reason: + '''Command completion configuration for $anotherCommandName should still exist.''', + ); + final anotherCommandCompletionConfigurationFile = File( + path.join( + installation.completionConfigDir.path, + '$anotherCommandName.zsh', + ), + ); + expect( + anotherCommandCompletionConfigurationFile.existsSync(), + isTrue, + reason: + '''Command completion configuration for $anotherCommandName should still exist.''', + ); + }, + ); test('adds command to uninstalls when not the last command', () { const systemShell = SystemShell.zsh; @@ -973,11 +1005,14 @@ void main() { final completionConfigurationFile = installation.completionConfigurationFile; - final completionConfiguration = - CompletionConfiguration.fromFile(completionConfigurationFile); + final completionConfiguration = CompletionConfiguration.fromFile( + completionConfigurationFile, + ); expect( - completionConfiguration.uninstalls - .contains(command: command, systemShell: systemShell), + completionConfiguration.uninstalls.contains( + command: command, + systemShell: systemShell, + ), isTrue, reason: 'Command should be added to uninstalls after uninstalling.', ); @@ -1003,11 +1038,14 @@ void main() { final completionConfigurationFile = installation.completionConfigurationFile; - final completionConfiguration = - CompletionConfiguration.fromFile(completionConfigurationFile); + final completionConfiguration = CompletionConfiguration.fromFile( + completionConfigurationFile, + ); expect( - completionConfiguration.installs - .contains(command: command, systemShell: systemShell), + completionConfiguration.installs.contains( + command: command, + systemShell: systemShell, + ), isFalse, reason: 'Command should be removed from installs after uninstalling.', ); diff --git a/test/src/installer/script_configuration_entry_test.dart b/test/src/installer/script_configuration_entry_test.dart index 5cf6226..cc2bc2a 100644 --- a/test/src/installer/script_configuration_entry_test.dart +++ b/test/src/installer/script_configuration_entry_test.dart @@ -61,7 +61,8 @@ void main() { ScriptConfigurationEntry('name').appendTo(file, content: entryContent); final fileContent = file.readAsStringSync(); - const expectedContent = ''' + const expectedContent = + ''' $initialContent ## [name] $entryContent @@ -83,7 +84,8 @@ $entryContent ScriptConfigurationEntry('name').appendTo(file); final fileContent = file.readAsStringSync(); - const expectedContent = ''' + const expectedContent = + ''' $initialContent ## [name] ## [/name] @@ -187,57 +189,60 @@ $initialContent }); test( - '''removes file when there is only a single matching entry and should delete''', - () { - final tempDirectory = Directory.systemTemp.createTempSync(); - addTearDown(() => tempDirectory.deleteSync(recursive: true)); + '''removes file when there is only a single matching entry and should delete''', + () { + final tempDirectory = Directory.systemTemp.createTempSync(); + addTearDown(() => tempDirectory.deleteSync(recursive: true)); - final filePath = path.join(tempDirectory.path, 'file'); - final file = File(filePath)..createSync(); + final filePath = path.join(tempDirectory.path, 'file'); + final file = File(filePath)..createSync(); - final entry = ScriptConfigurationEntry('name')..appendTo(file); - expect(entry.existsIn(file), isTrue); + final entry = ScriptConfigurationEntry('name')..appendTo(file); + expect(entry.existsIn(file), isTrue); - ScriptConfigurationEntry('name').removeFrom(file, shouldDelete: true); - expect(file.existsSync(), isFalse); - }); + ScriptConfigurationEntry('name').removeFrom(file, shouldDelete: true); + expect(file.existsSync(), isFalse); + }, + ); test( - '''preseves file when there is a single matching entry and should not delete''', - () { - final tempDirectory = Directory.systemTemp.createTempSync(); - addTearDown(() => tempDirectory.deleteSync(recursive: true)); + '''preseves file when there is a single matching entry and should not delete''', + () { + final tempDirectory = Directory.systemTemp.createTempSync(); + addTearDown(() => tempDirectory.deleteSync(recursive: true)); - final filePath = path.join(tempDirectory.path, 'file'); - final file = File(filePath)..createSync(); + final filePath = path.join(tempDirectory.path, 'file'); + final file = File(filePath)..createSync(); - final entry = ScriptConfigurationEntry('name')..appendTo(file); - expect(entry.existsIn(file), isTrue); + final entry = ScriptConfigurationEntry('name')..appendTo(file); + expect(entry.existsIn(file), isTrue); - ScriptConfigurationEntry('name').removeFrom(file); - expect(file.existsSync(), isTrue); - final currentContent = file.readAsStringSync(); - expect(currentContent, isEmpty); - }); + ScriptConfigurationEntry('name').removeFrom(file); + expect(file.existsSync(), isTrue); + final currentContent = file.readAsStringSync(); + expect(currentContent, isEmpty); + }, + ); test( - '''removes file when there are only multiple matching entries and should delete''', - () { - final tempDirectory = Directory.systemTemp.createTempSync(); - addTearDown(() => tempDirectory.deleteSync(recursive: true)); + '''removes file when there are only multiple matching entries and should delete''', + () { + final tempDirectory = Directory.systemTemp.createTempSync(); + addTearDown(() => tempDirectory.deleteSync(recursive: true)); - final filePath = path.join(tempDirectory.path, 'file'); - final file = File(filePath)..createSync(); + final filePath = path.join(tempDirectory.path, 'file'); + final file = File(filePath)..createSync(); - final entry = ScriptConfigurationEntry('name') - ..appendTo(file) - ..appendTo(file) - ..appendTo(file); - expect(entry.existsIn(file), isTrue); + final entry = ScriptConfigurationEntry('name') + ..appendTo(file) + ..appendTo(file) + ..appendTo(file); + expect(entry.existsIn(file), isTrue); - ScriptConfigurationEntry('name').removeFrom(file, shouldDelete: true); - expect(file.existsSync(), isFalse); - }); + ScriptConfigurationEntry('name').removeFrom(file, shouldDelete: true); + expect(file.existsSync(), isFalse); + }, + ); test('only removes matching entries from file', () { final tempDirectory = Directory.systemTemp.createTempSync(); diff --git a/test/src/installer/shell_completion_configuration_test.dart b/test/src/installer/shell_completion_configuration_test.dart index fc58cf3..1e885aa 100644 --- a/test/src/installer/shell_completion_configuration_test.dart +++ b/test/src/installer/shell_completion_configuration_test.dart @@ -7,8 +7,9 @@ void main() { late ShellCompletionConfiguration zshConfiguration; setUp(() { - zshConfiguration = - ShellCompletionConfiguration.fromSystemShell(SystemShell.zsh); + zshConfiguration = ShellCompletionConfiguration.fromSystemShell( + SystemShell.zsh, + ); }); test('shell', () { @@ -58,8 +59,9 @@ fi late ShellCompletionConfiguration bashConfiguration; setUp(() { - bashConfiguration = - ShellCompletionConfiguration.fromSystemShell(SystemShell.bash); + bashConfiguration = ShellCompletionConfiguration.fromSystemShell( + SystemShell.bash, + ); }); test('shell', () { diff --git a/test/src/parser/completion_level_test.dart b/test/src/parser/completion_level_test.dart index 8a0082b..65af1b4 100644 --- a/test/src/parser/completion_level_test.dart +++ b/test/src/parser/completion_level_test.dart @@ -61,10 +61,11 @@ void main() { 'gets completion level from the innermost aspet', () { final commanrRunner = _TestCompletionCommandRunner(); - final args = '--rootFlag ' - 'subcommand --level1Flag ' - 'subsubcommand --level2Flag' - .split(' '); + final args = + '--rootFlag ' + 'subcommand --level1Flag ' + 'subsubcommand --level2Flag' + .split(' '); final completionLevel = CompletionLevel.find( args, @@ -130,9 +131,10 @@ void main() { 'finds level when subcommand is added via "ArgParser.addCommand"', () { final commanrRunner = _TestCompletionCommandRunner(); - final args = '--rootFlag ' - 'fakesubcommand --fakeSubcommandFlag' - .split(' '); + final args = + '--rootFlag ' + 'fakesubcommand --fakeSubcommandFlag' + .split(' '); final completionLevel = CompletionLevel.find( args, diff --git a/test/src/parser/parser_test.dart b/test/src/parser/parser_test.dart index ec9b14c..c66907b 100644 --- a/test/src/parser/parser_test.dart +++ b/test/src/parser/parser_test.dart @@ -176,8 +176,7 @@ void main() { }); }); - group( - 'when the user started to type something after writing ' + group('when the user started to type something after writing ' 'an option', () { group('an option without allowed values', () { test('returns OptionValuesCompletionResults', () { @@ -293,8 +292,11 @@ void main() { expect(result.length, 1); expect( result.first, - isA() - .having((res) => res.pattern, 'commands pattern', 'command'), + isA().having( + (res) => res.pattern, + 'commands pattern', + 'command', + ), ); }); }); @@ -315,13 +317,19 @@ void main() { expect(result.length, 2); expect( result.first, - isA() - .having((res) => res.pattern, 'commands pattern', '--option'), + isA().having( + (res) => res.pattern, + 'commands pattern', + '--option', + ), ); expect( result.last, - isA() - .having((res) => res.pattern, 'option pattern', 'option'), + isA().having( + (res) => res.pattern, + 'option pattern', + 'option', + ), ); }); }); From 09730401b523ce8a1f08d961af6b1b54218a42cd Mon Sep 17 00:00:00 2001 From: Marcos Sevilla Date: Thu, 10 Jul 2025 14:15:47 +0200 Subject: [PATCH 5/5] fix: format --- example/bin/example_cli.dart | 6 +- example/lib/src/command_runner.dart | 4 +- example/lib/src/commands/some_commmand.dart | 9 +-- example/pubspec.yaml | 2 +- .../completion_integration_test.dart | 69 ++++++++++--------- example/test/integration/utils.dart | 8 +-- .../src/commands/some_other_command_test.dart | 5 +- pubspec.yaml | 2 +- 8 files changed, 57 insertions(+), 48 deletions(-) diff --git a/example/bin/example_cli.dart b/example/bin/example_cli.dart index 8250a50..1600f65 100644 --- a/example/bin/example_cli.dart +++ b/example/bin/example_cli.dart @@ -13,6 +13,8 @@ Future main(List args) async { /// exited already. This is useful to prevent Future chains from proceeding /// after you've decided to exit. Future _flushThenExit(int status) { - return Future.wait([stdout.close(), stderr.close()]) - .then((_) => exit(status)); + return Future.wait([ + stdout.close(), + stderr.close(), + ]).then((_) => exit(status)); } diff --git a/example/lib/src/command_runner.dart b/example/lib/src/command_runner.dart index 81efbf0..9613f70 100644 --- a/example/lib/src/command_runner.dart +++ b/example/lib/src/command_runner.dart @@ -18,8 +18,8 @@ class ExampleCommandRunner extends CompletionCommandRunner { /// {@macro example_command_runner} ExampleCommandRunner({ Logger? logger, - }) : _logger = logger ?? Logger(), - super(executableName, description) { + }) : _logger = logger ?? Logger(), + super(executableName, description) { // Add root options and flags argParser ..addFlag( diff --git a/example/lib/src/commands/some_commmand.dart b/example/lib/src/commands/some_commmand.dart index fb21824..adb2134 100644 --- a/example/lib/src/commands/some_commmand.dart +++ b/example/lib/src/commands/some_commmand.dart @@ -35,7 +35,8 @@ class SomeCommand extends Command { ) ..addOption( 'no-option', - help: 'An option that starts with "no" just to make confusion ' + help: + 'An option that starts with "no" just to make confusion ' 'with negated flags', ) ..addMultiOption( @@ -95,9 +96,9 @@ class SomeCommand extends Command { @override List get aliases => [ - 'disguised:some_commmand', - 'melon', - ]; + 'disguised:some_commmand', + 'melon', + ]; @override Future run() async { diff --git a/example/pubspec.yaml b/example/pubspec.yaml index cd64579..9d91bca 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -4,7 +4,7 @@ version: 0.0.1 publish_to: none environment: - sdk: ^3.8.0 + sdk: ^3.8.1 dependencies: args: ^2.5.0 diff --git a/example/test/integration/completion_integration_test.dart b/example/test/integration/completion_integration_test.dart index 41e8df3..dda1bc7 100644 --- a/example/test/integration/completion_integration_test.dart +++ b/example/test/integration/completion_integration_test.dart @@ -196,7 +196,7 @@ void main() { '--continuous': r'A continuous option\: any value is allowed', '--no-option': 'An option that starts with "no" just to make confusion with negated ' - 'flags', + 'flags', '--multi-d': 'An discrete option that can be passed multiple times ', '--multi-c': 'An continuous option that can be passed multiple times', '--flag': null, @@ -313,7 +313,7 @@ void main() { suggests({ '--no-option': 'An option that starts with "no" just to make confusion with ' - 'negated flags', + 'negated flags', '--no-flag': null, '--no-inverseflag': 'A flag that the default value is true', }), @@ -410,13 +410,14 @@ void main() { }); test( - '**do not** suggest possible options when using equals/quote syntax', - () async { - await expectLater( - 'example_cli some_command --discrete="', - suggests(noSuggestions), - ); - }); + '**do not** suggest possible options when using equals/quote syntax', + () async { + await expectLater( + 'example_cli some_command --discrete="', + suggests(noSuggestions), + ); + }, + ); }); group('discrete (aliases)', () { @@ -431,17 +432,19 @@ void main() { ); }); - test('suggest matching options for alias option when typed 2', - () async { - await expectLater( - 'example_cli some_command --defined-values ', - suggests({ - 'foo': 'foo help', - 'bar': 'bar help', - 'faa': 'faa help', - }), - ); - }); + test( + 'suggest matching options for alias option when typed 2', + () async { + await expectLater( + 'example_cli some_command --defined-values ', + suggests({ + 'foo': 'foo help', + 'bar': 'bar help', + 'faa': 'faa help', + }), + ); + }, + ); }); group('continuous', () { @@ -634,18 +637,20 @@ void main() { tags: 'known-issues', ); - test('include discrete multi option value after it is specified', - () async { - await expectLater( - 'example_cli some_command --multi-d bar -m ', - suggests({ - 'fii': 'fii help', - 'bar': 'bar help', - 'fee': 'fee help', - 'i have space': 'an allowed option with space on it', - }), - ); - }); + test( + 'include discrete multi option value after it is specified', + () async { + await expectLater( + 'example_cli some_command --multi-d bar -m ', + suggests({ + 'fii': 'fii help', + 'bar': 'bar help', + 'fee': 'fee help', + 'i have space': 'an allowed option with space on it', + }), + ); + }, + ); }); }); }); diff --git a/example/test/integration/utils.dart b/example/test/integration/utils.dart index b00e8d1..c2a3c28 100644 --- a/example/test/integration/utils.dart +++ b/example/test/integration/utils.dart @@ -18,10 +18,10 @@ class CliCompletionMatcher extends CustomMatcher { Map suggestions, { this.cursorIndex, }) : super( - 'Completes with the expected suggestions', - 'suggestions', - completion(suggestions), - ); + 'Completes with the expected suggestions', + 'suggestions', + completion(suggestions), + ); final int? cursorIndex; diff --git a/example/test/src/commands/some_other_command_test.dart b/example/test/src/commands/some_other_command_test.dart index 79b0467..e8c296f 100644 --- a/example/test/src/commands/some_other_command_test.dart +++ b/example/test/src/commands/some_other_command_test.dart @@ -25,8 +25,9 @@ void main() { expect(exitCode, ExitCode.success.code); - verify(() => logger.info('A sub command of some_other_command')) - .called(1); + verify( + () => logger.info('A sub command of some_other_command'), + ).called(1); verify(() => logger.info(' - anything')).called(1); verify(() => logger.info(' - after')).called(1); verify(() => logger.info(' - command')).called(1); diff --git a/pubspec.yaml b/pubspec.yaml index f2fec3a..cc45ea1 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -9,7 +9,7 @@ screenshots: path: doc/screen.png environment: - sdk: ^3.8.0 + sdk: ^3.8.1 dependencies: args: ^2.5.0