[DRE-maint] Experimenting with autopkgtest

Jérémy Bobbio lunar at debian.org
Fri Sep 20 09:19:04 UTC 2013


As a recreational break, I took a couple of hours to look at how we
could add support for autopkgtest [1] in Ruby packages.

I've used ruby-backports as a playground. See the `pu/autopkgtest`
branch in the Git repository [2].

[1] http://anonscm.debian.org/gitweb/?p=autopkgtest/autopkgtest.git;a=blob_plain;f=doc/README.package-tests;hb=HEAD
[2] http://anonscm.debian.org/gitweb/?p=pkg-ruby-extras/ruby-backports.git;a=shortlog;h=refs/heads/pu/autopkgtest

Here's some highlihts on the patch:

diff --git a/debian/tests/control b/debian/tests/control
new file mode 100644
index 0000000..c684055
--- /dev/null
+++ b/debian/tests/control
@@ -0,0 +1,2 @@
+Tests: gem2deb
+Depends: gem2deb rake

I decided to name the test `gem2deb` because my hope is that we can
have the code starting the tests as part as gem2deb.

In the specific case of ruby-backports, `ruby-tests.rb` starts the test
suite by using rake to launch a target in upstream Rakefile.

diff --git a/debian/tests/gem2deb b/debian/tests/gem2deb
new file mode 100755
index 0000000..d48b2ed
--- /dev/null
+++ b/debian/tests/gem2deb
@@ -0,0 +1,55 @@
+require 'gem2deb/metadata'
+require 'gem2deb/dh_ruby'
+require 'tmpdir'
+require 'fileutils'
+class Tester < Gem2Deb::DhRuby
+  def run
+    run_tests
+  end
+unless ENV['ADTTMP']
+  $stderr.puts 'ADTTMP is not set. Exiting'
+  exit 1
+dest = ENV['ADTTMP']
+unless Dir.entries(dest) == ['.', '..']
+  $stderr.puts 'ADTTMP is not empty. Exiting'
+  exit 1
+# Copy test files
+metadata = Gem2Deb::Metadata.new('.')
+metadata.test_files.each do |path|
+  next if File.directory?(path)
+  FileUtils.mkdir_p File.join(dest, File.dirname(path))
+  FileUtils.install path, File.join(dest, path)
+# Copy Rakefile if there's one
+# XXX: not sure if we need that
+FileUtils.cp 'Rakefile', dest if File.exists?('Rakefile')
+# Dump gemspecs in static form (because upstream gemspec might use Git or
+# other tools)
+Dir.glob('*.gemspec').each do |path|
+  spec = Gem::Specification.load(path)
+  File.open(File.join(dest, path), 'w') { |f| f.write(spec.to_ruby) }
+# Copy Debian directory
+FileUtils.cp_r 'debian', dest
+# Copy metadata for DhRuby
+FileUtils.cp 'metadata.yml', dest
+# Run the tests
+Dir.chdir(dest) do
+  Tester.new.run

So the idea here is that we use the empty directory that autopkgtest
creates for us and populate it with the test files declared in the
gemspec. We also copy/generate enough other files so DhRuby is happy to
run the tests as dh_ruby usually does.

Pretty small, but not the nicest.

I also had to patch the upstream test suite because it assumed it was
run in the same source tree as the library.

Anyone should feel free to take it up from here, I don't think I'll
spend more time on this anytime soon.

Lunar                                .''`. 
lunar at debian.org                    : :Ⓐ  :  # apt-get install anarchism
                                    `. `'` 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.alioth.debian.org/pipermail/pkg-ruby-extras-maintainers/attachments/20130920/01c82f1f/attachment.sig>

More information about the Pkg-ruby-extras-maintainers mailing list