2016-02-01 07:43:26 -05:00
|
|
|
# frozen_string_literal: true
|
2011-01-28 18:46:47 -05:00
|
|
|
require 'rubygems/test_case'
|
2009-06-09 17:38:59 -04:00
|
|
|
require 'rubygems'
|
2020-06-16 07:15:22 -04: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 17:38:59 -04:00
|
|
|
|
2011-01-28 18:46:47 -05:00
|
|
|
class TestGemPackageTask < Gem::TestCase
|
2009-06-09 17:38:59 -04:00
|
|
|
def test_gem_package
|
2020-05-21 13:19:50 -04:00
|
|
|
original_rake_fileutils_verbosity = RakeFileUtils.verbose_flag
|
2020-05-16 08:43:21 -04:00
|
|
|
RakeFileUtils.verbose_flag = false
|
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
gem = Gem::Specification.new do |g|
|
|
|
|
g.name = "pkgr"
|
|
|
|
g.version = "1.2.3"
|
2013-08-26 16:24:51 -04:00
|
|
|
|
|
|
|
g.authors = %w[author]
|
|
|
|
g.files = %w[x]
|
|
|
|
g.summary = 'summary'
|
2009-06-09 17:38:59 -04:00
|
|
|
end
|
2013-08-26 16:24:51 -04: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 12:52:30 -04:00
|
|
|
Rake.application = Rake::Application.new
|
|
|
|
|
2019-05-03 13:56:58 -04:00
|
|
|
pkg = Gem::PackageTask.new(gem) do |p|
|
2009-06-09 17:38:59 -04:00
|
|
|
p.package_files << "y"
|
|
|
|
end
|
2013-08-26 16:24:51 -04:00
|
|
|
|
|
|
|
assert_equal %w[x y], pkg.package_files
|
|
|
|
|
|
|
|
Dir.chdir @tempdir do
|
|
|
|
FileUtils.touch 'x'
|
|
|
|
FileUtils.touch 'y'
|
|
|
|
|
|
|
|
Rake.application['package'].invoke
|
|
|
|
|
|
|
|
assert_path_exists 'pkg/pkgr-1.2.3.gem'
|
|
|
|
end
|
2020-05-21 13:19:50 -04:00
|
|
|
ensure
|
|
|
|
RakeFileUtils.verbose_flag = original_rake_fileutils_verbosity
|
2009-06-09 17:38:59 -04:00
|
|
|
end
|
|
|
|
|
2020-05-16 08:45:08 -04: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
|
|
|
|
|
[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 12:52:30 -04:00
|
|
|
_, err = capture_io do
|
|
|
|
Rake.application = Rake::Application.new
|
2020-05-16 08:45:08 -04: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 12:52:30 -04:00
|
|
|
pkg = Gem::PackageTask.new(gem) do |p|
|
|
|
|
p.package_files << "y"
|
|
|
|
end
|
2020-05-16 08:45:08 -04: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 12:52:30 -04:00
|
|
|
assert_equal %w[x y], pkg.package_files
|
|
|
|
|
|
|
|
Dir.chdir @tempdir do
|
|
|
|
FileUtils.touch 'x'
|
|
|
|
FileUtils.touch 'y'
|
2020-05-16 08:45:08 -04: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 12:52:30 -04:00
|
|
|
|
|
|
|
assert_empty err
|
2020-05-16 08:45:08 -04:00
|
|
|
end
|
|
|
|
|
2009-06-09 17:38:59 -04: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 13:56:58 -04:00
|
|
|
pkg = Gem::PackageTask.new(gem) do |p|
|
2009-06-09 17:38:59 -04: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 13:56:58 -04:00
|
|
|
pkg = Gem::PackageTask.new(gem) do |p|
|
2009-06-09 17:38:59 -04:00
|
|
|
p.package_files << "y"
|
|
|
|
end
|
|
|
|
assert_equal ["x", "y"], pkg.package_files
|
|
|
|
end
|
|
|
|
|
2011-01-31 22:11:34 -05: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 07:15:22 -04:00
|
|
|
end if defined?(Rake::PackageTask)
|