sysexits 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/ChangeLog +9 -0
- data/LICENSE +27 -0
- data/README.md +46 -0
- data/Rakefile +358 -0
- data/lib/sysexits.rb +222 -0
- data/rake/191_compat.rb +26 -0
- data/rake/dependencies.rb +76 -0
- data/rake/documentation.rb +88 -0
- data/rake/helpers.rb +502 -0
- data/rake/hg.rb +275 -0
- data/rake/manual.rb +782 -0
- data/rake/packaging.rb +129 -0
- data/rake/publishing.rb +278 -0
- data/rake/style.rb +62 -0
- data/rake/svn.rb +668 -0
- data/rake/testing.rb +187 -0
- data/rake/verifytask.rb +64 -0
- data/spec/sysexits_spec.rb +62 -0
- metadata +99 -0
data/rake/testing.rb
ADDED
@@ -0,0 +1,187 @@
|
|
1
|
+
#
|
2
|
+
# Rake tasklib for testing tasks
|
3
|
+
|
4
|
+
#
|
5
|
+
# Authors:
|
6
|
+
# * Michael Granger <ged@FaerieMUD.org>
|
7
|
+
#
|
8
|
+
|
9
|
+
unless defined?( COVERAGE_MINIMUM )
|
10
|
+
if ENV['COVVERAGE_MINIMUM']
|
11
|
+
COVERAGE_MINIMUM = Float( ENV['COVERAGE_MINIMUM'] )
|
12
|
+
else
|
13
|
+
COVERAGE_MINIMUM = 85.0
|
14
|
+
end
|
15
|
+
end
|
16
|
+
SPEC_FILES = [] unless defined?( SPEC_FILES )
|
17
|
+
TEST_FILES = [] unless defined?( TEST_FILES )
|
18
|
+
|
19
|
+
COMMON_SPEC_OPTS = ['-Du'] unless defined?( COMMON_SPEC_OPTS )
|
20
|
+
|
21
|
+
COVERAGE_TARGETDIR = BASEDIR + 'coverage' unless defined?( COVERAGE_TARGETDIR )
|
22
|
+
RCOV_EXCLUDES = 'spec,tests,/Library/Ruby,/var/lib,/usr/local/lib' unless
|
23
|
+
defined?( RCOV_EXCLUDES )
|
24
|
+
|
25
|
+
|
26
|
+
desc "Run all defined tests"
|
27
|
+
task :test do
|
28
|
+
unless SPEC_FILES.empty?
|
29
|
+
log "Running specs"
|
30
|
+
Rake::Task['spec:quiet'].invoke
|
31
|
+
end
|
32
|
+
|
33
|
+
unless TEST_FILES.empty?
|
34
|
+
log "Running unit tests"
|
35
|
+
Rake::Task[:unittests].invoke
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
|
40
|
+
### RSpec specifications
|
41
|
+
begin
|
42
|
+
gem 'rspec', '>= 1.1.3'
|
43
|
+
|
44
|
+
require 'spec'
|
45
|
+
require 'spec/rake/spectask'
|
46
|
+
|
47
|
+
### Task: spec
|
48
|
+
desc "Run specs"
|
49
|
+
task :spec => 'spec:doc'
|
50
|
+
|
51
|
+
namespace :spec do
|
52
|
+
desc "Run rspec every time there's a change to one of the files"
|
53
|
+
task :autotest do
|
54
|
+
require 'autotest/rspec'
|
55
|
+
|
56
|
+
autotester = Autotest::Rspec.new
|
57
|
+
autotester.run
|
58
|
+
end
|
59
|
+
|
60
|
+
desc "Generate regular color 'doc' spec output"
|
61
|
+
Spec::Rake::SpecTask.new( :doc ) do |task|
|
62
|
+
task.spec_files = SPEC_FILES
|
63
|
+
task.spec_opts = COMMON_SPEC_OPTS + ['-f', 's', '-c']
|
64
|
+
end
|
65
|
+
|
66
|
+
desc "Generate spec output with profiling"
|
67
|
+
Spec::Rake::SpecTask.new( :profile ) do |task|
|
68
|
+
task.spec_files = SPEC_FILES
|
69
|
+
task.spec_opts = COMMON_SPEC_OPTS + ['-f', 'o']
|
70
|
+
end
|
71
|
+
|
72
|
+
desc "Generate quiet non-colored plain-text output"
|
73
|
+
Spec::Rake::SpecTask.new( :quiet ) do |task|
|
74
|
+
task.spec_files = SPEC_FILES
|
75
|
+
task.spec_opts = COMMON_SPEC_OPTS + ['-f', 'p']
|
76
|
+
end
|
77
|
+
|
78
|
+
desc "Generate HTML output"
|
79
|
+
Spec::Rake::SpecTask.new( :html ) do |task|
|
80
|
+
task.spec_files = SPEC_FILES
|
81
|
+
task.spec_opts = COMMON_SPEC_OPTS + ['-f', 'h']
|
82
|
+
end
|
83
|
+
|
84
|
+
end
|
85
|
+
rescue LoadError => err
|
86
|
+
task :no_rspec do
|
87
|
+
$stderr.puts "Specification tasks not defined: %s" % [ err.message ]
|
88
|
+
end
|
89
|
+
|
90
|
+
task :spec => :no_rspec
|
91
|
+
namespace :spec do
|
92
|
+
task :autotest => :no_rspec
|
93
|
+
task :doc => :no_rspec
|
94
|
+
task :profile => :no_rspec
|
95
|
+
task :quiet => :no_rspec
|
96
|
+
task :html => :no_rspec
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
|
101
|
+
### Test::Unit tests
|
102
|
+
begin
|
103
|
+
require 'rake/testtask'
|
104
|
+
|
105
|
+
Rake::TestTask.new( :unittests ) do |task|
|
106
|
+
task.libs += [LIBDIR]
|
107
|
+
task.test_files = TEST_FILES
|
108
|
+
task.verbose = true
|
109
|
+
end
|
110
|
+
|
111
|
+
rescue LoadError => err
|
112
|
+
task :no_test do
|
113
|
+
$stderr.puts "Test tasks not defined: %s" % [ err.message ]
|
114
|
+
end
|
115
|
+
|
116
|
+
task :unittests => :no_rspec
|
117
|
+
end
|
118
|
+
|
119
|
+
|
120
|
+
### RCov (via RSpec) tasks
|
121
|
+
begin
|
122
|
+
gem 'rcov'
|
123
|
+
gem 'rspec', '>= 1.1.3'
|
124
|
+
|
125
|
+
require 'spec'
|
126
|
+
require 'rcov'
|
127
|
+
|
128
|
+
### Task: coverage (via RCov)
|
129
|
+
desc "Build test coverage reports"
|
130
|
+
unless SPEC_FILES.empty?
|
131
|
+
Spec::Rake::SpecTask.new( :coverage ) do |task|
|
132
|
+
task.spec_files = SPEC_FILES
|
133
|
+
task.libs += [LIBDIR]
|
134
|
+
task.spec_opts = ['-f', 'p', '-b']
|
135
|
+
task.rcov_opts = RCOV_OPTS
|
136
|
+
task.rcov = true
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
|
141
|
+
### Task: rcov
|
142
|
+
task :rcov => :coverage
|
143
|
+
|
144
|
+
### Other coverage tasks
|
145
|
+
namespace :coverage do
|
146
|
+
desc "Generate a detailed text coverage report"
|
147
|
+
Spec::Rake::SpecTask.new( :text ) do |task|
|
148
|
+
task.spec_files = SPEC_FILES
|
149
|
+
task.rcov_opts = RCOV_OPTS + ['--text-report']
|
150
|
+
task.rcov = true
|
151
|
+
end
|
152
|
+
|
153
|
+
desc "Show differences in coverage from last run"
|
154
|
+
Spec::Rake::SpecTask.new( :diff ) do |task|
|
155
|
+
task.spec_files = SPEC_FILES
|
156
|
+
task.spec_opts = ['-f', 'p', '-b']
|
157
|
+
task.rcov_opts = RCOV_OPTS - ['--save'] + ['--text-coverage-diff']
|
158
|
+
task.rcov = true
|
159
|
+
end
|
160
|
+
|
161
|
+
desc "Run RCov in 'spec-only' mode to check coverage from specs"
|
162
|
+
Spec::Rake::SpecTask.new( :speconly ) do |task|
|
163
|
+
task.spec_files = SPEC_FILES
|
164
|
+
task.rcov_opts = ['--exclude', RCOV_EXCLUDES, '--text-report', '--save']
|
165
|
+
task.rcov = true
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
169
|
+
CLOBBER.include( COVERAGE_TARGETDIR )
|
170
|
+
|
171
|
+
rescue LoadError => err
|
172
|
+
task :no_rcov do
|
173
|
+
$stderr.puts "Coverage tasks not defined: RSpec+RCov tasklib not available: %s" %
|
174
|
+
[ err.message ]
|
175
|
+
end
|
176
|
+
|
177
|
+
task :coverage => :no_rcov
|
178
|
+
task :clobber_coverage
|
179
|
+
task :rcov => :no_rcov
|
180
|
+
namespace :coverage do
|
181
|
+
task :text => :no_rcov
|
182
|
+
task :diff => :no_rcov
|
183
|
+
end
|
184
|
+
task :verify => :no_rcov
|
185
|
+
end
|
186
|
+
|
187
|
+
|
data/rake/verifytask.rb
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
#####################################################################
|
2
|
+
### S U B V E R S I O N T A S K S A N D H E L P E R S
|
3
|
+
#####################################################################
|
4
|
+
|
5
|
+
require 'rake/tasklib'
|
6
|
+
|
7
|
+
#
|
8
|
+
# Work around the inexplicable behaviour of the original RDoc::VerifyTask, which
|
9
|
+
# errors if your coverage isn't *exactly* the threshold.
|
10
|
+
#
|
11
|
+
|
12
|
+
# A task that can verify that the RCov coverage doesn't
|
13
|
+
# drop below a certain threshold. It should be run after
|
14
|
+
# running Spec::Rake::SpecTask.
|
15
|
+
class VerifyTask < Rake::TaskLib
|
16
|
+
|
17
|
+
COVERAGE_PERCENTAGE_PATTERN =
|
18
|
+
%r{<tt class='coverage_code'>(\d+\.\d+)%</tt>}
|
19
|
+
|
20
|
+
# Name of the task. Defaults to :verify_rcov
|
21
|
+
attr_accessor :name
|
22
|
+
|
23
|
+
# Path to the index.html file generated by RCov, which
|
24
|
+
# is the file containing the total coverage.
|
25
|
+
# Defaults to 'coverage/index.html'
|
26
|
+
attr_accessor :index_html
|
27
|
+
|
28
|
+
# Whether or not to output details. Defaults to true.
|
29
|
+
attr_accessor :verbose
|
30
|
+
|
31
|
+
# The threshold value (in percent) for coverage. If the
|
32
|
+
# actual coverage is not equal to this value, the task will raise an
|
33
|
+
# exception.
|
34
|
+
attr_accessor :threshold
|
35
|
+
|
36
|
+
def initialize( name=:verify )
|
37
|
+
@name = name
|
38
|
+
@index_html = 'coverage/index.html'
|
39
|
+
@verbose = true
|
40
|
+
yield self if block_given?
|
41
|
+
raise "Threshold must be set" if @threshold.nil?
|
42
|
+
define
|
43
|
+
end
|
44
|
+
|
45
|
+
def define
|
46
|
+
desc "Verify that rcov coverage is at least #{threshold}%"
|
47
|
+
|
48
|
+
task @name do
|
49
|
+
total_coverage = nil
|
50
|
+
if match = File.read( index_html ).match( COVERAGE_PERCENTAGE_PATTERN )
|
51
|
+
total_coverage = Float( match[1] )
|
52
|
+
else
|
53
|
+
raise "Couldn't find the coverage percentage in #{index_html}"
|
54
|
+
end
|
55
|
+
|
56
|
+
puts "Coverage: #{total_coverage}% (threshold: #{threshold}%)" if verbose
|
57
|
+
if total_coverage < threshold
|
58
|
+
raise "Coverage must be at least #{threshold}% but was #{total_coverage}%"
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
# vim: set nosta noet ts=4 sw=4:
|
@@ -0,0 +1,62 @@
|
|
1
|
+
#!/usr/bin/env spec -cfs -b
|
2
|
+
|
3
|
+
BEGIN {
|
4
|
+
require 'pathname'
|
5
|
+
basedir = Pathname( __FILE__ ).dirname.parent
|
6
|
+
libdir = basedir + 'lib'
|
7
|
+
|
8
|
+
$LOAD_PATH.unshift( libdir.to_s ) unless $LOAD_PATH.include?( libdir.to_s )
|
9
|
+
}
|
10
|
+
|
11
|
+
require 'spec'
|
12
|
+
require 'sysexits'
|
13
|
+
|
14
|
+
describe Sysexits do
|
15
|
+
|
16
|
+
it "contains common exit codes as constants" do
|
17
|
+
Sysexits::EX_OK.should == 0
|
18
|
+
Sysexits::EX_USAGE.should == 64
|
19
|
+
end
|
20
|
+
|
21
|
+
|
22
|
+
it "provides an alternative 'exit' function that can take status names as Strings" do
|
23
|
+
expect {
|
24
|
+
Sysexits.exit( :usage )
|
25
|
+
}.to raise_exception( SystemExit, 'exit' ) do |exc|
|
26
|
+
exc.status.should == Sysexits::EX_USAGE
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
it "provides an alternative 'exit' function that can take status names as Symbols" do
|
31
|
+
expect {
|
32
|
+
Sysexits.exit( 'permission_denied' )
|
33
|
+
}.to raise_exception( SystemExit, 'exit' ) do |exc|
|
34
|
+
exc.status.should == Sysexits::EX_NOPERM
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
it "defaults to exiting with a successful status, just like the Kernel version" do
|
39
|
+
expect {
|
40
|
+
Sysexits.exit( :usage )
|
41
|
+
}.to raise_exception( SystemExit, 'exit' ) do |exc|
|
42
|
+
exc.status.should == Sysexits::EX_OK
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
|
47
|
+
it "overrides Kernel.exit without patching any monkeys" do
|
48
|
+
monkey = Class.new do
|
49
|
+
include Sysexits
|
50
|
+
|
51
|
+
def eek_eek
|
52
|
+
exit :usage
|
53
|
+
end
|
54
|
+
end
|
55
|
+
expect {
|
56
|
+
monkey.new.eek_eek
|
57
|
+
}.to raise_exception( SystemExit, 'exit' ) do |exc|
|
58
|
+
exc.status.should == Sysexits::EX_USAGE
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
metadata
ADDED
@@ -0,0 +1,99 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sysexits
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 23
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 1
|
8
|
+
- 0
|
9
|
+
- 0
|
10
|
+
version: 1.0.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Michael Granger
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2010-06-19 00:00:00 -07:00
|
19
|
+
default_executable:
|
20
|
+
dependencies: []
|
21
|
+
|
22
|
+
description: |-
|
23
|
+
Have you ever wanted to call exit() with an error condition, but weren't sure what
|
24
|
+
number to use? No? Maybe it's just me, then.
|
25
|
+
|
26
|
+
Anyway, I was reading W. Richard Stephens's book _Advanced Programming in the UNIX Environment_, and
|
27
|
+
I wanted to make my program exit with a reasonable exit code just like his C examples, but much
|
28
|
+
to my chagrin, I couldn't find a 'sysexits' for Ruby! Well, for the other 2 people that actually
|
29
|
+
care about this kind of thing, now there is!
|
30
|
+
email:
|
31
|
+
- ged@FaerieMUD.org
|
32
|
+
executables: []
|
33
|
+
|
34
|
+
extensions: []
|
35
|
+
|
36
|
+
extra_rdoc_files:
|
37
|
+
- ChangeLog
|
38
|
+
- README.md
|
39
|
+
- LICENSE
|
40
|
+
files:
|
41
|
+
- Rakefile
|
42
|
+
- ChangeLog
|
43
|
+
- README.md
|
44
|
+
- LICENSE
|
45
|
+
- spec/sysexits_spec.rb
|
46
|
+
- lib/sysexits.rb
|
47
|
+
- rake/191_compat.rb
|
48
|
+
- rake/dependencies.rb
|
49
|
+
- rake/documentation.rb
|
50
|
+
- rake/helpers.rb
|
51
|
+
- rake/hg.rb
|
52
|
+
- rake/manual.rb
|
53
|
+
- rake/packaging.rb
|
54
|
+
- rake/publishing.rb
|
55
|
+
- rake/style.rb
|
56
|
+
- rake/svn.rb
|
57
|
+
- rake/testing.rb
|
58
|
+
- rake/verifytask.rb
|
59
|
+
has_rdoc: true
|
60
|
+
homepage: http://rubygems.org/gems/sysexits
|
61
|
+
licenses: []
|
62
|
+
|
63
|
+
post_install_message: Happy exiting!
|
64
|
+
rdoc_options:
|
65
|
+
- --tab-width=4
|
66
|
+
- --show-hash
|
67
|
+
- --include
|
68
|
+
- .
|
69
|
+
- --main=README.md
|
70
|
+
- --title=sysexits
|
71
|
+
require_paths:
|
72
|
+
- lib
|
73
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
74
|
+
none: false
|
75
|
+
requirements:
|
76
|
+
- - ">="
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
hash: 3
|
79
|
+
segments:
|
80
|
+
- 0
|
81
|
+
version: "0"
|
82
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
83
|
+
none: false
|
84
|
+
requirements:
|
85
|
+
- - ">="
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
hash: 3
|
88
|
+
segments:
|
89
|
+
- 0
|
90
|
+
version: "0"
|
91
|
+
requirements: []
|
92
|
+
|
93
|
+
rubyforge_project:
|
94
|
+
rubygems_version: 1.3.7
|
95
|
+
signing_key:
|
96
|
+
specification_version: 3
|
97
|
+
summary: A Ruby front end to sysexits.h
|
98
|
+
test_files:
|
99
|
+
- spec/sysexits_spec.rb
|