uartois / sonar-golang

Sonarqube plugin for the golang language.
GNU Lesser General Public License v3.0
245 stars 32 forks source link

Improve parsing of test files to locate functions #52

Closed reubent closed 6 years ago

reubent commented 6 years ago

I didn't actually mean to submit this - force of habit creating pull requests after pushing kicked in. This was written for our own internal use but feel free to use if it is helpful. It works around a number of issues we were having with parsing of test files.

thibaultfalque commented 6 years ago

@reubent Thanks you for your contribution !

danielleberre commented 6 years ago

Thanks @reubent for your contrib. It will probably fix some issues for other users of the plugin too (e.g. #49).

Would it be possible to make your PR against the maintenance branch instead of master?

The maintenance branch contains the 1.2.X releases code while the master branch contains code for the next major release.

It would be nice too if you could prevent pom.xml to be changed in the PR :).

Tvli commented 6 years ago

Hi @reubent @danielleberre It looks like this PR breaks the bug I fixed in https://github.com/uartois/sonar-golang/pull/27 . Please take a look in the above link for the detailed explanation. Also please make sure the new tests covers all the existing tests. As far as I can tell the tests for people who use testSuite have been removed.

danielleberre commented 6 years ago

Thanks @Tvli for pointing that out. I guess that we could add the following test sample to test_test.go to make sure that the proposed REGEXP also works for you?

func (suite *ExampleTestSuite) TestExample() {
    suite.Equal(5, suite.VariableThatShouldStartAtFive)
}
danielleberre commented 6 years ago

I resolved the conflicts in reubent-fix_test_parsing branch.

Please check that everything is fine (we may want to create a new PR from that branch).

@Tvli your test case has been added in the file test_test.go, and the test case now breaks. So we can improve the PR with your specific testcase.

@thibaultfalque the build is successful while there are failing test cases, as such the CI is not very useful right now for PR ...

Tvli commented 6 years ago

Hey @danielleberre

The test case looks good to me. Thanks 👍

danielleberre commented 6 years ago

@Tvli I updated the REGEXP in a282eeec91dd87d3da5687c2d12d0f8d4a5cac3e to match your specific needs. I assume that testsuite always start with (suite, is that correct?

Tvli commented 6 years ago

Hi @danielleberre No it's not. In Go lang , the syntax for a struct instance method is

func (alias struct) methodName() {}

To be more exact:

type A struct {
  Val string 
}

func (whateverIWant A) printVal() {
  print(whateverIwant.Val)
}

so the "suite" can be any alias people want to use to represent the struct within the function's scope.

I guess you probably want to find the Test function name after the first ).

danielleberre commented 6 years ago

@Tvli Thanks for the explanation. I added a new test case and fixed now properly the REGEXP.