2016-02-01 12:43:26 +00:00
|
|
|
# frozen_string_literal: true
|
2021-06-02 12:32:47 +09:00
|
|
|
require_relative "helper"
|
2009-06-09 21:38:59 +00:00
|
|
|
require "rubygems"
|
2020-06-16 13:15:22 +02:00
|
|
|
|
|
|
|
begin
|
|
|
|
require "rubygems/package_task"
|
|
|
|
rescue LoadError => e
|
|
|
|
raise unless e.path == "rake/packagetask"
|
|
|
|
end
|
|
|
|
|
|
|
|
unless defined?(Rake::PackageTask)
|
|
|
|
warn "Skipping Gem::PackageTask tests. rake not found."
|
|
|
|
end
|
2009-06-09 21:38:59 +00:00
|
|
|
|
2011-01-28 23:46:47 +00:00
|
|
|
class TestGemPackageTask < Gem::TestCase
|
2009-06-09 21:38:59 +00:00
|
|
|
def test_gem_package
|
2020-05-21 19:19:50 +02:00
|
|
|
original_rake_fileutils_verbosity = RakeFileUtils.verbose_flag
|
2020-05-16 14:43:21 +02:00
|
|
|
RakeFileUtils.verbose_flag = false
|
|
|
|
|
2009-06-09 21:38:59 +00:00
|
|
|
gem = Gem::Specification.new do |g|
|
|
|
|
g.name = "pkgr"
|
|
|
|
g.version = "1.2.3"
|
2013-08-26 20:24:51 +00:00
|
|
|
|
|
|
|
g.authors = %w[author]
|
|
|
|
g.files = %w[x]
|
|
|
|
g.summary = "summary"
|
2009-06-09 21:38:59 +00:00
|
|
|
end
|
2013-08-26 20:24:51 +00:00
|
|
|
|
[rubygems/rubygems] Fix test warnings
Since `rake package` started printing to stdout by default, we get these
warnings printed when running rubygems tests:
```
$ rake
Run options: --seed 6097
# Running:
...............................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................mkdir -p pkg
mkdir -p pkg/pkgr-1.2.3
rm -f pkg/pkgr-1.2.3/x
ln x pkg/pkgr-1.2.3/x
rm -f pkg/pkgr-1.2.3/y
ln y pkg/pkgr-1.2.3/y
cd pkg/pkgr-1.2.3
cd -
....
Finished in 50.578889s, 43.0812 runs/s, 134.8191 assertions/s.
2179 runs, 6819 assertions, 0 failures, 0 errors, 0 skips
Coverage report generated for Unit Tests to /home/deivid/Code/rubygems/coverage. 8080 / 8978 LOC (90.0%) covered.
```
The reason is that, although these tests wrap the
`Rake.application["package"].invoke` with a `capture_io` block, the rake
application initialization happens outside of this block, and a copy of
`$stdout` is saved in there, and that's where the task prints. So the
`capture_io` `$stdout` and `$stderr` dance is not effective.
To fix, we move the `Rake` application initialization inside the
`capture_io` block.
https://github.com/rubygems/rubygems/commit/7f6e2398a5
2020-05-21 18:52:30 +02:00
|
|
|
Rake.application = Rake::Application.new
|
|
|
|
|
2019-05-03 19:56:58 +02:00
|
|
|
pkg = Gem::PackageTask.new(gem) do |p|
|
2009-06-09 21:38:59 +00:00
|
|
|
p.package_files << "y"
|
|
|
|
end
|
2013-08-26 20:24:51 +00:00
|
|
|
|
|
|
|
assert_equal %w[x y], pkg.package_files
|
|
|
|
|
|
|
|
Dir.chdir @tempdir do
|
|
|
|
FileUtils.touch "x"
|
|
|
|
FileUtils.touch "y"
|
|
|
|
|
|
|
|
Rake.application["package"].invoke
|
|
|
|
|
2020-05-25 21:05:45 +09:00
|
|
|
assert_path_exist "pkg/pkgr-1.2.3.gem"
|
2013-08-26 20:24:51 +00:00
|
|
|
end
|
2020-05-21 19:19:50 +02:00
|
|
|
ensure
|
|
|
|
RakeFileUtils.verbose_flag = original_rake_fileutils_verbosity
|
2009-06-09 21:38:59 +00:00
|
|
|
end
|
|
|
|
|
2020-05-16 14:45:08 +02:00
|
|
|
def test_gem_package_prints_to_stdout_by_default
|
|
|
|
gem = Gem::Specification.new do |g|
|
|
|
|
g.name = "pkgr"
|
|
|
|
g.version = "1.2.3"
|
|
|
|
|
|
|
|
g.authors = %w[author]
|
|
|
|
g.files = %w[x]
|
|
|
|
g.summary = "summary"
|
|
|
|
end
|
|
|
|
|
2020-05-25 21:58:27 +09:00
|
|
|
_, err = capture_output do
|
[rubygems/rubygems] Fix test warnings
Since `rake package` started printing to stdout by default, we get these
warnings printed when running rubygems tests:
```
$ rake
Run options: --seed 6097
# Running:
...............................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................mkdir -p pkg
mkdir -p pkg/pkgr-1.2.3
rm -f pkg/pkgr-1.2.3/x
ln x pkg/pkgr-1.2.3/x
rm -f pkg/pkgr-1.2.3/y
ln y pkg/pkgr-1.2.3/y
cd pkg/pkgr-1.2.3
cd -
....
Finished in 50.578889s, 43.0812 runs/s, 134.8191 assertions/s.
2179 runs, 6819 assertions, 0 failures, 0 errors, 0 skips
Coverage report generated for Unit Tests to /home/deivid/Code/rubygems/coverage. 8080 / 8978 LOC (90.0%) covered.
```
The reason is that, although these tests wrap the
`Rake.application["package"].invoke` with a `capture_io` block, the rake
application initialization happens outside of this block, and a copy of
`$stdout` is saved in there, and that's where the task prints. So the
`capture_io` `$stdout` and `$stderr` dance is not effective.
To fix, we move the `Rake` application initialization inside the
`capture_io` block.
https://github.com/rubygems/rubygems/commit/7f6e2398a5
2020-05-21 18:52:30 +02:00
|
|
|
Rake.application = Rake::Application.new
|
2020-05-16 14:45:08 +02:00
|
|
|
|
[rubygems/rubygems] Fix test warnings
Since `rake package` started printing to stdout by default, we get these
warnings printed when running rubygems tests:
```
$ rake
Run options: --seed 6097
# Running:
...............................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................mkdir -p pkg
mkdir -p pkg/pkgr-1.2.3
rm -f pkg/pkgr-1.2.3/x
ln x pkg/pkgr-1.2.3/x
rm -f pkg/pkgr-1.2.3/y
ln y pkg/pkgr-1.2.3/y
cd pkg/pkgr-1.2.3
cd -
....
Finished in 50.578889s, 43.0812 runs/s, 134.8191 assertions/s.
2179 runs, 6819 assertions, 0 failures, 0 errors, 0 skips
Coverage report generated for Unit Tests to /home/deivid/Code/rubygems/coverage. 8080 / 8978 LOC (90.0%) covered.
```
The reason is that, although these tests wrap the
`Rake.application["package"].invoke` with a `capture_io` block, the rake
application initialization happens outside of this block, and a copy of
`$stdout` is saved in there, and that's where the task prints. So the
`capture_io` `$stdout` and `$stderr` dance is not effective.
To fix, we move the `Rake` application initialization inside the
`capture_io` block.
https://github.com/rubygems/rubygems/commit/7f6e2398a5
2020-05-21 18:52:30 +02:00
|
|
|
pkg = Gem::PackageTask.new(gem) do |p|
|
|
|
|
p.package_files << "y"
|
|
|
|
end
|
2020-05-16 14:45:08 +02:00
|
|
|
|
[rubygems/rubygems] Fix test warnings
Since `rake package` started printing to stdout by default, we get these
warnings printed when running rubygems tests:
```
$ rake
Run options: --seed 6097
# Running:
...............................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................mkdir -p pkg
mkdir -p pkg/pkgr-1.2.3
rm -f pkg/pkgr-1.2.3/x
ln x pkg/pkgr-1.2.3/x
rm -f pkg/pkgr-1.2.3/y
ln y pkg/pkgr-1.2.3/y
cd pkg/pkgr-1.2.3
cd -
....
Finished in 50.578889s, 43.0812 runs/s, 134.8191 assertions/s.
2179 runs, 6819 assertions, 0 failures, 0 errors, 0 skips
Coverage report generated for Unit Tests to /home/deivid/Code/rubygems/coverage. 8080 / 8978 LOC (90.0%) covered.
```
The reason is that, although these tests wrap the
`Rake.application["package"].invoke` with a `capture_io` block, the rake
application initialization happens outside of this block, and a copy of
`$stdout` is saved in there, and that's where the task prints. So the
`capture_io` `$stdout` and `$stderr` dance is not effective.
To fix, we move the `Rake` application initialization inside the
`capture_io` block.
https://github.com/rubygems/rubygems/commit/7f6e2398a5
2020-05-21 18:52:30 +02:00
|
|
|
assert_equal %w[x y], pkg.package_files
|
|
|
|
|
|
|
|
Dir.chdir @tempdir do
|
|
|
|
FileUtils.touch "x"
|
|
|
|
FileUtils.touch "y"
|
2020-05-16 14:45:08 +02:00
|
|
|
|
|
|
|
Rake.application["package"].invoke
|
|
|
|
end
|
|
|
|
end
|
[rubygems/rubygems] Fix test warnings
Since `rake package` started printing to stdout by default, we get these
warnings printed when running rubygems tests:
```
$ rake
Run options: --seed 6097
# Running:
...............................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................mkdir -p pkg
mkdir -p pkg/pkgr-1.2.3
rm -f pkg/pkgr-1.2.3/x
ln x pkg/pkgr-1.2.3/x
rm -f pkg/pkgr-1.2.3/y
ln y pkg/pkgr-1.2.3/y
cd pkg/pkgr-1.2.3
cd -
....
Finished in 50.578889s, 43.0812 runs/s, 134.8191 assertions/s.
2179 runs, 6819 assertions, 0 failures, 0 errors, 0 skips
Coverage report generated for Unit Tests to /home/deivid/Code/rubygems/coverage. 8080 / 8978 LOC (90.0%) covered.
```
The reason is that, although these tests wrap the
`Rake.application["package"].invoke` with a `capture_io` block, the rake
application initialization happens outside of this block, and a copy of
`$stdout` is saved in there, and that's where the task prints. So the
`capture_io` `$stdout` and `$stderr` dance is not effective.
To fix, we move the `Rake` application initialization inside the
`capture_io` block.
https://github.com/rubygems/rubygems/commit/7f6e2398a5
2020-05-21 18:52:30 +02:00
|
|
|
|
|
|
|
assert_empty err
|
2020-05-16 14:45:08 +02:00
|
|
|
end
|
|
|
|
|
2009-06-09 21:38:59 +00:00
|
|
|
def test_gem_package_with_current_platform
|
|
|
|
gem = Gem::Specification.new do |g|
|
|
|
|
g.name = "pkgr"
|
|
|
|
g.version = "1.2.3"
|
|
|
|
g.files = Rake::FileList["x"].resolve
|
|
|
|
g.platform = Gem::Platform::CURRENT
|
|
|
|
end
|
2019-05-03 19:56:58 +02:00
|
|
|
pkg = Gem::PackageTask.new(gem) do |p|
|
2009-06-09 21:38:59 +00:00
|
|
|
p.package_files << "y"
|
|
|
|
end
|
|
|
|
assert_equal ["x", "y"], pkg.package_files
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_gem_package_with_ruby_platform
|
|
|
|
gem = Gem::Specification.new do |g|
|
|
|
|
g.name = "pkgr"
|
|
|
|
g.version = "1.2.3"
|
|
|
|
g.files = Rake::FileList["x"].resolve
|
|
|
|
g.platform = Gem::Platform::RUBY
|
|
|
|
end
|
2019-05-03 19:56:58 +02:00
|
|
|
pkg = Gem::PackageTask.new(gem) do |p|
|
2009-06-09 21:38:59 +00:00
|
|
|
p.package_files << "y"
|
|
|
|
end
|
|
|
|
assert_equal ["x", "y"], pkg.package_files
|
|
|
|
end
|
|
|
|
|
2011-02-01 03:11:34 +00:00
|
|
|
def test_package_dir_path
|
|
|
|
gem = Gem::Specification.new do |g|
|
|
|
|
g.name = "nokogiri"
|
|
|
|
g.version = "1.5.0"
|
|
|
|
g.platform = "java"
|
|
|
|
end
|
|
|
|
|
|
|
|
pkg = Gem::PackageTask.new gem
|
|
|
|
pkg.define
|
|
|
|
|
|
|
|
assert_equal "pkg/nokogiri-1.5.0-java", pkg.package_dir_path
|
|
|
|
end
|
2020-06-16 13:15:22 +02:00
|
|
|
end if defined?(Rake::PackageTask)
|