2021-01-31 14:50:29 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require "language/python"
|
|
|
|
require "utils/shebang"
|
|
|
|
|
|
|
|
describe Language::Python::Shebang do
|
|
|
|
let(:file) { Tempfile.new("python-shebang") }
|
|
|
|
let(:python_f) do
|
2022-08-09 22:38:05 +08:00
|
|
|
formula "python@3.11" do
|
2021-01-31 14:50:29 -05:00
|
|
|
url "https://brew.sh/python-1.0.tgz"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
let(:f) do
|
|
|
|
formula "foo" do
|
|
|
|
url "https://brew.sh/foo-1.0.tgz"
|
|
|
|
|
2022-08-09 22:38:05 +08:00
|
|
|
depends_on "python@3.11"
|
2021-01-31 14:50:29 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
before do
|
|
|
|
file.write <<~EOS
|
2022-08-13 01:11:09 +08:00
|
|
|
#!/usr/bin/python2
|
2021-01-31 14:50:29 -05:00
|
|
|
a
|
|
|
|
b
|
|
|
|
c
|
|
|
|
EOS
|
|
|
|
file.flush
|
|
|
|
end
|
|
|
|
|
|
|
|
after { file.unlink }
|
|
|
|
|
|
|
|
describe "#detected_python_shebang" do
|
|
|
|
it "can be used to replace Python shebangs" do
|
2022-11-09 14:45:43 +00:00
|
|
|
allow(Formulary).to receive(:factory)
|
|
|
|
allow(Formulary).to receive(:factory).with(python_f.name).and_return(python_f)
|
2023-04-17 11:18:51 -07:00
|
|
|
Utils::Shebang.rewrite_shebang(
|
|
|
|
described_class.detected_python_shebang(f, use_python_from_path: false), file.path
|
|
|
|
)
|
2021-01-31 14:50:29 -05:00
|
|
|
|
|
|
|
expect(File.read(file)).to eq <<~EOS
|
2022-08-09 22:38:05 +08:00
|
|
|
#!#{HOMEBREW_PREFIX}/opt/python@3.11/bin/python3.11
|
2021-01-31 14:50:29 -05:00
|
|
|
a
|
|
|
|
b
|
|
|
|
c
|
|
|
|
EOS
|
|
|
|
end
|
2022-08-13 01:11:09 +08:00
|
|
|
|
|
|
|
it "can be pointed to a `python3` in PATH" do
|
2023-04-17 11:18:51 -07:00
|
|
|
Utils::Shebang.rewrite_shebang(
|
|
|
|
described_class.detected_python_shebang(f, use_python_from_path: true), file.path
|
|
|
|
)
|
2022-08-13 01:11:09 +08:00
|
|
|
|
|
|
|
expect(File.read(file)).to eq <<~EOS
|
|
|
|
#!/usr/bin/env python3
|
|
|
|
a
|
|
|
|
b
|
|
|
|
c
|
|
|
|
EOS
|
|
|
|
end
|
2021-01-31 14:50:29 -05:00
|
|
|
end
|
|
|
|
end
|