1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

Clean up temporary directory for racc

This commit is contained in:
Nobuyoshi Nakada 2019-07-02 14:10:50 +09:00
parent eb043c8888
commit 92dcee393a
No known key found for this signature in database
GPG key ID: 4BC7D6DF58D8DF60
3 changed files with 17 additions and 19 deletions

View file

@ -15,34 +15,30 @@ module Racc
test_dir = File.join(PROJECT_DIR, 'test') test_dir = File.join(PROJECT_DIR, 'test')
test_dir = File.join(PROJECT_DIR, 'racc') unless File.exist?(test_dir) test_dir = File.join(PROJECT_DIR, 'racc') unless File.exist?(test_dir)
TEST_DIR = test_dir TEST_DIR = test_dir
TEMP_DIR = Dir.mktmpdir("racc")
racc = File.join(PROJECT_DIR, 'bin', 'racc') racc = File.join(PROJECT_DIR, 'bin', 'racc')
racc = File.join(PROJECT_DIR, '..', 'libexec', 'racc') unless File.exist?(racc) racc = File.join(PROJECT_DIR, '..', 'libexec', 'racc') unless File.exist?(racc)
RACC = racc RACC = racc
OUT_DIR = File.join(TEMP_DIR, 'out')
TAB_DIR = File.join(TEMP_DIR, 'tab') # generated parsers go here
LOG_DIR = File.join(TEMP_DIR, 'log')
ERR_DIR = File.join(TEMP_DIR, 'err')
ASSET_DIR = File.join(TEST_DIR, 'assets') # test grammars ASSET_DIR = File.join(TEST_DIR, 'assets') # test grammars
REGRESS_DIR = File.join(TEST_DIR, 'regress') # known-good generated outputs REGRESS_DIR = File.join(TEST_DIR, 'regress') # known-good generated outputs
FileUtils.cp File.join(TEST_DIR, "src.intp"), TEMP_DIR
INC = [ INC = [
File.join(PROJECT_DIR, 'lib'), File.join(PROJECT_DIR, 'lib'),
File.join(PROJECT_DIR, 'ext'), File.join(PROJECT_DIR, 'ext'),
].join(':') ].join(':')
def setup def setup
[OUT_DIR, TAB_DIR, LOG_DIR, ERR_DIR].each do |dir| @TEMP_DIR = Dir.mktmpdir("racc")
FileUtils.mkdir_p(dir) @OUT_DIR = File.join(@TEMP_DIR, 'out')
end @TAB_DIR = File.join(@TEMP_DIR, 'tab') # generated parsers go here
@LOG_DIR = File.join(@TEMP_DIR, 'log')
@ERR_DIR = File.join(@TEMP_DIR, 'err')
FileUtils.mkdir_p([@OUT_DIR, @TAB_DIR, @LOG_DIR, @ERR_DIR])
FileUtils.cp File.join(TEST_DIR, "src.intp"), @TEMP_DIR
end end
def teardown def teardown
[OUT_DIR, TAB_DIR, LOG_DIR, ERR_DIR].each do |dir| FileUtils.rm_f(File.join(@TEMP_DIR, "src.intp"))
FileUtils.rm_rf(dir) FileUtils.rm_rf([@OUT_DIR, @TAB_DIR, @LOG_DIR, @ERR_DIR, @TEMP_DIR])
end
end end
def assert_compile(asset, args = [], **opt) def assert_compile(asset, args = [], **opt)
@ -50,15 +46,15 @@ module Racc
args = ([args].flatten) + [ args = ([args].flatten) + [
"#{ASSET_DIR}/#{file}.y", "#{ASSET_DIR}/#{file}.y",
'-Do', '-Do',
"-O#{OUT_DIR}/#{file}", "-O#{@OUT_DIR}/#{file}",
"-o#{TAB_DIR}/#{file}", "-o#{@TAB_DIR}/#{file}",
] ]
racc(*args, **opt) racc(*args, **opt)
end end
def assert_debugfile(asset, ok) def assert_debugfile(asset, ok)
file = File.basename(asset, '.y') file = File.basename(asset, '.y')
Dir.chdir(LOG_DIR) do Dir.chdir(@LOG_DIR) do
File.foreach("#{file}.y") do |line| File.foreach("#{file}.y") do |line|
line.strip! line.strip!
case line case line
@ -76,7 +72,7 @@ module Racc
def assert_exec(asset) def assert_exec(asset)
file = File.basename(asset, '.y') file = File.basename(asset, '.y')
ruby("#{TAB_DIR}/#{file}") ruby("#{@TAB_DIR}/#{file}")
end end
def strip_version(source) def strip_version(source)
@ -87,7 +83,7 @@ module Racc
file = File.basename(asset, '.y') file = File.basename(asset, '.y')
expected = File.read("#{REGRESS_DIR}/#{file}") expected = File.read("#{REGRESS_DIR}/#{file}")
actual = File.read("#{TAB_DIR}/#{file}") actual = File.read("#{@TAB_DIR}/#{file}")
result = (strip_version(expected) == strip_version(actual)) result = (strip_version(expected) == strip_version(actual))
assert(result, "Output of test/assets/#{file}.y differed from " \ assert(result, "Output of test/assets/#{file}.y differed from " \
@ -99,7 +95,7 @@ module Racc
end end
def ruby(*arg, **opt) def ruby(*arg, **opt)
assert_ruby_status(["-C", TEMP_DIR, *arg], **opt) assert_ruby_status(["-C", @TEMP_DIR, *arg], **opt)
end end
end end
end end

View file

@ -3,6 +3,7 @@ require File.expand_path(File.join(File.dirname(__FILE__), 'helper'))
module Racc module Racc
class TestChkY < TestCase class TestChkY < TestCase
def setup def setup
super
file = File.join(ASSET_DIR, 'chk.y') file = File.join(ASSET_DIR, 'chk.y')
@debug_flags = Racc::DebugFlags.parse_option_string('o') @debug_flags = Racc::DebugFlags.parse_option_string('o')
parser = Racc::GrammarFileParser.new(@debug_flags) parser = Racc::GrammarFileParser.new(@debug_flags)

View file

@ -3,6 +3,7 @@ require File.expand_path(File.join(File.dirname(__FILE__), 'helper'))
module Racc module Racc
class TestScanY < TestCase class TestScanY < TestCase
def setup def setup
super
file = File.join(ASSET_DIR, 'scan.y') file = File.join(ASSET_DIR, 'scan.y')
@debug_flags = Racc::DebugFlags.parse_option_string('o') @debug_flags = Racc::DebugFlags.parse_option_string('o')
parser = Racc::GrammarFileParser.new(@debug_flags) parser = Racc::GrammarFileParser.new(@debug_flags)