live_ast 0.2.3 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,4 +1,4 @@
1
- require_relative 'shared/main'
1
+ require_relative 'main'
2
2
 
3
3
  # test for flushing side-effects: unsort this TestCase from other
4
4
  # TestCases.
@@ -39,7 +39,7 @@ define_unsorted_test_case "FlushCacheTest", RegularTest do
39
39
 
40
40
  LiveAST.flush_cache
41
41
 
42
- assert_raise LiveAST::FlushedError do
42
+ assert_raises LiveAST::FlushedError do
43
43
  klass.instance_method(:g).to_ast
44
44
  end
45
45
  end
@@ -59,7 +59,7 @@ define_unsorted_test_case "FlushCacheTest", RegularTest do
59
59
  assert_equal f_ast.object_id,
60
60
  klass.instance_method(:f).to_ast.object_id
61
61
 
62
- assert_raise LiveAST::FlushedError do
62
+ assert_raises LiveAST::FlushedError do
63
63
  klass.instance_method(:g).to_ast
64
64
  end
65
65
  end
@@ -91,7 +91,7 @@ define_unsorted_test_case "FlushCacheTest", RegularTest do
91
91
 
92
92
  assert_equal a_ast.object_id, a.to_ast.object_id
93
93
 
94
- assert_raise LiveAST::FlushedError do
94
+ assert_raises LiveAST::FlushedError do
95
95
  b.to_ast
96
96
  end
97
97
  end
data/test/lambda_test.rb CHANGED
@@ -1,4 +1,4 @@
1
- require_relative 'shared/main'
1
+ require_relative 'main'
2
2
 
3
3
  class LambdaTest < RegularTest
4
4
  def test_block_braces_multiline
@@ -1,4 +1,4 @@
1
- require_relative 'shared/main'
1
+ require_relative 'main'
2
2
 
3
3
  class AAA_LoadPathTest < BaseTest
4
4
  include FileUtils
@@ -58,10 +58,10 @@ class AAA_LoadPathTest < BaseTest
58
58
  end
59
59
 
60
60
  def compare_load_errors(file)
61
- orig = assert_raise LoadError do
61
+ orig = assert_raises LoadError do
62
62
  load file
63
63
  end
64
- live = assert_raise LoadError do
64
+ live = assert_raises LoadError do
65
65
  LiveAST.load file
66
66
  end
67
67
  assert_equal orig.message, live.message
data/test/load_test.rb CHANGED
@@ -1,4 +1,4 @@
1
- require_relative 'shared/main'
1
+ require_relative 'main'
2
2
 
3
3
  class AAA_LoadFileTest < BaseTest
4
4
  class << self
@@ -20,7 +20,7 @@ class AAA_LoadFileTest < BaseTest
20
20
  assert_equal true, ret
21
21
  assert_equal :code_a, AAA_LoadFileTest.flag
22
22
 
23
- assert_raise NameError do
23
+ assert_raises NameError do
24
24
  eval("x", TOPLEVEL_BINDING)
25
25
  end
26
26
 
@@ -1,4 +1,4 @@
1
- $LOAD_PATH.unshift File.dirname(__FILE__) + '/../../lib'
1
+ $LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/../lib')
2
2
 
3
3
  # require first for stdlib_test
4
4
  require 'pp'
@@ -7,10 +7,9 @@ require 'fileutils'
7
7
 
8
8
  require 'minitest/unit'
9
9
  require 'minitest/mock'
10
- require 'minitest/autorun'
11
- require 'live_ast/base'
10
+ require 'minitest/autorun' unless defined? Rake
12
11
 
13
- require_relative "ast_generators"
12
+ require 'live_ast/base'
14
13
 
15
14
  def define_unsorted_test_case(name, superclass, &block)
16
15
  klass = Class.new superclass, &block
@@ -48,23 +47,36 @@ class JLMiniTest < MiniTest::Unit::TestCase
48
47
  end
49
48
  end
50
49
 
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
50
  def assert_nothing_raised
