summaryrefslogtreecommitdiff
path: root/test/rubygems
diff options
context:
space:
mode:
Diffstat (limited to 'test/rubygems')
-rw-r--r--test/rubygems/test_gem_commands_build_command.rb32
-rw-r--r--test/rubygems/test_gem_package.rb27
2 files changed, 59 insertions, 0 deletions
diff --git a/test/rubygems/test_gem_commands_build_command.rb b/test/rubygems/test_gem_commands_build_command.rb
index 0c511b2f085..50c447e2ebf 100644
--- a/test/rubygems/test_gem_commands_build_command.rb
+++ b/test/rubygems/test_gem_commands_build_command.rb
@@ -457,4 +457,36 @@ class TestGemCommandsBuildCommand < Gem::TestCase
assert_match(/INFO: Your expired cert will be located at: .+\Wgem-public_cert\.pem\.expired\.[0-9]+/, output.shift)
end
+ def test_build_is_reproducible
+ epoch = ENV["SOURCE_DATE_EPOCH"]
+ new_epoch = Time.now.to_i.to_s
+ ENV["SOURCE_DATE_EPOCH"] = new_epoch
+
+ gem_file = File.basename(@gem.cache_file)
+
+ gemspec_file = File.join(@tempdir, @gem.spec_name)
+ File.write(gemspec_file, @gem.to_ruby)
+ @cmd.options[:args] = [gemspec_file]
+
+ util_test_build_gem @gem
+
+ build1_contents = File.read(gem_file)
+
+ # Guarantee the time has changed.
+ sleep 1 if Time.now.to_i == new_epoch
+
+ ENV["SOURCE_DATE_EPOCH"] = new_epoch
+
+ @ui = Gem::MockGemUi.new
+ @cmd.options[:args] = [gemspec_file]
+
+ util_test_build_gem @gem
+
+ build2_contents = File.read(gem_file)
+
+ assert_equal build1_contents, build2_contents
+ ensure
+ ENV["SOURCE_DATE_EPOCH"] = epoch
+ end
+
end
diff --git a/test/rubygems/test_gem_package.rb b/test/rubygems/test_gem_package.rb
index f2f712ebe0b..a282e0cc5f1 100644
--- a/test/rubygems/test_gem_package.rb
+++ b/test/rubygems/test_gem_package.rb
@@ -2,6 +2,7 @@
# frozen_string_literal: true
require 'rubygems/package/tar_test_case'
+require 'digest'
class TestGemPackage < Gem::Package::TarTestCase
@@ -123,6 +124,32 @@ class TestGemPackage < Gem::Package::TarTestCase
ENV["SOURCE_DATE_EPOCH"] = epoch
end
+ def test_build_time_source_date_epoch_automatically_set
+ epoch = ENV["SOURCE_DATE_EPOCH"]
+ ENV["SOURCE_DATE_EPOCH"] = nil
+
+ start_time = Time.now.utc.to_i
+
+ spec = Gem::Specification.new 'build', '1'
+ spec.summary = 'build'
+ spec.authors = 'build'
+ spec.files = ['lib/code.rb']
+ spec.rubygems_version = Gem::Version.new '0'
+
+ package = Gem::Package.new spec.file_name
+
+ end_time = Time.now.utc.to_i
+
+ assert package.build_time.is_a?(Time)
+
+ build_time = package.build_time.to_i
+
+ assert(start_time <= build_time)
+ assert(build_time <= end_time)
+ ensure
+ ENV["SOURCE_DATE_EPOCH"] = epoch
+ end
+
def test_add_files
spec = Gem::Specification.new
spec.files = %w[lib/code.rb lib/empty]