treetop 1.1.2 → 1.1.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (74) hide show
  1. data/Rakefile +6 -6
  2. data/doc/images/bottom_background.png +0 -0
  3. data/doc/images/middle_backgound.png +0 -0
  4. data/doc/images/middle_background.png +0 -0
  5. data/doc/images/top_background.png +0 -0
  6. data/doc/index.markdown +13 -8
  7. data/doc/screen.css +52 -0
  8. data/doc/site.html +34 -0
  9. data/doc/site.rb +41 -0
  10. data/examples/lambda_calculus/lambda_calculus.rb +2 -2
  11. data/lib/treetop/bootstrap_gen_1_metagrammar.rb +37 -0
  12. data/lib/treetop/compiler/metagrammar. +0 -0
  13. data/lib/treetop/compiler/metagrammar.rb +20 -9
  14. data/lib/treetop/compiler/metagrammar.treetop +1 -1
  15. data/lib/treetop/compiler/node_classes/declaration_sequence.rb +1 -7
  16. data/lib/treetop/compiler/node_classes/grammar.rb +2 -2
  17. data/lib/treetop/runtime/compiled_parser.rb +15 -2
  18. metadata +12 -74
  19. data/test/compilation_target/target.rb +0 -143
  20. data/test/compilation_target/target.treetop +0 -15
  21. data/test/compilation_target/target_test.rb +0 -56
  22. data/test/compiler/and_predicate_test.rb +0 -33
  23. data/test/compiler/anything_symbol_test.rb +0 -24
  24. data/test/compiler/character_class_test.rb +0 -45
  25. data/test/compiler/choice_test.rb +0 -74
  26. data/test/compiler/circular_compilation_test.rb +0 -20
  27. data/test/compiler/failure_propagation_functional_test.rb +0 -20
  28. data/test/compiler/grammar_compiler_test.rb +0 -58
  29. data/test/compiler/grammar_test.rb +0 -37
  30. data/test/compiler/nonterminal_symbol_test.rb +0 -38
  31. data/test/compiler/not_predicate_test.rb +0 -35
  32. data/test/compiler/one_or_more_test.rb +0 -30
  33. data/test/compiler/optional_test.rb +0 -32
  34. data/test/compiler/parenthesized_expression_test.rb +0 -17
  35. data/test/compiler/parsing_rule_test.rb +0 -30
  36. data/test/compiler/sequence_test.rb +0 -68
  37. data/test/compiler/terminal_symbol_test.rb +0 -35
  38. data/test/compiler/test_grammar.treetop +0 -7
  39. data/test/compiler/zero_or_more_test.rb +0 -51
  40. data/test/composition/a.treetop +0 -11
  41. data/test/composition/b.treetop +0 -11
  42. data/test/composition/c.treetop +0 -10
  43. data/test/composition/d.treetop +0 -10
  44. data/test/composition/grammar_composition_test.rb +0 -23
  45. data/test/parser/syntax_node_test.rb +0 -53
  46. data/test/parser/terminal_parse_failure_test.rb +0 -22
  47. data/test/ruby_extensions/string_test.rb +0 -33
  48. data/test/screw/Rakefile +0 -16
  49. data/test/screw/unit.rb +0 -37
  50. data/test/screw/unit/assertion_failed_error.rb +0 -14
  51. data/test/screw/unit/assertions.rb +0 -615
  52. data/test/screw/unit/auto_runner.rb +0 -227
  53. data/test/screw/unit/collector.rb +0 -45
  54. data/test/screw/unit/collector/dir.rb +0 -107
  55. data/test/screw/unit/collector/objectspace.rb +0 -28
  56. data/test/screw/unit/error.rb +0 -48
  57. data/test/screw/unit/failure.rb +0 -45
  58. data/test/screw/unit/sugar.rb +0 -25
  59. data/test/screw/unit/test_case.rb +0 -176
  60. data/test/screw/unit/test_result.rb +0 -73
  61. data/test/screw/unit/test_suite.rb +0 -70
  62. data/test/screw/unit/ui.rb +0 -4
  63. data/test/screw/unit/ui/console/test_runner.rb +0 -118
  64. data/test/screw/unit/ui/fox/test_runner.rb +0 -268
  65. data/test/screw/unit/ui/gtk/test_runner.rb +0 -416
  66. data/test/screw/unit/ui/gtk2/testrunner.rb +0 -465
  67. data/test/screw/unit/ui/test_runner_mediator.rb +0 -58
  68. data/test/screw/unit/ui/test_runner_utilities.rb +0 -46
  69. data/test/screw/unit/ui/tk/test_runner.rb +0 -260
  70. data/test/screw/unit/util.rb +0 -4
  71. data/test/screw/unit/util/backtrace_filter.rb +0 -40
  72. data/test/screw/unit/util/observable.rb +0 -82
  73. data/test/screw/unit/util/proc_wrapper.rb +0 -48
  74. data/test/test_helper.rb +0 -90