56
51
  assert_equal 3, 3
57
52
  yield
58
53
  rescue => ex
59
54
  raise MiniTest::Assertion,
60
- exception_details(ex, "Expected nothing raised, but got:")
55
+ exception_details(ex, "Expected nothing raised, but got:")
61
56
  end
57
+
58
+ %w[
59
+ empty
60
+ equal
61
+ in_delta
62
+ in_epsilon
63
+ includes
64
+ instance_of
65
+ kind_of
66
+ match
67
+ nil
68
+ operator
69
+ respond_to
70
+ same
71
+ ].each { |name|
72
+ alias_method "assert_not_#{name}", "refute_#{name}"
73
+ }
62
74
  end
63
75
 
64
76
  class BaseTest < JLMiniTest
65
- include ASTGenerators
77
+ include LiveAST.parser::TestForms
66
78
 
67
- DATA_DIR = File.expand_path(File.dirname(__FILE__) + "/../data")
79
+ DATA_DIR = File.expand_path(File.dirname(__FILE__) + "/data")
68
80
 
69
81
  def self.stdlib_has_source?
70
82
  case RUBY_ENGINE
@@ -78,14 +90,12 @@ class BaseTest < JLMiniTest
78
90
  path = DATA_DIR + "/" + basename
79
91
  FileUtils.mkdir DATA_DIR unless File.directory? DATA_DIR
80
92
 
93
+ FileUtils.rm_f path
81
94
  begin
82
- FileUtils.rm_f path
83
95
  yield path
84
96
  ensure
85
- unless defined? SimpleCov
86
- FileUtils.rm_f path
87
- FileUtils.rmdir DATA_DIR rescue nil
88
- end
97
+ FileUtils.rm_f path
98
+ FileUtils.rmdir DATA_DIR rescue nil
89
99
  end
90
100
  end
91
101
 
@@ -1,4 +1,4 @@
1
- require_relative 'shared/main'
1
+ require_relative 'main'
2
2
 
3
3
  class AAA_NoninvasiveTest < BaseTest
4
4
  def test_no_clutter
data/test/readme_test.rb CHANGED
@@ -1,11 +1,13 @@
1
- require_relative 'shared/main'
1
+ require_relative 'main'
2
2
  require_relative '../devel/jumpstart'
3
3
 
4
- sections = [
5
- "Synopsis",
6
- "Loading Source",
7
- "Noninvasive Interface",
8
- "+to_ruby+",
9
- ]
4
+ if LiveAST.parser.respond_to?(:unified?) and LiveAST.parser.unified?
5
+ sections = [
6
+ "Synopsis",
7
+ "Loading Source",
8
+ "Noninvasive Interface",
9
+ "+to_ruby+",
10
+ ]
10
11
 
11
- Jumpstart.doc_to_test("README.rdoc", *sections)
12
+ Jumpstart.doc_to_test("README.rdoc", *sections)
13
+ end
@@ -1,4 +1,4 @@
1
- require_relative 'shared/main'
1
+ require_relative 'main'
2
2
 
3
3
  class RecursiveEvalTest < RegularTest
4
4
  DEFINE = lambda do
@@ -1,4 +1,4 @@
1
- require_relative 'shared/main'
1
+ require_relative 'main'
2
2
 
3
3
  class RedefineMethodTest < RegularTest
4
4
  DEFINE_A = lambda do
data/test/reload_test.rb CHANGED
@@ -1,4 +1,4 @@
1
- require_relative 'shared/main'
1
+ require_relative 'main'
2
2
 
3
3
  class AAB_ReloadTest < BaseTest
4
4
  include FileUtils
data/test/stdlib_test.rb CHANGED
@@ -1,4 +1,4 @@
1
- require_relative 'shared/main'
1
+ require_relative 'main'
2
2
 
3
3
  class StdlibTest < RegularTest
4
4
  if stdlib_has_source?
