From 29467520831474fc62cdd948aecfe6deb2254a8b Mon Sep 17 00:00:00 2001 From: Max Eisner <4730112+max-ae@users.noreply.github.com> Date: Mon, 5 Sep 2022 19:46:42 +0200 Subject: [PATCH] extend tests --- .../lines/generate_completions_spec.rb | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/Library/Homebrew/test/rubocops/lines/generate_completions_spec.rb b/Library/Homebrew/test/rubocops/lines/generate_completions_spec.rb index 248f95f362..2a04add73e 100644 --- a/Library/Homebrew/test/rubocops/lines/generate_completions_spec.rb +++ b/Library/Homebrew/test/rubocops/lines/generate_completions_spec.rb @@ -76,6 +76,29 @@ describe RuboCop::Cop::FormulaAudit do RUBY end + it "reports an offense when writing to a shell completions file using a custom flag for the shell parameter" do + expect_offense(<<~RUBY, "/homebrew-core/Formula/foo.rb") + class Foo < Formula + name "foo" + + def install + (bash_completion/"foo").write Utils.safe_popen_read(bin/"foo", "completions", "--completion-script-bash") + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Use `generate_completions_from_executable(bin/"foo", "completions", shells: [:bash], shell_parameter_format: "--completion-script-")` instead of `(bash_completion/"foo").write Utils.safe_popen_read(bin/"foo", "completions", "--completion-script-bash")`. + end + end + RUBY + + expect_correction(<<~RUBY) + class Foo < Formula + name "foo" + + def install + generate_completions_from_executable(bin/"foo", "completions", shells: [:bash], shell_parameter_format: "--completion-script-") + end + end + RUBY + end + it "reports an offense when writing to a completions file indirectly" do expect_offense(<<~RUBY) class Foo < Formula