live_ast 0.2.0
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/CHANGES.rdoc +6 -0
- data/MANIFEST +54 -0
- data/README.rdoc +388 -0
- data/Rakefile +19 -0
- data/devel/jumpstart.rb +983 -0
- data/lib/live_ast/ast_eval.rb +13 -0
- data/lib/live_ast/ast_load.rb +15 -0
- data/lib/live_ast/base.rb +56 -0
- data/lib/live_ast/cache.rb +14 -0
- data/lib/live_ast/error.rb +30 -0
- data/lib/live_ast/evaler.rb +66 -0
- data/lib/live_ast/linker.rb +107 -0
- data/lib/live_ast/loader.rb +69 -0
- data/lib/live_ast/parser.rb +48 -0
- data/lib/live_ast/replace_load.rb +14 -0
- data/lib/live_ast/replace_raise.rb +21 -0
- data/lib/live_ast/to_ast.rb +17 -0
- data/lib/live_ast/to_ruby.rb +12 -0
- data/lib/live_ast/version.rb +3 -0
- data/lib/live_ast.rb +4 -0
- data/test/ast_eval_feature_test.rb +11 -0
- data/test/ast_load_feature_test.rb +11 -0
- data/test/backtrace_test.rb +159 -0
- data/test/covert_define_method_test.rb +23 -0
- data/test/def_test.rb +35 -0
- data/test/define_method_test.rb +41 -0
- data/test/define_singleton_method_test.rb +15 -0
- data/test/encoding_test/bad.rb +1 -0
- data/test/encoding_test/cp932.rb +6 -0
- data/test/encoding_test/default.rb +5 -0
- data/test/encoding_test/eucjp.rb +6 -0
- data/test/encoding_test/koi8.rb +6 -0
- data/test/encoding_test/koi8_shebang.rb +7 -0
- data/test/encoding_test/usascii.rb +6 -0
- data/test/encoding_test/utf8.rb +6 -0
- data/test/encoding_test.rb +51 -0
- data/test/error_test.rb +115 -0
- data/test/eval_test.rb +269 -0
- data/test/flush_cache_test.rb +98 -0
- data/test/lambda_test.rb +56 -0
- data/test/load_path_test.rb +84 -0
- data/test/load_test.rb +85 -0
- data/test/noninvasive_test.rb +51 -0
- data/test/readme_test.rb +11 -0
- data/test/recursive_eval_test.rb +52 -0
- data/test/redefine_method_test.rb +83 -0
- data/test/reload_test.rb +108 -0
- data/test/shared/ast_generators.rb +124 -0
- data/test/shared/main.rb +110 -0
- data/test/stdlib_test.rb +11 -0
- data/test/thread_test.rb +44 -0
- data/test/to_ast_feature_test.rb +15 -0
- data/test/to_ruby_feature_test.rb +15 -0
- data/test/to_ruby_test.rb +86 -0
- metadata +223 -0
data/test/shared/main.rb
ADDED
@@ -0,0 +1,110 @@
|
|
1
|
+
$LOAD_PATH.unshift File.dirname(__FILE__) + '/../../lib'
|
2
|
+
|
3
|
+
# require first for stdlib_test
|
4
|
+
require 'pp'
|
5
|
+
require 'find'
|
6
|
+
require 'fileutils'
|
7
|
+
|
8
|
+
require 'minitest/unit'
|
9
|
+
require 'minitest/mock'
|
10
|
+
require 'minitest/autorun'
|
11
|
+
require 'live_ast/base'
|
12
|
+
|
13
|
+
require_relative "ast_generators"
|
14
|
+
|
15
|
+
def define_unsorted_test_case(name, superclass, &block)
|
16
|
+
klass = Class.new superclass, &block
|
17
|
+
letter = ('A'..'Z').to_a[rand(26)]
|
18
|
+
Object.const_set "#{letter}#{name}", klass
|
19
|
+
end
|
20
|
+
|
21
|
+
class JLMiniTest < MiniTest::Unit::TestCase
|
22
|
+
def self.test_methods
|
23
|
+
default = super
|
24
|
+
onlies = default.select { |m| m =~ %r!__only\Z! }
|
25
|
+
if onlies.empty?
|
26
|
+
default
|
27
|
+
else
|
28
|
+
puts "\n!!! NOTE: running ONLY *__only tests for #{self}"
|
29
|
+
onlies
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def delim(char)
|
34
|
+
":\n" << (char*72) << "\n"
|
35
|
+
end
|
36
|
+
|
37
|
+
def mu_pp(obj)
|
38
|
+
delim("_") <<
|
39
|
+
obj.pretty_inspect.chomp <<
|
40
|
+
delim("=")
|
41
|
+
end
|
42
|
+
|
43
|
+
def unfixable
|
44
|
+
begin
|
45
|
+
yield
|
46
|
+
raise "claimed to be unfixable, but assertion succeeded"
|
47
|
+
rescue MiniTest::Assertion
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
alias_method :assert_raise, :assert_raises
|
52
|
+
alias_method :assert_not_equal, :refute_equal
|
53
|
+
alias_method :assert_not_nil, :refute_nil
|
54
|
+
|
55
|
+
def assert_nothing_raised
|
56
|
+
assert_equal 3, 3
|
57
|
+
yield
|
58
|
+
rescue => ex
|
59
|
+
raise MiniTest::Assertion,
|
60
|
+
exception_details(ex, "Expected nothing raised, but got:")
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
class BaseTest < JLMiniTest
|
65
|
+
include ASTGenerators
|
66
|
+
|
67
|
+
DATA_DIR = File.expand_path(File.dirname(__FILE__) + "/../data")
|
68
|
+
|
69
|
+
def temp_file(basename = nil)
|
70
|
+
unless basename
|
71
|
+
basename = ('a'..'z').to_a.shuffle.join + ".rb"
|
72
|
+
end
|
73
|
+
|
74
|
+
path = DATA_DIR + "/" + basename
|
75
|
+
FileUtils.mkdir DATA_DIR unless File.directory? DATA_DIR
|
76
|
+
|
77
|
+
begin
|
78
|
+
FileUtils.rm_f path
|
79
|
+
yield path
|
80
|
+
ensure
|
81
|
+
unless defined? SimpleCov
|
82
|
+
FileUtils.rm_f path
|
83
|
+
FileUtils.rmdir DATA_DIR rescue nil
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
def write_file(file, contents)
|
89
|
+
File.open(file, "w") { |f| f.print contents }
|
90
|
+
end
|
91
|
+
|
92
|
+
def return_block(&block)
|
93
|
+
block
|
94
|
+
end
|
95
|
+
|
96
|
+
def exception_backtrace
|
97
|
+
begin
|
98
|
+
yield
|
99
|
+
rescue Exception => e
|
100
|
+
e.backtrace
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
class RegularTest < BaseTest
|
106
|
+
def setup
|
107
|
+
super
|
108
|
+
require 'live_ast'
|
109
|
+
end
|
110
|
+
end
|
data/test/stdlib_test.rb
ADDED
data/test/thread_test.rb
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
require_relative 'shared/main'
|
2
|
+
|
3
|
+
require 'thread'
|
4
|
+
|
5
|
+
class ThreadTest < RegularTest
|
6
|
+
|
7
|
+
def test_threads
|
8
|
+
klass = nil
|
9
|
+
mutex = Mutex.new
|
10
|
+
stop = false
|
11
|
+
results = []
|
12
|
+
num_threads = 50
|
13
|
+
|
14
|
+
workers = (0...num_threads).map {
|
15
|
+
Thread.new {
|
16
|
+
until stop
|
17
|
+
if klass
|
18
|
+
found = klass.instance_method(:f).to_ast
|
19
|
+
mutex.synchronize {
|
20
|
+
results << found
|
21
|
+
}
|
22
|
+
break
|
23
|
+
end
|
24
|
+
end
|
25
|
+
}
|
26
|
+
}
|
27
|
+
|
28
|
+
klass = Class.new do
|
29
|
+
def f
|
30
|
+
"anon#f"
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
sleep(0.2)
|
35
|
+
stop = true
|
36
|
+
|
37
|
+
workers.each { |t| t.join }
|
38
|
+
|
39
|
+
assert_equal num_threads, results.size
|
40
|
+
results.each { |result|
|
41
|
+
assert_equal no_arg_def(:f, "anon#f"), result
|
42
|
+
}
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require_relative 'shared/main'
|
2
|
+
|
3
|
+
class AAB_ToASTFeatureTest < BaseTest
|
4
|
+
def test_require
|
5
|
+
[Method, UnboundMethod, Proc].each { |obj|
|
6
|
+
assert !obj.instance_methods.include?(:to_ast)
|
7
|
+
}
|
8
|
+
|
9
|
+
require 'live_ast/to_ast'
|
10
|
+
|
11
|
+
[Method, UnboundMethod, Proc].each { |obj|
|
12
|
+
assert obj.instance_methods.include?(:to_ast)
|
13
|
+
}
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require_relative 'shared/main'
|
2
|
+
|
3
|
+
class AAB_ToRubyFeatureTest < BaseTest
|
4
|
+
def test_require
|
5
|
+
[Method, UnboundMethod, Proc].each { |obj|
|
6
|
+
assert !obj.instance_methods.include?(:to_ruby)
|
7
|
+
}
|
8
|
+
|
9
|
+
require 'live_ast/to_ruby'
|
10
|
+
|
11
|
+
[Method, UnboundMethod, Proc].each { |obj|
|
12
|
+
assert obj.instance_methods.include?(:to_ruby)
|
13
|
+
}
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,86 @@
|
|
1
|
+
require_relative 'shared/main'
|
2
|
+
|
3
|
+
class AAC_ToRubyTest < RegularTest
|
4
|
+
def setup
|
5
|
+
super
|
6
|
+
require 'live_ast/to_ruby'
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_lambda_0
|
10
|
+
src = %{lambda { "moo" }}
|
11
|
+
dst = ast_eval(src, binding).to_ruby
|
12
|
+
assert_equal src, dst
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_lambda_1
|
16
|
+
src = %{lambda { |x| (x ** 2) }}
|
17
|
+
dst = ast_eval(src, binding).to_ruby
|
18
|
+
assert_equal src, dst
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_lambda_2
|
22
|
+
src = %{lambda { |x, y| (x + y) }}
|
23
|
+
dst = ast_eval(src, binding).to_ruby
|
24
|
+
assert_equal src, dst
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_proc_0
|
28
|
+
src = %{proc { "moo" }}
|
29
|
+
dst = ast_eval(src, binding).to_ruby
|
30
|
+
assert_equal src, dst
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_proc_1
|
34
|
+
src = %{proc { |x| (x ** 2) }}
|
35
|
+
dst = ast_eval(src, binding).to_ruby
|
36
|
+
assert_equal src, dst
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_proc_2
|
40
|
+
src = %{proc { |x, y| (x * y) }}
|
41
|
+
dst = ast_eval(src, binding).to_ruby
|
42
|
+
assert_equal src, dst
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_block_0
|
46
|
+
src = %{return_block { "moo" }}
|
47
|
+
dst = ast_eval(src, binding).to_ruby
|
48
|
+
assert_equal src, dst
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_block_1
|
52
|
+
src = %{return_block { |x| (x ** 2) }}
|
53
|
+
dst = ast_eval(src, binding).to_ruby
|
54
|
+
assert_equal src, dst
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_block_2
|
58
|
+
src = %{return_block { |x, y| (x - y) }}
|
59
|
+
dst = ast_eval(src, binding).to_ruby
|
60
|
+
assert_equal src, dst
|
61
|
+
end
|
62
|
+
|
63
|
+
def test_method_0
|
64
|
+
src = %{def f\n "moo"\nend}
|
65
|
+
dst = Class.new do
|
66
|
+
ast_eval(src, binding)
|
67
|
+
end.instance_method(:f).to_ruby
|
68
|
+
assert_equal src, dst
|
69
|
+
end
|
70
|
+
|
71
|
+
def test_method_1
|
72
|
+
src = %{def f(x)\n (x ** 2)\nend}
|
73
|
+
dst = Class.new do
|
74
|
+
ast_eval(src, binding)
|
75
|
+
end.instance_method(:f).to_ruby
|
76
|
+
assert_equal src, dst
|
77
|
+
end
|
78
|
+
|
79
|
+
def test_method_2
|
80
|
+
src = %{def f(x, y)\n (x / y)\nend}
|
81
|
+
dst = Class.new do
|
82
|
+
ast_eval(src, binding)
|
83
|
+
end.instance_method(:f).to_ruby
|
84
|
+
assert_equal src, dst
|
85
|
+
end
|
86
|
+
end
|
metadata
ADDED
@@ -0,0 +1,223 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: live_ast
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 0.2.0
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- James M. Lawrence
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2011-02-17 00:00:00 -05:00
|
14
|
+
default_executable:
|
15
|
+
dependencies:
|
16
|
+
- !ruby/object:Gem::Dependency
|
17
|
+
name: ruby_parser
|
18
|
+
prerelease: false
|
19
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
20
|
+
none: false
|
21
|
+
requirements:
|
22
|
+
- - "="
|
23
|
+
- !ruby/object:Gem::Version
|
24
|
+
version: 2.0.5
|
25
|
+
type: :runtime
|
26
|
+
version_requirements: *id001
|
27
|
+
description: LiveAST enables a program to find the ASTs of objects created by dynamically generated code.
|
28
|
+
email:
|
29
|
+
- quixoticsycophant@gmail.com
|
30
|
+
executables: []
|
31
|
+
|
32
|
+
extensions: []
|
33
|
+
|
34
|
+
extra_rdoc_files:
|
35
|
+
- README.rdoc
|
36
|
+
files:
|
37
|
+
- CHANGES.rdoc
|
38
|
+
- README.rdoc
|
39
|
+
- Rakefile
|
40
|
+
- devel/jumpstart.rb
|
41
|
+
- lib/live_ast.rb
|
42
|
+
- lib/live_ast/ast_eval.rb
|
43
|
+
- lib/live_ast/ast_load.rb
|
44
|
+
- lib/live_ast/base.rb
|
45
|
+
- lib/live_ast/cache.rb
|
46
|
+
- lib/live_ast/error.rb
|
47
|
+
- lib/live_ast/evaler.rb
|
48
|
+
- lib/live_ast/linker.rb
|
49
|
+
- lib/live_ast/loader.rb
|
50
|
+
- lib/live_ast/parser.rb
|
51
|
+
- lib/live_ast/replace_load.rb
|
52
|
+
- lib/live_ast/replace_raise.rb
|
53
|
+
- lib/live_ast/to_ast.rb
|
54
|
+
- lib/live_ast/to_ruby.rb
|
55
|
+
- lib/live_ast/version.rb
|
56
|
+
- test/ast_eval_feature_test.rb
|
57
|
+
- test/ast_load_feature_test.rb
|
58
|
+
- test/backtrace_test.rb
|
59
|
+
- test/covert_define_method_test.rb
|
60
|
+
- test/def_test.rb
|
61
|
+
- test/define_method_test.rb
|
62
|
+
- test/define_singleton_method_test.rb
|
63
|
+
- test/encoding_test.rb
|
64
|
+
- test/encoding_test/bad.rb
|
65
|
+
- test/encoding_test/cp932.rb
|
66
|
+
- test/encoding_test/default.rb
|
67
|
+
- test/encoding_test/eucjp.rb
|
68
|
+
- test/encoding_test/koi8.rb
|
69
|
+
- test/encoding_test/koi8_shebang.rb
|
70
|
+
- test/encoding_test/usascii.rb
|
71
|
+
- test/encoding_test/utf8.rb
|
72
|
+
- test/error_test.rb
|
73
|
+
- test/eval_test.rb
|
74
|
+
- test/flush_cache_test.rb
|
75
|
+
- test/lambda_test.rb
|
76
|
+
- test/load_path_test.rb
|
77
|
+
- test/load_test.rb
|
78
|
+
- test/noninvasive_test.rb
|
79
|
+
- test/readme_test.rb
|
80
|
+
- test/recursive_eval_test.rb
|
81
|
+
- test/redefine_method_test.rb
|
82
|
+
- test/reload_test.rb
|
83
|
+
- test/shared/ast_generators.rb
|
84
|
+
- test/shared/main.rb
|
85
|
+
- test/stdlib_test.rb
|
86
|
+
- test/thread_test.rb
|
87
|
+
- test/to_ast_feature_test.rb
|
88
|
+
- test/to_ruby_feature_test.rb
|
89
|
+
- test/to_ruby_test.rb
|
90
|
+
- MANIFEST
|
91
|
+
has_rdoc: true
|
92
|
+
homepage: http://liveast.rubyforge.org
|
93
|
+
licenses: []
|
94
|
+
|
95
|
+
post_install_message:
|
96
|
+
rdoc_options:
|
97
|
+
- --main
|
98
|
+
- README.rdoc
|
99
|
+
- --title
|
100
|
+
- "LiveAST: Live Abstract Syntax Trees"
|
101
|
+
- --exclude
|
102
|
+
- CHANGES.rdoc
|
103
|
+
- --exclude
|
104
|
+
- Rakefile
|
105
|
+
- --exclude
|
106
|
+
- devel/jumpstart.rb
|
107
|
+
- --exclude
|
108
|
+
- lib/live_ast.rb
|
109
|
+
- --exclude
|
110
|
+
- lib/live_ast/ast_load.rb
|
111
|
+
- --exclude
|
112
|
+
- lib/live_ast/cache.rb
|
113
|
+
- --exclude
|
114
|
+
- lib/live_ast/error.rb
|
115
|
+
- --exclude
|
116
|
+
- lib/live_ast/evaler.rb
|
117
|
+
- --exclude
|
118
|
+
- lib/live_ast/linker.rb
|
119
|
+
- --exclude
|
120
|
+
- lib/live_ast/loader.rb
|
121
|
+
- --exclude
|
122
|
+
- lib/live_ast/parser.rb
|
123
|
+
- --exclude
|
124
|
+
- lib/live_ast/replace_load.rb
|
125
|
+
- --exclude
|
126
|
+
- lib/live_ast/replace_raise.rb
|
127
|
+
- --exclude
|
128
|
+
- lib/live_ast/to_ast.rb
|
129
|
+
- --exclude
|
130
|
+
- lib/live_ast/to_ruby.rb
|
131
|
+
- --exclude
|
132
|
+
- test/ast_eval_feature_test.rb
|
133
|
+
- --exclude
|
134
|
+
- test/ast_load_feature_test.rb
|
135
|
+
- --exclude
|
136
|
+
- test/backtrace_test.rb
|
137
|
+
- --exclude
|
138
|
+
- test/covert_define_method_test.rb
|
139
|
+
- --exclude
|
140
|
+
- test/def_test.rb
|
141
|
+
- --exclude
|
142
|
+
- test/define_method_test.rb
|
143
|
+
- --exclude
|
144
|
+
- test/define_singleton_method_test.rb
|
145
|
+
- --exclude
|
146
|
+
- test/encoding_test.rb
|
147
|
+
- --exclude
|
148
|
+
- test/encoding_test/bad.rb
|
149
|
+
- --exclude
|
150
|
+
- test/encoding_test/cp932.rb
|
151
|
+
- --exclude
|
152
|
+
- test/encoding_test/default.rb
|
153
|
+
- --exclude
|
154
|
+
- test/encoding_test/eucjp.rb
|
155
|
+
- --exclude
|
156
|
+
- test/encoding_test/koi8.rb
|
157
|
+
- --exclude
|
158
|
+
- test/encoding_test/koi8_shebang.rb
|
159
|
+
- --exclude
|
160
|
+
- test/encoding_test/usascii.rb
|
161
|
+
- --exclude
|
162
|
+
- test/encoding_test/utf8.rb
|
163
|
+
- --exclude
|
164
|
+
- test/error_test.rb
|
165
|
+
- --exclude
|
166
|
+
- test/eval_test.rb
|
167
|
+
- --exclude
|
168
|
+
- test/flush_cache_test.rb
|
169
|
+
- --exclude
|
170
|
+
- test/lambda_test.rb
|
171
|
+
- --exclude
|
172
|
+
- test/load_path_test.rb
|
173
|
+
- --exclude
|
174
|
+
- test/load_test.rb
|
175
|
+
- --exclude
|
176
|
+
- test/noninvasive_test.rb
|
177
|
+
- --exclude
|
178
|
+
- test/readme_test.rb
|
179
|
+
- --exclude
|
180
|
+
- test/recursive_eval_test.rb
|
181
|
+
- --exclude
|
182
|
+
- test/redefine_method_test.rb
|
183
|
+
- --exclude
|
184
|
+
- test/reload_test.rb
|
185
|
+
- --exclude
|
186
|
+
- test/shared/ast_generators.rb
|
187
|
+
- --exclude
|
188
|
+
- test/shared/main.rb
|
189
|
+
- --exclude
|
190
|
+
- test/stdlib_test.rb
|
191
|
+
- --exclude
|
192
|
+
- test/thread_test.rb
|
193
|
+
- --exclude
|
194
|
+
- test/to_ast_feature_test.rb
|
195
|
+
- --exclude
|
196
|
+
- test/to_ruby_feature_test.rb
|
197
|
+
- --exclude
|
198
|
+
- test/to_ruby_test.rb
|
199
|
+
- --exclude
|
200
|
+
- MANIFEST
|
201
|
+
require_paths:
|
202
|
+
- lib
|
203
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
204
|
+
none: false
|
205
|
+
requirements:
|
206
|
+
- - ">="
|
207
|
+
- !ruby/object:Gem::Version
|
208
|
+
version: "0"
|
209
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
210
|
+
none: false
|
211
|
+
requirements:
|
212
|
+
- - ">="
|
213
|
+
- !ruby/object:Gem::Version
|
214
|
+
version: "0"
|
215
|
+
requirements: []
|
216
|
+
|
217
|
+
rubyforge_project: liveast
|
218
|
+
rubygems_version: 1.5.2
|
219
|
+
signing_key:
|
220
|
+
specification_version: 3
|
221
|
+
summary: A pure Ruby library for obtaining live abstract syntax trees of methods and procs.
|
222
|
+
test_files: []
|
223
|
+
|