data/test/thread_test.rb CHANGED
@@ -1,4 +1,4 @@
1
- require_relative 'shared/main'
1
+ require_relative 'main'
2
2
 
3
3
  require 'thread'
4
4
 
@@ -1,4 +1,4 @@
1
- require_relative 'shared/main'
1
+ require_relative 'main'
2
2
 
3
3
  class AAB_ToASTFeatureTest < BaseTest
4
4
  def test_require
@@ -1,4 +1,4 @@
1
- require_relative 'shared/main'
1
+ require_relative 'main'
2
2
 
3
3
  class AAB_ToRubyFeatureTest < BaseTest
4
4
  def test_require
data/test/to_ruby_test.rb CHANGED
@@ -1,4 +1,4 @@
1
- require_relative 'shared/main'
1
+ require_relative 'main'
2
2
 
3
3
  class AAC_ToRubyTest < RegularTest
4
4
  def setup
@@ -83,4 +83,6 @@ class AAC_ToRubyTest < RegularTest
83
83
  end.instance_method(:f).to_ruby
84
84
  assert_equal src, dst
85
85
  end
86
- end
86
+ end if (un = LiveAST.parser::Unparser rescue nil) &&
87
+ un.respond_to?(:ruby2ruby?) &&
88
+ un.ruby2ruby?
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: live_ast
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.2.3
5
+ version: 0.5.0
6
6
  platform: ruby
7
7
  authors:
8
8
  - James M. Lawrence
@@ -10,18 +10,18 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-02-21 00:00:00 -05:00
13
+ date: 2011-02-24 00:00:00 -05:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
- name: ruby_parser
17
+ name: live_ast_ruby_parser
18
18
  prerelease: false
19
19
  requirement: &id001 !ruby/object:Gem::Requirement
20
20
  none: false
21
21
  requirements:
22
- - - "="
22
+ - - ">="
23
23
  - !ruby/object:Gem::Version
24
- version: 2.0.6
24
+ version: "0"
25
25
  type: :runtime
26
26
  version_requirements: *id001
27
27
  description: LiveAST enables a program to find the ASTs of objects created by dynamically generated code.
@@ -46,7 +46,6 @@ files:
46
46
  - lib/live_ast/evaler.rb
47
47
  - lib/live_ast/linker.rb
48
48
  - lib/live_ast/loader.rb
49
- - lib/live_ast/parser.rb
50
49
  - lib/live_ast/reader.rb
51
50
  - lib/live_ast/replace_load.rb
52
51
  - lib/live_ast/replace_raise.rb
@@ -79,13 +78,12 @@ files:
79
78
  - test/lambda_test.rb
80
79
  - test/load_path_test.rb
81
80
  - test/load_test.rb
81
+ - test/main.rb
82
82
  - test/noninvasive_test.rb
83
83
  - test/readme_test.rb
84
84
  - test/recursive_eval_test.rb
85
85
  - test/redefine_method_test.rb
86
86
  - test/reload_test.rb
87
- - test/shared/ast_generators.rb
88
- - test/shared/main.rb
89
87
  - test/stdlib_test.rb
90
88
  - test/thread_test.rb
91
89
  - test/to_ast_feature_test.rb
@@ -103,14 +101,6 @@ rdoc_options:
103
101
  - --title
104
102
  - "LiveAST: Live Abstract Syntax Trees"
105
103
  - --exclude
106
- - CHANGES.rdoc
107
- - --exclude
108
- - Rakefile
109
- - --exclude
110
- - devel/jumpstart.rb
111
- - --exclude
112
- - lib/live_ast.rb
113
- - --exclude
114
104
  - lib/live_ast/ast_load.rb
115
105
  - --exclude
116
106
  - lib/live_ast/error.rb
@@ -121,91 +111,14 @@ rdoc_options:
121
111
  - --exclude
122
112
  - lib/live_ast/loader.rb
123
113
  - --exclude
124
- - lib/live_ast/parser.rb
125
- - --exclude
126
114
  - lib/live_ast/reader.rb
