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

GIT_REMOTE_PATTERNS regexes are being overly greedy #4132

Conversation

Sija
Copy link
Contributor

@Sija Sija commented Mar 12, 2017

This PR fixes overly greedy regexes found in Crystal::Doc::Generator::GIT_REMOTE_PATTERNS, which atm are stripping last part after (and including) special character given as a part of the repo name.

With given remote url: "https://github.com/foo/bar.cr.git" they would incorrectly return bar as a repo key, despite of .cr suffix being legitimate part of the repository name.

With given remote url: “https://github.com/foo/bar.cr.git”
- Before: {repo: “bar”}
- Now: {repo: “bar.cr”}
@bcardiff
Copy link
Member

There has been many changes to those regex. @Sija would you mind adding some specs for these corner cases? I think there are no Doc::Generator specs. If you will, you can put them in ./spec/compiler/crystal/tools/doc_spec.cr or similar.

This might force some refactor to allow unit testing.

It not, let us know and we will pick it from there.

@Sija
Copy link
Contributor Author

Sija commented Mar 14, 2017

@bcardiff I've added specs according to your suggestion. Any suggestions are welcome :)

@Sija
Copy link
Contributor Author

Sija commented Mar 14, 2017

Btw, running crystal tool format fails with:

Error:, couldn't format './spec/compiler/crystal/tools/doc_spec.cr', please report a bug including the contents of it: https://github.com/crystal-lang/crystal/issues

require "../../../spec_helper"

GIT_REMOTE_PATTERNS = Crystal::Doc::Generator::GIT_REMOTE_PATTERNS.keys
private def assert_matches_pattern(url, **options : Object)
Copy link
Member

Choose a reason for hiding this comment

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

Remove the : Object restriction and the formatter will success.

Extracted to #4145

end

describe Crystal::Doc::Generator do
describe "GIT_REMOTE_PATTERNS" do
Copy link
Member

Choose a reason for hiding this comment

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

Definitely an improvement. Another approach would be to refactor #compute_repository to allow specs for the potential outputs of git remote -v. But I'm ok on keeping it this way for now.

@@ -0,0 +1,43 @@
require "../../../spec_helper"

GIT_REMOTE_PATTERNS = Crystal::Doc::Generator::GIT_REMOTE_PATTERNS.keys
Copy link
Member

Choose a reason for hiding this comment

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

I would avoid declaring this constant. It is used only once.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Isn't it used every time assert_matches_patten is invoked?

Copy link
Member

Choose a reason for hiding this comment

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

Ok, so you project the keys. That is not recomputed, but the assert_matches_pattern use .each.compact_map.
I will use Crystal::Doc::Generator::GIT_REMOTE_PATTERNS.each_key.compact_map ... directly.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

np, done as requested.

@Sija Sija force-pushed the fix-doc-generator-git-remote-patterns-repo-regex branch from 231b9bd to 194e7c3 Compare March 14, 2017 17:10
@Sija Sija force-pushed the fix-doc-generator-git-remote-patterns-repo-regex branch from 194e7c3 to 9cde94d Compare March 14, 2017 18:36
@bcardiff bcardiff added this to the Next milestone Mar 17, 2017
@bcardiff bcardiff merged commit 9e67166 into crystal-lang:master Mar 17, 2017
@bcardiff
Copy link
Member

Thanks @Sija

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants