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

Check fails on eunit tests #403

Closed
bartekgorny opened this issue Oct 4, 2016 · 5 comments
Closed

Check fails on eunit tests #403

bartekgorny opened this issue Oct 4, 2016 · 5 comments

Comments

@bartekgorny
Copy link
Contributor

When checking a test module using eunit's ?assertEqual macros, elvis fails because of naming convention violation. This is because stock eunit.hrl defines those macros using variable names like __X, macros are expanded etc. We need at least a workaround, otherwise we'd have to choose between elvis and eunit which would be a difficult choice indeed.

@elbrujohalcon
Copy link
Member

@bartekgorny you can configure that rule… or just disable it for the test modules.

@jfacorro
Copy link
Contributor

jfacorro commented Oct 4, 2016

@elbrujohalcon The macro_names rule doesn't seem to have any configurable option 😞 .

@harenson
Copy link
Member

harenson commented Oct 5, 2016

@jfacorro I think the he is getting an error about variable_naming_convention not about macro_names. If that is the case @bartekgorny you can override the rule's configuration by passing a map containing a regex key with a proper regex to allow underscores at the beginning of variable names or ignore that file using the ignore configuration key.

If you want to accept underscores at the beginning of the variable names by overriding the variable_naming_convention rule use something like this:

[
 {
   elvis,
   [
    {config,
     [#{dirs => ["src"],
        filter => "*.erl",
        rules => [{elvis_style,
                   variable_naming_convention,
                   #{ regex => "^([_A-Z][0-9a-zA-Z]*)$" }}],
        ruleset => erl_files
       } %,
       % ...
     ]
    }
   ]
 }
].

@bartekgorny if that isn't the case, please paste the elvis output here so we can get a better idea about the issue.

@elbrujohalcon
Copy link
Member

@harenson: he's having issues with macro_names and @jfacorro is right: the Regex is hardcoded.

A PR with a regex parameter for this rule, like the one for variable_naming_convention would be much appreciated.

@bartekgorny
Copy link
Contributor Author

The message is about variable naming:

- variable_naming_convention
    - The variable "_V" on line 90 does not respect the format defined by the regular expression '"^([A-Z][0-9a-zA-Z]*)$"'.

It comes from a macro because ?assertEqual defined in eunit.hrl does things like:

-define(assertEqual(Expect, Expr),
    begin
    ((fun (__X) ->
        case (Expr) of
        __X -> ok;

So, yes, seems I can solve it by crafting a regexp allowing double underscore at the beginning of a variable name. Thanks a lot!

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

No branches or pull requests

4 participants