127
115
  - --exclude
128
116
  - lib/live_ast/replace_load.rb
129
117
  - --exclude
130
118
  - lib/live_ast/replace_raise.rb
131
119
  - --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/koi8_with_utf8bom.rb
161
- - --exclude
162
- - test/encoding_test/usascii.rb
163
- - --exclude
164
- - test/encoding_test/usascii_with_utf8bom.rb
165
- - --exclude
166
- - test/encoding_test/utf8.rb
167
- - --exclude
168
- - test/encoding_test/utf8bom.rb
169
- - --exclude
170
- - test/encoding_test/utf8bom_only.rb
171
- - --exclude
172
- - test/error_test.rb
173
- - --exclude
174
- - test/eval_test.rb
175
- - --exclude
176
- - test/flush_cache_test.rb
177
- - --exclude
178
- - test/lambda_test.rb
179
- - --exclude
180
- - test/load_path_test.rb
181
- - --exclude
182
- - test/load_test.rb
183
- - --exclude
184
- - test/noninvasive_test.rb
185
- - --exclude
186
- - test/readme_test.rb
187
- - --exclude
188
- - test/recursive_eval_test.rb
189
- - --exclude
190
- - test/redefine_method_test.rb
191
- - --exclude
192
- - test/reload_test.rb
193
- - --exclude
194
- - test/shared/ast_generators.rb
195
- - --exclude
196
- - test/shared/main.rb
197
- - --exclude
198
- - test/stdlib_test.rb
199
- - --exclude
200
- - test/thread_test.rb
201
- - --exclude
202
- - test/to_ast_feature_test.rb
203
- - --exclude
204
- - test/to_ruby_feature_test.rb
205
- - --exclude
206
- - test/to_ruby_test.rb
207
- - --exclude
208
- - MANIFEST
120
+ - lib/live_ast.rb
121
+ - -a
209
122
  require_paths:
210
123
  - lib