@@ -1,227 +0,0 @@
1
- dir =
2
- require 'optparse'
3
-
4
- module Screw
5
- module Unit
6
- class AutoRunner
7
- def self.run(force_standalone=false, default_dir=nil, argv=ARGV, &block)
8
- r = new(force_standalone || standalone?, &block)
9
- r.base = default_dir
10
- r.process_args(argv)
11
- r.run
12
- end
13
-
14
- def self.standalone?
15
- return false unless("-e" == $0)
16
- ObjectSpace.each_object(Class) do |klass|
17
- return false if(klass < TestCase)
18
- end
19
- true
20
- end
21
-
22
- def self.require_runner(name)
23
- require File.join(File.dirname(__FILE__), 'ui', name, 'test_runner')
24
- end
25
-
26
- def self.require_collector(name)
27
- require File.join(File.dirname(__FILE__), 'collector', name)
28
- end
29
-
30
- RUNNERS = {
31
- :console => proc do |r|
32
- require_runner 'console'
33
- Screw::Unit::UI::Console::TestRunner
34
- end,
35
- :gtk => proc do |r|
36
- require_runner 'gtk'
37
- Screw::Unit::UI::GTK::TestRunner
38
- end,
39
- :gtk2 => proc do |r|
40
- require_runner 'gtk2'
41
- Screw::Unit::UI::GTK2::TestRunner
42
- end,
43
- :fox => proc do |r|
44
- require_runner 'fox'
45
- Screw::Unit::UI::Fox::TestRunner
46
- end,
47
- :tk => proc do |r|
48
- require_runner 'tk'
49
- Screw::Unit::UI::Tk::TestRunner
50
- end,
51
- }
52
-
53
- OUTPUT_LEVELS = [
54
- [:silent, UI::SILENT],
55
- [:progress, UI::PROGRESS_ONLY],
56
- [:normal, UI::NORMAL],
57
- [:verbose, UI::VERBOSE],
58
- ]
59
-
60
- COLLECTORS = {
61
- :objectspace => proc do |r|
62
- require_collector 'objectspace'
63
- c = Collector::ObjectSpace.new
64
- c.filter = r.filters
65
- c.collect($0.sub(/\.rb\Z/, ''))
66
- end,
67
- :dir => proc do |r|
68
- require_collector 'dir'
69
- c = Collector::Dir.new
70
- c.filter = r.filters
71
- c.pattern.concat(r.pattern) if(r.pattern)
72
- c.exclude.concat(r.exclude) if(r.exclude)
73
- c.base = r.base
74
- $:.push(r.base) if r.base
75
- c.collect(*(r.to_run.empty? ? ['.'] : r.to_run))
76
- end,
77
- }
78
-
79
- attr_reader :suite
80
- attr_accessor :output_level, :filters, :to_run, :pattern, :exclude, :base, :workdir
81
- attr_writer :runner, :collector
82
-
83
- def initialize(standalone)
84
- Unit.run = true
85
- @standalone = standalone
86
- @runner = RUNNERS[:console]
87
- @collector = COLLECTORS[(standalone ? :dir : :objectspace)]
88
- @filters = []
89
- @to_run = []
90
- @output_level = UI::NORMAL
91
- @workdir = nil
92
- yield(self) if(block_given?)
93
- end
94
-
95
- def process_args(args = ARGV)
96
- begin
97
- options.order!(args) {|arg| @to_run << arg}
98
- rescue OptionRuntime::ParseError => e
99
- puts e
100
- puts options
101
- $! = nil
102
- abort
103
- else
104
- @filters << proc{false} unless(@filters.empty?)
105
- end
106
- not @to_run.empty?
107
- end
108
-
109
- def options
110
- @options ||= OptionParser.new do |o|
111
- o.banner = "Screw::Unit automatic runner."
112
- o.banner << "\nUsage: #{$0} [options] [-- untouched arguments]"
113
-
114
- o.on
115
- o.on('-r', '--runner=RUNNER', RUNNERS,
116
- "Use the given RUNNER.",
117
- "(" + keyword_display(RUNNERS) + ")") do |r|
118
- @runner = r
119
- end
120
-
121
- if(@standalone)
122
- o.on('-b', '--basedir=DIR', "Base directory of test suites.") do |b|
123
- @base = b
124
- end
125
-
126
- o.on('-w', '--workdir=DIR', "Working directory to run tests.") do |w|
127
- @workdir = w
128
- end
129
-
130
- o.on('-a', '--add=TORUN', Array,
131
- "Add TORUN to the list of things to run;",
132
- "can be a file or a directory.") do |a|
133
- @to_run.concat(a)
134
- end
135
-
136
- @pattern = []
137
- o.on('-p', '--pattern=PATTERN', Regexp,
138
- "Match files to collect against PATTERN.") do |e|
139
- @pattern << e
140
- end
141
-
142
- @exclude = []
143
- o.on('-x', '--exclude=PATTERN', Regexp,
144
- "Ignore files to collect against PATTERN.") do |e|
145
- @exclude << e
146
- end
147
- end
148
-
149
- o.on('-n', '--name=NAME', String,
150
- "Runs tests matching NAME.",
151
- "(patterns may be used).") do |n|
152
- n = (%r{\A/(.*)/\Z} =~ n ? Regexp.new($1) : n)
153
- case n
154
- when Regexp
155
- @filters << proc{|t| n =~ t.method_name ? true : nil}
156
- else
157
- @filters << proc{|t| n == t.method_name ? true : nil}
158
- end
159
- end
160
-
161
- o.on('-t', '--testcase=TESTCASE', String,
162
- "Runs tests in TestCases matching TESTCASE.",
163
- "(patterns may be used).") do |n|
164
- n = (%r{\A/(.*)/\Z} =~ n ? Regexp.new($1) : n)
165
- case n
166
- when Regexp
167
- @filters << proc{|t| n =~ t.class.name ? true : nil}
168
- else
169
- @filters << proc{|t| n == t.class.name ? true : nil}
170
- end
171
- end
172
-
173
- o.on('-I', "--load-path=DIR[#{File::PATH_SEPARATOR}DIR...]",
174
- "Appends directory list to $LOAD_PATH.") do |dirs|
175
- $LOAD_PATH.concat(dirs.split(File::PATH_SEPARATOR))
176
- end
177
-
178
- o.on('-v', '--verbose=[LEVEL]', OUTPUT_LEVELS,
179
- "Set the output level (default is verbose).",
180
- "(" + keyword_display(OUTPUT_LEVELS) + ")") do |l|
181
- @output_level = l || UI::VERBOSE
182
- end
183
-
184
- o.on('--',
185
- "Stop processing options so that the",
186
- "remaining options will be passed to the",
187
- "test."){o.terminate}
188
-
189
- o.on('-h', '--help', 'Display this help.'){puts o; exit}
190
-
191
- o.on_tail
192
- o.on_tail('Deprecated options:')
193
-
194
- o.on_tail('--console', 'Console runner (use --runner).') do
195
- warn("Deprecated option (--console).")
196
- @runner = RUNNERS[:console]
197
- end
198
-
199
- o.on_tail('--gtk', 'GTK runner (use --runner).') do
200
- warn("Deprecated option (--gtk).")
201
- @runner = RUNNERS[:gtk]
202
- end
203
-
204
- o.on_tail('--fox', 'Fox runner (use --runner).') do
205
- warn("Deprecated option (--fox).")
206
- @runner = RUNNERS[:fox]
207
- end
208
-
209
- o.on_tail
210
- end
211
- end
212
-
213
- def keyword_display(array)
214
- list = array.collect {|e, *| e.to_s}
215
- Array === array or list.sort!
216
- list.collect {|e| e.sub(/^(.)([A-Za-z]+)(?=\w*$)/, '\\1[\\2]')}.join(", ")
217
- end
218
-
219
- def run
220
- @suite = @collector[self]
221
- result = @runner[self] or return false
222
- Dir.chdir(@workdir) if @workdir
223
- result.run(@suite, @output_level).passed?
224
- end
225
- end
226
- end
227
- end
@@ -1,45 +0,0 @@
1
- dir = File.dirname(__FILE__)
2
-
3
- module Screw
4
- module Unit
5
- module Collector
6
- def initialize
7
- @filters = []
8
- end
9
-
10
- def filter=(filters)
11
- @filters = case(filters)
12
- when Proc
13
- [filters]
14
- when Array
15
- filters
16
- end
17
- end
18
-
19
- def add_suite(destination, suite)
20
- to_delete = suite.tests.find_all{|t| !include?(t)}
21
- to_delete.each{|t| suite.delete(t)}
22
- destination << suite unless(suite.size == 0)
23
- end
24
-
25
- def include?(test)
26
- return true if(@filters.empty?)
27
- @filters.each do |filter|
28
- result = filter[test]
29
- if(result.nil?)
30
- next
31
- elsif(!result)
32
- return false
33
- else
34
- return true
35
- end
36
- end
37
- true
38
- end
39
-
40
- def sort(suites)
41
- suites.sort_by{|s| s.name}
42
- end
43
- end
44
- end
45
- end
@@ -1,107 +0,0 @@
1
- require 'fancy/unit/testsuite'
2
- require 'fancy/unit/collector'
3
-
4
- module Screw
5
- module Unit
6
- module Collector
7
- class Dir
8
- include Collector
9
-
10
- attr_reader :pattern, :exclude
11
- attr_accessor :base
12
-
13
- def initialize(dir=::Dir, file=::File, object_space=::ObjectSpace, req=nil)
14
- super()
15
- @dir = dir
16
- @file = file
17
- @object_space = object_space
18
- @req = req
19
- @pattern = [/\btest_.*\.rb\Z/m]
20
- @exclude = []
21
- end
22
-
23
- def collect(*from)
24
- basedir = @base
25
- $:.push(basedir) if basedir
26
- if(from.empty?)
27
- recursive_collect('.', find_test_cases)
28
- elsif(from.size == 1)
29
- recursive_collect(from.first, find_test_cases)
30
- else
31
- suites = []
32
- from.each do |f|
33
- suite = recursive_collect(f, find_test_cases)
34
- suites << suite unless(suite.tests.empty?)
35
- end
36
- suite = TestSuite.new("[#{from.join(', ')}]")
37
- sort(suites).each{|s| suite << s}
38
- suite
39
- end
40
- ensure
41
- $:.delete_at($:.rindex(basedir)) if basedir
42
- end
43
-
44
- def find_test_cases(ignore=[])
45
- cases = []
46
- @object_space.each_object(Class) do |c|
47
- cases << c if(c < TestCase && !ignore.include?(c))
48
- end
49
- ignore.concat(cases)
50
- cases
51
- end
52
-
53
- def recursive_collect(name, already_gathered)
54
- sub_suites = []
55
- path = realdir(name)
56
- if @file.directory?(path)
57
- dir_name = name unless name == '.'
58
- @dir.entries(path).each do |e|
59
- next if(e == '.' || e == '..')
60
- e_name = dir_name ? @file.join(dir_name, e) : e
61
- if @file.directory?(realdir(e_name))
62
- next if /\ACVS\z/ =~ e
63
- sub_suite = recursive_collect(e_name, already_gathered)
64
- sub_suites << sub_suite unless(sub_suite.empty?)
65
- else
66
- next if /~\z/ =~ e_name or /\A\.\#/ =~ e
67
- if @pattern and !@pattern.empty?
68
- next unless @pattern.any? {|pat| pat =~ e_name}
69
- end
70
- if @exclude and !@exclude.empty?
71
- next if @exclude.any? {|pat| pat =~ e_name}
72
- end
73
- collect_file(e_name, sub_suites, already_gathered)
74
- end
75
- end
76
- else
77
- collect_file(name, sub_suites, already_gathered)
78
- end
79
- suite = TestSuite.new(@file.basename(name))
80
- sort(sub_suites).each{|s| suite << s}
81
- suite
82
- end
83
-
84
- def collect_file(name, suites, already_gathered)
85
- dir = @file.dirname(@file.expand_path(name, @base))
86
- $:.unshift(dir)
87
- if(@req)
88
- @req.require(name)
89
- else
90
- require(name)
91
- end
92
- find_test_cases(already_gathered).each{|t| add_suite(suites, t.suite)}
93
- ensure
94
- $:.delete_at($:.rindex(dir)) if(dir)
95
- end
96
-
97
- def realdir(path)
98
- if @base
99
- @file.join(@base, path)
100
- else
101
- path
102
- end
103
- end
104
- end
105
- end
106
- end
107
- end
@@ -1,28 +0,0 @@
1
- module Screw
2
- module Unit
3
- module Collector
4
- class ObjectSpace
5
- include Collector
6
-
7
- NAME = 'collected from the ObjectSpace'
8
-
9
- def initialize(source=::ObjectSpace)
10
- super()
11
- @source = source
12
- end
13
-
14
- def collect(name=NAME)
15
- suite = TestSuite.new(name)
16
- sub_suites = []
17
- @source.each_object(Class) do |klass|
18
- if(Screw::Unit::TestCase > klass)
19
- add_suite(sub_suites, klass.suite)
20
- end
21
- end
22
- sort(sub_suites).each{|s| suite << s}
23
- suite
24
- end
25
- end
26
- end
27
- end
28
- end
@@ -1,48 +0,0 @@
1
- module Screw
2
- module Unit
3
-
4
- # Encapsulates an error in a test. Created by
5
- # Screw::Unit::TestCase when it rescues an exception thrown
6
- # during the processing of a test.
7
- class Error
8
- include Util::BacktraceFilter
9
-
10
- attr_reader(:test_name, :exception)
11
-
12
- SINGLE_CHARACTER = 'E'
13
-
14
- # Creates a new Error with the given test_name and
15
- # exception.
16
- def initialize(test_name, exception)
17
- @test_name = test_name
18
- @exception = exception
19
- end
20
-
21
- # Returns a single character representation of an error.
22
- def single_character_display
23
- SINGLE_CHARACTER
24
- end
25
-
26
- # Returns the message associated with the error.
27
- def message
28
- "#{@exception.class.name}: #{@exception.message}"
29
- end
30
-
31
- # Returns a brief version of the error description.
32
- def short_display
33
- "#@test_name: #{message.split("\n")[0]}"
34
- end
35
-
36
- # Returns a verbose version of the error description.
37
- def long_display
38
- backtrace = filter_backtrace(@exception.backtrace).join("\n ")
39
- "Error:\n#@test_name:\n#{message}\n #{backtrace}"
40
- end
41
-
42
- # Overridden to return long_display.
43
- def to_s
44
- long_display
45
- end
46
- end
47
- end
48
- end