summaryrefslogtreecommitdiff
path: root/spec/syntax_suggest
diff options
context:
space:
mode:
authorHiroshi SHIBATA <hsbt@ruby-lang.org>2022-12-09 15:12:51 +0900
committerHiroshi SHIBATA <hsbt@ruby-lang.org>2022-12-09 16:36:22 +0900
commit0677bbe3ff139a4f369c128bdab3526450c5ee6f (patch)
treed114f89cd3150e50cfeaa3d20542287dcacf85ae /spec/syntax_suggest
parent9557c8edf2dcf18fdece066c596a71696b2f2b30 (diff)
downloadruby-0677bbe3ff139a4f369c128bdab3526450c5ee6f.tar.gz
Merge syntax_suggest master
Pick from https://github.com/ruby/syntax_suggest/commit/daee74dcb06296fa69fe8595fdff5d93d432b30d
Diffstat (limited to 'spec/syntax_suggest')
-rw-r--r--spec/syntax_suggest/integration/ruby_command_line_spec.rb12
-rw-r--r--spec/syntax_suggest/unit/api_spec.rb30
2 files changed, 34 insertions, 8 deletions
diff --git a/spec/syntax_suggest/integration/ruby_command_line_spec.rb b/spec/syntax_suggest/integration/ruby_command_line_spec.rb
index 9e488df93a..5c7ee06d83 100644
--- a/spec/syntax_suggest/integration/ruby_command_line_spec.rb
+++ b/spec/syntax_suggest/integration/ruby_command_line_spec.rb
@@ -76,9 +76,17 @@ module SyntaxSuggest
end
end
- it "annotates a syntax error in Ruby 3.2+ when require is not used" do
- pending("Support for SyntaxError#detailed_message monkeypatch needed https://gist.github.com/schneems/09f45cc23b9a8c46e9af6acbb6e6840d?permalink_comment_id=4172585#gistcomment-4172585")
+ it "gem can be tested when executing on Ruby with default gem included" do
+ skip if ruby_core?
+ skip if Gem::Version.new(RUBY_VERSION) < Gem::Version.new("3.2")
+
+ out = `ruby -I#{lib_dir} -rsyntax_suggest -e "puts SyntaxError.instance_method(:detailed_message).source_location" 2>&1`
+ expect($?.success?).to be_truthy
+ expect(out).to include(lib_dir.join("syntax_suggest").join("core_ext.rb").to_s).once
+ end
+
+ it "annotates a syntax error in Ruby 3.2+ when require is not used" do
skip if ruby_core?
skip if Gem::Version.new(RUBY_VERSION) < Gem::Version.new("3.2")
diff --git a/spec/syntax_suggest/unit/api_spec.rb b/spec/syntax_suggest/unit/api_spec.rb
index a89d9f6a33..079a91e46d 100644
--- a/spec/syntax_suggest/unit/api_spec.rb
+++ b/spec/syntax_suggest/unit/api_spec.rb
@@ -65,11 +65,20 @@ module SyntaxSuggest
it "respects highlight API" do
skip if Gem::Version.new(RUBY_VERSION) < Gem::Version.new("3.2")
- error = SyntaxError.new("#{fixtures_dir.join("this_project_extra_def.rb.txt")}:1 ")
+ core_ext_file = lib_dir.join("syntax_suggest").join("core_ext.rb")
+ require_relative core_ext_file
- skip if error.respond_to?(:path)
+ error_klass = Class.new do
+ def path
+ fixtures_dir.join("this_project_extra_def.rb.txt")
+ end
- require "syntax_suggest/core_ext"
+ def detailed_message(**kwargs)
+ "error"
+ end
+ end
+ error_klass.prepend(SyntaxSuggest.module_for_detailed_message)
+ error = error_klass.new
expect(error.detailed_message(highlight: true)).to include(SyntaxSuggest::DisplayCodeWithLineNumbers::TERMINAL_HIGHLIGHT)
expect(error.detailed_message(highlight: false)).to_not include(SyntaxSuggest::DisplayCodeWithLineNumbers::TERMINAL_HIGHLIGHT)
@@ -78,11 +87,20 @@ module SyntaxSuggest
it "can be disabled via falsey kwarg" do
skip if Gem::Version.new(RUBY_VERSION) < Gem::Version.new("3.2")
- error = SyntaxError.new("#{fixtures_dir.join("this_project_extra_def.rb.txt")}:1 ")
+ core_ext_file = lib_dir.join("syntax_suggest").join("core_ext.rb")
+ require_relative core_ext_file
- skip if error.respond_to?(:path)
+ error_klass = Class.new do
+ def path
+ fixtures_dir.join("this_project_extra_def.rb.txt")
+ end
- require "syntax_suggest/core_ext"
+ def detailed_message(**kwargs)
+ "error"
+ end
+ end
+ error_klass.prepend(SyntaxSuggest.module_for_detailed_message)
+ error = error_klass.new
expect(error.detailed_message(syntax_suggest: true)).to_not eq(error.detailed_message(syntax_suggest: false))
end