Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrades to cpan_spec.rb #1973

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 48 additions & 12 deletions spec/fpm/package/cpan_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,9 @@
have_cpanm = program_exists?("cpanm")
if !have_cpanm
Cabin::Channel.get("rspec") \
.warn("Skipping CPAN#input tests because 'cpanm' isn't in your PATH")
.warn("Skipping CPAN tests because 'cpanm' isn't in your PATH")
end

is_travis = ENV["TRAVIS_OS_NAME"] && !ENV["TRAVIS_OS_NAME"].empty?

describe FPM::Package::CPAN do
before do
skip("Missing cpanm program") unless have_cpanm
Expand All @@ -22,24 +20,60 @@
subject.cleanup
end

it "should prepend package name prefix" do
subject.attributes[:cpan_package_name_prefix] = "prefix"
insist { subject.instance_eval { fix_name("Foo::Bar") } } == "prefix-Foo-Bar"
end

it "should wrap name in perl()" do
insist { subject.instance_eval { cap_name("Foo::Bar") } } == "perl(Foo::Bar)"
end

it "should return successful HTTP resonse" do
response = subject.instance_eval { httpfetch("https://fastapi.metacpan.org/v1/module/File::Temp") }
insist { response.class } == Net::HTTPOK
end

it "should return successful HTTP resonse" do
response = subject.instance_eval {httppost(
"https://fastapi.metacpan.org/v1/release/_search",
"{\"fields\":[\"download_url\"],\"filter\":{\"term\":{\"name\":\"File-Temp-0.2310\"}}}"
)}
insist { response.class } == Net::HTTPOK
end

it "should return metadata hash" do
metadata = subject.instance_eval { search("File::Temp") }
insist { metadata.class } == Hash
insist { metadata["name"] } == "Temp.pm"
insist { metadata["distribution"] } == "File-Temp"
end

it "should download precise version" do
metadata = subject.instance_eval { search("File::Temp") }
insist { File.basename(subject.instance_eval { download(metadata, "0.2310")}) } == "File-Temp-0.2310.tar.gz"
end

it "should package Digest::MD5" do
pending("Disabled on travis-ci because it always fails, and there is no way to debug it?") if is_travis
# Set the version explicitly because we default to installing the newest
# version, and a new version could be released that breaks the test.
subject.instance_variable_set(:@version, "2.58");

# Disable testing because we don't really need to run the cpan tests. The
# goal is to see the parsed result (name, module description, etc)
# Additionally, it fails on my workstation when cpan_test? is enabled due
# to not finding `Test.pm`, and it seems like a flakey test if we keep this
# enabled.
subject.attributes[:cpan_test?] = false

subject.input("Digest::MD5")
insist { subject.name } == "perl-Digest-MD5"
insist { subject.description } == "Perl interface to the MD-5 algorithm"
insist { subject.vendor } == "Gisle Aas <gisle@activestate.com>"
# TODO(sissel): Check dependencies
insist { subject.dependencies.sort } == ["perl >= 5.006", "perl(Digest::base) >= 1.00", "perl(XSLoader)"]
end

it "should unpack tarball containing ./ leading paths" do
pending("Disabled on travis-ci because it always fails, and there is no way to debug it?") if is_travis

Dir.mktmpdir do |tmpdir|
# Create tarball containing a file './foo/bar.txt'
Expand All @@ -55,29 +89,31 @@
end

it "should package File::Spec" do
pending("Disabled on travis-ci because it always fails, and there is no way to debug it?") if is_travis
subject.instance_variable_set(:@version, "3.75");
subject.attributes[:cpan_test?] = false

subject.input("File::Spec")

# the File::Spec module comes from the PathTools CPAN distribution
insist { subject.name } == "perl-PathTools"
end

it "should package Class::Data::Inheritable" do
pending("Disabled on travis-ci because it always fails, and there is no way to debug it?") if is_travis

# Class::Data::Inheritable version 0.08 has a blank author field in its
# META.yml file.
subject.instance_variable_set(:@version, "0.08");

subject.attributes[:cpan_test?] = false

subject.input("Class::Data::Inheritable")
insist { subject.vendor } == "No Vendor Or Author Provided"
end

context "given a distribution without a META.* file" do
it "should package IPC::Session" do
pending("Disabled on travis-ci because it always fails, and there is no way to debug it?") if is_travis

# IPC::Session fails 'make test'
subject.instance_variable_set(:@version, "0.05");
subject.attributes[:cpan_test?] = false
# IPC::Session fails 'make test'
subject.input("IPC::Session")
end
end
Expand Down
3 changes: 3 additions & 0 deletions spec/spec_setup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
require "tempfile" # stdlib
require "fileutils" # stdlib
require "date" # stdlib
require "net/http" # stdlib
require "json" # stdlib
require "yaml" # stdlib

# put "lib" in RUBYLIB
$: << File.join(File.dirname(File.dirname(__FILE__)), "lib")
Expand Down