summaryrefslogtreecommitdiff
path: root/test/racc/test_racc_command.rb
blob: 0d2c5829e4a8f89a310960df135263a6ed0ea6b5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
require File.expand_path(File.join(File.dirname(__FILE__), 'helper'))

module Racc
  class TestRaccCommand < TestCase
    def test_syntax_y
      assert_compile 'syntax.y', '-v'
      assert_debugfile 'syntax.y', [0,0,0,0,0]
    end

    def test_percent_y
      assert_compile 'percent.y'
      assert_debugfile 'percent.y', []
      assert_exec 'percent.y'
    end

    def test_scan_y
      assert_compile 'scan.y'
      assert_debugfile 'scan.y', []
      assert_exec 'scan.y'
    end

    def test_newsyn_y
      assert_compile 'newsyn.y'
      assert_debugfile 'newsyn.y', []
    end

    def test_normal_y
      assert_compile 'normal.y'
      assert_debugfile 'normal.y', []

      assert_compile 'normal.y', '-vg'
      assert_debugfile 'normal.y', []
    end

    def test_chk_y
      assert_compile 'chk.y', '-vg'
      assert_debugfile 'chk.y', []
      assert_exec 'chk.y'

      assert_compile 'chk.y', '--line-convert-all'
      assert_debugfile 'chk.y', []
      assert_exec 'chk.y'
    end

    def test_echk_y
      assert_compile 'echk.y', '-E'
      assert_debugfile 'echk.y', []
      assert_exec 'echk.y'
    end

    def test_err_y
      assert_compile 'err.y'
      assert_debugfile 'err.y', []
      assert_exec 'err.y'
    end

    def test_mailp_y
      assert_compile 'mailp.y'
      assert_debugfile 'mailp.y', []
    end

    def test_conf_y
      assert_compile 'conf.y', '-v'
      assert_debugfile 'conf.y', [4,1,1,2]
    end

    def test_rrconf_y
      assert_compile 'rrconf.y'
      assert_debugfile 'rrconf.y', [1,1,0,0]
    end

    def test_useless_y
      assert_compile 'useless.y'
      assert_debugfile 'useless.y', [0,0,1,2]
    end

    def test_opt_y
      assert_compile 'opt.y'
      assert_debugfile 'opt.y', []
      assert_exec 'opt.y'
    end

    def test_yyerr_y
      assert_compile 'yyerr.y'
      assert_debugfile 'yyerr.y', []
      assert_exec 'yyerr.y'
    end

    def test_recv_y
      assert_compile 'recv.y'
      assert_debugfile 'recv.y', [5,10,1,4]
    end

    def test_ichk_y
      assert_compile 'ichk.y'
      assert_debugfile 'ichk.y', []
      assert_exec 'ichk.y'
    end

    def test_intp_y
      assert_compile 'intp.y'
      assert_debugfile 'intp.y', []
      assert_exec 'intp.y'
    end

    def test_expect_y
      assert_compile 'expect.y'
      assert_debugfile 'expect.y', [1,0,0,0,1]
    end

    def test_nullbug1_y
      assert_compile 'nullbug1.y'
      assert_debugfile 'nullbug1.y', [0,0,0,0]
    end

    def test_nullbug2_y
      assert_compile 'nullbug2.y'
      assert_debugfile 'nullbug2.y', [0,0,0,0]
    end

    def test_firstline_y
      assert_compile 'firstline.y'
      assert_debugfile 'firstline.y', []
    end

    def test_nonass_y
      assert_compile 'nonass.y'
      assert_debugfile 'nonass.y', []
      assert_exec 'nonass.y'
    end

    def test_digraph_y
      assert_compile 'digraph.y'
      assert_debugfile 'digraph.y', []
      assert_exec 'digraph.y'
    end

    def test_noend_y
      assert_compile 'noend.y'
      assert_debugfile 'noend.y', []
    end

    def test_norule_y
      assert_raise(Test::Unit::AssertionFailedError) {
        assert_compile 'norule.y'
      }
    end

    def test_unterm_y
      assert_raise(Test::Unit::AssertionFailedError) {
        assert_compile 'unterm.y'
      }
    end

    # Regression test for a problem where error recovery at EOF would cause
    # a Racc-generated parser to go into an infinite loop (on some grammars)
    def test_error_recovery_y
      assert_compile 'error_recovery.y'
      Timeout.timeout(10) do
        assert_exec 'error_recovery.y'
      end
    end

    # .y files from `parser` gem

    def test_ruby18
      assert_compile 'ruby18.y', [], timeout: 60
      assert_debugfile 'ruby18.y', []
      assert_output_unchanged 'ruby18.y'
    end

    def test_ruby22
      assert_compile 'ruby22.y', [], timeout: 60
      assert_debugfile 'ruby22.y', []
      assert_output_unchanged 'ruby22.y'
    end

    # .y file from csspool gem

    def test_csspool
      assert_compile 'csspool.y'
      assert_debugfile 'csspool.y', [5, 3]
      assert_output_unchanged 'csspool.y'
    end

    # .y file from opal gem

    def test_opal
      assert_compile 'opal.y', [], timeout: 60
      assert_debugfile 'opal.y', []
      assert_output_unchanged 'opal.y'
    end

    # .y file from journey gem

    def test_journey
      assert_compile 'journey.y'
      assert_debugfile 'journey.y', []
      assert_output_unchanged 'journey.y'
    end

    # .y file from nokogiri gem

    def test_nokogiri_css
      assert_compile 'nokogiri-css.y'
      assert_debugfile 'nokogiri-css.y', [0, 1]
      assert_output_unchanged 'nokogiri-css.y'
    end

    # .y file from edtf-ruby gem

    def test_edtf
      assert_compile 'edtf.y'
      assert_debugfile 'edtf.y', [0, 0, 0, 0, 0]
      assert_output_unchanged 'edtf.y'
    end

    # .y file from namae gem

    def test_namae
      assert_compile 'namae.y'
      assert_debugfile 'namae.y', [0, 0, 0, 0, 0]
      assert_output_unchanged 'namae.y'
    end

    # .y file from liquor gem

    def test_liquor
      assert_compile 'liquor.y'
      assert_debugfile 'liquor.y', [0, 0, 0, 0, 15]
      assert_output_unchanged 'liquor.y'
    end

    # .y file from nasl gem

    def test_nasl
      assert_compile 'nasl.y'
      assert_debugfile 'nasl.y', [0, 0, 0, 0, 1]
      assert_output_unchanged 'nasl.y'
    end

    # .y file from riml gem

    def test_riml
      assert_compile 'riml.y'
      assert_debugfile 'riml.y', [289, 0, 0, 0]
      assert_output_unchanged 'riml.y'
    end

    # .y file from ruby-php-serialization gem

    def test_php_serialization
      assert_compile 'php_serialization.y'
      assert_debugfile 'php_serialization.y', [0, 0, 0, 0]
      assert_output_unchanged 'php_serialization.y'
    end

    # .y file from huia language implementation

    def test_huia
      assert_compile 'huia.y'
      assert_debugfile 'huia.y', [285, 0, 0, 0]
      assert_output_unchanged 'huia.y'
    end

    # .y file from cast gem

    def test_cast
      assert_compile 'cast.y'
      assert_debugfile 'cast.y', [0, 0, 0, 0, 1]
      assert_output_unchanged 'cast.y'
    end

    # .y file from cadenza gem

    def test_cadenza
      assert_compile 'cadenza.y'
      assert_debugfile 'cadenza.y', [0, 0, 0, 0, 37]
      assert_output_unchanged 'cadenza.y'
    end

    # .y file from mediacloth gem

    def test_mediacloth
      assert_compile 'mediacloth.y'
      assert_debugfile 'mediacloth.y', [0, 0, 0, 0]
      assert_output_unchanged 'mediacloth.y'
    end

    # .y file from twowaysql gem

    def test_twowaysql
      assert_compile 'twowaysql.y'
      assert_debugfile 'twowaysql.y', [4, 0, 0, 0]
      assert_output_unchanged 'twowaysql.y'
    end

    # .y file from machete gem

    def test_machete
      assert_compile 'machete.y'
      assert_debugfile 'machete.y', [0, 0, 0, 0]
      assert_output_unchanged 'machete.y'
    end

    # .y file from mof gem

    def test_mof
      assert_compile 'mof.y'
      assert_debugfile 'mof.y', [7, 4, 0, 0]
      assert_output_unchanged 'mof.y'
    end

    # .y file from tp_plus gem

    def test_tp_plus
      assert_compile 'tp_plus.y'
      assert_debugfile 'tp_plus.y', [21, 0, 0, 0]
      assert_output_unchanged 'tp_plus.y'
    end

    def test_ifelse
      omit if RUBY_PLATFORM =~ /java/

      stderr = nil
      racc "-o#{@TAB_DIR}/ifelse", "#{ASSET_DIR}/ifelse.y", stdout_filter: ->(s) { stderr = s }
      stderr = stderr.lines[1..-1].join if RUBY_PLATFORM.match?(/java/)
      assert_equal(<<~STDERR, stderr)
        1 useless nonterminals:
          dummy
        2 useless rules:
          #4 (dummy)
          #5 (dummy)
        1 shift/reduce conflicts
        Turn on logging with "-v" and check ".output" file for details
      STDERR
    end
  end
end