Skip to content

Commit 8b4e649

Browse files
committed
Fix embedded parser redefinition warnings
1 parent bf9d9a7 commit 8b4e649

5 files changed

Lines changed: 35 additions & 9 deletions

File tree

Rakefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ file 'lib/racc/parser-text.rb' => ['lib/racc/parser.rb', 'lib/racc/info.rb', __F
3434
lib = $1
3535
code = File.read("lib/#{lib}.rb")
3636
code.sub!(/\A(?:#.*\n)+/, '')
37-
%[unless $".find {|p| p.end_with?('/#{lib}.rb')}\n$".push "\#{__dir__}/#{lib}.rb"\n#{code}\nend\n]
37+
%[unless $".find {|p| p.tr('\\\\', '/').end_with?('/#{lib}.rb')}\n$".push "\#{__dir__}/#{lib}.rb"\n#{code}\nend\n]
3838
rescue
3939
$&
4040
end

lib/racc/parserfilegenerator.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ def runtime_source
138138

139139
def embed_library(src)
140140
line %[###### #{src.filename} begin]
141-
line %[unless $".find {|p| p.end_with?('/#{src.filename}')}]
141+
line %[unless $".find {|p| p.tr('\\\\', '/').end_with?('/#{src.filename}')}]
142142
line %[$".push "\#{__dir__}/#{src.filename}"]
143143
put src, @params.convert_line?
144144
line %[end]

test/case.rb

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
require 'test/unit'
66
require 'racc/static'
77
require 'fileutils'
8+
require 'open3'
9+
require 'rbconfig'
810
require 'tempfile'
911
require 'timeout'
1012

@@ -101,12 +103,15 @@ def racc(*arg, **opt)
101103
ruby "-I#{LIB_DIR}", "-S", RACC, *arg, **opt
102104
end
103105

104-
def ruby(*arg, quiet: false, **opt)
105-
if quiet
106-
assert_in_out_err(["-C", @TEMP_DIR, *arg], **opt)
107-
else
108-
assert_ruby_status(["-C", @TEMP_DIR, *arg], **opt)
109-
end
106+
def ruby(*arg, quiet: false, **_opt)
107+
stdout, stderr, status = Open3.capture3(RbConfig.ruby, *arg, chdir: @TEMP_DIR)
108+
message = +"command failed: #{([RbConfig.ruby] + arg).join(' ')}"
109+
message << "\nstatus: #{status.exitstatus}"
110+
message << "\nstdout:\n#{stdout}" unless stdout.empty?
111+
message << "\nstderr:\n#{stderr}" unless stderr.empty?
112+
113+
assert(status.success?, message)
114+
assert_equal('', stderr, message) if quiet
110115
end
111116
end
112117
end

test/test_parser_text.rb

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,17 @@ module Racc
44
class TestRaccParserText < TestCase
55
def test_parser_text_require
66
assert_not_match(/^require/, Racc::PARSER_TEXT)
7-
assert_in_out_err(%W[-I#{LIB_DIR} -rracc/parser-text -e$:.clear -eeval(Racc::PARSER_TEXT)])
7+
ruby "-I#{LIB_DIR}", "-rracc/parser-text", "-e", "$:.clear", "-e", "eval(Racc::PARSER_TEXT)", quiet: true
8+
end
9+
10+
def test_parser_text_require_with_backslash_loaded_feature
11+
ruby "-I#{LIB_DIR}", "-rracc/parser-text", "-e", <<~'RUBY', quiet: true
12+
require 'racc/info'
13+
$".map! do |feature|
14+
feature.end_with?('/racc/info.rb') ? 'C:\\tmp\\racc\\info.rb' : feature
15+
end
16+
eval(Racc::PARSER_TEXT)
17+
RUBY
818
end
919
end
1020
end

test/test_racc_command.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,17 @@ def test_echk_y
4848
assert_exec 'echk.y', quiet: true
4949
end
5050

51+
def test_echk_y_with_backslash_loaded_feature
52+
assert_compile 'echk.y', '-E'
53+
assert_debugfile 'echk.y', []
54+
ruby "-I#{LIB_DIR}", "-rracc/parser", "-e", <<~'RUBY', "#{@TAB_DIR}/echk", quiet: true
55+
$".map! do |feature|
56+
feature.end_with?('/racc/parser.rb') ? 'C:\\tmp\\racc\\parser.rb' : feature
57+
end
58+
load ARGV.shift
59+
RUBY
60+
end
61+
5162
def test_err_y
5263
assert_compile 'err.y'
5364
assert_debugfile 'err.y', []

0 commit comments

Comments
 (0)