Exit_Zero 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,8 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
5
+
6
+ coverage
7
+ rdoc
8
+ .yardoc
data/Exit_Zero.gemspec ADDED
@@ -0,0 +1,34 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ $:.push File.expand_path("../lib", __FILE__)
4
+ require "Exit_Zero/version"
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "Exit_Zero"
8
+ s.version = Exit_Zero::VERSION
9
+ s.authors = ["da99"]
10
+ s.email = ["i-hate-spam-45671204@mailinator.com"]
11
+ s.homepage = ""
12
+ s.summary = %q{Make sure your last process exited with 0.}
13
+ s.description = %q{
14
+ A simple method that raises Exit_Zero::Non_Zero
15
+ if $?.exitstatus is not zero.
16
+ Be sure to use the "posix-spawn" since almost everything
17
+ else is just plain wrong when handling child processes.
18
+ }
19
+
20
+ s.files = `git ls-files`.split("\n")
21
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
22
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
23
+ s.require_paths = ["lib"]
24
+
25
+ s.add_development_dependency "bacon"
26
+ s.add_development_dependency "rake"
27
+ s.add_development_dependency 'Bacon_Colored'
28
+ s.add_development_dependency 'pry'
29
+
30
+ # s.rubyforge_project = "Exit_Zero"
31
+ # specify any dependencies here; for example:
32
+ s.add_runtime_dependency "Split_Lines"
33
+ s.add_runtime_dependency "posix-spawn"
34
+ end
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ source "http://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in Bob.gemspec
6
+ gemspec
data/Rakefile ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/gem_tasks"
@@ -0,0 +1,3 @@
1
+ class Exit_Zero
2
+ VERSION = "0.1.0"
3
+ end
data/lib/Exit_Zero.rb ADDED
@@ -0,0 +1,60 @@
1
+ require 'Exit_Zero/version'
2
+ require 'Split_Lines'
3
+ require 'posix/spawn'
4
+
5
+ def Exit_Zero cmd=:no_cmd, &blok
6
+
7
+ if cmd == :no_cmd
8
+ r = yield
9
+ Exit_Zero.check blok, r
10
+ r
11
+ else
12
+ raise ArgumentError, "Both command and block are not allowed." if block_given?
13
+ r = Exit_Zero::Result.new(POSIX::Spawn::Child.new(cmd))
14
+ Exit_Zero.check cmd, r.status
15
+ r
16
+ end
17
+
18
+ end # === Exit_Zero
19
+
20
+ class Exit_Zero
21
+
22
+ module Class_Methods
23
+
24
+ def check cmd, r = :no_status
25
+ r = $? if !r.respond_to?(:exitstatus)
26
+ raise(Exit_Zero::Non_Zero, cmd) if r.exitstatus != 0
27
+ end
28
+
29
+ end # === Class_Methods
30
+
31
+ extend Class_Methods
32
+
33
+ class Non_Zero < RuntimeError
34
+ end # === class Non_Zero
35
+
36
+ class Result
37
+ module Base
38
+
39
+ attr_reader :child
40
+ def initialize child
41
+ @child = child
42
+ end
43
+
44
+ def split_lines
45
+ Split_Lines(child.out)
46
+ end
47
+
48
+ %w{ out err status }.each { |m|
49
+ eval %~
50
+ def #{m}
51
+ child.#{m}
52
+ end
53
+ ~
54
+ }
55
+
56
+ end # === Base
57
+ include Base
58
+ end # === Result
59
+
60
+ end # === class Exit_Zero
data/spec/helper.rb ADDED
@@ -0,0 +1,15 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.print e.message, "\n"
7
+ $stderr.print "Run `bundle install` to install missing gems\n"
8
+ exit e.status_code
9
+ end
10
+ require 'bacon'
11
+
12
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
13
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
14
+
15
+ Bacon.summary_on_exit
data/spec/main.rb ADDED
@@ -0,0 +1,15 @@
1
+
2
+ require File.expand_path('spec/helper')
3
+ require 'Exit_Zero'
4
+ require 'Bacon_Colored'
5
+ require 'pry'
6
+
7
+
8
+ # ======== Include the tests.
9
+ if ARGV.size > 1 && ARGV[1, ARGV.size - 1].detect { |a| File.exists?(a) }
10
+ # Do nothing. Bacon grabs the file.
11
+ else
12
+ Dir.glob('spec/tests/*.rb').each { |file|
13
+ require File.expand_path(file.sub('.rb', '')) if File.file?(file)
14
+ }
15
+ end
@@ -0,0 +1,54 @@
1
+ describe "Exit_Zero::Result" do
2
+
3
+ it "provides split_lines" do
4
+ r = Exit_Zero::Result.new(POSIX::Spawn::Child.new('ls -Al'))
5
+ r.split_lines.should == `ls -Al`.strip.split("\n")
6
+ end
7
+
8
+ %w{ out err status }.each { |m|
9
+ it "sets :#{m} equal to Child##{m}" do
10
+ cmd = %q! ruby -e "puts 'a'; warn 'b'; exit(127);"!
11
+ target = POSIX::Spawn::Child.new(cmd)
12
+ Exit_Zero::Result.new(POSIX::Spawn::Child.new(cmd))
13
+ .send(m).should == target.send(m)
14
+ end
15
+ }
16
+
17
+ end # === Exit_Zero::Result
18
+
19
+ describe "Exit_Zero 'cmd'" do
20
+
21
+ it "raises Exit_Zero::Non_Zero if command exits with non-zero" do
22
+ lambda {
23
+ Exit_Zero 'uptimes'
24
+ }.should.raise(Exit_Zero::Non_Zero)
25
+ end
26
+
27
+ it "returns a Exit_Zero::Result" do
28
+ Exit_Zero('whoami').class.should.be == Exit_Zero::Result
29
+ end
30
+
31
+ it "executes valid command" do
32
+ Exit_Zero('pwd').out.should == `pwd`
33
+ end
34
+
35
+ it "raises ArgumentError if both a cmd and block are given" do
36
+ lambda { Exit_Zero('uptime') {} }
37
+ .should.raise(ArgumentError)
38
+ .message.should.match %r!are not allowed!i
39
+ end
40
+
41
+ end # === Exit_Zero 'cmd'
42
+
43
+ describe "Exit_Zero { }" do
44
+
45
+ it "raises Exit_Zero::Non_Zero if $?.exitstatus != 0" do
46
+ lambda {
47
+ Exit_Zero {
48
+ POSIX::Spawn::Child.new("uptimes")
49
+ }
50
+ }.should.raise(Exit_Zero::Non_Zero)
51
+ end
52
+
53
+ end # === Exit_Zero { }
54
+
data/spec/tests/bin.rb ADDED
@@ -0,0 +1,10 @@
1
+
2
+ describe "permissions of bin/" do
3
+
4
+ it "should be 750" do
5
+ `stat -c %a bin`.strip
6
+ .should.be == "750"
7
+ end
8
+
9
+ end # === permissions of bin/
10
+
metadata ADDED
@@ -0,0 +1,123 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: Exit_Zero
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - da99
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-02-20 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bacon
16
+ requirement: &8271400 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: *8271400
25
+ - !ruby/object:Gem::Dependency
26
+ name: rake
27
+ requirement: &8270660 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *8270660
36
+ - !ruby/object:Gem::Dependency
37
+ name: Bacon_Colored
38
+ requirement: &8270180 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *8270180
47
+ - !ruby/object:Gem::Dependency
48
+ name: pry
49
+ requirement: &8269700 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *8269700
58
+ - !ruby/object:Gem::Dependency
59
+ name: Split_Lines
60
+ requirement: &8269260 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ type: :runtime
67
+ prerelease: false
68
+ version_requirements: *8269260
69
+ - !ruby/object:Gem::Dependency
70
+ name: posix-spawn
71
+ requirement: &8268760 !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ type: :runtime
78
+ prerelease: false
79
+ version_requirements: *8268760
80
+ description: ! "\n A simple method that raises Exit_Zero::Non_Zero\n if $?.exitstatus
81
+ is not zero.\n Be sure to use the \"posix-spawn\" since almost everything \n
82
+ \ else is just plain wrong when handling child processes.\n "
83
+ email:
84
+ - i-hate-spam-45671204@mailinator.com
85
+ executables: []
86
+ extensions: []
87
+ extra_rdoc_files: []
88
+ files:
89
+ - .gitignore
90
+ - Exit_Zero.gemspec
91
+ - Gemfile
92
+ - Rakefile
93
+ - lib/Exit_Zero.rb
94
+ - lib/Exit_Zero/version.rb
95
+ - spec/helper.rb
96
+ - spec/main.rb
97
+ - spec/tests/Exit_Zero.rb
98
+ - spec/tests/bin.rb
99
+ homepage: ''
100
+ licenses: []
101
+ post_install_message:
102
+ rdoc_options: []
103
+ require_paths:
104
+ - lib
105
+ required_ruby_version: !ruby/object:Gem::Requirement
106
+ none: false
107
+ requirements:
108
+ - - ! '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ required_rubygems_version: !ruby/object:Gem::Requirement
112
+ none: false
113
+ requirements:
114
+ - - ! '>='
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
+ requirements: []
118
+ rubyforge_project:
119
+ rubygems_version: 1.8.17
120
+ signing_key:
121
+ specification_version: 3
122
+ summary: Make sure your last process exited with 0.
123
+ test_files: []