Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix method scope in test in order to invoke the tests properly and fix exception message #182

Merged
merged 4 commits into from
Jul 19, 2024

Conversation

Watson1978
Copy link
Contributor

@Watson1978 Watson1978 commented Jul 19, 2024

This PR includes following two fixes.

  1. The test_empty and test_linear_performance_gt were defined as private method. Seems that test-unit runner does not invoke private methods even if the methods have test_ prefix.
  2. When parse malformed entity declaration, the exception might have the message about NoMethodError. The proper exception message will be contained by this fix.

The `test_empty` and `test_linear_performance_gt` were defined as private method.
Seems that test-unit runner does not invoke private methods even if the methods have `test_` prefix.
Comment on lines 27 to 33
assert_equal(<<-DETAIL.chomp, exception.to_s)
Malformed notation declaration: name is missing
Line: 5
Position: 72
Last 80 unconsumed characters:
<!ENTITY> ]> <r/>
DETAIL
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test raises following exception:

<"#<NoMethodError: undefined method `captures' for nil>\n" +
"/home/watson/prj/rexml/lib/rexml/parsers/baseparser.rb:321:in `pull_event'\n" +
"/home/watson/prj/rexml/lib/rexml/parsers/baseparser.rb:225:in `pull'\n" +
"/home/watson/prj/rexml/lib/rexml/parsers/treeparser.rb:22:in `parse'\n" +
"/home/watson/prj/rexml/lib/rexml/document.rb:448:in `build'\n" +

I removed because I didn't think the need to check NoMethodError message.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should raise ParseException.
Could you fix the implementation in this PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I was wrong above comment. sorry.

It raises ParseException, but it has #<NoMethodError: undefined method captures' for nil>` exception message.

#<REXML::ParseException:"#<NoMethodError: undefined method `captures' for nil>

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK. Then, could you fix the NoMethodError error message in this PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I fixed with 93ec28f

Comment on lines 27 to 33
assert_equal(<<-DETAIL.chomp, exception.to_s)
Malformed notation declaration: name is missing
Line: 5
Position: 72
Last 80 unconsumed characters:
<!ENTITY> ]> <r/>
DETAIL
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should raise ParseException.
Could you fix the implementation in this PR?

end

def test_linear_performance_gt
seq = [10000, 50000, 100000, 150000, 200000]
assert_linear_performance(seq, rehearsal: 10) do |n|
REXML::Document.new('<!DOCTYPE rubynet [<!ENTITY rbconfig.ruby_version "' + '>' * n + '">')
begin
REXML::Document.new('<!DOCTYPE rubynet [<!ENTITY rbconfig.ruby_version "' + '>' * n + '">')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use a valid XML to reproduce this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I fixed with 36ba79e

@Watson1978 Watson1978 requested a review from kou July 19, 2024 05:46
@@ -318,7 +318,11 @@ def pull_event
raise REXML::ParseException.new( "Bad ELEMENT declaration!", @source ) if md.nil?
return [ :elementdecl, "<!ELEMENT" + md[1] ]
elsif @source.match("ENTITY", true)
match = [:entitydecl, *@source.match(Private::ENTITYDECL_PATTERN, true, term: Private::ENTITY_TERM).captures.compact]
scanner = @source.match(Private::ENTITYDECL_PATTERN, true, term: Private::ENTITY_TERM)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you use match_data not scanner?
We want to use MatchData instead of StringScanner because we don't want to use StringScanner in REXML::Source directly. But REXML::Source#match returns StringScanner directly for performance reason.
So we should assume that the return value of REXML::Source#match is a MatchData and we should only use MatchData compatible API provided by StringScanner.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, so that's the intention.
563bb57

Last 80 unconsumed characters:
<!ENTITY> ]> <r/>
> ]> <r/>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nits] There is a unnecessary white space.

Suggested change
> ]> <r/>
> ]> <r/>

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately, the exception message contains trailing space.
So I cannot remove it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh I see. I'm so sorry mm

@kou
Copy link
Member

kou commented Jul 19, 2024

Could you update the description that this PR also includes NoMethodError fix before we merge this?

@Watson1978 Watson1978 changed the title Fix method scope in test in order to invoke the tests properly Fix method scope in test in order to invoke the tests properly and exception message Jul 19, 2024
@Watson1978 Watson1978 changed the title Fix method scope in test in order to invoke the tests properly and exception message Fix method scope in test in order to invoke the tests properly and fix exception message Jul 19, 2024
@Watson1978
Copy link
Contributor Author

Could you update the description that this PR also includes NoMethodError fix before we merge this?

@kou OK, I updated the description. Thanks.

@kou kou merged commit 2c39c91 into ruby:master Jul 19, 2024
61 checks passed
@kou
Copy link
Member

kou commented Jul 19, 2024

Thanks.

@Watson1978 Watson1978 deleted the fix-test branch July 19, 2024 08:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants