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

CPPCheckBear.py: Support language parameter #2710

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

gutsytechster
Copy link
Contributor

@gutsytechster gutsytechster commented Oct 12, 2018

It adds the command line argument 'language' which can be
given whenever using the CPPCheckBear. It can hold two values
either C or C++.

Closes #2450

For short term contributors: we understand that getting your commits well
defined like we require is a hard task and takes some learning. If you
look to help without wanting to contribute long term there's no need
for you to learn this. Just drop us a message and we'll take care of brushing
up your stuff for merge!

Checklist

  • I read the commit guidelines and I've followed
    them.
  • I ran coala over my code locally. (All commits have to pass
    individually.
    It is not sufficient to have "fixup commits" on your PR,
    our bot will still report the issues for the previous commit.) You will
    likely receive a lot of bot comments and build failures if coala does not
    pass on every single commit!

After you submit your pull request, DO NOT click the 'Update Branch' button.
When asked for a rebase, consult coala.io/rebase
instead.

Please consider helping us by reviewing other peoples pull requests as well:

The more you review, the more your score will grow at coala.io and we will
review your PRs faster!

"""
args = ('--template={line}:{severity}:{id}:{message}',)
files = tuple(self.file_dict.keys())

if enable:
args += ('--enable=' + ','.join(enable),)

if language:
args += ('--language={language}',)
Copy link
Member

Choose a reason for hiding this comment

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

CI is failing because you need to add tests for these lines.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jayvdb , can you guide me a bit what should language parameter would do if we provide it.
Because in tests, already defined parameters are giving error or warnings.
But I am unable to understand what would it return.

Copy link
Member

Choose a reason for hiding this comment

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

If existings tests are failing on your PR, it is because your code is buggy.

The existing tests for CPPCheckBear work correctly in the CI on master builds and other peoples PRs.

@gutsytechster
Copy link
Contributor Author

gutsytechster commented Nov 12, 2018

I have two different versions of cppcheck installed on two different machines. One of them has version 1.76.1 and other one has version 1.82 installed. However, when I used cppcheck on the newly added test file language_test.h which is a header file containing a bit of c++ specific code, on version 1.82, it did give an error like Code 'classFoo{' is invalid C code. Use --std or --language to configure the language. which means that version 1.82 considering .h files to be C specific. However, on cppcheck version 1.76.1 it doesn't give any error.
It seems that coala tests are using the previous version of cppcheck, and that's the reason the tests are failing.
What should be done here?

@jayvdb
Copy link
Member

jayvdb commented Nov 13, 2018

@gutsytechster , you need to build a test case which works with the version of cppclean that coala uses.
See the file bear-requirements.txt to see which version that is.

@gutsytechster
Copy link
Contributor Author

Isn't cppcheck and cppclean different?
And doesn't CPPCheckBear uses cppcheck?

@jayvdb
Copy link
Member

jayvdb commented Nov 13, 2018

Yes, my apology, I should have said cppcheck

Copy link
Member

@jayvdb jayvdb left a comment

Choose a reason for hiding this comment

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

needs rebase and tests are failing

@gutsytechster
Copy link
Contributor Author

gutsytechster commented Jan 14, 2019

@jayvdb can you review it?

I just need to know if I am taking the correct approach for using the Language class defined.

Copy link
Member

@rajgoesout rajgoesout left a comment

Choose a reason for hiding this comment

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

You are getting errors in the tests. After changing the language parameter, try to go through the logs and rectify your tests.

@@ -30,18 +33,37 @@ class CPPCheckBear:

def create_arguments(self, config_file,
enable: typed_list(str) = [],
language: str = '',
Copy link
Member

Choose a reason for hiding this comment

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

Use this:

Suggested change
language: str = '',
language: Language = Language['Unknown'],

It will set a default of None.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks @rajdeepbharati for your review!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The part where I am confused is that the whichever parameter the user will input would be treated as a string so how come the value of variable language will be of Language type.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So, if I input --language=c++, it will be treated as "c++".
But what I need to do is that it should be like Language['c++'].

Choose a reason for hiding this comment

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

Hello @gutsytechster do you still plan to work on this ? We need it for our game (play0ad.com)

You can't do what you want in one line. This won't work :

def create_arguments(self, config_file, enable: typed_list(str) = [], language: str = Language[language]):

From what I understand the default should be language = None

def create_arguments(self, config_file, enable: typed_list(str) = [], language: str = None):

Then line 55 check for

        if language is not None:
            try:
                lang = Language[language]
                if isinstance(lang, Language.CPP):
                    args += ('--language=c++',)
                elif isinstance(lang, Language.C):
                    args += ('--language=c',)
                else:
                    logging.error('Language can be either c or c++')
                    return
            except(AttributeError):
                logging.error('Language can be either c or c++')
                return
        else
            args += ('--language=c',)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@StanleySweet, thanks for update on this.
Yes, I'll finish the issue :)

Copy link

Choose a reason for hiding this comment

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

Cool. I think you need to add tests now. The Appveyor fails because the coberage went from 100% to 87 something
Not sure why travis fails but I guess it's related
Do younow how to write the tests ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh yeah! I am trying to resolve these issues

self.section.append(Setting('enable', 'unusedFunction'))
self.section.append(Setting('language', 'c++'))
Copy link
Contributor

Choose a reason for hiding this comment

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

Missing self.section.language = Language[<language_name>]
Please check other bears tests to get more information on this. As well suggesting you to have a look what does run_section_from_bear does! You can find this function definition in coala repository.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@KVGarg, do we add a Language type parameter using self.section.language = Language[<language_name>] instead of self.section.append(Setting('language', 'c++')) or alongwith self.section.append(Setting('language', 'c++'))?

Copy link
Contributor

Choose a reason for hiding this comment

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

along with the line you’ve already added to the new tests!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh! Thanks


def test_no_enable_entered(self):
def test_language_c(self):
self.section.append(Setting('language', 'c'))
results = self.get_results(self.test_files)
messages = [result.message for result in results]
self.assertEqual(len(messages), 1)
Copy link
Contributor

Choose a reason for hiding this comment

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

Test were reporting a different number. Please check that!

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 is getting passed on my local machine. I am not sure what else it is expecting?

Copy link
Contributor

Choose a reason for hiding this comment

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

May the messages count is greater than 3, due to above reason. Just check with that first.
btw i reported this change request because https://ci.appveyor.com/project/coala/coala-bears/builds/26862272/job/81isokrqkuiupbf1#L1446 this was logging that there are 3 messages

@jayvdb
Copy link
Member

jayvdb commented Aug 22, 2019

Tests are still missing 100% coverage

@gutsytechster gutsytechster force-pushed the issue2450 branch 2 times, most recently from 00fa538 to 4b4aa73 Compare August 22, 2019 06:30
@gutsytechster
Copy link
Contributor Author

Hey @jayvdb can you help to find why appveyor and travis are giving different assertion errors and even though they are passing on local?

It adds the command line argument 'language' which can be
given whenever using the CPPCheckBear. It can hold two values
either c or c++.

Closes coala#2450
@gutsytechster
Copy link
Contributor Author

On researching, I found that the Travis is failing because it is using cppcheck 1.52(https://travis-ci.org/coala/coala-bears/jobs/575212105#L295) which doesn't support the language parameter and hence generating error resulting in return a None object instead of a list type object.

@gutsytechster
Copy link
Contributor Author

gutsytechster commented Aug 22, 2019

Appveyor is failing because it is using cppcheck 1.88(https://ci.appveyor.com/project/coala/coala-bears/builds/26877468/job/i2incdndjdui7jvf#L246) which generates different output when using the language parameter. As expected, it does generate 3 error when I specify --language=c though not for the older versions.

As far as I've understood, the cause for failing tests is because of using different cppcheck version across different test environments. Since different version acts differently, the tests are failing.
@jayvdb kindly have a look.

Shouldn't we use the same versions for apt packages across all testing environments?

@StanleySweet
Copy link

Any news ?

@gutsytechster
Copy link
Contributor Author

@StanleySweet the parameter seems to work. But as I explained above, the tests are failing due to different versions of cppcheck for Appveyor and Travis. IMO the solution to it would be to use the same cppcheck version which also supports the use of language parameter.
I am waiting for the reviews over it.

@StanleySweet
Copy link

Yeah, I was actually just bumping the ticket since it had been 18 days.

@graugans
Copy link

graugans commented Feb 19, 2020

Hey any news on this? For a C++17 code base a cppcheck version 1.90 is needed what the coala.io does not support due to the fact this PR is not merged.... Should this PR also address the change in the CI scripts? .travis.yml

@StanleySweet
Copy link

I'm also interested.

@StanleySweet
Copy link

@jayvdb Anything we can do to get this merged?

@StanleySweet
Copy link

@abhishalya Any news?

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

Successfully merging this pull request may close these issues.

CPPCheckBear: Support language parameter
8 participants