dia 1.5.pre.2 → 1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/NEWS.md CHANGED
@@ -1,14 +1,13 @@
1
1
  ## NEWS
2
2
 
3
3
  ### 1.5
4
- * Added Dia::Sandbox#exception() for inspecting an exception raised in a sandbox
5
- from the parent process.
4
+ * Added Dia::Sandbox#exit_status()
5
+ * Added Dia::Sandbox#exception_raised?().
6
+ * Added Dia::Sandbox#exception()
6
7
  * Fixed a small bug introduced in 1.5.pre - a typo, only encountered if
7
8
  Dia::SandboxException was raised.
8
9
  * Dia::Sandbox#running?, Dia::Sandbox#exit_status, and Dia::Sandbox#terminate
9
10
  will return nil if you call them before calling Dia::Sandbox#run().
10
- * Added Dia::Sandbox#exit_status for collecting the exit status of a child
11
- process running under a sandbox.
12
11
  * Dia::Sandbox#run was not returning the PID of the process running under a
13
12
  sandbox like told in the documentation - it is now.
14
13
 
data/README.md CHANGED
@@ -121,6 +121,32 @@ capturing it so Dia can forward the exception to the parent process.
121
121
 
122
122
  puts sandbox.exception().class # prints "RuntimeError"
123
123
 
