From 7380f58173c380e9c942d7b1550ea564c21d8ca7 Mon Sep 17 00:00:00 2001 From: Max Eisner <4730112+max-ae@users.noreply.github.com> Date: Mon, 5 Sep 2022 19:32:17 +0200 Subject: [PATCH] extend tests --- .../lines/generate_completions_spec.rb | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/Library/Homebrew/test/rubocops/lines/generate_completions_spec.rb b/Library/Homebrew/test/rubocops/lines/generate_completions_spec.rb index f927b9cf08..248f95f362 100644 --- a/Library/Homebrew/test/rubocops/lines/generate_completions_spec.rb +++ b/Library/Homebrew/test/rubocops/lines/generate_completions_spec.rb @@ -30,6 +30,52 @@ describe RuboCop::Cop::FormulaAudit do RUBY end + it "reports an offense when writing to a shell completions file differing from the formula name" do + expect_offense(<<~RUBY, "/homebrew-core/Formula/foo-cli.rb") + class FooCli < Formula + name "foo-cli" + + def install + (bash_completion/"foo").write Utils.safe_popen_read(bin/"foo", "completions", "bash") + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Use `generate_completions_from_executable(bin/"foo", "completions", base_name: "foo", shells: [:bash])` instead of `(bash_completion/"foo").write Utils.safe_popen_read(bin/"foo", "completions", "bash")`. + end + end + RUBY + + expect_correction(<<~RUBY) + class FooCli < Formula + name "foo-cli" + + def install + generate_completions_from_executable(bin/"foo", "completions", base_name: "foo", shells: [:bash]) + end + end + RUBY + end + + it "reports an offense when writing to a shell completions file using an arg 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", "--shell=bash") + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Use `generate_completions_from_executable(bin/"foo", "completions", shells: [:bash], shell_parameter_format: :arg)` instead of `(bash_completion/"foo").write Utils.safe_popen_read(bin/"foo", "completions", "--shell=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: :arg) + end + end + RUBY + end + it "reports an offense when writing to a completions file indirectly" do expect_offense(<<~RUBY) class Foo < Formula