From b58551cd677eed32028adba09dd1baa7cc273adb Mon Sep 17 00:00:00 2001 From: Rylan Polster Date: Fri, 3 Dec 2021 22:29:10 -0500 Subject: [PATCH] Control for CPU type and Rosetta in `os_arch_prefix_ci` tests --- Library/Homebrew/test/utils/analytics_spec.rb | 24 +++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/Library/Homebrew/test/utils/analytics_spec.rb b/Library/Homebrew/test/utils/analytics_spec.rb index c218052268..11fd3a8bd4 100644 --- a/Library/Homebrew/test/utils/analytics_spec.rb +++ b/Library/Homebrew/test/utils/analytics_spec.rb @@ -11,12 +11,28 @@ describe Utils::Analytics do described_class.clear_os_arch_prefix_ci end - it "returns OS_VERSION and prefix when HOMEBREW_PREFIX is a custom prefix" do + it "returns OS_VERSION and prefix when HOMEBREW_PREFIX is a custom prefix on intel" do allow(Hardware::CPU).to receive(:type).and_return(:intel) + allow(Hardware::CPU).to receive(:in_rosetta2?).and_return(false) allow(Homebrew).to receive(:default_prefix?).and_return(false) - arch = ", #{described_class.arch_label}" if described_class.arch_label.present? - expected = "#{OS_VERSION}#{arch}, #{described_class.custom_prefix_label}" - expect(described_class.os_arch_prefix_ci).to include(expected) + expected = "#{OS_VERSION}, #{described_class.custom_prefix_label}" + expect(described_class.os_arch_prefix_ci).to eq expected + end + + it 'returns OS_VERSION, "ARM" and prefix when HOMEBREW_PREFIX is a custom prefix on arm' do + allow(Hardware::CPU).to receive(:type).and_return(:arm) + allow(Hardware::CPU).to receive(:in_rosetta2?).and_return(false) + allow(Homebrew).to receive(:default_prefix?).and_return(false) + expected = "#{OS_VERSION}, ARM, #{described_class.custom_prefix_label}" + expect(described_class.os_arch_prefix_ci).to eq expected + end + + it 'returns OS_VERSION, "Rosetta" and prefix when HOMEBREW_PREFIX is a custom prefix using Rosetta' do + allow(Hardware::CPU).to receive(:type).and_return(:intel) + allow(Hardware::CPU).to receive(:in_rosetta2?).and_return(true) + allow(Homebrew).to receive(:default_prefix?).and_return(false) + expected = "#{OS_VERSION}, Rosetta, #{described_class.custom_prefix_label}" + expect(described_class.os_arch_prefix_ci).to eq expected end it "does not include prefix when HOMEBREW_PREFIX is the default prefix" do