211
124
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -1,48 +0,0 @@
1
- require 'ruby_parser'
2
- require 'sexp_processor'
3
-
4
- module LiveAST
5
- class Parser < SexpProcessor
6
- def parse(source)
7
- @defs = {}
8
- process RubyParser.new.parse(source)
9
- @defs
10
- end
11
-
12
- def process_defn(sexp)
13
- result = Sexp.new
14
- result << sexp.shift
15
- result << sexp.shift
16
- result << process(sexp.shift)
17
- result << process(sexp.shift)
18
-
19
- store_sexp(result, sexp.line)
20
- s()
21
- end
22
-
23
- def process_iter(sexp)
24
- line = sexp[1].line
25
-
26
- result = Sexp.new
27
- result << sexp.shift
28
- result << process(sexp.shift)
29
- result << process(sexp.shift)
30
- result << process(sexp.shift)
31
-
32
- #
33
- # ruby_parser bug: a method without args attached to a
34
- # multi-line block reports the wrong line. workaround.
35
- #
36
- if result[1][3].size == 1
37
- line = sexp.line
38
- end
39
-
40
- store_sexp(result, line)
41
- s()
42
- end
43
-
44
- def store_sexp(sexp, line)
45
- @defs[line] = @defs.has_key?(line) ? :multiple : sexp
46
- end
47
- end
48
- end
@@ -1,124 +0,0 @@
1
- module ASTGenerators
2
- #
3
- # no_arg_def(:f, "A#f") returns the ast of
4
- #
5
- # def f
6
- # "A#f"
7
- # end
8
- #
9
- def no_arg_def(name, ret)
10
- s(:defn, name, s(:args), s(:scope, s(:block, s(:str, ret))))
11
- end
12
-
13
- #
14
- # no_arg_def_return(no_arg_def(:f, "A#f")) == "A#f"
15
- #
16
- def no_arg_def_return(ast)
17
- ast[3][1][1][1]
18
- end
19
-
20
- #
21
- # binop_def(:f, :+) returns the ast of
22
- #
23
- # def f(x, y)
24
- # x + y
25
- # end
26
- #
27
- def binop_def(name, op)
28
- s(:defn,
29
- name,
30
- s(:args, :x, :y),
31
- s(:scope,
32
- s(:block, s(:call, s(:lvar, :x), op, s(:arglist, s(:lvar, :y))))))
33
- end
34
-
35
- #
36
- # binop_define_method(:f, :*) returns the ast of
37
- #
38
- # define_method :f do |x, y|
39
- # x * y
40
- # end
41
- #
42
- def binop_define_method(name, op)
43
- s(:iter,
44
- s(:call, nil, :define_method, s(:arglist, s(:lit, name))),
45
- s(:masgn, s(:array, s(:lasgn, :x), s(:lasgn, :y))),
46
- s(:call, s(:lvar, :x), op, s(:arglist, s(:lvar, :y))))
47
- end
48
-
49
- #
50
- # binop_covert_define_method(:f, :-, :my_def) returns the ast of
51
- #
52
- # my_def :f do |x, y|
53
- # x - y
54
- # end
55
- #
56
- def binop_covert_define_method(name, op, covert_name)
57
- s(:iter,
58
- s(:call, nil, covert_name, s(:arglist, s(:lit, name))),
59
- s(:masgn, s(:array, s(:lasgn, :x), s(:lasgn, :y))),
60
- s(:call, s(:lvar, :x), op, s(:arglist, s(:lvar, :y))))
61
- end
62
-
63
- #
64
- # binop_define_method_with_var(:method_name, :/) returns the ast of
65
- #
66
- # define_method method_name do |x, y|
67
- # x / y
68
- # end
69
- #
70
- def binop_define_method_with_var(name, op)
71
- s(:iter,
72
- s(:call, nil, :define_method, s(:arglist, s(:lvar, name))),
73
- s(:masgn, s(:array, s(:lasgn, :x), s(:lasgn, :y))),
74
- s(:call, s(:lvar, :x), op, s(:arglist, s(:lvar, :y))))
75
- end
76
-
77
- #
78
- # binop_define_singleton_method(:f, :+, :a) returns the ast of
79
- #
80
- # a.define_singleton_method :f do |x, y|
81
- # x + y
82
- # end
83
- #
84
- def binop_define_singleton_method(name, op, receiver)
85
- s(:iter,
86
- s(:call, s(:lvar, receiver), :define_singleton_method,
87
- s(:arglist, s(:lit, name))),
88
- s(:masgn, s(:array, s(:lasgn, :x), s(:lasgn, :y))),
89
- s(:call, s(:lvar, :x), op, s(:arglist, s(:lvar, :y))))
90
- end
91
-
92
- #
93
- # no_arg_block(:foo, "bar") returns the ast of
94
- #
95
- # foo { "bar" }
96
- #
97
- def no_arg_block(name, ret)
98
- s(:iter, s(:call, nil, name, s(:arglist)), nil, s(:str, ret))
99
- end
100
-
101
- #
102
- # binop_block(:foo, :+) returns the ast of
103
- #
104
- # foo { |x, y| x + y }
105
- #
106
- def binop_block(name, op, receiver = nil, args = [])
107
- s(:iter,
108
- s(:call, receiver, name, s(:arglist, *args)),
109
- s(:masgn, s(:array, s(:lasgn, :x), s(:lasgn, :y))),
110
- s(:call, s(:lvar, :x), op, s(:arglist, s(:lvar, :y))))
111
- end
112
-
113
- #
114
- # binop_proc_new(:*) returns the ast of
115
- #
116
- # Proc.new { |x, y| x * y }
117
- #
118
- def binop_proc_new(op)
119
- s(:iter,
120
- s(:call, s(:const, :Proc), :new, s(:arglist)),
121
- s(:masgn, s(:array, s(:lasgn, :x), s(:lasgn, :y))),
122
- s(:call, s(:lvar, :x), op, s(:arglist, s(:lvar, :y))))
123
- end
124
- end