124
+ **Checking if an exception has been raised in a sandbox**
125
+
126
+ Since 1.5, Sandbox#exception_raised?() is available for checking if a block of
127
+ ruby code running under a sandbox has raised an exception.
128
+
129
+ require 'rubygems'
130
+ require 'dia'
131
+
132
+ require 'rubygems'
133
+ require 'dia'
134
+ sandbox = Dia::Sandbox.new(Dia::Profiles::NO_OS_SERVICES) do
135
+ raise()
136
+ end
137
+
138
+ sandbox.run()
139
+ sleep(0.1) # Let the parent receive the exception.
140
+ # Only neccesary for scenarios where an exception is raised
141
+ # rather quickly.
142
+
143
+ sandbox.exception_raised?() # => true
144
+
145
+ `#exception()` & `#exception_raised?()` can only be applied to Ruby blocks. For
146
+ the 2.0 release, a redesign is planned that will fix this issue, as well as
147
+ data encapsulation issues(ie: @app shouldn't belong to a class that doesn't make
148
+ use of it, which is the case if you're sandboxing a ruby block).
149
+
124
150
  .. Please see the yardoc [documentation](http://yardoc.org/docs/robgleeson-Dia) for more in-depth coverage of these methods,
125
151
  in particular the documentation for the `Dia::Sandbox` class.
126
152
 
data/lib/dia.rb CHANGED
@@ -5,7 +5,7 @@ require File.join(File.dirname(__FILE__), 'dia/commonapi.rb')
5
5
  require File.join(File.dirname(__FILE__), 'dia/sandbox.rb')
6
6
 
7
7
  module Dia
8
- VERSION = '1.5.pre.2'
8
+ VERSION = '1.5'
9
9
  class SandboxException < StandardError; end
10
10
  end
11
11
 
@@ -53,8 +53,21 @@ module Dia
53
53
  initialize_streams()
54
54
  end
55
55
 
56
- # The exception() method returns an instance or subclass instance of
57
- # Exception which has been raised in a sandbox.
56
+ # The #exception_raised?() method returns true if an exception has been
57
+ # raised in the last call to #run(), and false otherwise.
58
+ #
59
+ # @return [Boolean] Returns true or false.
60
+ # @since 1.5
61
+ def exception_raised?()
62
+ !!exception()
63
+ end
64
+
65
+ # The exception() method returns the last exception raised after a
66
+ # a call to #run(), or nil.
67
+ #
68
+ # Every call to #run() resets the variable storing the exception object
69
+ # to nil, and it will only be a non-nil value if the last call to #run()
70
+ # raised an exception.
58
71
  #
59
72
  # This method can be used if you need access(from the parent process)
60
73
  # to an exception raised in your sandbox.
@@ -70,13 +83,11 @@ module Dia
70
83
  def exception()
71
84
  @write.close()
72
85
  if @read.ready?()
73
- ret = Marshal.load(@read.gets())
74
- else
75
- ret = nil
86
+ @e = Marshal.load(@read.readlines().join())
76
87
  end
77
88
  @read.close()
78
89
  initialize_streams()
79
- ret
90
+ @e
80
91
  end
81
92
 
82
93
  # The run method will spawn a child process and run the application _or_
@@ -102,6 +113,7 @@ module Dia
102
113
  # @return [Fixnum] The Process ID(PID) that the sandboxed
103
114
  # application is being run under.
104
115
  def run(*args)
116
+ @e = nil
105
117
  initialize_streams()
106
118
  @pid = fork do
107
119
  begin
@@ -0,0 +1,55 @@
1
+ BareTest.suite('Dia::Sandbox#exception()') do
2
+ assert('#exception() will return an exception raised in the sandbox') do
3
+ sandbox = Dia::Sandbox.new(Dia::Profiles::NO_OS_SERVICES) do
4
+ raise()
5
+ end
6
+
7
+ sandbox.run()
8
+ sleep(0.1)
9
+ equal(RuntimeError, sandbox.exception.class())
10
+ end
11
+
12
+ assert('#exception() returns nil if called before ' \
13
+ 'Dia::Sandbox#run()') do
14
+ sandbox = Dia::Sandbox.new(Dia::Profiles::NO_OS_SERVICES) do
15
+ # ...
16
+ end
17
+ equal(nil, sandbox.exception())
18
+ end
19
+
20
+ assert('#exception() returns an exception object the first' \
21
+ ' and second time it is called after a single call to #run()') do
22
+ sandbox = Dia::Sandbox.new(Dia::Profiles::NO_OS_SERVICES) do
23
+ raise()
24
+ end
25
+
26
+ sandbox.run()
27
+ sleep(0.1)
28
+ equal(RuntimeError, sandbox.exception().class)
29
+ equal(RuntimeError, sandbox.exception().class)
30
+ end
31
+
32
+ assert('#exception() will be set to nil after the first call to ' \
33
+ '#run raises an exception, and the second does not') do
34
+
35
+ sandbox = Dia::Sandbox.new(Dia::Profiles::NO_OS_SERVICES) do
36
+ raise()
37
+ end
38
+
39
+ sandbox.run()
40
+ sleep(0.1)
41
+ equal(RuntimeError, sandbox.exception().class)
42
+ sandbox.instance_variable_set("@blk", proc { })
43
+ sandbox.run()
44
+ equal(nil, sandbox.exception())
45
+ end
46
+
47
+ assert('#exception() can marshal data containing one or more \n') do
48
+ sandbox = Dia::Sandbox.new(Dia::Profiles::NO_OS_SERVICES) do
49
+ fork {}
50
+ end
51
+ sandbox.run()
52
+ sleep(0.5)
53
+ equal(Errno::EPERM, sandbox.exception().class)
54
+ end
55
+ end
@@ -0,0 +1,22 @@
1
+ BareTest.suite('Dia::Sandbox#exception_raised?()',
2
+ :tags => [ :exception_raised] ) do
3
+ assert('#exception_raised?() returns false when no exception has been ' \
4
+ 'raised') do
5
+ sandbox = Dia::Sandbox.new(Dia::Profiles::NO_OS_SERVICES) do
6
+ # ...
7
+ end
8
+ sandbox.run()
9
+ sleep(0.1)
10
+ equal(false, sandbox.exception_raised?())
11
+ end
12
+
13
+ assert('#exception_raised?() returns true when an exception has been ' \
14
+ 'raised') do
15
+ sandbox = Dia::Sandbox.new(Dia::Profiles::NO_OS_SERVICES) do
16
+ raise(StandardError, 'Exception')
17
+ end
18
+ sandbox.run()
19
+ sleep(0.1)
20
+ equal(true, sandbox.exception_raised?())
21
+ end
22
+ end
@@ -0,0 +1,12 @@
1
+ BareTest.suite('Exceptions', :tags => [ :sandbox_init_exception ]) do
2
+ assert('Dia::SandboxException is raised if a call to sandbox_init() fails') do
3
+ sandbox = Dia::Sandbox.new(Dia::Profiles::NO_OS_SERVICES) do
4
+ # ...
5
+ end
6
+ sandbox.instance_variable_set("@profile", "i am going to break")
7
+ sandbox.run
8
+ sleep(0.1)
9
+ equal(Dia::SandboxException, sandbox.exception().class)
10
+ end
11
+ end
12
+
metadata CHANGED
@@ -1,13 +1,11 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dia
3
3
  version: !ruby/object:Gem::Version
4
- prerelease: true
4
+ prerelease: false
5
5
  segments:
6
6
  - 1
7
7
  - 5
8
- - pre
9
- - 2
10
- version: 1.5.pre.2
8
+ version: "1.5"
11
9
  platform: ruby
12
10
  authors:
13
11
  - Robert Gleeson
@@ -15,7 +13,7 @@ autorequire:
15
13
  bindir: bin
16
14
  cert_chain: []
17
15
 
18
- date: 2010-05-07 00:00:00 +01:00
16
+ date: 2010-05-10 00:00:00 +01:00
19
17
  default_executable:
20
18
  dependencies:
21
19
  - !ruby/object:Gem::Dependency
@@ -80,11 +78,11 @@ files:
80
78
  - lib/dia.rb
81
79
  - .yardopts
82
80
  - LICENSE
83
- has_rdoc: yard
81
+ has_rdoc: true
84
82
  homepage:
85
83
  licenses: []
86
84
 
87
- post_install_message: " ********************************************************************\n Dia (1.5.pre.2)\n \n Thanks for installing Dia, 1.5.pre.2! \n \n Keep up with the latest @ GitHub:\n http://github.com/robgleeson/dia\n ********************************************************************\n"
85
+ post_install_message: " ********************************************************************\n Dia (1.5)\n \n Thanks for installing Dia, 1.5! \n \n Keep up with the latest @ GitHub:\n http://github.com/robgleeson/dia\n ********************************************************************\n"
88
86
  rdoc_options: []
89
87
 
90
88
  require_paths:
@@ -98,13 +96,11 @@ required_ruby_version: !ruby/object:Gem::Requirement
98
96
  version: "0"
99
97
  required_rubygems_version: !ruby/object:Gem::Requirement
100
98
  requirements:
101
- - - ">"
99
+ - - ">="
102
100
  - !ruby/object:Gem::Version
103
101
  segments:
104
- - 1
105
- - 3
106
- - 1
107
- version: 1.3.1
102
+ - 0
103
+ version: "0"
108
104
  requirements: []
109
105
 
110
106
  rubyforge_project:
@@ -115,7 +111,9 @@ summary: Dia allows you to sandbox application(s) or block(s) of rubyon the OSX
115
111
  test_files:
116
112
  - test/setup.rb
117
113
  - test/suite/check_if_sandbox_is_alive_test.rb
118
- - test/suite/exceptions_text.rb
114
+ - test/suite/exception()_test.rb
115
+ - test/suite/exception_raised?_test.rb
116
+ - test/suite/exceptions_test.rb
119
117
  - test/suite/exit_status_test.rb
120
118
  - test/suite/passing_parameters_to_constructer_test.rb
121
119
  - test/suite/run_block_in_sandbox_test.rb
@@ -1,41 +0,0 @@
1
- BareTest.suite('Exceptions', :tags => [ :exception ]) do
2
- assert('Dia::SandboxException is raised if a call to sandbox_init() fails') do
3
- sandbox = Dia::Sandbox.new(Dia::Profiles::NO_OS_SERVICES) do
4
- # ...
5
- end
6
- sandbox.instance_variable_set("@profile", "i am going to break")
7
- sandbox.run
8
- sleep(0.1)
9
- equal(Dia::SandboxException, sandbox.exception().class)
10
- end
11
-
12
- assert('Dia::Sandbox#exception() will return an exception raised in the sandbox') do
13
- sandbox = Dia::Sandbox.new(Dia::Profiles::NO_OS_SERVICES) do
14
- raise()
15
- end
16
-
17
- sandbox.run()
18
- sleep(0.1)
19
- equal(RuntimeError, sandbox.exception.class())
20
- end
21
-
22
- assert('Dia::Sandbox#exception() returns nil if called before ' \
23
- 'Dia::Sandbox#run()') do
24
- sandbox = Dia::Sandbox.new(Dia::Profiles::NO_OS_SERVICES) do
25
- # ...
26
- end
27
- equal(nil, sandbox.exception())
28
- end
29
-
30
- assert('Dia::Sandbox#exception() returns nil after a second call') do
31
- sandbox = Dia::Sandbox.new(Dia::Profiles::NO_OS_SERVICES) do
32
- raise()
33
- end
34
-
35
- sandbox.run()
36
- sleep(0.1)
37
- equal(RuntimeError, sandbox.exception().class)
38
- equal(nil, sandbox.exception())
39
- end
40
-
41
- end