From 843a189d40996822125550effa39da06c2a550b5 Mon Sep 17 00:00:00 2001 From: danielnachun Date: Mon, 28 Feb 2022 15:40:39 -0800 Subject: [PATCH] test/keg_relocate/binary_relocation_spec.rb: add new unit test --- .../keg_relocate/binary_relocation_spec.rb | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 Library/Homebrew/test/keg_relocate/binary_relocation_spec.rb diff --git a/Library/Homebrew/test/keg_relocate/binary_relocation_spec.rb b/Library/Homebrew/test/keg_relocate/binary_relocation_spec.rb new file mode 100644 index 0000000000..29bf25703a --- /dev/null +++ b/Library/Homebrew/test/keg_relocate/binary_relocation_spec.rb @@ -0,0 +1,44 @@ +# typed: false +# frozen_string_literal: true + +require "keg_relocate" + +describe Keg do + subject(:keg) { described_class.new(HOMEBREW_CELLAR/"foo/1.0.0") } + + let(:dir) { HOMEBREW_CELLAR/"foo/1.0.0" } + let(:newdir) { HOMEBREW_CELLAR/"foo" } + let(:binary_file) { dir/"file.bin" } + + before do + dir.mkpath + end + + def setup_binary_file + binary_file.atomic_write <<~EOS + \x00#{dir}\x00 + EOS + end + + describe "#relocate_build_prefix" do + specify "replace prefix in binary files" do + setup_binary_file + + keg.relocate_build_prefix(keg, dir, newdir) + + old_prefix_matches = Set.new + keg.each_unique_file_matching(dir) do |file| + old_prefix_matches << file + end + + expect(old_prefix_matches.size).to eq 0 + + new_prefix_matches = Set.new + keg.each_unique_file_matching(newdir) do |file| + new_prefix_matches << file + end + + expect(new_prefix_matches.size).to eq 1 + end + end +end