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

CPPCleanBear.py: Add include_paths for header file #2037

Merged
merged 1 commit into from
Sep 28, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions bears/c_languages/CPPCleanBear.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from coalib.bearlib.abstractions.Linter import linter
from dependency_management.requirements.PipRequirement import PipRequirement
from coalib.settings.Setting import typed_list


@linter(executable='cppclean',
Expand All @@ -22,5 +23,13 @@ class CPPCleanBear:
CAN_DETECT = {'Smell', 'Unused Code', 'Security'}

@staticmethod
def create_arguments(filename, file, config_file):
return filename,
def create_arguments(filename,
file,
config_file,
include_paths: typed_list(str)=()):
args = [filename]
for include_path in include_paths:
args.append('--include-path')
args.append(include_path)

return args
41 changes: 40 additions & 1 deletion tests/c_languages/CPPCleanBearTest.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import os
from bears.c_languages.CPPCleanBear import CPPCleanBear
from coalib.testing.LocalBearTestHelper import verify_local_bear
from coala_utils.string_processing import escape

good_file = """
int main() {
Expand All @@ -17,6 +19,43 @@
"""


test_include_paths_file = """
#include "foo.h"
#include "bar.h"

int main() {
foo();
bar();
return 0;
}
"""


def get_testdirectory_name(test_directory):
return os.path.join(os.path.dirname(__file__),
'test_files',
test_directory)


CPPCleanBearTest = verify_local_bear(CPPCleanBear,
valid_files=(good_file,),
invalid_files=(bad_file,))
invalid_files=(bad_file,
test_include_paths_file,),
tempfile_kwargs={'suffix': '.cpp'})
Copy link
Member

Choose a reason for hiding this comment

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

please move this change in L41 into an own commit ;)

Copy link
Member Author

@stellargo stellargo Sep 27, 2017

Choose a reason for hiding this comment

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

@Makman2 So you asked me to move 'test_include_paths_file' to the CPPCleanBearTest. It doesn't work without explicitly having L41. I can either have a different test as I had before for it or I will have to include it here

Copy link
Member

Choose a reason for hiding this comment

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

it doesn't work without? okay then nvm :)


CPPCleanBearValidIncludeMultiplePathTest = verify_local_bear(
CPPCleanBear,
valid_files=(test_include_paths_file,),
invalid_files=(),
settings={'include_paths':
escape(get_testdirectory_name('headers1'), '\\') + ',' +
escape(get_testdirectory_name('headers2'), '\\')},
tempfile_kwargs={'suffix': '.cpp'})

CPPCleanBearInvalidIncludeSinglePathTest = verify_local_bear(
CPPCleanBear,
valid_files=(),
invalid_files=(test_include_paths_file,),
settings={'include_paths':
escape(get_testdirectory_name('headers1'), '\\')},
tempfile_kwargs={'suffix': '.cpp'})
3 changes: 3 additions & 0 deletions tests/c_languages/test_files/headers1/foo.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
void foo(){

}
3 changes: 3 additions & 0 deletions tests/c_languages/test_files/headers2/bar.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
void bar(){

}