mirror of
https://github.com/ruby/ruby.git
synced 2025-08-27 06:56:13 +02:00
[ruby/yarp] Move tests from test/* to test/yarp/* to match CRuby
This should make it easier on the sync to determine what changed
and hopefully result in fewer merge conflicts that have to be
manually resolved.
17d82afbfc
This commit is contained in:
parent
9b8602dd90
commit
439f069b4b
19 changed files with 118 additions and 18 deletions
|
@ -4,7 +4,7 @@
|
|||
# test.
|
||||
return if RUBY_ENGINE == "jruby" || RUBY_ENGINE == "truffleruby"
|
||||
|
||||
require "yarp_test_helper"
|
||||
require_relative "test_helper"
|
||||
|
||||
class BOMTest < Test::Unit::TestCase
|
||||
def test_ident
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require "yarp_test_helper"
|
||||
require_relative "test_helper"
|
||||
|
||||
class CommentsTest < Test::Unit::TestCase
|
||||
include ::YARP::DSL
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require "yarp_test_helper"
|
||||
require_relative "test_helper"
|
||||
|
||||
class DesugarVisitorTest < Test::Unit::TestCase
|
||||
def test_and_write
|
|
@ -1,6 +1,6 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require "yarp_test_helper"
|
||||
require_relative "test_helper"
|
||||
|
||||
class EncodingTest < Test::Unit::TestCase
|
||||
%w[
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require "yarp_test_helper"
|
||||
require_relative "test_helper"
|
||||
|
||||
class ErrorsTest < Test::Unit::TestCase
|
||||
include ::YARP::DSL
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require "yarp_test_helper"
|
||||
require_relative "test_helper"
|
||||
|
||||
module YARP
|
||||
class HeredocDedentTest < Test::Unit::TestCase
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require "yarp_test_helper"
|
||||
require_relative "test_helper"
|
||||
|
||||
if RUBY_PLATFORM =~ /linux/
|
||||
#
|
||||
|
|
|
@ -13,7 +13,7 @@ return if !defined?(RubyVM::InstructionSequence) || RUBY_VERSION < "3.2"
|
|||
# Ruby is handling large ISeqs on 32-bit machines
|
||||
return if RUBY_PLATFORM =~ /i686/
|
||||
|
||||
require "yarp_test_helper"
|
||||
require_relative "test_helper"
|
||||
|
||||
class LocalsTest < Test::Unit::TestCase
|
||||
invalid = []
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require "yarp_test_helper"
|
||||
require_relative "test_helper"
|
||||
|
||||
module YARP
|
||||
class LocationTest < Test::Unit::TestCase
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require "yarp_test_helper"
|
||||
require_relative "test_helper"
|
||||
|
||||
return if YARP::BACKEND == :FFI
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require "yarp_test_helper"
|
||||
require_relative "test_helper"
|
||||
|
||||
return unless defined?(RubyVM::InstructionSequence)
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require "yarp_test_helper"
|
||||
require_relative "test_helper"
|
||||
|
||||
return if YARP::BACKEND == :FFI
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require "yarp_test_helper"
|
||||
require_relative "test_helper"
|
||||
|
||||
class ParseTest < Test::Unit::TestCase
|
||||
# When we pretty-print the trees to compare against the snapshots, we want to
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require "yarp_test_helper"
|
||||
require_relative "test_helper"
|
||||
|
||||
return if YARP::BACKEND == :FFI
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require "yarp_test_helper"
|
||||
require_relative "test_helper"
|
||||
|
||||
module YARP
|
||||
class RipperCompatTest < Test::Unit::TestCase
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require "yarp_test_helper"
|
||||
require_relative "test_helper"
|
||||
|
||||
class YARPRubyAPITest < Test::Unit::TestCase
|
||||
def test_ruby_api
|
||||
|
|
100
test/yarp/test_helper.rb
Normal file
100
test/yarp/test_helper.rb
Normal file
|
@ -0,0 +1,100 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require "yarp"
|
||||
require "ripper"
|
||||
require "pp"
|
||||
require "test/unit"
|
||||
require "tempfile"
|
||||
|
||||
puts "Using YARP backend: #{YARP::BACKEND}" if ENV["YARP_FFI_BACKEND"]
|
||||
|
||||
module YARP
|
||||
module Assertions
|
||||
private
|
||||
|
||||
def assert_equal_nodes(expected, actual, compare_location: true, parent: nil)
|
||||
assert_equal expected.class, actual.class
|
||||
|
||||
case expected
|
||||
when Array
|
||||
assert_equal(
|
||||
expected.size,
|
||||
actual.size,
|
||||
-> { "Arrays were different sizes. Parent: #{parent.pretty_inspect}" }
|
||||
)
|
||||
|
||||
expected.zip(actual).each do |(expected_element, actual_element)|
|
||||
assert_equal_nodes(
|
||||
expected_element,
|
||||
actual_element,
|
||||
compare_location: compare_location,
|
||||
parent: actual
|
||||
)
|
||||
end
|
||||
when YARP::SourceFileNode
|
||||
deconstructed_expected = expected.deconstruct_keys(nil)
|
||||
deconstructed_actual = actual.deconstruct_keys(nil)
|
||||
assert_equal deconstructed_expected.keys, deconstructed_actual.keys
|
||||
|
||||
# Filepaths can be different if test suites were run
|
||||
# on different machines.
|
||||
# We accommodate for this by comparing the basenames,
|
||||
# and not the absolute filepaths
|
||||
assert_equal deconstructed_expected.except(:filepath), deconstructed_actual.except(:filepath)
|
||||
assert_equal File.basename(deconstructed_expected[:filepath]), File.basename(deconstructed_actual[:filepath])
|
||||
when YARP::Node
|
||||
deconstructed_expected = expected.deconstruct_keys(nil)
|
||||
deconstructed_actual = actual.deconstruct_keys(nil)
|
||||
assert_equal deconstructed_expected.keys, deconstructed_actual.keys
|
||||
|
||||
deconstructed_expected.each_key do |key|
|
||||
assert_equal_nodes(
|
||||
deconstructed_expected[key],
|
||||
deconstructed_actual[key],
|
||||
compare_location: compare_location,
|
||||
parent: actual
|
||||
)
|
||||
end
|
||||
when YARP::Location
|
||||
assert_operator actual.start_offset, :<=, actual.end_offset, -> {
|
||||
"start_offset > end_offset for #{actual.inspect}, parent is #{parent.pretty_inspect}"
|
||||
}
|
||||
if compare_location
|
||||
assert_equal(
|
||||
expected.start_offset,
|
||||
actual.start_offset,
|
||||
-> { "Start locations were different. Parent: #{parent.pretty_inspect}" }
|
||||
)
|
||||
|
||||
assert_equal(
|
||||
expected.end_offset,
|
||||
actual.end_offset,
|
||||
-> { "End locations were different. Parent: #{parent.pretty_inspect}" }
|
||||
)
|
||||
|
||||
end
|
||||
else
|
||||
assert_equal expected, actual
|
||||
end
|
||||
end
|
||||
|
||||
def assert_valid_locations(value, parent: nil)
|
||||
case value
|
||||
when Array
|
||||
value.each do |element|
|
||||
assert_valid_locations(element, parent: value)
|
||||
end
|
||||
when YARP::Node
|
||||
value.deconstruct_keys(nil).each_value do |field|
|
||||
assert_valid_locations(field, parent: value)
|
||||
end
|
||||
when YARP::Location
|
||||
assert_operator value.start_offset, :<=, value.end_offset, -> {
|
||||
"start_offset > end_offset for #{value.inspect}, parent is #{parent.pretty_inspect}"
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Test::Unit::TestCase.include(YARP::Assertions)
|
|
@ -1,6 +1,6 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require "yarp_test_helper"
|
||||
require_relative "test_helper"
|
||||
|
||||
return if YARP::BACKEND == :FFI
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require "yarp_test_helper"
|
||||
require_relative "test_helper"
|
||||
|
||||
class VersionTest < Test::Unit::TestCase
|
||||
def test_version_is_set
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue