From 926d9f45399aab283351794fe0b19cc54d094b97 Mon Sep 17 00:00:00 2001 From: Andreas Scherer Date: Tue, 24 Dec 2024 19:09:11 +0100 Subject: [PATCH 1/2] Write tests for 'brew list --version [--cask]'. HELP WANTED! How can I create test packages in the 'Caskroom'? I can only run 'brew tests' on Linux, because my Mac Mini (macOS 14.7.2) fails due to missing "mutex.h" (or some such). At least the new test for 'brew list --version' succeeds (on Linux). Squashed commits to (partial) success: Try 'brew style list_spec.rb'. Try 'rubocop -a'. Generic OS fails. Generic OS fails again. The 'Caskroom' is not yet populated. --- Library/Homebrew/test/cmd/list_spec.rb | 29 ++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/Library/Homebrew/test/cmd/list_spec.rb b/Library/Homebrew/test/cmd/list_spec.rb index 97a6f1466a1db..9ac7cc0b63072 100644 --- a/Library/Homebrew/test/cmd/list_spec.rb +++ b/Library/Homebrew/test/cmd/list_spec.rb @@ -4,7 +4,8 @@ require "cmd/shared_examples/args_parse" RSpec.describe Homebrew::Cmd::List do - let(:formulae) { %w[bar foo qux] } + let(:formulae) { %w[bar qux foo] } + let(:casks) { %w[tex git sgb] } it_behaves_like "parseable arguments" @@ -12,11 +13,35 @@ formulae.each do |f| (HOMEBREW_CELLAR/f/"1.0/somedir").mkpath end + # casks.each do |f| + # (HOMEBREW_CELLAR/"../Caskroom"/f/"42.0/somedir").mkpath + # end expect { brew "list", "--formula" } - .to output("#{formulae.join("\n")}\n").to_stdout + .to output("#{formulae.sort.join("\n")}\n").to_stdout .and not_to_output.to_stderr .and be_a_success + + # expect { brew "list", "--cask" } + # .to output("#{casks.sort.join("\n")}\n").to_stdout + # .and not_to_output.to_stderr + # .and be_a_success + + expect { brew "list", "--formula", "--version" } + .to output("#{formulae.sort.map { |name| "#{name} 1.0" }.join("\n")}\n").to_stdout + .and not_to_output.to_stderr + .and be_a_success + + # expect { brew "list", "--cask", "--version" } + # .to output("#{casks.sort.map { |name| "#{name} 42.0" }.join("\n")}\n").to_stdout + # .and not_to_output.to_stderr + # .and be_a_success + + # expect { brew "list", "--version" } + # .to output("#{formulae.sort.map { |name| "#{name} 1.0" }.join("\n")}\n" + + # "#{casks.sort.map { |name| "#{name} 42.0" }.join("\n")}\n").to_stdout + # .and not_to_output.to_stderr + # .and be_a_success end # TODO: add a test for the shell fast-path (`brew_sh`) From 2f3806a47dda2d926e9a1397455c9dcc7b72e56e Mon Sep 17 00:00:00 2001 From: Andreas Scherer Date: Wed, 25 Dec 2024 10:36:16 +0100 Subject: [PATCH 2/2] Partial solution for cask processing. 'brew list --cask' seems to work, but both 'brew list --cask --version' and 'brew list --version' fail because of empty cask list. --- Library/Homebrew/test/cmd/list_spec.rb | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/Library/Homebrew/test/cmd/list_spec.rb b/Library/Homebrew/test/cmd/list_spec.rb index 9ac7cc0b63072..64f5a2e0d2451 100644 --- a/Library/Homebrew/test/cmd/list_spec.rb +++ b/Library/Homebrew/test/cmd/list_spec.rb @@ -13,19 +13,19 @@ formulae.each do |f| (HOMEBREW_CELLAR/f/"1.0/somedir").mkpath end - # casks.each do |f| - # (HOMEBREW_CELLAR/"../Caskroom"/f/"42.0/somedir").mkpath - # end + casks.each do |f| + (HOMEBREW_PREFIX/"Caskroom"/f/"42.0/somedir").mkpath + end expect { brew "list", "--formula" } .to output("#{formulae.sort.join("\n")}\n").to_stdout .and not_to_output.to_stderr .and be_a_success - # expect { brew "list", "--cask" } - # .to output("#{casks.sort.join("\n")}\n").to_stdout - # .and not_to_output.to_stderr - # .and be_a_success + expect { brew "list", "--cask" } + .to output("#{casks.sort.join("\n")}\n").to_stdout + .and not_to_output.to_stderr + .and be_a_success expect { brew "list", "--formula", "--version" } .to output("#{formulae.sort.map { |name| "#{name} 1.0" }.join("\n")}\n").to_stdout @@ -38,8 +38,11 @@ # .and be_a_success # expect { brew "list", "--version" } - # .to output("#{formulae.sort.map { |name| "#{name} 1.0" }.join("\n")}\n" + - # "#{casks.sort.map { |name| "#{name} 42.0" }.join("\n")}\n").to_stdout + # .to output(<<~OUTPUT, + # #{formulae.sort.map { |name| "#{name} 1.0" }.join("\n")} + # #{casks.sort.map { |name| "#{name} 42.0" }.join("\n")} + # OUTPUT + # ).to_stdout # .and not_to_output.to_stderr # .and be_a_success end