| 1 |
#!/usr/bin/ruby -EUTF-8 |
| 2 |
|
| 3 |
# Copyright © 2011, Lucas Nussbaum <[email protected]> |
| 4 |
# |
| 5 |
# This program is free software: you can redistribute it and/or modify |
| 6 |
# it under the terms of the GNU General Public License as published by |
| 7 |
# the Free Software Foundation, either version 3 of the License, or |
| 8 |
# (at your option) any later version. |
| 9 |
# |
| 10 |
# This program is distributed in the hope that it will be useful, |
| 11 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 |
# GNU General Public License for more details. |
| 14 |
# |
| 15 |
# You should have received a copy of the GNU General Public License |
| 16 |
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 17 |
|
| 18 |
require 'rbconfig' |
| 19 |
require 'fileutils' |
| 20 |
require 'optparse' |
| 21 |
require 'shellwords' |
| 22 |
|
| 23 |
require 'gem2deb/test_runner' |
| 24 |
|
| 25 |
options = {} |
| 26 |
|
| 27 |
if ENV['GEM2DEB_TEST_RUNNER'] |
| 28 |
opts = Shellwords.split(ENV['GEM2DEB_TEST_RUNNER']) |
| 29 |
ARGV.unshift(*opts) |
| 30 |
end |
| 31 |
|
| 32 |
optparse = OptionParser.new do |opts| |
| 33 |
|
| 34 |
opts.banner = "Usage: #{File.basename($PROGRAM_NAME)} [OPTIONS]" |
| 35 |
opts.separator 'Options:' |
| 36 |
|
| 37 |
opts.on('--autopkgtest', 'Runs tests against the installed package') do |
| 38 |
options[:autopkgtest] = true |
| 39 |
end |
| 40 |
|
| 41 |
opts.on('-c', '--check-dependencies', 'Check dependencies') do |
| 42 |
options[:check_dependencies] = true |
| 43 |
end |
| 44 |
|
| 45 |
opts.on( |
| 46 |
'-b', '--check-bundler', |
| 47 |
"Check loading the package under bundler" |
| 48 |
) do |
| 49 |
options[:check_bundler] = true |
| 50 |
end |
| 51 |
|
| 52 |
end |
| 53 |
|
| 54 |
optparse.parse! |
| 55 |
|
| 56 |
runner = Gem2Deb::TestRunner.detect! |
| 57 |
options.each do |opt,value| |
| 58 |
runner.send("#{opt}=", value) |
| 59 |
end |
| 60 |
runner.run_tests |
| 61 |
|
| 62 |
__END__ |
| 63 |
=head1 NAME |
| 64 |
|
| 65 |
gem2deb-test-runner - runs test suite contained in Debian Ruby packages |
| 66 |
|
| 67 |
=head1 SYNOPSIS |
| 68 |
|
| 69 |
B<gem2deb-test-runner> [B<OPTIONS>] |
| 70 |
|
| 71 |
=head1 DESCRIPTION |
| 72 |
|
| 73 |
B<gem2deb-test-runner> runs the tests shipped inside a source Debian Ruby |
| 74 |
package. The way the tests are run is configured in one of the three files: |
| 75 |
I<debian/ruby-test-files.yaml>, I<debian/ruby-tests.rake>, |
| 76 |
I<debian/ruby-tests.rb>. See the B<FILES> section in B<dh_ruby>(1) for details. |
| 77 |
|
| 78 |
If called without argument in the root of the source package after the package |
| 79 |
is built and installed under debian/I<package_name>, then the tests will be run |
| 80 |
using the files of the package installed under debian/I<package_name>. This call |
| 81 |
is part of the B<dh_ruby>(1) sequence when building a Ruby package with gem2deb. |
| 82 |
|
| 83 |
If the option B<--autopkgtest> is used, the package needs to be installed on |
| 84 |
the system. B<gem2deb-test-runner> will not try to load files under debian/ and |
| 85 |
will move away temporarily the lib/ and ext/ directory to ensure the test |
| 86 |
suite is run against the installed package. This is used in the context of |
| 87 |
automatic as-installed package testing, through the autopkgtest framework. |
| 88 |
|
| 89 |
=head1 OPTIONS |
| 90 |
|
| 91 |
=over |
| 92 |
|
| 93 |
=item B<--autopkgtest> |
| 94 |
|
| 95 |
Run the tests against the installed package for automatic as-installed package |
| 96 |
testing. Useful in conjunction with B<adt-run>(1). |
| 97 |
|
| 98 |
=item B<-c>, B<--check-dependencies> |
| 99 |
|
| 100 |
Before running the tests, checks whether all dependencies of the package, as |
| 101 |
declared in the Rubygems metadata, are present. Makes the program exit with a |
| 102 |
non-zero status code (i.e. fails) if they aren't. |
| 103 |
|
| 104 |
=item B<-b>, B<--check-bundler> |
| 105 |
|
| 106 |
Check that the package can be correctly loaded by bundler. This tests that the |
| 107 |
package can be loaded properly by bundler with the following two types of |
| 108 |
Gemfiles. One lists the package as a top-level dependency: |
| 109 |
|
| 110 |
gem "foo" |
| 111 |
|
| 112 |
This will be tested by calling `B<ruby -rbundler/setup>`. |
| 113 |
|
| 114 |
The other type includes the package in a group: |
| 115 |
|
| 116 |
group :test do |
| 117 |
gem "foo" |
| 118 |
end |
| 119 |
|
| 120 |
That will be tested by calling `B<ruby -rbundler -e 'Bundler.require(:test)'>`. |
| 121 |
|
| 122 |
=back |
| 123 |
|
| 124 |
=head1 ENVIRONMENT |
| 125 |
|
| 126 |
=over |
| 127 |
|
| 128 |
=item GEM2DEB_TEST_RUNNER |
| 129 |
|
| 130 |
Used to pass options to gem2deb-test-runner via the environment. For example, |
| 131 |
to make gem2deb-test-runner check dependencies during package build, you can |
| 132 |
add the following to I<debian/rules>: |
| 133 |
|
| 134 |
=over |
| 135 |
|
| 136 |
export GEM2DEB_TEST_RUNNER = --check-dependencies |
| 137 |
|
| 138 |
=back |
| 139 |
|
| 140 |
=back |
| 141 |
|
| 142 |
=head1 EXIT STATUS |
| 143 |
|
| 144 |
=over |
| 145 |
|
| 146 |
=item |
| 147 |
|
| 148 |
0 if tests pass. |
| 149 |
|
| 150 |
=item |
| 151 |
|
| 152 |
1 if tests fail. |
| 153 |
|
| 154 |
=item |
| 155 |
|
| 156 |
77 if B<--autopkgtest> was passed and B<gem2deb-test-runner> cannot determine |
| 157 |
how to run the test suite. |
| 158 |
|
| 159 |
=back |
| 160 |
|
| 161 |
=head1 SEE ALSO |
| 162 |
|
| 163 |
L<B<dh_ruby>>(1), L<B<gem2deb>>(1) |