forked from whitequark/parser
/
test_runner_rewrite.rb
47 lines (39 loc) · 1.5 KB
/
test_runner_rewrite.rb
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
# frozen_string_literal: true
require 'pathname'
require 'fileutils'
require 'shellwords'
require 'open3'
BASE_DIR = Pathname.new(__FILE__) + '..'
require (BASE_DIR + 'helper').expand_path
class TestRunnerRewrite < Minitest::Test
def assert_rewriter_output(path, args, input: 'input.rb', output: 'output.rb', expected_output: '', expected_error: '')
@ruby_rewrite = BASE_DIR.expand_path + '../bin/ruby-rewrite'
@test_dir = BASE_DIR + path
@fixtures_dir = @test_dir + 'fixtures'
Dir.mktmpdir("parser", BASE_DIR.expand_path.to_s) do |tmp_dir|
tmp_dir = Pathname.new(tmp_dir)
sample_file = tmp_dir + "#{path}.rb"
sample_file_expanded = sample_file.expand_path
expected_file = @fixtures_dir + output
FileUtils.cp(@fixtures_dir + input, sample_file_expanded)
stdout, stderr, _exit_code = Dir.chdir @test_dir do
Open3.capture3 %Q{
#{Shellwords.escape(@ruby_rewrite.to_s)} #{args} \
#{Shellwords.escape(sample_file_expanded.to_s)}
}
end
assert_equal expected_output.chomp, stdout.chomp
assert_match expected_error.chomp, stderr.chomp
assert_equal File.read(expected_file.expand_path), File.read(sample_file)
end
end
def test_rewriter_bug_163
assert_rewriter_output('bug_163',
'--modify -l rewriter.rb',
expected_error: Parser::Rewriter::DEPRECATION_WARNING
)
end
def test_tree_rewriter
assert_rewriter_output('using_tree_rewriter', '-l using_tree_rewriter.rb --modify')
end
end