language/test: add shebang tests

This commit is contained in:
Bo Anderson 2020-03-27 19:18:05 +00:00
parent 5d68856350
commit 3955e7e13b
2 changed files with 95 additions and 0 deletions

View File

@ -0,0 +1,52 @@
# frozen_string_literal: true
require "language/perl"
require "utils/shebang"
describe Language::Perl::Shebang do
let(:file) { Tempfile.new("perl-shebang") }
let(:perl_f) do
formula "perl" do
url "https://brew.sh/perl-1.0.tgz"
end
end
let(:f) do
formula "foo" do
url "https://brew.sh/foo-1.0.tgz"
uses_from_macos "perl"
end
end
before do
file.write <<~EOS
#!/usr/bin/env perl
a
b
c
EOS
file.flush
end
after { file.unlink }
describe "#detected_perl_shebang" do
it "can be used to replace Perl shebangs" do
allow(Formulary).to receive(:factory).with(perl_f.name).and_return(perl_f)
Utils::Shebang.rewrite_shebang described_class.detected_perl_shebang(f), file
expected_shebang = if OS.mac?
"/usr/bin/perl"
else
HOMEBREW_PREFIX/"opt/perl/bin/perl"
end
expect(File.read(file)).to eq <<~EOS
#!#{expected_shebang}
a
b
c
EOS
end
end
end

View File

@ -2,6 +2,7 @@
require "language/python" require "language/python"
require "resource" require "resource"
require "utils/shebang"
describe Language::Python, :needs_python do describe Language::Python, :needs_python do
describe "#major_minor_version" do describe "#major_minor_version" do
@ -32,6 +33,48 @@ describe Language::Python, :needs_python do
end end
end end
describe Language::Python::Shebang do
let(:file) { Tempfile.new("python-shebang") }
let(:python_f) do
formula "python" do
url "https://brew.sh/python-1.0.tgz"
end
end
let(:f) do
formula "foo" do
url "https://brew.sh/foo-1.0.tgz"
depends_on "python"
end
end
before do
file.write <<~EOS
#!/usr/bin/env python3
a
b
c
EOS
file.flush
end
after { file.unlink }
describe "#detected_python_shebang" do
it "can be used to replace Python shebangs" do
expect(Formulary).to receive(:factory).with(python_f.name).and_return(python_f)
Utils::Shebang.rewrite_shebang described_class.detected_python_shebang(f), file
expect(File.read(file)).to eq <<~EOS
#!#{HOMEBREW_PREFIX}/opt/python/bin/python3
a
b
c
EOS
end
end
end
describe Language::Python::Virtualenv::Virtualenv do describe Language::Python::Virtualenv::Virtualenv do
subject { described_class.new(formula, dir, "python") } subject { described_class.new(formula, dir, "python") }